summaryrefslogtreecommitdiff
path: root/Build/source/texk/kpathsea
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
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')
-rw-r--r--Build/source/texk/kpathsea/ChangeLog12
-rw-r--r--Build/source/texk/kpathsea/Makefile.am4
-rw-r--r--Build/source/texk/kpathsea/Makefile.in13
-rw-r--r--Build/source/texk/kpathsea/xbasename.c27
-rw-r--r--Build/source/texk/kpathsea/xdirname.c88
-rw-r--r--Build/source/texk/kpathsea/xdirtest.c148
6 files changed, 237 insertions, 55 deletions
diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog
index 012d0c4ce73..548a2029994 100644
--- a/Build/source/texk/kpathsea/ChangeLog
+++ b/Build/source/texk/kpathsea/ChangeLog
@@ -1,3 +1,15 @@
+2011-08-04 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ More diffs between TeX Live and W32TeX.
+ * xbasename.c: Test for 2-Byte Kanji (CP 932, SJIS) codes and
+ for Unc names.
+ * xdirname.c: Test for 2-Byte Kanji (CP 932, SJIS) codes and
+ slashify the result.
+
+ * xdirtest.c (new): Standalone program to test xdirname() and
+ xbasename(), based on code moved to here ...
+ * xdirname.c [TEST]: ... from here.
+
2011-08-03 Akira Kakuto <kakuto@fuk.kindai.ac.jp>
* db.c (db_build): No need to slashify lines from db_file.
diff --git a/Build/source/texk/kpathsea/Makefile.am b/Build/source/texk/kpathsea/Makefile.am
index 392e99a39cb..d9ab4a53847 100644
--- a/Build/source/texk/kpathsea/Makefile.am
+++ b/Build/source/texk/kpathsea/Makefile.am
@@ -219,6 +219,10 @@ kpsereadlink_SOURCES = readlink.c
kpsewhich_LDADD = libkpathsea.la
+EXTRA_PROGRAMS = xdirtest
+
+xdirtest_LDADD = libkpathsea.la
+
## The scripts and their data
web2cdir = ${prefix}/texmf/web2c
diff --git a/Build/source/texk/kpathsea/Makefile.in b/Build/source/texk/kpathsea/Makefile.in
index 5c15cb711b4..b4aac202f9b 100644
--- a/Build/source/texk/kpathsea/Makefile.in
+++ b/Build/source/texk/kpathsea/Makefile.in
@@ -43,6 +43,7 @@ host_triplet = @host@
@WIN32_TRUE@am__append_3 = knj.c
bin_PROGRAMS = kpseaccess$(EXEEXT) kpsereadlink$(EXEEXT) \
kpsestat$(EXEEXT) kpsewhich$(EXEEXT)
+EXTRA_PROGRAMS = xdirtest$(EXEEXT)
subdir = .
DIST_COMMON = README $(am__configure_deps) $(dist_noinst_DATA) \
$(dist_noinst_SCRIPTS) $(dist_web2c_DATA) \
@@ -167,6 +168,9 @@ kpsestat_LDADD = $(LDADD)
kpsewhich_SOURCES = kpsewhich.c
kpsewhich_OBJECTS = kpsewhich.$(OBJEXT)
kpsewhich_DEPENDENCIES = libkpathsea.la
+xdirtest_SOURCES = xdirtest.c
+xdirtest_OBJECTS = xdirtest.$(OBJEXT)
+xdirtest_DEPENDENCIES = libkpathsea.la
SCRIPTS = $(dist_noinst_SCRIPTS) $(dist_web2c_SCRIPTS)
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/../../build-aux/depcomp
@@ -182,10 +186,10 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(libkpathsea_la_SOURCES) $(kpseaccess_SOURCES) \
- $(kpsereadlink_SOURCES) kpsestat.c kpsewhich.c
+ $(kpsereadlink_SOURCES) kpsestat.c kpsewhich.c xdirtest.c
DIST_SOURCES = $(am__libkpathsea_la_SOURCES_DIST) \
$(kpseaccess_SOURCES) $(kpsereadlink_SOURCES) kpsestat.c \
- kpsewhich.c
+ kpsewhich.c xdirtest.c
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
html-recursive info-recursive install-data-recursive \
install-dvi-recursive install-exec-recursive \
@@ -445,6 +449,7 @@ DISTCLEANFILES = paths.h stamp-paths kpathsea.h
kpseaccess_SOURCES = access.c
kpsereadlink_SOURCES = readlink.c
kpsewhich_LDADD = libkpathsea.la
+xdirtest_LDADD = libkpathsea.la
web2cdir = ${prefix}/texmf/web2c
dist_web2c_SCRIPTS = mktexdir mktexnam mktexupd
dist_web2c_DATA = mktex.opt mktexdir.opt mktexnam.opt
@@ -601,6 +606,9 @@ kpsestat$(EXEEXT): $(kpsestat_OBJECTS) $(kpsestat_DEPENDENCIES)
kpsewhich$(EXEEXT): $(kpsewhich_OBJECTS) $(kpsewhich_DEPENDENCIES)
@rm -f kpsewhich$(EXEEXT)
$(LINK) $(kpsewhich_OBJECTS) $(kpsewhich_LDADD) $(LIBS)
+xdirtest$(EXEEXT): $(xdirtest_OBJECTS) $(xdirtest_DEPENDENCIES)
+ @rm -f xdirtest$(EXEEXT)
+ $(LINK) $(xdirtest_OBJECTS) $(xdirtest_LDADD) $(LIBS)
install-dist_web2cSCRIPTS: $(dist_web2c_SCRIPTS)
@$(NORMAL_INSTALL)
test -z "$(web2cdir)" || $(MKDIR_P) "$(DESTDIR)$(web2cdir)"
@@ -709,6 +717,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libkpathsea_la-xstat.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libkpathsea_la-xstrdup.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readlink.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xdirtest.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/Build/source/texk/kpathsea/xbasename.c b/Build/source/texk/kpathsea/xbasename.c
index e725ce71c95..c66da1cf622 100644
--- a/Build/source/texk/kpathsea/xbasename.c
+++ b/Build/source/texk/kpathsea/xbasename.c
@@ -31,8 +31,31 @@ xbasename (const_string name)
const_string base = name;
const_string p;
- for (p = name; *p; p++) {
- if (IS_DIR_SEP(*p) || IS_DEVICE_SEP(*p))
+ if (NAME_BEGINS_WITH_DEVICE(name))
+ base += 2;
+
+ else if (IS_UNC_NAME(name)) {
+ unsigned 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++] && 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
+ ;
+ } else
+ /* malformed UNC name, backup */
+ limit = 0;
+ base += limit;
+ }
+
+ for (p = base; *p; p++) {
+ if (IS_DIR_SEP(*p))
base = p + 1;
#if defined(WIN32)
else if (IS_KANJI(p))
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:
-*/
diff --git a/Build/source/texk/kpathsea/xdirtest.c b/Build/source/texk/kpathsea/xdirtest.c
new file mode 100644
index 00000000000..47163e3889d
--- /dev/null
+++ b/Build/source/texk/kpathsea/xdirtest.c
@@ -0,0 +1,148 @@
+/* xdirtest.c: standalone test xdirname() and xbasename().
+
+ Copyright 1999 Karl Berry.
+ Copyright 2005 Olaf Weber.
+ Copyright 2011 Peter Breitenlohner.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <kpathsea/config.h>
+
+static const char *tab[] = {
+/* UNC names */
+#if defined (WIN32)
+ "\\\\neuromancer\\fptex\\bin\\win32\\kpsewhich.exe",
+ "\\\\neuromancer\\fptex\\win32\\kpsewhich.exe",
+ "\\\\neuromancer\\fptex\\kpsewhich.exe",
+ "\\\\neuromancer\\kpsewhich.exe",
+ "//server.host/share/file",
+ "//server.host//share", /* malformed */
+ "//server.host", /* malformed */
+ "//.host/share", /* not UNC name */
+#endif
+ "//neuromancer/kpsewhich.exe",
+/* names with device */
+#if defined (WIN32)
+ "p:\\bin\\win32\\kpsewhich.exe",
+ "p:\\win32\\kpsewhich.exe",
+ "p:\\kpsewhich.exe",
+ "p:bin\\win32\\kpsewhich.exe",
+ "p:win32\\kpsewhich.exe",
+#endif
+ "p:win32//kpsewhich.exe",
+ "p:kpsewhich.exe",
+ "p:///kpsewhich.exe",
+/* 'normal' names */
+ "/usr/bin/win32/kpsewhich.exe",
+ "/usr/bin/kpsewhich.exe",
+ "/usr/kpsewhich.exe",
+ "///usr/kpsewhich.exe",
+ "///kpsewhich.exe",
+ "",
+ NULL
+};
+
+#if defined (WIN32)
+static const char *ktab[] = {
+/* UNC names */
+ "\\\\serverK\\\\shareK\\\\file",
+ "\\\\serverKK\\shareKK\\file",
+ "\\\\serverK\\\\shareK\\",
+ "\\\\serverKK\\shareKK",
+/* 'normal' names */
+ "\\abcK\\deKKfK\\\\hijK\\",
+ "\\abcKKdeKKfKK\\hijKK",
+ "\\abcK\\deKKfK\\",
+ "\\abcKKdeKKfKK",
+ NULL
+};
+
+static char *
+to_kanji (const char *str) {
+ char *p, *ret = xstrdup(str);
+
+ for (p = ret; *p; p++)
+ if (*p == 'K')
+ *p = 0x81;
+
+ return ret;
+}
+
+static char *
+from_kanji (char *str) {
+ char *p;
+
+ for (p = str; *p; p++)
+ if ((unsigned char) *p == 0x81)
+ *p = 'K';
+
+ return str;
+}
+
+static void
+do_kanji (void) {
+ const char **p;
+
+ printf("\nAssuming CP %s 932\n", is_cp932_system ? "is" : "is not");
+
+ for (p = ktab; *p; p++) {
+ char *q = to_kanji(*p);
+ char *r = xdirname(q);
+
+ printf("%s -> %s + %s\n", *p, from_kanji(r), *p + (xbasename(q)-q));
+
+ free (r);
+ free (q);
+ }
+}
+
+static void
+kanji_test(void) {
+ int save_cp932 = is_cp932_system;
+
+ printf("\nTesting 2-Byte Kanji (CP 932, SJIS) codes with 'K' representing 0x81\n");
+
+ is_cp932_system = 1; /* pretend CP is 932 */
+ do_kanji();
+
+ is_cp932_system = 0; /* pretend CP is not 932 */
+ do_kanji();
+
+ is_cp932_system = save_cp932;
+}
+#endif
+
+int main(int argc, char **argv)
+{
+ const char **p;
+ kpathsea kpse = kpathsea_new();
+
+ kpathsea_set_program_name (kpse, argv[0], NULL);
+
+ printf("\n%s: name -> xdirname(name) + xbasename(name)\n\n",
+ kpse->invocation_short_name);
+
+ for (p = tab; *p; p++) {
+ char *q = xdirname(*p);
+
+ printf("%s -> %s + %s\n", *p, q, xbasename(*p));
+ free (q);
+ }
+
+#if defined (WIN32)
+ kanji_test();
+#endif
+
+ return 0;
+}