summaryrefslogtreecommitdiff
path: root/Build/source/texk/kpathsea/expand.c
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2009-03-16 15:13:07 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2009-03-16 15:13:07 +0000
commite967e0cc978d647040ac5616d389e9007d593464 (patch)
tree1f33ce27a77473b2e90b549d42399b73d4123497 /Build/source/texk/kpathsea/expand.c
parent49f1fb6887627cdb7cf524aaef9b92108c894381 (diff)
new reentrant kpathsea API (from Taco)
git-svn-id: svn://tug.org/texlive/trunk@12401 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/kpathsea/expand.c')
-rw-r--r--Build/source/texk/kpathsea/expand.c97
1 files changed, 62 insertions, 35 deletions
diff --git a/Build/source/texk/kpathsea/expand.c b/Build/source/texk/kpathsea/expand.c
index 4f3d02d7e09..0d9d16c7262 100644
--- a/Build/source/texk/kpathsea/expand.c
+++ b/Build/source/texk/kpathsea/expand.c
@@ -31,10 +31,10 @@
shells do.) */
string
-kpse_expand P1C(const_string, s)
+kpathsea_expand (kpathsea kpse, const_string s)
{
- string var_expansion = kpse_var_expand (s);
- string tilde_expansion = kpse_tilde_expand (var_expansion);
+ string var_expansion = kpathsea_var_expand (kpse, s);
+ string tilde_expansion = kpathsea_tilde_expand (kpse, 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
@@ -45,15 +45,22 @@ kpse_expand P1C(const_string, s)
return tilde_expansion;
}
+#if defined(KPSE_COMPAT_API)
+string
+kpse_expand (const_string s)
+{
+ return kpathsea_expand (kpse_def, s);
+}
+#endif
/* Forward declarations of functions from the original expand.c */
-static str_list_type brace_expand P1H(const_string*);
+static str_list_type brace_expand (kpathsea, const_string*);
/* If $KPSE_DOT is defined in the environment, prepend it to any relative
path components. */
static string
-kpse_expand_kpse_dot P1C(string, path)
+kpathsea_expand_kpse_dot (kpathsea kpse, string path)
{
string ret, elt;
string kpse_dot = getenv("KPSE_DOT");
@@ -80,12 +87,13 @@ kpse_expand_kpse_dot P1C(string, path)
}
#endif
- for (elt = kpse_path_element (path); elt; elt = kpse_path_element (NULL)) {
+ for (elt = kpathsea_path_element (kpse, path); elt;
+ elt = kpathsea_path_element (kpse, NULL)) {
string save_ret = ret;
boolean ret_copied = true;
/* 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] == '!')) {
+ if (kpathsea_absolute_p (kpse, 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);
@@ -118,16 +126,16 @@ kpse_expand_kpse_dot P1C(string, path)
string comprising all of the results separated by ENV_SEP_STRING. */
static string
-kpse_brace_expand_element P1C(const_string, elt)
+kpathsea_brace_expand_element (kpathsea kpse, const_string elt)
{
unsigned i;
- str_list_type expansions = brace_expand (&elt);
+ str_list_type expansions = brace_expand (kpse, &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 x = kpathsea_expand (kpse, 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
@@ -135,7 +143,7 @@ kpse_brace_expand_element P1C(const_string, elt)
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);
+ x = kpathsea_brace_expand_element (kpse, x);
free (save_x);
}
ret = concat3 (ret, x, ENV_SEP_STRING);
@@ -153,7 +161,7 @@ kpse_brace_expand_element P1C(const_string, elt)
/* Be careful to not waste all the memory we allocate for each element. */
string
-kpse_brace_expand P1C(const_string, path)
+kpathsea_brace_expand (kpathsea kpse, const_string path)
{
string kpse_dot_expansion;
string elt;
@@ -164,14 +172,15 @@ kpse_brace_expand P1C(const_string, path)
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 xpath = kpathsea_var_expand (kpse, path);
string ret = (string)xmalloc (1);
*ret = 0;
- for (elt = kpse_path_element (xpath); elt; elt = kpse_path_element (NULL)) {
+ for (elt = kpathsea_path_element (kpse, xpath); elt;
+ elt = kpathsea_path_element (kpse, NULL)) {
string save_ret = ret;
/* Do brace expansion first, so tilde expansion happens in {~ka,~kb}. */
- string expansion = kpse_brace_expand_element (elt);
+ string expansion = kpathsea_brace_expand_element (kpse, elt);
ret = concat3 (ret, expansion, ENV_SEP_STRING);
free (expansion);
free (save_ret);
@@ -183,17 +192,25 @@ kpse_brace_expand P1C(const_string, path)
ret[len - 1] = 0;
free (xpath);
- kpse_dot_expansion = kpse_expand_kpse_dot (ret);
+ kpse_dot_expansion = kpathsea_expand_kpse_dot (kpse, ret);
if (kpse_dot_expansion != ret)
free (ret);
return kpse_dot_expansion;
}
+
+#if defined(KPSE_COMPAT_API)
+string
+kpse_brace_expand (const_string path)
+{
+ return kpathsea_brace_expand (kpse_def, path);
+}
+#endif
/* 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)
+kpathsea_path_expand (kpathsea kpse, const_string path)
{
string ret;
string xpath;
@@ -206,10 +223,11 @@ kpse_path_expand P1C(const_string, path)
len = 0;
/* Expand variables and braces first. */
- xpath = kpse_brace_expand (path);
+ xpath = kpathsea_brace_expand (kpse, path);
/* Now expand each of the path elements, printing the results */
- for (elt = kpse_path_element (xpath); elt; elt = kpse_path_element (NULL)) {
+ for (elt = kpathsea_path_element (kpse, xpath); elt;
+ elt = kpathsea_path_element (kpse, NULL)) {
str_llist_type *dirs;
/* Skip and ignore magic leading chars. */
@@ -218,7 +236,7 @@ kpse_path_expand P1C(const_string, path)
/* 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);
+ dirs = kpathsea_element_dirs (kpse, elt);
if (dirs && *dirs) {
str_llist_elt_type *dir;
@@ -252,9 +270,17 @@ kpse_path_expand P1C(const_string, path)
return ret;
}
+#if defined(KPSE_COMPAT_API)
+string
+kpse_path_expand (const_string path)
+{
+ return kpathsea_path_expand (kpse_def, path);
+}
+#endif
+
/* ... */
-static void expand_append P3C(str_list_type*, partial,
- const_string, text, const_string, p)
+static void expand_append (str_list_type* partial,
+ const_string text, const_string p)
{
string new_string;
unsigned len;
@@ -270,7 +296,8 @@ static void expand_append P3C(str_list_type*, partial,
-static str_list_type brace_expand P1C(const_string *, text)
+static str_list_type
+brace_expand (kpathsea kpse, const_string *text)
{
str_list_type result, partial, recurse;
const_string p;
@@ -287,7 +314,7 @@ static str_list_type brace_expand P1C(const_string *, text)
} else if (*p == '{') {
expand_append(&partial, *text, p);
++p;
- recurse = brace_expand(&p);
+ recurse = brace_expand(kpse, &p);
str_list_concat_elements(&partial, recurse);
str_list_free(&recurse);
/* Check for missing closing brace. */
@@ -327,13 +354,14 @@ report_error (format, arg1, arg2)
fprintf (stderr, "\n");
}
-main ()
+main (int argc, char **argv)
{
char example[256];
+ kpse_set_program_name(argv[0], NULL);
for (;;)
{
- char **result;
+ char *result;
int i;
fprintf (stderr, "brace_expand> ");
@@ -345,19 +373,18 @@ main ()
if (strlen (example))
example[strlen (example) - 1] = 0;
- result = brace_expand (example);
+ result = kpse_brace_expand (example);
- for (i = 0; result[i]; i++)
- printf ("%s\n", result[i]);
+ printf ("%s\n", result);
- free_array (result);
}
}
-/*
- * Local variables:
- * test-compile-command: "gcc -g -DTEST -I.. -I. -o brace_expand braces.c -L. -lkpathsea"
- * end:
- */
#endif /* TEST */
+
+/*
+Local variables:
+standalone-compile-command: "gcc -g -I. -I.. -DTEST expand.c kpathsea.a"
+end:
+*/