summaryrefslogtreecommitdiff
path: root/Build/source/texk/kpathsea/xdirname.c
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2011-08-04 11:56:32 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2011-08-04 11:56:32 +0000
commit1491bd20a6acc228027bb0ef69f72b48aa6a572d (patch)
treebf28cbb1c4453dcaa76bbffe5d08a957fea30408 /Build/source/texk/kpathsea/xdirname.c
parentbe0be9e57afa091468dd619092180640d8c29a38 (diff)
kpathsea: More changes to reduce diffs with W32TeX
git-svn-id: svn://tug.org/texlive/trunk@23405 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/kpathsea/xdirname.c')
-rw-r--r--Build/source/texk/kpathsea/xdirname.c88
1 files changed, 37 insertions, 51 deletions
diff --git a/Build/source/texk/kpathsea/xdirname.c b/Build/source/texk/kpathsea/xdirname.c
index 57a84787f95..c5b38bae891 100644
--- a/Build/source/texk/kpathsea/xdirname.c
+++ b/Build/source/texk/kpathsea/xdirname.c
@@ -32,6 +32,7 @@ xdirname (const_string name)
unsigned limit = 0, loc;
#if defined(WIN32)
string p;
+ unsigned i, j;
#endif
/* Ignore a NULL name. */
@@ -40,40 +41,63 @@ xdirname (const_string name)
if (NAME_BEGINS_WITH_DEVICE(name)) {
limit = 2;
-#if defined(WIN32) || defined(__CYGWIN__)
} else if (IS_UNC_NAME(name)) {
- for (limit = 2; name[limit] && !IS_DIR_SEP(name[limit]); limit++)
+ for (limit = 2; name[limit] && !IS_DIR_SEP (name[limit]); limit++)
+#if defined(WIN32)
+ if (IS_KANJI(name+limit)) limit++
+#endif
;
- if (name[limit]) {
- for (limit++ ; name[limit] && !IS_DIR_SEP(name[limit]); limit++)
+ if (name[limit++] && name[limit] && !IS_DIR_SEP (name[limit])) {
+ for (; name[limit] && !IS_DIR_SEP (name[limit]); limit++)
+#if defined(WIN32)
+ if (IS_KANJI(name+limit)) limit++
+#endif
;
limit--;
- } else {
+ } else
/* malformed UNC name, backup */
- limit = 2;
- }
-#endif
+ limit = 0;
}
+#if defined(WIN32)
+ j = loc = limit;
+ if (j > 2) j++;
+ for (i = j; name[i]; i++) {
+ if (IS_DIR_SEP (name[i])) {
+ j = i;
+ for (i++; IS_DIR_SEP (name[i]); i++)
+ ;
+ loc = i + 1;
+ } else if (IS_KANJI(name+i)) i++;
+ }
+#else
for (loc = strlen (name); loc > limit && !IS_DIR_SEP (name[loc-1]); loc--)
;
+#endif
- if (loc == limit && limit > 0) {
- if (limit == 2) {
- ret = (string)xmalloc(limit + 2);
+ if (loc == limit) {
+ if (limit == 0)
+ ret = xstrdup (".");
+ else if (limit == 2) {
+ ret = (string)xmalloc(4);
ret[0] = name[0];
ret[1] = name[1];
ret[2] = '.';
ret[3] = '\0';
} else {
- ret = (string)xmalloc(limit + 2);
- strcpy(ret, name);
+ /* UNC name is "//server/share". */
+ ret = xstrdup (name);
}
} else {
/* If have ///a, must return /, so don't strip off everything. */
+#if defined(WIN32)
+ loc = j;
+ if (loc == limit && IS_DIR_SEP (name[loc])) loc++;
+#else
while (loc > limit+1 && IS_DIR_SEP (name[loc-1])) {
loc--;
}
+#endif
ret = (string)xmalloc(loc+1);
strncpy(ret, name, loc);
ret[loc] = '\0';
@@ -90,41 +114,3 @@ xdirname (const_string name)
return ret;
}
-
-#ifdef TEST
-
-char *tab[] = {
- "\\\\neuromancer\\fptex\\bin\\win32\\kpsewhich.exe",
- "\\\\neuromancer\\fptex\\win32\\kpsewhich.exe",
- "\\\\neuromancer\\fptex\\kpsewhich.exe",
- "\\\\neuromancer\\kpsewhich.exe",
- "p:\\bin\\win32\\kpsewhich.exe",
- "p:\\win32\\kpsewhich.exe",
- "p:\\kpsewhich.exe",
- "p:bin\\win32\\kpsewhich.exe",
- "p:win32\\kpsewhich.exe",
- "p:kpsewhich.exe",
- "p:///kpsewhich.exe",
- "/usr/bin/win32/kpsewhich.exe",
- "/usr/bin/kpsewhich.exe",
- "/usr/kpsewhich.exe",
- "///usr/kpsewhich.exe",
- "///kpsewhich.exe",
- NULL
-};
-
-int main()
-{
- char **p;
- for (p = tab; *p; p++)
- printf("name %s, dirname %s\n", *p, xdirname(*p));
- return 0;
-}
-#endif /* TEST */
-
-
-/*
-Local variables:
-standalone-compile-command: "gcc -g -I. -I.. -DTEST xdirname.c kpathsea.a"
-End:
-*/