static void expand P3C(fn_type *, expansion, const_string, start, const_string, end) { string value; unsigned len = end - start + 1; string var = xmalloc (len + 1); strncpy (var, start, len); var[len] = 0; if (expanding_p (var)) { WARNING1 ("kpathsea: variable `%s' references itself (eventually)", var); } else { #if 1 /* The mktex.c replacement for shell scripts needs a more sophisticated lookup for variables */ value = getval(var); #else /* Check for an environment variable. */ value = getenv (var); #endif /* If no envvar, check the config files. */ if (!value) value = kpse_cnf_get (var); if (value) { expanding (var, true); value = mktex_var_expand (value); expanding (var, false); fn_grow (expansion, value, strlen (value)); free (value); } free (var); } }
string getval(string name) { string *lookup = NULL; string res = NULL; /* Either the name is already in the symbol table ... */ if ((lookup = hash_lookup(symtab, name)) != NULL) { /* FIXME: we return the first value ... */ res = lookup[0]; free(lookup); } #if 0 else if ((lookup = hash_lookup(symtab, vname)) != NULL) { /* FIXME: we return the first value ... */ res = lookup[0]; free(lookup); } else { string dollar_name = concat("$", vname); res = kpse_cnf_get(vname); free(dollar_name); } #endif if (!res) { #if 0 /* ... Either it is known from kpathsea, in which case we put it in the symbol table. */ string dollar_name = concat("$", vname); res = expand_var(dollar_name); if (test_file('n', res)) { setval(vname, res); } else { /* res = "", so return NULL */ res = NULL; } free (dollar_name); #endif res = getenv(name); } if (KPSE_DEBUG_P(MKTEX_FINE_DEBUG)) { fprintf(stderr, "GetVal %s => %s\n", name, res); } /* In any case ... */ return res; }
static void init_path PVAR2C(kpse_format_info_type *, info, const_string, default_path, ap) { string env_name; string env_value = NULL; string var = NULL; info->default_path = 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 entries simultaneously, to avoid having to go through envvar list twice -- because of the PVAR?C macro, that would mean having to create a str_list and then use it twice. Yuck. */ 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 = kpse_cnf_get (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->path = info->raw_path = info->default_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"); info->path = kpse_brace_expand (info->path); }}