Back to index

tetex-bin  3.0
Classes | Defines | Functions | Variables
variable.c File Reference
#include <kpathsea/config.h>
#include <kpathsea/c-ctype.h>
#include <kpathsea/cnf.h>
#include <kpathsea/fn.h>
#include <kpathsea/variable.h>

Go to the source code of this file.

Classes

struct  expansion_type

Defines

#define IS_VAR_START(c)   ((c) == '$')
#define IS_VAR_CHAR(c)   (ISALNUM (c) || (c) == '_')
#define IS_VAR_BEGIN_DELIMITER(c)   ((c) == '{')
#define IS_VAR_END_DELIMITER(c)   ((c) == '}')

Functions

string kpse_var_value P1C (const_string, var)
static void expanding P2C (const_string, var, boolean, xp)
static void expand P3C (fn_type *, expansion, const_string, start, const_string, end)
string kpse_var_expand P1C (const_string, src)

Variables

static expansion_typeexpansions
static unsigned expansion_len = 0

Class Documentation

struct expansion_type

Definition at line 71 of file variable.c.

Class Members
boolean expanding
const_string var

Define Documentation

#define IS_VAR_BEGIN_DELIMITER (   c)    ((c) == '{')

Definition at line 160 of file variable.c.

#define IS_VAR_CHAR (   c)    (ISALNUM (c) || (c) == '_')

Definition at line 157 of file variable.c.

#define IS_VAR_END_DELIMITER (   c)    ((c) == '}')

Definition at line 163 of file variable.c.

#define IS_VAR_START (   c)    ((c) == '$')

Definition at line 154 of file variable.c.


Function Documentation

static boolean expanding_p P1C ( const_string  ,
var   
)

Definition at line 30 of file variable.c.

{
  string vtry, ret;

  assert(kpse_program_name);

  /* First look for VAR.progname. */
  vtry = concat3(var, ".", kpse_program_name);
  ret = getenv (vtry);
  free (vtry);

  if (!ret || !*ret) {
    /* Now look for VAR_progname. */
    vtry = concat3(var, "_", kpse_program_name);
    ret = getenv (vtry);
    free (vtry);
  }

  if (!ret || !*ret)
    ret = getenv (var);

  if (!ret || !*ret)
    ret = kpse_cnf_get (var);

  if (ret)
    ret = kpse_var_expand (ret);

#ifdef KPSE_DEBUG
  if (KPSE_DEBUG_P (KPSE_DEBUG_VARS))
    DEBUGF2("variable: %s = %s\n", var, ret ? ret : "(nil)");
#endif

  return ret;
}

Here is the call graph for this function:

string kpse_var_expand P1C ( const_string  ,
src   
)

Definition at line 171 of file variable.c.

{
  const_string s;
  string ret;
  fn_type expansion;
  expansion = fn_init ();
  
  /* Copy everything but variable constructs.  */
  for (s = src; *s; s++) {
    if (IS_VAR_START (*s)) {
      s++;

      /* Three cases: `$VAR', `${VAR}', `$<anything-else>'.  */
      if (IS_VAR_CHAR (*s)) {
        /* $V: collect name constituents, then expand.  */
        const_string var_end = s;

        do {
          var_end++;
        } while (IS_VAR_CHAR (*var_end));

        var_end--; /* had to go one past */
        expand (&expansion, s, var_end);
        s = var_end;

      } else if (IS_VAR_BEGIN_DELIMITER (*s)) {
        /* ${: scan ahead for matching delimiter, then expand.  */
        const_string var_end = ++s;

        while (*var_end && !IS_VAR_END_DELIMITER (*var_end))
          var_end++;

        if (! *var_end) {
          WARNING1 ("%s: No matching } for ${", src);
          s = var_end - 1; /* will incr to null at top of loop */
        } else {
          expand (&expansion, s, var_end - 1);
          s = var_end; /* will incr past } at top of loop*/
        }

      } else {
        /* $<something-else>: error.  */
        WARNING2 ("%s: Unrecognized variable construct `$%c'", src, *s);
        /* Just ignore those chars and keep going.  */
      }
    } else
     fn_1grow (&expansion, *s);
  }
  fn_1grow (&expansion, 0);
          
  ret = FN_STRING (expansion);
  return ret;
}

Here is the call graph for this function:

static void expanding P2C ( const_string  ,
var  ,
boolean  ,
xp   
) [static]

Definition at line 79 of file variable.c.

{
  unsigned e;
  for (e = 0; e < expansion_len; e++) {
    if (STREQ (expansions[e].var, var)) {
      expansions[e].expanding = xp;
      return;
    }
  }

  /* New variable, add it to the list.  */
  expansion_len++;
  XRETALLOC (expansions, expansion_len, expansion_type);
  expansions[expansion_len - 1].var = xstrdup (var);
  expansions[expansion_len - 1].expanding = xp;
}

Here is the call graph for this function:

static void expand P3C ( fn_type ,
expansion  ,
const_string  ,
start  ,
const_string  ,
end   
) [static]

Definition at line 116 of file variable.c.

{
  string value;
  unsigned len = end - start + 1;
  string var = (string)xmalloc (len + 1);
  strncpy (var, start, len);
  var[len] = 0;
  
  if (expanding_p (var)) {
    WARNING1 ("kpathsea: variable `%s' references itself (eventually)", var);
  } else {
    string vtry = concat3 (var, "_", kpse_program_name);
    /* Check for an environment variable.  */
    value = getenv (vtry);
    free (vtry);
    
    if (!value || !*value)
      value = getenv (var);

    /* If no envvar, check the config files.  */
    if (!value || !*value)
      value = kpse_cnf_get (var);

    if (value) {
      expanding (var, true);
      value = kpse_var_expand (value);
      expanding (var, false);
      fn_grow (expansion, value, strlen (value));
      free (value);
    }

    free (var);
  }
}

Here is the call graph for this function:


Variable Documentation

unsigned expansion_len = 0 [static]

Definition at line 76 of file variable.c.

Definition at line 75 of file variable.c.