diff options
author | Peter Breitenlohner <peb@mppmu.mpg.de> | 2011-07-28 08:51:08 +0000 |
---|---|---|
committer | Peter Breitenlohner <peb@mppmu.mpg.de> | 2011-07-28 08:51:08 +0000 |
commit | cfae1fdf8a2e58edcf68f3a64e9caa75922e0e22 (patch) | |
tree | b34b92941b15a57c2f8c29208ffa9aca4134e4ac | |
parent | ce679aa3ad2f099253cf4266614a3cf7164d4dcd (diff) |
kpathsea: More changes to reduce diffs with W32TeX
git-svn-id: svn://tug.org/texlive/trunk@23256 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Build/source/texk/kpathsea/ChangeLog | 9 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/expand.c | 34 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/find-suffix.c | 21 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/make-suffix.c | 36 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/path-elt.c | 11 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/tilde.c | 120 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/xbasename.c | 23 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/xdirname.c | 6 | ||||
-rw-r--r-- | Build/source/texk/kpathsea/xgetcwd.c | 6 |
9 files changed, 158 insertions, 108 deletions
diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog index 33a126008ea..41863ffb866 100644 --- a/Build/source/texk/kpathsea/ChangeLog +++ b/Build/source/texk/kpathsea/ChangeLog @@ -1,3 +1,12 @@ +2011-07-28 Peter Breitenlohner <peb@mppmu.mpg.de> + + More diffs between TeX Live and W32TeX. + * find-suffix.c, xbasename.c: + Reformulate and test for 2-Byte Kanji (CP 932, SJIS) codes. + + * expand.c, make-suffix.c, tilde.c: Slashify, reformulate, + and test for 2-Byte Kanji (CP 932, SJIS) codes. + 2011-07-27 Peter Breitenlohner <peb@mppmu.mpg.de> More diffs between TeX Live and W32TeX. diff --git a/Build/source/texk/kpathsea/expand.c b/Build/source/texk/kpathsea/expand.c index f1199559f17..453fa6d65ac 100644 --- a/Build/source/texk/kpathsea/expand.c +++ b/Build/source/texk/kpathsea/expand.c @@ -217,14 +217,36 @@ kpathsea_path_expand (kpathsea kpse, const_string path) string xpath; string elt; unsigned len; + const_string ypath; +#if defined(WIN32) + string zpath, p; +#endif /* Initialise ret to the empty string. */ ret = (string)xmalloc (1); *ret = 0; len = 0; +#if defined(WIN32) + zpath = xstrdup (path); + + for (p = zpath; *p; p++) + if (*p == '\\') + *p = '/'; + else if (IS_KANJI(p)) + p++; + + ypath = zpath; +#else + ypath = path; +#endif + /* Expand variables and braces first. */ - xpath = kpathsea_brace_expand (kpse, path); + xpath = kpathsea_brace_expand (kpse, ypath); + +#if defined(WIN32) + free (zpath); +#endif /* Now expand each of the path elements, printing the results */ for (elt = kpathsea_path_element (kpse, xpath); elt; @@ -304,12 +326,6 @@ brace_expand (kpathsea kpse, const_string *text) result = str_list_init(); partial = str_list_init(); for (p = *text; *p && *p != '}'; ++p) { -#if defined(WIN32) - if (IS_KANJI(p)) { - p++; - continue; - } -#endif /* FIXME: Should be IS_ENV_SEP(*p) */ if (*p == ENV_SEP || *p == ',') { expand_append(&partial, *text, p); @@ -333,6 +349,10 @@ brace_expand (kpathsea kpse, const_string *text) if (*(p+1) == '{') for (p+=2; *p!='}';++p); } +#if defined(WIN32) + else if (IS_KANJI(p)) + p++; +#endif } expand_append(&partial, *text, p); str_list_concat(&result, partial); diff --git a/Build/source/texk/kpathsea/find-suffix.c b/Build/source/texk/kpathsea/find-suffix.c index 107e1917de0..3aad8870fe9 100644 --- a/Build/source/texk/kpathsea/find-suffix.c +++ b/Build/source/texk/kpathsea/find-suffix.c @@ -1,6 +1,6 @@ /* find-suffix.c: return the stuff after a dot. - Copyright 1992, 1993, 1995, 2008 Karl Berry. + Copyright 1992, 1993, 1995, 2008, 2011 Karl Berry. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -38,19 +38,20 @@ const_string find_suffix (const_string name) { - const_string slash_pos; const_string dot_pos = strrchr (name, '.'); + const_string p; if (dot_pos == NULL) return NULL; - for (slash_pos = name + strlen (name); - slash_pos > dot_pos && !IS_DIR_SEP (*slash_pos); - slash_pos--) - ; + for (p = dot_pos + 1; *p; p++) { + if (IS_DIR_SEP (*p)) + return NULL; +#if defined(WIN32) + else if (IS_KANJI(p)) + p++; +#endif + } - return slash_pos > dot_pos ? NULL : dot_pos + 1; + return dot_pos + 1; } - - - diff --git a/Build/source/texk/kpathsea/make-suffix.c b/Build/source/texk/kpathsea/make-suffix.c index c578ab2b7a6..9264aaeb405 100644 --- a/Build/source/texk/kpathsea/make-suffix.c +++ b/Build/source/texk/kpathsea/make-suffix.c @@ -1,6 +1,6 @@ /* make-suffix.c: unconditionally add a filename suffix. - Copyright 1992, 1993, 1995, 2008 Karl Berry. + Copyright 1992, 1993, 1995, 2008, 2011 Karl Berry. Copyright 2001, 2005 Olaf Weber. This library is free software; you can redistribute it and/or @@ -27,24 +27,42 @@ make_suffix (const_string s, const_string suffix) { string new_s; const_string dot_pos = strrchr (s, '.'); - const_string slash_pos; + const_string p; +#if defined(WIN32) + string q; +#endif - for (slash_pos = s + strlen (s) - 1; slash_pos > dot_pos && slash_pos > s; - slash_pos--) { - if (IS_DIR_SEP (*slash_pos)) - break; - } + if (dot_pos) + for (p = dot_pos + 1; *p; p++) { + if (IS_DIR_SEP (*p)) { + dot_pos = NULL; + break; + } +#if defined(WIN32) + else if (IS_KANJI(p)) + p++; +#endif + } - if (dot_pos == NULL || slash_pos > dot_pos ) + if (dot_pos == NULL) new_s = concat3 (s, ".", suffix); else { unsigned past_dot_index = dot_pos + 1 - s; new_s = (string)xmalloc (past_dot_index + strlen (suffix) + 1); - strncpy (new_s, s, dot_pos + 1 - s); + strncpy (new_s, s, past_dot_index); strcpy (new_s + past_dot_index, suffix); } +#if defined(WIN32) + for (q = new_s; *q; q++) { + if (*q == '\\') + *q = '/'; + else if (IS_KANJI(q)) + q++; + } +#endif + return new_s; } diff --git a/Build/source/texk/kpathsea/path-elt.c b/Build/source/texk/kpathsea/path-elt.c index 841fb36f5cb..cadd6091806 100644 --- a/Build/source/texk/kpathsea/path-elt.c +++ b/Build/source/texk/kpathsea/path-elt.c @@ -53,16 +53,13 @@ element (kpathsea kpse, const_string passed_path, boolean env_p) brace_level = 0; while (*p != 0 && !(brace_level == 0 && (env_p ? IS_ENV_SEP (*p) : IS_DIR_SEP (*p)))) { + if (*p == '{') ++brace_level; + else if (*p == '}') --brace_level; #if defined(WIN32) - if (IS_KANJI(p)) { - p++; + else if (IS_KANJI(p)) p++; - continue; - } #endif - if (*p == '{') ++brace_level; - else if (*p == '}') --brace_level; - ++p; + p++; } /* Return the substring starting at `path'. */ diff --git a/Build/source/texk/kpathsea/tilde.c b/Build/source/texk/kpathsea/tilde.c index 2f3ff76bb01..13b7b05a35b 100644 --- a/Build/source/texk/kpathsea/tilde.c +++ b/Build/source/texk/kpathsea/tilde.c @@ -21,8 +21,12 @@ #include <kpathsea/c-pathch.h> #include <kpathsea/tilde.h> +#undef USE_GETPWNAM #ifdef HAVE_PWD_H #include <pwd.h> +#define USE_GETPWNAM 1 +#elif defined (WIN32) && !defined (__MINGW32__) +#define USE_GETPWNAM 1 #endif #ifdef WIN32 @@ -48,17 +52,6 @@ kpathsea_tilde_expand (kpathsea kpse, string name) (void)kpse; /* currenty not used */ assert (name); -#if defined(WIN32) - for (p = name; *p; p++) { - if (IS_KANJI(p)) { - p++; - continue; - } - if (*p == '\\') - *p = '/'; - } -#endif - /* If there is a leading "!!", set prefix to "!!", otherwise use the empty string. After this, we can test whether a prefix was found by checking *prefix, and it is safe to unconditionally @@ -71,45 +64,35 @@ kpathsea_tilde_expand (kpathsea kpse, string name) } /* If no leading tilde, do nothing, and return the original string. */ - if (*name != '~') { + if (*name != '~' +#ifndef USE_GETPWNAM + /* Same for `~user' or `~user/', but no passwd database. */ + || (name[1] && !IS_DIR_SEP (name[1])) +#endif + ) { if (*prefix) name -= 2; expansion = name; - /* If a bare tilde, return the home directory or `.'. (Very unlikely - that the directory name will do anyone any good, but ... */ - } else if (name[1] == 0) { - home = getenv (HOMEVAR); - if (!home) { - home = "."; - } - expansion = concat (prefix, home); - - /* If `~/', remove any trailing / or replace leading // in $HOME. - Should really check for doubled intermediate slashes, too. */ - } else if (IS_DIR_SEP (name[1])) { - unsigned c = 1; - home = getenv (HOMEVAR); - if (!home) { - home = "."; - } - if (IS_DIR_SEP (*home) && IS_DIR_SEP (home[1])) { /* handle leading // */ - home++; - } - if (IS_DIR_SEP (home[strlen (home) - 1])) { /* omit / after ~ */ - c++; - } - expansion = concat3 (prefix, home, name + c); - - /* If `~user' or `~user/', look up user in the passwd database (but - OS/2 doesn't have this concept. */ } else { -#ifdef HAVE_PWD_H + /* If a bare tilde, return the home directory or `.'; if just `~user', + return that user's home directory or `.'. Very unlikely that the + directory name will do anyone any good, but ... */ + unsigned c; + +#ifdef USE_GETPWNAM + /* If `~user' or `~user/', look up user in the passwd database. */ + if (name[1] && !IS_DIR_SEP (name[1])) { struct passwd *p; string user; - unsigned c = 2; - while (!IS_DIR_SEP (name[c]) && name[c] != 0) /* find user name */ + c = 2; + while (!IS_DIR_SEP (name[c]) && name[c] != 0) { /* find user name */ +#if defined(WIN32) + if (IS_KANJI(name+c)) + c++; +#endif c++; + } user = (string) xmalloc (c); strncpy (user, name + 1, c - 1); @@ -122,21 +105,48 @@ kpathsea_tilde_expand (kpathsea kpse, string name) /* If no such user, just use `.'. */ home = p ? p->pw_dir : "."; - if (IS_DIR_SEP (*home) && IS_DIR_SEP (home[1])) { /* handle leading // */ - home++; + } else +#endif /* USE_GETPWNAM */ + { + c = 1; + home = getenv (HOMEVAR); + if (!home) + home = "."; + } + + /* handle leading // */ + if (IS_DIR_SEP (*home) && IS_DIR_SEP (home[1])) + home++; + + /* If HOME ends in /, omit the / in ~/ or ~user/. */ + if (name[c]) { +#if defined(WIN32) + const_string q; + + for (q = home; *q; q++) { + if (IS_DIR_SEP (*q) && q[1] == 0) + c++; + else if (IS_KANJI(q)) + q++; } - if (IS_DIR_SEP (home[strlen (home) - 1]) && name[c] != 0) - c++; /* If HOME ends in /, omit the / after ~user. */ - - expansion = concat3 (prefix, home, name + c); -#else /* not HAVE_PWD_H */ - /* Since we don't know how to look up a user name, just return the - original string. */ - if (*prefix) - name -= 2; - expansion = name; -#endif /* not HAVE_PWD_H */ +#else + if (IS_DIR_SEP (home[strlen (home) - 1])) + c++; +#endif + } + + expansion = concat3 (prefix, home, name + c); } + +#if defined(WIN32) + for (p = expansion; *p; p++) { + if (*p == '\\') + *p = '/'; + else if (IS_KANJI(p)) + p++; + } +#endif + /* We may return the same thing as the original, and then we might not be returning a malloc-ed string. Callers beware. Sorry. */ return expansion; diff --git a/Build/source/texk/kpathsea/xbasename.c b/Build/source/texk/kpathsea/xbasename.c index df066d68a6c..e725ce71c95 100644 --- a/Build/source/texk/kpathsea/xbasename.c +++ b/Build/source/texk/kpathsea/xbasename.c @@ -1,6 +1,6 @@ /* xbasename.c: return the last element in a path. - Copyright 1992, 1994, 1995, 1996, 2008 Karl Berry. + Copyright 1992, 1994, 1995, 1996, 2008, 2011 Karl Berry. Copyright 2005 Olaf Weber. This library is free software; you can redistribute it and/or @@ -28,18 +28,17 @@ const_string xbasename (const_string name) { - const_string base = NULL; - unsigned len; - - for (len = strlen(name); len > 0; len--) { - if (IS_DIR_SEP(name[len - 1]) || IS_DEVICE_SEP(name[len - 1])) { - base = name + len; - break; - } + const_string base = name; + const_string p; + + for (p = name; *p; p++) { + if (IS_DIR_SEP(*p) || IS_DEVICE_SEP(*p)) + base = p + 1; +#if defined(WIN32) + else if (IS_KANJI(p)) + p++; +#endif } - if (!base) - base = name; - return base; } diff --git a/Build/source/texk/kpathsea/xdirname.c b/Build/source/texk/kpathsea/xdirname.c index 8b3585ecea8..57a84787f95 100644 --- a/Build/source/texk/kpathsea/xdirname.c +++ b/Build/source/texk/kpathsea/xdirname.c @@ -81,12 +81,10 @@ xdirname (const_string name) #if defined(WIN32) for (p = ret; *p; p++) { - if (IS_KANJI(p)) { - p++; - continue; - } if (*p == '\\') *p = '/'; + else if (IS_KANJI(p)) + p++; } #endif diff --git a/Build/source/texk/kpathsea/xgetcwd.c b/Build/source/texk/kpathsea/xgetcwd.c index 79f1d832055..dae50ddb998 100644 --- a/Build/source/texk/kpathsea/xgetcwd.c +++ b/Build/source/texk/kpathsea/xgetcwd.c @@ -59,12 +59,10 @@ xgetcwd (void) #if defined(WIN32) for (pp = path; *pp; pp++) { - if (IS_KANJI(pp)) { - pp++; - continue; - } if (*pp == '\\') *pp = '/'; + else if (IS_KANJI(pp)) + pp++; } #endif |