Example #1
0
static int lua_kpathsea_expand_braces(lua_State * L)
{
    kpathsea *kp = (kpathsea *) luaL_checkudata(L, 1, KPATHSEA_METATABLE);
    const char *st = luaL_checkstring(L, 2);
    lua_pushstring(L, kpathsea_brace_expand(*kp, st));
    return 1;
}
Example #2
0
static void
init_path (kpathsea kpse, kpse_format_info_type *info,
           const_string default_path, ...)
{
  string env_name;
  string env_value = NULL;
  string var = NULL;
  string tmp;
  va_list ap;

  info->default_path = default_path;

  va_start (ap, default_path);
  /* First envvar that's set to a nonempty value will exit the loop.  If
     none are set, we want the first cnf entry that matches.  Find the
     cnf value simultaneously with the envvar value, to avoid having to
     go through the envvar list twice,
     that would mean having to create a str_list and use it twice.  */
  while ((env_name = va_arg (ap, string)) != NULL) {
    /* Since sh doesn't like envvar names with `.', check PATH_prog
       as well as PATH.prog.  */
    if (!var) { /* Try PATH.prog. */
      string evar = concat3 (env_name, ".", kpse->program_name);
      env_value = getenv (evar);
      if (env_value && *env_value) {
        var = evar;
      } else { /* Try PATH_prog. */
        free (evar);
        evar = concat3 (env_name, "_", kpse->program_name);
        env_value = getenv (evar);
        if (env_value && *env_value) {
          var = evar;
        } else { /* Try simply PATH.  */
          free (evar);
          env_value = getenv (env_name);
          if (env_value && *env_value) {
            var = env_name;
          }
        }
      }
    }

    /* If we are initializing the cnf path, don't try to get any
       values from the cnf files; that's infinite loop time.  */
    if (!info->cnf_path && info != &(kpse->format_info[kpse_cnf_format]))
      info->cnf_path = kpathsea_cnf_get (kpse, env_name);

    if (var && info->cnf_path)
      break;
  }
  va_end (ap);

  /* Expand any extra :'s.  For each level, we replace an extra : with
     the path at the next lower level.  For example, an extra : in a
     user-set envvar should be replaced with the path from the cnf file.
     things are complicated because none of the levels above the very
     bottom are guaranteed to exist.  */

  /* Assume we can reliably start with the compile-time default.  */
  info->raw_path = info->default_path;
  info->path = xstrdup (info->raw_path);
  info->path_source = "compile-time paths.h";

  EXPAND_DEFAULT (info->cnf_path, "texmf.cnf");
  EXPAND_DEFAULT (info->client_path, "program config file");

  if (var) {
    /* Translate `;' in the envvar into `:' if that's our ENV_SEP. */
    if (IS_ENV_SEP (':')) {
      string loc;
      env_value = xstrdup (env_value);  /* Freed below. */
      for (loc = env_value; *loc; loc++) {
        if (*loc == ';')
          *loc = ':';
      }
    }
    EXPAND_DEFAULT (env_value, concat (var, " environment variable"));
    /* Do not free the copied env_value, because EXPAND_DEFAULT set
       raw_path to point to it.  If it gets overwritten again, tough.  */
  }

  EXPAND_DEFAULT (info->override_path, "application override variable");
  tmp = info->path;
  info->path = kpathsea_brace_expand (kpse, info->path);
  free (tmp);
}