static int expand_braces(lua_State * L) { const char *st = luaL_checkstring(L, 1); TEST_PROGRAM_NAME_SET; lua_pushstring(L, kpse_brace_expand(st)); return 1; }
/* Expand all special constructs in a path, and include only the actually existing directories in the result. */ string kpse_path_expand P1C(const_string, path) { string ret; string xpath; string elt; unsigned len; /* Initialise ret to the empty string. */ ret = (string)xmalloc (1); *ret = 0; len = 0; /* Expand variables and braces first. */ xpath = kpse_brace_expand (path); /* Now expand each of the path elements, printing the results */ for (elt = kpse_path_element (xpath); elt; elt = kpse_path_element (NULL)) { str_llist_type *dirs; /* Skip and ignore magic leading chars. */ if (*elt == '!' && *(elt + 1) == '!') elt += 2; /* Search the disk for all dirs in the component specified. Be faster to check the database, but this is more reliable. */ dirs = kpse_element_dirs (elt); if (dirs && *dirs) { str_llist_elt_type *dir; for (dir = *dirs; dir; dir = STR_LLIST_NEXT (*dir)) { string thedir = STR_LLIST (*dir); unsigned dirlen = strlen (thedir); string save_ret = ret; /* We need to retain trailing slash if that's the root directory. * On unix, "/" is root dir, "" often taken to be current dir. * On windows, "C:/" is root dir of drive C, and "C:" is current * on drive C. There's no need to look at other cases, like UNC * names. */ if (dirlen == 1 || (dirlen == 3 && NAME_BEGINS_WITH_DEVICE (thedir) && IS_DIR_SEP (thedir[2]))) { ret = concat3 (ret, thedir, ENV_SEP_STRING); len += dirlen + 1; ret[len - 1] = ENV_SEP; } else { ret = concat (ret, thedir); len += dirlen; ret [len - 1] = ENV_SEP; } free (save_ret); } } } /* Get rid of trailing ':', if any. */ if (len != 0) ret[len - 1] = 0; return ret; }
void mktexupd (char *s) { char fname[MBUF]; char lsrname[SBUF]; char path[LBUF]; char *rootdir[MAXTREE]; int i, j, treenum; char *pa, *pb, *pc; int existflag = 0; FILE *f; pa = kpse_var_value (DBS); if (pa == NULL) { fprintf (stderr, "No definition of TEXMFDBS.\n"); fprintf (stderr, "Maybe you are not using ls-R.\n"); return; } pb = kpse_brace_expand (pa); free (pa); if (pb == NULL) { fprintf (stderr, "I cannot expand braces in TEXMFDBS.\n"); fprintf (stderr, "Maybe you are not using ls-R.\n"); return; } for (i = 0; i < MAXTREE; i++) rootdir[i] = (char *) malloc (MBUF); pa = pb; i = 0; while (*pa && i < MAXTREE) { if (*pa == '!' && *(pa + 1) == '!') { pa++; pa++; } pc = rootdir[i]; while (*pa != ';' && *pa) *pc++ = *pa++; *pc = '\0'; if (*pa == ';') { pa++; i++; } } i++; treenum = i; free (pb); for (i = 0; i < treenum; i++) { j = strlen (rootdir[i]); if (rootdir[i][j - 1] == '/') rootdir[i][j - 1] = '\0'; } strcpy (path, s); pa = strrchr (path, '/'); if (pa == NULL) { fprintf (stderr, "Path name of the file may be incorrect.\n"); for (i = 0; i < MAXTREE; i++) free (rootdir[i]); return; } *pa = '\0'; pa++; strcpy (fname, pa); for (i = 0; i < treenum; i++) { j = strlen (rootdir[i]); if (j && strnicmp (path, rootdir[i], j) == 0) { existflag = 1; break; } } if (existflag) { strcpy (lsrname, rootdir[i]); strcat (lsrname, "/ls-R"); if (_access (lsrname, 0) != 0) { for (j = 0; j < MAXTREE; j++) free (rootdir[j]); return; } pa = path; pb = rootdir[i]; while (tolower (*pa) == tolower (*pb) && *pb) { pa++; pb++; } f = fopen (lsrname, "ab"); fprintf (f, "\n.%s:\n%s\n", pa, fname); fclose (f); } else { fprintf(stderr, "mktexupd failed\n"); } for (i = 0; i < MAXTREE; i++) free (rootdir[i]); }
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); }}