Back to index

tetex-bin  3.0
Functions
expand.c File Reference
#include <kpathsea/config.h>
#include <kpathsea/c-pathch.h>
#include <kpathsea/expand.h>
#include <kpathsea/pathsearch.h>
#include <kpathsea/tilde.h>
#include <kpathsea/variable.h>
#include <kpathsea/concatn.h>
#include <kpathsea/absolute.h>
#include <kpathsea/str-list.h>

Go to the source code of this file.

Functions

string kpse_expand P1C (const_string, s)
static str_list_type brace_expand P1H (const_string *)
static string kpse_expand_kpse_dot P1C (string, path)
static string
kpse_brace_expand_element 
P1C (const_string, elt)
string kpse_brace_expand P1C (const_string, path)
static void expand_append P3C (str_list_type *, partial, const_string, text, const_string, p)
static str_list_type brace_expand P1C (const_string *, text)

Function Documentation

string kpse_expand P1C ( const_string  ,
s   
)

Definition at line 34 of file expand.c.

{
  string var_expansion = kpse_var_expand (s);
  string tilde_expansion = kpse_tilde_expand (var_expansion);
  
  /* `kpse_var_expand' always gives us new memory; `kpse_tilde_expand'
     doesn't, necessarily.  So be careful that we don't free what we are
     about to return.  */
  if (tilde_expansion != var_expansion)
    free (var_expansion);
  
  return tilde_expansion;
}

Here is the call graph for this function:

static string kpse_expand_kpse_dot P1C ( string  ,
path   
) [static]

Definition at line 56 of file expand.c.

{
  string ret, elt;
  string kpse_dot = getenv("KPSE_DOT");
#ifdef MSDOS
  boolean malloced_kpse_dot = false;
#endif
  
  if (kpse_dot == NULL)
    return path;
  ret = (string)xmalloc(1);
  *ret = 0;

#ifdef MSDOS
  /* Some setups of ported Bash force $KPSE_DOT to have the //d/foo/bar
     form (when `pwd' is used), which is not understood by libc and the OS.
     Convert them back to the usual d:/foo/bar form.  */
  if (kpse_dot[0] == '/' && kpse_dot[1] == '/'
      && kpse_dot[2] >= 'A' && kpse_dot[2] <= 'z' && kpse_dot[3] == '/') {
    kpse_dot++;
    kpse_dot = xstrdup (kpse_dot);
    kpse_dot[0] = kpse_dot[1];  /* drive letter */
    kpse_dot[1] = ':';
    malloced_kpse_dot = true;
  }
#endif

  for (elt = kpse_path_element (path); elt; elt = kpse_path_element (NULL)) {
    string save_ret = ret;
    /* We assume that the !! magic is only used on absolute components.
       Single "." gets special treatment, as does "./" or its equivalent. */
    if (kpse_absolute_p (elt, false) || (elt[0] == '!' && elt[1] == '!')) {
      ret = concat3(ret, elt, ENV_SEP_STRING);
    } else if (elt[0] == '.' && elt[1] == 0) {
      ret = concat3 (ret, kpse_dot, ENV_SEP_STRING);
#ifndef VMS
    } else if (elt[0] == '.' && IS_DIR_SEP(elt[1])) {
      ret = concatn (ret, kpse_dot, elt + 1, ENV_SEP_STRING, NULL);
    } else {
      ret = concatn (ret, kpse_dot, DIR_SEP_STRING, elt, ENV_SEP_STRING, NULL);
#endif
    }
    free (save_ret);
  }

#ifdef MSDOS
  if (malloced_kpse_dot) free (kpse_dot);
#endif

  ret[strlen (ret) - 1] = 0;
  return ret;
}

Here is the call graph for this function:

static string kpse_brace_expand_element P1C ( const_string  ,
elt   
) [static]

Definition at line 115 of file expand.c.

