static int expand_var(lua_State * L) { const char *st = luaL_checkstring(L, 1); TEST_PROGRAM_NAME_SET; lua_pushstring(L, kpse_var_expand(st)); return 1; }
static void test_var (string test, string right_answer) { string result = kpse_var_expand (test); printf ("expansion of `%s'\t=> %s", test, result); if (!STREQ (result, right_answer)) printf (" [should be `%s']", right_answer); putchar ('\n'); }
string kpse_expand P1C(const_string, s) { 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; }
static string bitmap_name P3C(const_string, name, unsigned, dpi, const_string, suffix) { string ret; const_string spec = getenv ("KPATHSEA_BITMAP_NAME"); /* We could save a speck of time by setting the environment variable to our compile-time default at the beginning of the program, but it it doesn't seem worth the code separation. */ if (!spec) spec = KPATHSEA_BITMAP_NAME; ret = kpse_var_expand (spec); return ret; }
static string try_format P3C(const_string, fontname, unsigned, dpi, kpse_file_format_type, format) { static const_string bitmap_specs[] = { UNIX_BITMAP_SPEC, DPI_BITMAP_SPEC, NULL }; const_string *spec; boolean must_exist; string ret = NULL; const_string path = kpse_format_info[format].path; const_string *sfx; if (!path) path = kpse_init_format (format); /* Set the suffix on the name we'll be searching for. */ sfx = kpse_format_info[format].suffix; if (sfx && *sfx) xputenv ("KPATHSEA_FORMAT", *sfx); /* OK, the limits on this for loop are a little hokey, but it saves having to repeat the body. We want to do it once with `must_exist' false to avoid looking on the disk for cmr10.600pk if dpi600/cmr10.pk is in ls-R. (The time spent in the extra variable expansions and db searches is negligible.) */ for (must_exist = false; !ret && must_exist <= true; must_exist++) { for (spec = bitmap_specs; !ret && *spec; spec++) { string name = kpse_var_expand (*spec); ret = kpse_path_search (path, name, must_exist); if (name != ret) free (name); } } return ret; }
string kpse_brace_expand P1C(const_string, path) { 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; }
string kpse_make_tex P2C(kpse_file_format_type, format, const_string, base) { kpse_format_info_type spec; /* some compilers lack struct initialization */ string ret = NULL; spec = kpse_format_info[format]; if (!spec.type) { /* Not initialized yet? */ kpse_init_format (format); spec = kpse_format_info[format]; } if (spec.program && spec.program_enabled_p) { /* See the documentation for the envvars we're dealing with here. */ /* Number of arguments is spec.argc + 1, plus the trailing NULL. */ string *args = XTALLOC (spec.argc + 2, string); /* Helpers */ int argnum; int i; /* FIXME * Check whether the name we were given is likely to be a problem. * Right now we err on the side of strictness: * - may not start with a hyphen (fixable in the scripts). * - allowed are: alphanumeric, underscore, hyphen, period * ? also allowed DIRSEP, as we can be fed that when creating pk fonts * No doubt some possibilities were overlooked. */ if (base[0] == '-' /* || IS_DIR_SEP(base[0]) */) { fprintf(stderr, "kpathsea: Illegal fontname `%s': starts with '%c'\n", base, base[0]); return NULL; } for (i = 0; base[i]; i++) { if (!ISALNUM(base[i]) && base[i] != '+' && base[i] != '-' && base[i] != '_' && base[i] != '.' && !IS_DIR_SEP(base[i])) { fprintf(stderr, "kpathsea: Illegal fontname `%s': contains '%c'\n", base, base[i]); return NULL; } } if (format == kpse_gf_format || format == kpse_pk_format || format == kpse_any_glyph_format) set_maketex_mag (); /* Here's an awful kludge: if the mode is `/', mktexpk recognizes it as a special case. `kpse_prog_init' sets it to this in the first place when no mode is otherwise specified; this is so when the user defines a resolution, they don't also have to specify a mode; instead, mktexpk's guesses will take over. They use / for the value because then when it is expanded as part of the PKFONTS et al. path values, we'll wind up searching all the pk directories. We put $MAKETEX_MODE in the path values in the first place so that sites with two different devices with the same resolution can find the right fonts; but such sites are uncommon, so they shouldn't make things harder for everyone else. */ for (argnum = 0; argnum < spec.argc; argnum++) { args[argnum] = kpse_var_expand (spec.argv[argnum]); } args[argnum++] = xstrdup(base); args[argnum] = NULL; ret = maketex (format, args); for (argnum = 0; args[argnum] != NULL; argnum++) free (args[argnum]); free (args); } return ret; }