diff options
author | Peter Breitenlohner <peb@mppmu.mpg.de> | 2009-03-16 15:13:07 +0000 |
---|---|---|
committer | Peter Breitenlohner <peb@mppmu.mpg.de> | 2009-03-16 15:13:07 +0000 |
commit | e967e0cc978d647040ac5616d389e9007d593464 (patch) | |
tree | 1f33ce27a77473b2e90b549d42399b73d4123497 /Build/source/texk/kpathsea/cnf.c | |
parent | 49f1fb6887627cdb7cf524aaef9b92108c894381 (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/cnf.c')
-rw-r--r-- | Build/source/texk/kpathsea/cnf.c | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/Build/source/texk/kpathsea/cnf.c b/Build/source/texk/kpathsea/cnf.c index 89fc9c93da8..3ec7e8678e7 100644 --- a/Build/source/texk/kpathsea/cnf.c +++ b/Build/source/texk/kpathsea/cnf.c @@ -31,10 +31,6 @@ #include <kpathsea/tex-file.h> #include <kpathsea/variable.h> -/* Declared in recorder.h, used in fontmap.c, web2c/lib/texmfmp.c. */ -void (*kpse_record_input) (const_string); -void (*kpse_record_output) (const_string); - /* By using our own hash table, instead of the environment, we complicate variable expansion (because we have to look in two places), but we don't bang so much on the system. DOS and System V @@ -42,7 +38,7 @@ void (*kpse_record_output) (const_string); `kpse_init_format' can distinguish between values originating from the cnf file and ones from environment variables, which can be useful for users trying to figure out what's going on. */ -static hash_table_type cnf_hash; + #define CNF_HASH_SIZE 751 #define CNF_NAME "texmf.cnf" @@ -53,7 +49,7 @@ static hash_table_type cnf_hash; looking for the cnf value. */ static void -do_line P1C(string, line) +do_line (kpathsea kpse, string line) { unsigned len; string start; @@ -146,7 +142,7 @@ do_line P1C(string, line) free (prog); var = lhs; } - hash_insert (&cnf_hash, var, value); + hash_insert (&(kpse->cnf_hash), var, value); /* We could check that anything remaining is preceded by a comment character, but let's not bother. */ @@ -155,21 +151,21 @@ do_line P1C(string, line) /* Read all the configuration files in the path. */ static void -read_all_cnf P1H(void) +read_all_cnf (kpathsea kpse) { string *cnf_files; string *cnf; - const_string cnf_path = kpse_init_format (kpse_cnf_format); + const_string cnf_path = kpathsea_init_format (kpse, kpse_cnf_format); - cnf_hash = hash_create (CNF_HASH_SIZE); + kpse->cnf_hash = hash_create (CNF_HASH_SIZE); - cnf_files = kpse_all_path_search (cnf_path, CNF_NAME); + cnf_files = kpathsea_all_path_search (kpse, cnf_path, CNF_NAME); if (cnf_files && *cnf_files) { for (cnf = cnf_files; *cnf; cnf++) { string line; FILE *cnf_file = xfopen (*cnf, FOPEN_R_MODE); - if (kpse_record_input) - kpse_record_input (*cnf); + if (kpse->record_input) + kpse->record_input (*cnf); while ((line = read_line (cnf_file)) != NULL) { unsigned len = strlen (line); @@ -193,7 +189,7 @@ read_all_cnf P1H(void) } } - do_line (line); + do_line (kpse, line); free (line); } @@ -214,11 +210,10 @@ read_all_cnf P1H(void) returned list -- this will be from the last-read cnf file. */ string -kpse_cnf_get P1C(const_string, name) +kpathsea_cnf_get (kpathsea kpse, const_string name) { string ret, ctry; string *ret_list; - static boolean doing_cnf_init = false; /* When we expand the compile-time value for DEFAULT_TEXMFCNF, we end up needing the value for TETEXDIR and other variables, @@ -226,31 +221,31 @@ kpse_cnf_get P1C(const_string, name) code is not sufficient, somehow the ls-R path needs to be computed when initializing the cnf path. Better to ensure that the compile-time path does not contain variable references. */ - if (doing_cnf_init) + if (kpse->doing_cnf_init) return NULL; - if (cnf_hash.size == 0) { + if (kpse->cnf_hash.size == 0) { /* Read configuration files and initialize databases. */ - doing_cnf_init = true; - read_all_cnf (); - doing_cnf_init = false; + kpse->doing_cnf_init = true; + read_all_cnf (kpse); + kpse->doing_cnf_init = false; /* Since `kpse_init_db' recursively calls us, we must call it from outside a `kpse_path_element' loop (namely, the one in `read_all_cnf' above): `kpse_path_element' is not reentrant. */ - kpse_init_db (); + kpathsea_init_db (kpse); } - /* First look up NAME.`kpse_program_name', then NAME. */ - assert (kpse_program_name); - ctry = concat3 (name, ".", kpse_program_name); - ret_list = hash_lookup (cnf_hash, ctry); + /* First look up NAME.`kpse->program_name', then NAME. */ + assert (kpse->program_name); + ctry = concat3 (name, ".", kpse->program_name); + ret_list = hash_lookup (kpse->cnf_hash, ctry); free (ctry); if (ret_list) { ret = *ret_list; free (ret_list); } else { - ret_list = hash_lookup (cnf_hash, name); + ret_list = hash_lookup (kpse->cnf_hash, name); if (ret_list) { ret = *ret_list; free (ret_list); @@ -261,3 +256,12 @@ kpse_cnf_get P1C(const_string, name) return ret; } + +#if defined(KPSE_COMPAT_API) +string +kpse_cnf_get (const_string name) +{ + return kpathsea_cnf_get(kpse_def, name); +} +#endif + |