summaryrefslogtreecommitdiff
path: root/Build/source/texk/kpathsea/elt-dirs.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/elt-dirs.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/elt-dirs.c')
-rw-r--r--Build/source/texk/kpathsea/elt-dirs.c98
1 files changed, 52 insertions, 46 deletions
diff --git a/Build/source/texk/kpathsea/elt-dirs.c b/Build/source/texk/kpathsea/elt-dirs.c
index 9c223b37845..415de99753b 100644
--- a/Build/source/texk/kpathsea/elt-dirs.c
+++ b/Build/source/texk/kpathsea/elt-dirs.c
@@ -32,7 +32,7 @@
DIR ends with a DIR_SEP for the benefit of later searches. */
static void
-dir_list_add P2C(str_llist_type *, l, const_string, dir)
+dir_list_add (str_llist_type *l, const_string dir)
{
char last_char = dir[strlen (dir) - 1];
string saved_dir
@@ -47,9 +47,9 @@ dir_list_add P2C(str_llist_type *, l, const_string, dir)
/* If DIR is a directory, add it to the list L. */
static void
-checked_dir_list_add P2C(str_llist_type *, l, const_string, dir)
+checked_dir_list_add (kpathsea kpse, str_llist_type *l, const_string dir)
{
- if (dir_p (dir))
+ if (kpathsea_dir_p (kpse, dir))
dir_list_add (l, dir);
}
@@ -59,16 +59,6 @@ checked_dir_list_add P2C(str_llist_type *, l, const_string, dir)
the dir_links call, that's not enough -- without this path element
caching as well, the execution time doubles. */
-typedef struct
-{
- const_string key;
- str_llist_type *value;
-} cache_entry;
-
-static cache_entry *the_cache = NULL;
-static unsigned cache_length = 0;
-
-
/* Associate KEY with VALUE. We implement the cache as a simple linear
list, since it's unlikely to ever be more than a dozen or so elements
long. We don't bother to check here if PATH has already been saved;
@@ -76,26 +66,26 @@ static unsigned cache_length = 0;
that's right, but it seems to be all that's needed. */
static void
-cache P2C(const_string, key, str_llist_type *, value)
+cache (kpathsea kpse, const_string key, str_llist_type *value)
{
- cache_length++;
- XRETALLOC (the_cache, cache_length, cache_entry);
- the_cache[cache_length - 1].key = xstrdup (key);
- the_cache[cache_length - 1].value = value;
+ kpse->cache_length++;
+ XRETALLOC (kpse->the_cache, kpse->cache_length, cache_entry);
+ kpse->the_cache[kpse->cache_length - 1].key = xstrdup (key);
+ kpse->the_cache[kpse->cache_length - 1].value = value;
}
/* To retrieve, just check the list in order. */
static str_llist_type *
-cached P1C(const_string, key)
+cached (kpathsea kpse, const_string key)
{
unsigned p;
- for (p = 0; p < cache_length; p++)
+ for (p = 0; p < kpse->cache_length; p++)
{
- if (FILESTRCASEEQ (the_cache[p].key, key))
- return the_cache[p].value;
+ if (FILESTRCASEEQ (kpse->the_cache[p].key, key))
+ return kpse->the_cache[p].value;
}
return NULL;
@@ -104,7 +94,7 @@ cached P1C(const_string, key)
/* Handle the magic path constructs. */
/* Declare recursively called routine. */
-static void expand_elt P3H(str_llist_type *, const_string, unsigned);
+static void expand_elt (kpathsea, str_llist_type *, const_string, unsigned);
/* POST is a pointer into the original element (which may no longer be
@@ -118,8 +108,8 @@ static char dirname[MAX_PATH];
#endif
static void
-do_subdir P4C(str_llist_type *, str_list_ptr, const_string, elt,
- unsigned, elt_length, const_string, post)
+do_subdir (kpathsea kpse, str_llist_type *str_list_ptr, const_string elt,
+ unsigned elt_length, const_string post)
{
#ifdef WIN32
WIN32_FIND_DATA find_file_data;
@@ -156,7 +146,7 @@ do_subdir P4C(str_llist_type *, str_list_ptr, const_string, elt,
example, POST might be `pk/ljfour', and they might have a
directory `$TEXMF/fonts/pk/ljfour' that we should find. */
fn_str_grow (&name, post);
- expand_elt (str_list_ptr, FN_STRING (name), elt_length);
+ expand_elt (kpse, str_list_ptr, FN_STRING (name), elt_length);
fn_shrink_to (&name, elt_length);
}
proceed = 1;
@@ -170,7 +160,7 @@ do_subdir P4C(str_llist_type *, str_list_ptr, const_string, elt,
/* Maybe we have cached the leafness of this directory.
The function will return 0 if unknown,
else the actual (Unix-like) value. */
- links = dir_links (FN_STRING (name), 0);
+ links = kpathsea_dir_links (kpse, FN_STRING (name), 0);
if (find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
unsigned potential_len = FN_LENGTH (name);
@@ -186,7 +176,7 @@ do_subdir P4C(str_llist_type *, str_list_ptr, const_string, elt,
name here, we just have a path spec. This means we
may descend into a leaf directory cm/pk, if the
spec is ...fonts//pk//. */
- expand_elt (str_list_ptr, FN_STRING (name), potential_len);
+ expand_elt (kpse, str_list_ptr, FN_STRING (name), potential_len);
fn_shrink_to (&name, potential_len);
}
/* Should we recurse? To see if the subdirectory is a
@@ -198,7 +188,7 @@ do_subdir P4C(str_llist_type *, str_list_ptr, const_string, elt,
if (links == 0 || links > 2)
/* All criteria are met; find subdirectories. */
- do_subdir (str_list_ptr, FN_STRING (name),
+ do_subdir (kpse, str_list_ptr, FN_STRING (name),
potential_len, post);
else if (*post == 0)
/* Nothing to match, no recursive subdirectories to
@@ -210,7 +200,7 @@ do_subdir P4C(str_llist_type *, str_list_ptr, const_string, elt,
proceed = FindNextFile (hnd, &find_file_data);
}
/* Update the leafness of name. */
- dir_links(FN_STRING(name), nlinks);
+ kpathsea_dir_links(kpse, FN_STRING(name), nlinks);
fn_free (&name);
FindClose(hnd);
@@ -232,7 +222,7 @@ do_subdir P4C(str_llist_type *, str_list_ptr, const_string, elt,
example, POST might be `pk/ljfour', and they might have a
directory `$TEXMF/fonts/pk/ljfour' that we should find. */
fn_str_grow (&name, post);
- expand_elt (str_list_ptr, FN_STRING (name), elt_length);
+ expand_elt (kpse, str_list_ptr, FN_STRING (name), elt_length);
fn_shrink_to (&name, elt_length);
}
@@ -247,7 +237,7 @@ do_subdir P4C(str_llist_type *, str_list_ptr, const_string, elt,
fn_str_grow (&name, e->d_name);
/* If we can't stat it, or if it isn't a directory, continue. */
- links = dir_links (FN_STRING (name), 0);
+ links = kpathsea_dir_links (kpse, FN_STRING (name), 0);
if (links >= 0)
{
@@ -264,7 +254,7 @@ do_subdir P4C(str_llist_type *, str_list_ptr, const_string, elt,
name here, we just have a path spec. This means we
may descend into a leaf directory cm/pk, if the
spec is ...fonts//pk//. */
- expand_elt (str_list_ptr, FN_STRING (name), potential_len);
+ expand_elt (kpse, str_list_ptr, FN_STRING (name), potential_len);
fn_shrink_to (&name, potential_len);
}
@@ -288,7 +278,7 @@ do_subdir P4C(str_llist_type *, str_list_ptr, const_string, elt,
if (links != 2)
#endif /* ST_NLINK_TRICK */
/* All criteria are met; find subdirectories. */
- do_subdir (str_list_ptr, FN_STRING (name),
+ do_subdir (kpse, str_list_ptr, FN_STRING (name),
potential_len, post);
#ifdef ST_NLINK_TRICK
else if (*post == 0)
@@ -314,8 +304,8 @@ do_subdir P4C(str_llist_type *, str_list_ptr, const_string, elt,
looking for magic constructs at START. */
static void
-expand_elt P3C(str_llist_type *, str_list_ptr, const_string, elt,
- unsigned, start)
+expand_elt (kpathsea kpse, str_llist_type * str_list_ptr, const_string elt,
+ unsigned start)
{
const_string dir = elt + start, post;
@@ -327,7 +317,7 @@ expand_elt P3C(str_llist_type *, str_list_ptr, const_string, elt,
if (IS_DIR_SEP (dir[1]))
{
for (post = dir + 1; IS_DIR_SEP (*post); post++) ;
- do_subdir (str_list_ptr, elt, dir - elt + 1, post);
+ do_subdir (kpse, str_list_ptr, elt, dir - elt + 1, post);
return;
}
@@ -338,7 +328,7 @@ expand_elt P3C(str_llist_type *, str_list_ptr, const_string, elt,
}
/* When we reach the end of ELT, it will be a normal filename. */
- checked_dir_list_add (str_list_ptr, elt);
+ checked_dir_list_add (kpse, str_list_ptr, elt);
}
/* The first bits of a path element can be problematic because they
@@ -359,7 +349,7 @@ expand_elt P3C(str_llist_type *, str_list_ptr, const_string, elt,
expanding from the root of a UNIX filesystem tree. */
unsigned
-kpse_normalize_path P1C(string, elt)
+kpathsea_normalize_path (kpathsea kpse, string elt)
{
unsigned ret;
unsigned i;
@@ -386,16 +376,24 @@ kpse_normalize_path P1C(string, elt)
;
}
- if (KPSE_DEBUG_P (KPSE_DEBUG_STAT) && ret != 1)
+ if (KPATHSEA_DEBUG_P (KPSE_DEBUG_STAT) && ret != 1)
DEBUGF2 ("kpse_normalize_path (%s) => %u\n", elt, ret);
return ret;
}
+
+#if defined(KPSE_COMPAT_API)
+unsigned
+kpse_normalize_path (string elt)
+{
+ return kpathsea_normalize_path(kpse_def, elt);
+}
+#endif
/* Here is the entry point. Returns directory list for ELT. */
str_llist_type *
-kpse_element_dirs P1C(string, elt)
+kpathsea_element_dirs (kpathsea kpse, string elt)
{
str_llist_type *ret;
@@ -404,7 +402,7 @@ kpse_element_dirs P1C(string, elt)
return NULL;
/* If we've already cached the answer for ELT, return it. */
- ret = cached (elt);
+ ret = cached (kpse, elt);
if (ret)
return ret;
@@ -413,14 +411,14 @@ kpse_element_dirs P1C(string, elt)
*ret = NULL;
/* We handle the hard case in a subroutine. */
- expand_elt (ret, elt, kpse_normalize_path (elt));
+ expand_elt (kpse, ret, elt, kpathsea_normalize_path (kpse, elt));
/* Remember the directory list we just found, in case future calls are
made with the same ELT. */
- cache (elt, ret);
+ cache (kpse, elt, ret);
#ifdef KPSE_DEBUG
- if (KPSE_DEBUG_P (KPSE_DEBUG_EXPAND))
+ if (KPATHSEA_DEBUG_P (KPSE_DEBUG_EXPAND))
{
DEBUGF1 ("path element %s =>", elt);
if (ret)
@@ -436,6 +434,14 @@ kpse_element_dirs P1C(string, elt)
return ret;
}
+
+#if defined(KPSE_COMPAT_API)
+str_llist_type *
+kpse_element_dirs (string elt)
+{
+ return kpathsea_element_dirs(kpse_def, elt);
+}
+#endif
#ifdef TEST
@@ -497,6 +503,6 @@ main ()
/*
Local variables:
-test-compile-command: "gcc -g -I. -I.. -DTEST elt-dirs.c kpathsea.a"
+standalone-compile-command: "gcc -g -I. -I.. -DTEST elt-dirs.c kpathsea.a"
End:
*/