{
  unsigned i;
  str_list_type expansions = brace_expand (&elt);
  string ret = (string)xmalloc (1);
  *ret = 0;

  for (i = 0; i != STR_LIST_LENGTH(expansions); i++) {
    /* Do $ and ~ expansion on each element.  */
    string x = kpse_expand (STR_LIST_ELT(expansions,i));
    string save_ret = ret;
    if (!STREQ (x, STR_LIST_ELT(expansions,i))) {
      /* If we did any expansions, do brace expansion again.  Since
         recursive variable definitions are not allowed, this recursion
         must terminate.  (In practice, it's unlikely there will ever be
         more than one level of recursion.)  */
      string save_x = x;
      x = kpse_brace_expand_element (x);
      free (save_x);
    }
    ret = concat3 (ret, x, ENV_SEP_STRING);
    free (save_ret);
    free (x);
  }
  for (i = 0; i != STR_LIST_LENGTH(expansions); ++i) {
      free(STR_LIST_ELT(expansions,i));
  }
  str_list_free(&expansions);
  ret[strlen (ret) - 1] = 0; /* waste the trailing null */
  return ret;
}

Here is the call graph for this function:

string kpse_path_expand P1C ( const_string  ,
path   
)

Definition at line 150 of file expand.c.

{
  string kpse_dot_expansion;
  string elt;
  unsigned len;
  /* Must do variable expansion first because if we have
       foo = .:~
       TEXINPUTS = $foo
     we want to end up with TEXINPUTS = .:/home/karl.
     Since kpse_path_element is not reentrant, we must get all
     the path elements before we start the loop.  */
  string xpath = kpse_var_expand (path);
  string ret = (string)xmalloc (1);
  *ret = 0;

  for (elt = kpse_path_element (xpath); elt; elt = kpse_path_element (NULL)) {
    string save_ret = ret;
    /* Do brace expansion first, so tilde expansion happens in {~ka,~kb}.  */
    string expansion = kpse_brace_expand_element (elt);
    ret = concat3 (ret, expansion, ENV_SEP_STRING);
    free (expansion);
    free (save_ret);
  }

  /* Waste the last byte by overwriting the trailing env_sep with a null.  */
  len = strlen (ret);
  if (len != 0)
    ret[len - 1] = 0;
  free (xpath);

  kpse_dot_expansion = kpse_expand_kpse_dot (ret);
  if (kpse_dot_expansion != ret)
    free (ret);

  return kpse_dot_expansion;
}

Here is the call graph for this function:

static str_list_type brace_expand P1C ( const_string ,
text   
) [static]

Definition at line 267 of file expand.c.

{
    str_list_type result, partial, recurse;
    const_string p;
    result = str_list_init();
    partial = str_list_init();
    for (p = *text; *p && *p != '}'; ++p) {
        if (*p == ENV_SEP || *p == ',') {
            expand_append(&partial, *text, p);
            str_list_concat(&result, partial);
            str_list_free(&partial);
            *text = p+1;
            partial = str_list_init();
        } else if (*p == '{') {
            expand_append(&partial, *text, p);
            ++p;
            recurse = brace_expand(&p);
            str_list_concat_elements(&partial, recurse);
            str_list_free(&recurse);
            /* Check for missing closing brace. */
            if (*p != '}') {
                WARNING1 ("%s: Unmatched {", *text);
            }
            *text = p+1;
        } else if (*p == '$') {
            /* Skip ${VAR} */
            if (*(p+1) == '{')
                for (p+=2; *p!='}';++p);
        }
    }
    expand_append(&partial, *text, p);
    str_list_concat(&result, partial);
    str_list_free(&partial);
    *text = p;
    return result;
}
static str_list_type brace_expand P1H ( const_string ) [static]
static void expand_append P3C ( str_list_type ,
partial  ,
const_string  ,
text  ,
const_string  ,
p   
) [static]

Definition at line 250 of file expand.c.

{
    string new_string;
    unsigned len;
    str_list_type tmp;
    tmp = str_list_init();
    len = p - text;
    new_string = (string)xmalloc(len+1);
    strncpy(new_string, text, len);
    new_string[len]=0;
    str_list_add(&tmp, new_string);
    str_list_concat_elements(partial, tmp);
}

Here is the call graph for this function: