Debian Codegraph @

texk/kpathsea/xdirtest.c

raw
1 /* xdirtest.c: standalone program to test xdirname() and xbasename().
2
3 Copyright 1999 Karl Berry.
4 Copyright 2005 Olaf Weber.
5 Copyright 2011 Peter Breitenlohner.
6 Copyright 2016 Akira Kakuto.
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with this library; if not, see <http://www.gnu.org/licenses/>. */
20
21 #include <kpathsea/config.h>
22
23 static const char *tab[] = {
24 /* UNC names */
25 #if defined (WIN32)
26 "\\\\neuromancer\\fptex\\bin\\win32\\kpsewhich.exe",
27 "\\\\neuromancer\\fptex\\win32\\kpsewhich.exe",
28 "\\\\neuromancer\\fptex\\kpsewhich.exe",
29 "\\\\neuromancer\\kpsewhich.exe",
30 "//server.host/share/file",
31 "//server.host/share/file/",
32 "//server.host/share/",
33 "//server.host//share", /* malformed */
34 "//server.host", /* malformed */
35 "//.host/share", /* not UNC name */
36 #endif
37 "//neuromancer/kpsewhich.exe",
38 /* names with device */
39 #if defined (WIN32)
40 "p:\\bin\\win32\\kpsewhich.exe",
41 "p:\\bin\\win32\\\\",
42 "p:\\win32\\kpsewhich.exe",
43 "p:\\win32\\",
44 "p:\\kpsewhich.exe",
45 "p:\\",
46 "p:bin\\win32\\kpsewhich.exe",
47 "p:win32\\kpsewhich.exe",
48 #endif
49 "p:win32//kpsewhich.exe",
50 "p:win32/",
51 "p:kpsewhich.exe",
52 "p:///kpsewhich.exe",
53 /* 'normal' names */
54 "/usr/bin/win32/kpsewhich.exe",
55 "/usr/bin/win32//",
56 "/usr/bin/kpsewhich.exe",
57 "/usr/bin/",
58 "///usr/kpsewhich.exe",
59 "/usr/kpsewhich.exe",
60 "///kpsewhich.exe",
61 "/kpsewhich.exe",
62 "",
63 NULL
64 };
65
66 #if defined (WIN32)
67 static const char *ktab[] = {
68 /* UNC names */
69 "\\\\serverK\\\\shareK\\\\file",
70 "\\\\serverKK\\shareKK\\file",
71 "\\\\serverK\\\\shareK\\",
72 "\\\\serverKK\\shareKK",
73 /* 'normal' names */
74 "\\abcK\\deKKfK\\\\hijK\\",
75 "\\abcKKdeKKfKK\\hijKK",
76 "\\abcK\\deKKfK\\",
77 "\\abcKKdeKKfKK",
78 NULL
79 };
80
81 static char *
82 to_kanji (const char *str) {
83 char *p, *ret = xstrdup(str);
84
85 for (p = ret; *p; p++)
86 if (*p == 'K')
87 *p = 0x81;
88
89 return ret;
90 }
91
92 static char *
93 from_kanji (char *str) {
94 char *p;
95
96 for (p = str; *p; p++)
97 if ((unsigned char) *p == 0x81)
98 *p = 'K';
99
100 return str;
101 }
102
103 static void
104 do_kanji (kpathsea kpse) {
105 const char **p;
106
107 printf("\nAssuming CP %s 932\n", kpse->Is_cp932_system ? "is" : "is not");
108
109 for (p = ktab; *p; p++) {
110 char *q = to_kanji(*p);
111 char *r = xdirname(q);
112
113 printf("%s -> %s + %s\n", *p, from_kanji(r), *p + (xbasename(q)-q));
114
115 free (r);
116 free (q);
117 }
118 }
119
120 static void
121 kanji_test(kpathsea kpse) {
122 int save_cp932 = kpse->Is_cp932_system;
123
124 printf("\nTesting 2-Byte Kanji (CP 932, SJIS) codes with 'K' representing 0x81\n");
125
126 kpse->Is_cp932_system = 932; /* pretend CP is 932 */
127 do_kanji(kpse);
128
129 kpse->Is_cp932_system = 0; /* pretend CP is not 932 */
130 do_kanji(kpse);
131
132 kpse->Is_cp932_system = save_cp932;
133 }
134 #endif
135
136 int main(int argc, char **argv)
137 {
138 const char **p;
139 kpathsea kpse = kpathsea_new();
140
141 kpathsea_set_program_name (kpse, argv[0], NULL);
142
143 printf("\n%s: name -> xdirname(name) + xbasename(name)\n\n",
144 kpse->invocation_short_name);
145
146 for (p = tab; *p; p++) {
147 char *q = xdirname(*p);
148
149 printf("%s -> %s + %s\n", *p, q, xbasename(*p));
150 free (q);
151 }
152
153 #if defined (WIN32)
154 kanji_test(kpse);
155 #endif
156
157 return 0;
158 }