Mercurial > octave-nkf
annotate liboctave/util/kpse.cc @ 20052:4b7b7ac7af2c
use get_home_directory instead of getenv ("HOME") (bug #44694)
* files-dock-widget.cc (files_dock_widget::popdownmenu_home):
Use get_home_directory instead of getenv ("HOME") for the benefit of
Windows systems which may not have HOME set in the environment.
* kpse.cc (kpse_tilde_expand): Likewise.
* prefdir.m: Likewise.
* system.tst: Likewise.
* edit.m: Use get_home_directory instead of default_home.
(default_home): Delete subfunction.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 02 Apr 2015 13:19:30 -0400 |
parents | 17d647821d61 |
children | a9574e3c6e9e |
rev | line source |
---|---|
4399 | 1 // This file is not compiled to a separate object file. It is |
2 // included in pathsearch.cc. | |
3 | |
4 /* Look up a filename in a path. | |
4378 | 5 |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19444
diff
changeset
|
6 Copyright (C) 2003-2015 John W. Eaton |
4385 | 7 Copyright (C) 1993, 94, 95, 96, 97, 98 Karl Berry. |
4378 | 8 Copyright (C) 1993, 94, 95, 96, 97 Karl Berry & O. Weber. |
4399 | 9 Copyright (C) 1992, 93, 94, 95, 96, 97 Free Software Foundation, Inc. |
4378 | 10 |
16768 | 11 This file is part of Octave. |
12 | |
13 Octave is free software; you can redistribute it and/or modify it | |
14 under the terms of the GNU General Public License as published by the | |
15 Free Software Foundation; either version 3 of the License, or (at your | |
16 option) any later version. | |
17 | |
18 Octave is distributed in the hope that it will be useful, but WITHOUT | |
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
21 for more details. | |
22 | |
23 You should have received a copy of the GNU General Public License | |
24 along with Octave; see the file COPYING. If not, see | |
25 <http://www.gnu.org/licenses/>. | |
26 | |
27 */ | |
4378 | 28 |
29 #if defined (HAVE_CONFIG_H) | |
30 #include <config.h> | |
31 #endif | |
32 | |
4390 | 33 #include <map> |
4389 | 34 #include <string> |
35 | |
4399 | 36 /* System defines are for non-Unix systems only. (Testing for all Unix |
37 variations should be done in configure.) Presently the defines used | |
38 are: DOS OS2 WIN32. I do not use any of these systems | |
39 myself; if you do, I'd be grateful for any changes. --kb@mail.tug.org */ | |
40 | |
41 /* If we have either DOS or OS2, we are DOSISH. */ | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14155
diff
changeset
|
42 #if defined (DOS) || defined (OS2) || defined (WIN32) || defined (__MSDOS__) |
4399 | 43 #define DOSISH |
44 #endif | |
45 | |
46 #if defined (DOSISH) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
47 #define MONOCASE_FILENAMES /* case-insensitive filename comparisons */ |
4399 | 48 #endif |
49 | |
50 extern "C" { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14155
diff
changeset
|
51 #if defined (__MINGW32__) |
4399 | 52 #include <windows.h> |
53 #include <fcntl.h> | |
54 #include <dirent.h> | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14155
diff
changeset
|
55 #elif defined (WIN32) |
13718
a31c926fb0d5
Do not define __STDC__ under MSVC.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
56 #ifndef _MSC_VER |
4399 | 57 #define __STDC__ 1 |
58 #include "win32lib.h" | |
6106 | 59 #endif |
4399 | 60 #endif /* not WIN32 */ |
61 | |
62 #ifdef __DJGPP__ | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
63 #include <fcntl.h> /* for long filenames' stuff */ |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
64 #include <dir.h> /* for 'getdisk' */ |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
65 #include <io.h> /* for 'setmode' */ |
4399 | 66 #endif |
67 } | |
68 | |
69 /* Some drivers have partially integrated kpathsea changes. */ | |
70 #ifndef KPATHSEA | |
71 #define KPATHSEA 32 | |
72 #endif | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
73 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
74 /* System dependencies that are figured out by 'configure'. If we are |
4399 | 75 compiling standalone, we get our c-auto.h. Otherwise, the package |
76 containing us must provide this (unless it can somehow generate ours | |
77 from c-auto.in). We use <...> instead of "..." so that the current | |
78 cpp directory (i.e., kpathsea/) won't be searched. */ | |
79 | |
80 /* If you want to find subdirectories in a directory with non-Unix | |
81 semantics (specifically, if a directory with no subdirectories does | |
5622 | 82 not have exactly two links), define this. */ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14155
diff
changeset
|
83 #if defined (__DJGPP__) || ! defined (DOSISH) |
4399 | 84 /* Surprise! DJGPP returns st_nlink exactly like on Unix. */ |
85 #define ST_NLINK_TRICK | |
86 #endif /* either not DOSISH or __DJGPP__ */ | |
87 | |
88 #ifdef OS2 | |
89 #define access ln_access | |
90 #define fopen ln_fopen | |
91 #define rename ln_rename | |
92 #define stat ln_stat | |
93 #endif /* OS2 */ | |
94 | |
11236 | 95 /* Define the characters which separate components of |
96 filenames and environment variable paths. */ | |
97 | |
98 /* What separates filename components? */ | |
99 #ifndef DIR_SEP | |
100 #ifdef DOSISH | |
101 /* Either \'s or 's work. Wayne Sullivan's web2pc prefers /, so we'll | |
102 go with that. */ | |
103 #define DIR_SEP '/' | |
104 #define DIR_SEP_STRING "/" | |
105 #define IS_DEVICE_SEP(ch) ((ch) == ':') | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14155
diff
changeset
|
106 #define NAME_BEGINS_WITH_DEVICE(name) ((name.length ()>0) && IS_DEVICE_SEP((name)[1])) |
11236 | 107 /* On DOS, it's good to allow both \ and / between directories. */ |
108 #define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\') | |
109 #else | |
110 #define DIR_SEP '/' | |
111 #define DIR_SEP_STRING "/" | |
112 #endif /* not DOSISH */ | |
113 #endif /* not DIR_SEP */ | |
114 | |
115 #ifndef IS_DIR_SEP | |
116 #define IS_DIR_SEP(ch) ((ch) == DIR_SEP) | |
117 #endif | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
118 #ifndef IS_DEVICE_SEP /* No 'devices' on, e.g., Unix. */ |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
119 #define IS_DEVICE_SEP(ch) 0 |
11236 | 120 #endif |
121 #ifndef NAME_BEGINS_WITH_DEVICE | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
122 #define NAME_BEGINS_WITH_DEVICE(name) 0 |
11236 | 123 #endif |
4378 | 124 |
4396 | 125 #include "lo-error.h" |
4391 | 126 #include "oct-env.h" |
127 #include "oct-passwd.h" | |
4399 | 128 #include "str-vec.h" |
4385 | 129 |
130 /* Header files that essentially all of our sources need, and | |
131 that all implementations have. We include these first, to help with | |
132 NULL being defined multiple times. */ | |
133 #include <cstdio> | |
134 #include <cstdarg> | |
135 #include <cstdlib> | |
136 #include <cerrno> | |
137 #include <cassert> | |
138 | |
139 #include <sys/types.h> | |
140 #include <unistd.h> | |
141 | |
142 #include "sysdir.h" | |
143 #include "statdefs.h" | |
144 | |
145 /* define NAME_MAX, the maximum length of a single | |
146 component in a filename. No such limit may exist, or may vary | |
147 depending on the filesystem. */ | |
148 | |
149 /* Most likely the system will truncate filenames if it is not POSIX, | |
150 and so we can use the BSD value here. */ | |
151 #ifndef _POSIX_NAME_MAX | |
152 #define _POSIX_NAME_MAX 255 | |
153 #endif | |
154 | |
155 #ifndef NAME_MAX | |
156 #define NAME_MAX _POSIX_NAME_MAX | |
157 #endif | |
158 | |
159 #include <cctype> | |
160 | |
161 /* What separates elements in environment variable path lists? */ | |
162 #ifndef ENV_SEP | |
5451 | 163 #if defined (SEPCHAR) && defined (SEPCHAR_STR) |
164 #define ENV_SEP SEPCHAR | |
165 #define ENV_SEP_STRING SEPCHAR_STR | |
166 #elif defined (DOSISH) | |
4385 | 167 #define ENV_SEP ';' |
168 #define ENV_SEP_STRING ";" | |
169 #else | |
170 #define ENV_SEP ':' | |
171 #define ENV_SEP_STRING ":" | |
172 #endif /* not DOS */ | |
173 #endif /* not ENV_SEP */ | |
174 | |
175 #ifndef IS_ENV_SEP | |
176 #define IS_ENV_SEP(ch) ((ch) == ENV_SEP) | |
177 #endif | |
178 | |
4399 | 179 /* define PATH_MAX, the maximum length of a filename. Since no such |
180 limit may exist, it's preferable to dynamically grow filenames as | |
181 needed. */ | |
4385 | 182 |
183 /* Cheat and define this as a manifest constant no matter what, instead | |
184 of using pathconf. I forget why we want to do this. */ | |
185 | |
186 #ifndef _POSIX_PATH_MAX | |
187 #define _POSIX_PATH_MAX 255 | |
188 #endif | |
189 | |
190 #ifndef PATH_MAX | |
191 #ifdef MAXPATHLEN | |
192 #define PATH_MAX MAXPATHLEN | |
193 #else | |
194 #define PATH_MAX _POSIX_PATH_MAX | |
195 #endif | |
196 #endif /* not PATH_MAX */ | |
197 | |
198 /* If NO_DEBUG is defined (not recommended), skip all this. */ | |
199 #ifndef NO_DEBUG | |
200 | |
201 /* OK, we'll have tracing support. */ | |
202 #define KPSE_DEBUG | |
203 | |
204 /* Test if a bit is on. */ | |
205 #define KPSE_DEBUG_P(bit) (kpathsea_debug & (1 << (bit))) | |
206 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
207 #define KPSE_DEBUG_STAT 0 /* stat calls */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
208 #define KPSE_DEBUG_HASH 1 /* hash lookups */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
209 #define KPSE_DEBUG_FOPEN 2 /* fopen/fclose calls */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
210 #define KPSE_DEBUG_PATHS 3 /* search path initializations */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
211 #define KPSE_DEBUG_EXPAND 4 /* path element expansion */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
212 #define KPSE_DEBUG_SEARCH 5 /* searches */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
213 #define KPSE_DEBUG_VARS 6 /* variable values */ |
4385 | 214 #define KPSE_LAST_DEBUG KPSE_DEBUG_VARS |
215 | |
216 /* A printf for the debugging. */ | |
10411 | 217 #define DEBUGF_START() do { gnulib::fputs ("kdebug:", stderr) |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
218 #define DEBUGF_END() gnulib::fflush (stderr); } while (0) |
4385 | 219 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
220 #define DEBUGF(str) \ |
10411 | 221 DEBUGF_START (); gnulib::fputs (str, stderr); DEBUGF_END () |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
222 #define DEBUGF1(str, e1) \ |
10411 | 223 DEBUGF_START (); gnulib::fprintf (stderr, str, e1); DEBUGF_END () |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
224 #define DEBUGF2(str, e1, e2) \ |
10411 | 225 DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2); DEBUGF_END () |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
226 #define DEBUGF3(str, e1, e2, e3) \ |
10411 | 227 DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2, e3); DEBUGF_END () |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
228 #define DEBUGF4(str, e1, e2, e3, e4) \ |
10411 | 229 DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2, e3, e4); DEBUGF_END () |
4385 | 230 |
231 #endif /* not NO_DEBUG */ | |
232 | |
4399 | 233 #ifdef KPSE_DEBUG |
234 static unsigned int kpathsea_debug = 0; | |
235 #endif | |
236 | |
4385 | 237 #if defined (WIN32) && !defined (__MINGW32__) |
238 | |
239 /* System description file for Windows NT. */ | |
240 | |
241 /* | |
242 * Define symbols to identify the version of Unix this is. | |
243 * Define all the symbols that apply correctly. | |
244 */ | |
245 | |
246 #ifndef DOSISH | |
247 #define DOSISH | |
248 #endif | |
249 | |
250 #ifndef MAXPATHLEN | |
251 #define MAXPATHLEN _MAX_PATH | |
4378 | 252 #endif |
253 | |
4385 | 254 /* These have to be defined because our compilers treat __STDC__ as being |
255 defined (most of them anyway). */ | |
256 | |
257 #define access _access | |
258 #define stat _stat | |
259 #define strdup _strdup | |
260 | |
261 #define S_IFMT _S_IFMT | |
262 #define S_IFDIR _S_IFDIR | |
263 | |
264 /* Define this so that winsock.h definitions don't get included when | |
265 windows.h is... For this to have proper effect, config.h must | |
4391 | 266 always be included before windows.h. */ |
4385 | 267 #define _WINSOCKAPI_ 1 |
268 | |
269 #include <windows.h> | |
270 | |
271 /* For proper declaration of environ. */ | |
272 #include <io.h> | |
273 #include <fcntl.h> | |
274 #include <process.h> | |
275 | |
276 /* ============================================================ */ | |
277 | |
278 #endif /* WIN32 */ | |
279 | |
280 /* Define common sorts of messages. */ | |
281 | |
282 /* This should be called only after a system call fails. Don't exit | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
283 with status 'errno', because that might be 256, which would mean |
4385 | 284 success (exit statuses are truncated to eight bits). */ |
4396 | 285 #define FATAL_PERROR(str) \ |
286 do \ | |
287 { \ | |
10411 | 288 gnulib::fputs ("pathsearch: ", stderr); \ |
4396 | 289 perror (str); exit (EXIT_FAILURE); \ |
290 } \ | |
291 while (0) | |
292 | |
293 #define FATAL(str) \ | |
294 do \ | |
295 { \ | |
10411 | 296 gnulib::fputs ("pathsearch: fatal: ", stderr); \ |
297 gnulib::fputs (str, stderr); \ | |
298 gnulib::fputs (".\n", stderr); \ | |
4396 | 299 exit (1); \ |
300 } \ | |
301 while (0) | |
4385 | 302 |
4386 | 303 #ifndef WIN32 |
4385 | 304 static void xclosedir (DIR *d); |
4386 | 305 #endif |
4385 | 306 |
4399 | 307 /* It's a little bizarre to be using the same type for the list and the |
308 elements of the list, but no reason not to in this case, I think -- | |
309 we never need a NULL string in the middle of the list, and an extra | |
310 NULL/NULL element always at the end is inconsequential. */ | |
311 | |
312 struct str_llist_elt | |
313 { | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
314 str_llist_elt (void) : str (), moved (0), next (0) { } |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
315 |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
316 ~str_llist_elt (void) { } |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
317 |
4399 | 318 std::string str; |
319 int moved; | |
320 struct str_llist_elt *next; | |
321 }; | |
322 | |
323 typedef str_llist_elt str_llist_elt_type; | |
324 typedef str_llist_elt *str_llist_type; | |
325 | |
326 #define STR_LLIST(sl) ((sl).str) | |
327 #define STR_LLIST_MOVED(sl) ((sl).moved) | |
328 #define STR_LLIST_NEXT(sl) ((sl).next) | |
329 | |
4390 | 330 static void str_llist_add (str_llist_type *l, const std::string& str); |
4385 | 331 |
332 static void str_llist_float (str_llist_type *l, str_llist_elt_type *mover); | |
333 | |
4389 | 334 static std::string kpse_var_expand (const std::string& src); |
4385 | 335 |
4399 | 336 static str_llist_type *kpse_element_dirs (const std::string& elt); |
337 | |
338 static std::string kpse_expand (const std::string& s); | |
339 | |
340 static std::string kpse_expand_default (const std::string& path, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
341 const std::string& dflt); |
4399 | 342 |
343 static string_vector kpse_db_search (const std::string& name, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
344 const std::string& path_elt, bool all); |
4399 | 345 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
346 #include <ctime> /* for 'time' */ |
4385 | 347 |
4399 | 348 static bool |
4394 | 349 kpse_is_env_sep (char c) |
350 { | |
351 return IS_ENV_SEP (c); | |
352 } | |
353 | |
4392 | 354 /* These routines just check the return status from standard library |
355 routines and abort if an error happens. */ | |
356 | |
357 static FILE * | |
4393 | 358 xfopen (const std::string& filename, const char *mode) |
4392 | 359 { |
360 FILE *f; | |
361 | |
4393 | 362 assert (! filename.empty () && mode); |
363 | |
14153 | 364 f = gnulib::fopen (filename.c_str (), mode); |
4393 | 365 |
366 if (! f) | |
367 FATAL_PERROR (filename.c_str ()); | |
4392 | 368 |
14153 | 369 if (KPSE_DEBUG_P (KPSE_DEBUG_FOPEN)) |
370 DEBUGF3 ("fopen (%s, %s) => 0x%lx\n", filename.c_str (), mode, | |
16314
0723ea02dcdb
use intptr_t instead of long
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
371 reinterpret_cast<intptr_t> (f)); |
14153 | 372 |
4392 | 373 return f; |
374 } | |
375 | |
376 /* A single (key,value) pair. */ | |
377 | |
378 struct hash_element_type | |
379 { | |
380 std::string key; | |
381 std::string value; | |
382 struct hash_element_type *next; | |
383 }; | |
384 | |
385 /* The usual arrangement of buckets initialized to null. */ | |
386 | |
387 struct hash_table_type | |
388 { | |
389 hash_element_type **buckets; | |
390 unsigned size; | |
391 }; | |
392 | |
393 static unsigned | |
5764 | 394 kpse_hash (hash_table_type table, const std::string& key) |
4392 | 395 { |
396 unsigned n = 0; | |
397 | |
398 /* Our keys aren't often anagrams of each other, so no point in | |
399 weighting the characters. */ | |
400 size_t len = key.length (); | |
401 for (size_t i = 0; i < len; i++) | |
4394 | 402 n = (n + n + key[i]) % table.size; |
4392 | 403 |
404 return n; | |
405 } | |
406 | |
407 /* Look up STR in MAP. Return a (dynamically-allocated) list of the | |
408 corresponding strings or NULL if no match. */ | |
409 | |
410 static string_vector | |
411 hash_lookup (hash_table_type table, const std::string& key) | |
412 { | |
413 hash_element_type *p; | |
414 string_vector ret; | |
5764 | 415 unsigned n = kpse_hash (table, key); |
4392 | 416 |
417 /* Look at everything in this bucket. */ | |
4398 | 418 for (p = table.buckets[n]; p; p = p->next) |
4394 | 419 if (key == p->key) |
4392 | 420 ret.append (p->value); |
421 | |
422 #ifdef KPSE_DEBUG | |
423 if (KPSE_DEBUG_P (KPSE_DEBUG_HASH)) | |
424 { | |
425 DEBUGF1 ("hash_lookup (%s) =>", key.c_str ()); | |
426 if (ret.empty ()) | |
10411 | 427 gnulib::fputs (" (nil)\n", stderr); |
4392 | 428 else |
429 { | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
430 int len = ret.length (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
431 for (int i = 0; i < len; i++) |
4392 | 432 { |
10411 | 433 gnulib::putc (' ', stderr); |
434 gnulib::fputs (ret[i].c_str (), stderr); | |
4392 | 435 } |
10411 | 436 gnulib::putc ('\n', stderr); |
4392 | 437 } |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
438 gnulib::fflush (stderr); |
4392 | 439 } |
440 #endif | |
441 | |
442 return ret; | |
443 } | |
444 | |
4399 | 445 /* A way to step through a path, extracting one directory name at a |
446 time. */ | |
447 | |
448 class kpse_path_iterator | |
449 { | |
450 public: | |
451 | |
452 kpse_path_iterator (const std::string& p) | |
453 : path (p), b (0), e (0), len (path.length ()) { set_end (); } | |
454 | |
455 kpse_path_iterator (const kpse_path_iterator& pi) | |
456 : path (pi.path), b (pi.b), e (pi.e), len (pi.len) { } | |
457 | |
458 kpse_path_iterator operator ++ (int) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
459 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
460 kpse_path_iterator retval (*this); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
461 next (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
462 return retval; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
463 } |
4399 | 464 |
465 std::string operator * (void) { return path.substr (b, e-b); } | |
466 | |
467 bool operator != (const size_t sz) { return b != sz; } | |
468 | |
469 private: | |
470 | |
471 const std::string& path; | |
472 size_t b; | |
473 size_t e; | |
474 size_t len; | |
475 | |
476 void set_end (void) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
477 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
478 e = b + 1; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
479 |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
480 if (e == len) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
481 ; /* OK, we have found the last element. */ |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
482 else if (e > len) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
483 b = e = std::string::npos; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
484 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
485 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
486 /* Find the next colon not enclosed by braces (or the end of |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
487 the path). */ |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
488 |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
489 int brace_level = 0; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
490 while (e < len && ! (brace_level == 0 && kpse_is_env_sep (path[e]))) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
491 e++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
492 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
493 } |
4399 | 494 |
495 void next (void) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
496 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
497 b = e + 1; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
498 |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
499 /* Skip any consecutive colons. */ |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
500 while (b < len && kpse_is_env_sep (path[b])) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
501 b++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
502 |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
503 if (b >= len) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
504 b = e = std::string::npos; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
505 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
506 set_end (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
507 } |
5617 | 508 |
509 // No assignment. | |
510 kpse_path_iterator& operator = (const kpse_path_iterator&); | |
4399 | 511 }; |
512 | |
4391 | 513 /* Here's the simple one, when a program just wants a value. */ |
514 | |
515 static std::string | |
516 kpse_var_value (const std::string& var) | |
517 { | |
518 std::string ret; | |
519 | |
520 std::string tmp = octave_env::getenv (var); | |
521 | |
522 if (! tmp.empty ()) | |
523 ret = kpse_var_expand (tmp); | |
524 | |
525 #ifdef KPSE_DEBUG | |
526 if (KPSE_DEBUG_P (KPSE_DEBUG_VARS)) | |
527 DEBUGF2 ("variable: %s = %s\n", var.c_str (), | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
528 tmp.empty () ? "(nil)" : tmp.c_str ()); |
4391 | 529 #endif |
530 | |
531 return ret; | |
532 } | |
533 | |
534 /* Truncate any too-long components in NAME, returning the result. It's | |
535 too bad this is necessary. See comments in readable.c for why. */ | |
536 | |
4393 | 537 static std::string |
538 kpse_truncate_filename (const std::string& name) | |
4391 | 539 { |
540 unsigned c_len = 0; /* Length of current component. */ | |
541 unsigned ret_len = 0; /* Length of constructed result. */ | |
542 | |
4393 | 543 std::string ret = name; |
544 | |
545 size_t len = name.length (); | |
546 | |
547 for (size_t i = 0; i < len; i++) | |
4391 | 548 { |
4393 | 549 if (IS_DIR_SEP (name[i]) || IS_DEVICE_SEP (name[i])) |
4391 | 550 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
551 /* At a directory delimiter, reset component length. */ |
4391 | 552 c_len = 0; |
553 } | |
554 else if (c_len > NAME_MAX) | |
555 { | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
556 /* If past the max for a component, ignore this character. */ |
4391 | 557 continue; |
558 } | |
559 | |
560 /* Copy this character. */ | |
4393 | 561 ret[ret_len++] = name[i]; |
4391 | 562 c_len++; |
563 } | |
564 | |
4393 | 565 ret.resize (ret_len); |
4391 | 566 |
567 return ret; | |
568 } | |
569 | |
570 /* If access can read FN, run stat (assigning to stat buffer ST) and | |
571 check that fn is not a directory. Don't check for just being a | |
572 regular file, as it is potentially useful to read fifo's or some | |
573 kinds of devices. */ | |
574 | |
575 #ifdef WIN32 | |
576 static inline bool | |
4393 | 577 READABLE (const std::string& fn, struct stat&) |
4391 | 578 { |
4393 | 579 const char *t = fn.c_str (); |
580 return (GetFileAttributes (t) != 0xFFFFFFFF | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
581 && ! (GetFileAttributes (t) & FILE_ATTRIBUTE_DIRECTORY)); |
4391 | 582 } |
583 #else | |
584 static inline bool | |
4393 | 585 READABLE (const std::string& fn, struct stat& st) |
4391 | 586 { |
4393 | 587 const char *t = fn.c_str (); |
588 return (access (t, R_OK) == 0 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
589 && stat (t, &(st)) == 0 && ! S_ISDIR (st.st_mode)); |
4391 | 590 } |
591 #endif | |
592 | |
593 /* POSIX invented the brain-damage of not necessarily truncating | |
594 filename components; the system's behavior is defined by the value of | |
595 the symbol _POSIX_NO_TRUNC, but you can't change it dynamically! | |
596 | |
597 Generic const return warning. See extend-fname.c. */ | |
598 | |
4393 | 599 static std::string |
600 kpse_readable_file (const std::string& name) | |
4391 | 601 { |
602 struct stat st; | |
4393 | 603 std::string ret; |
4391 | 604 |
605 if (READABLE (name, st)) | |
606 { | |
4393 | 607 ret = name; |
4391 | 608 |
609 #ifdef ENAMETOOLONG | |
610 } | |
611 else if (errno == ENAMETOOLONG) | |
612 { | |
613 ret = kpse_truncate_filename (name); | |
614 | |
615 /* Perhaps some other error will occur with the truncated name, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
616 so let's call access again. */ |
4391 | 617 |
618 if (! READABLE (ret, st)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
619 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
620 /* Failed. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
621 ret = std::string (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
622 } |
4391 | 623 #endif /* ENAMETOOLONG */ |
624 | |
625 } | |
626 else | |
627 { | |
628 /* Some other error. */ | |
629 if (errno == EACCES) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
630 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
631 /* Maybe warn them if permissions are bad. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
632 perror (name.c_str ()); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
633 } |
4393 | 634 |
635 ret = std::string (); | |
4391 | 636 } |
637 | |
638 return ret; | |
639 } | |
640 | |
641 /* Sorry this is such a system-dependent mess, but I can't see any way | |
642 to usefully generalize. */ | |
643 | |
644 static bool | |
645 kpse_absolute_p (const std::string& filename, int relative_ok) | |
646 { | |
647 size_t len = filename.length (); | |
648 | |
4409 | 649 int absolute = (len > 0 && IS_DIR_SEP (filename[0])) |
4391 | 650 #ifdef DOSISH |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
651 /* Novell allows non-alphanumeric drive letters. */ |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
652 || (len > 0 && IS_DEVICE_SEP (filename[1])) |
4391 | 653 #endif /* DOSISH */ |
654 #ifdef WIN32 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
655 /* UNC names */ |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
656 || (len > 1 && filename[0] == '\\' && filename[1] == '\\') |
4391 | 657 #endif |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
658 ; |
4409 | 659 |
4391 | 660 int explicit_relative |
661 = relative_ok | |
662 && (len > 1 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
663 && filename[0] == '.' |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
664 && (IS_DIR_SEP (filename[1]) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
665 || (len > 2 && filename[1] == '.' && IS_DIR_SEP (filename[2])))); |
4391 | 666 |
667 return absolute || explicit_relative; | |
668 } | |
669 | |
4378 | 670 /* The very first search is for texmf.cnf, called when someone tries to |
671 initialize the TFM path or whatever. init_path calls kpse_cnf_get | |
672 which calls kpse_all_path_search to find all the texmf.cnf's. We | |
673 need to do various special things in this case, since we obviously | |
674 don't yet have the configuration files when we're searching for the | |
675 configuration files. */ | |
676 static bool first_search = true; | |
677 | |
678 /* This function is called after every search (except the first, since | |
679 we definitely want to allow enabling the logging in texmf.cnf) to | |
680 record the filename(s) found in $TEXMFLOG. */ | |
681 | |
682 static void | |
4391 | 683 log_search (const string_vector& filenames) |
4378 | 684 { |
4398 | 685 static FILE *log_file = 0; |
4378 | 686 static bool first_time = true; /* Need to open the log file? */ |
4391 | 687 |
688 if (first_time) | |
689 { | |
690 first_time = false; | |
691 | |
692 /* Get name from either envvar or config file. */ | |
693 std::string log_name = kpse_var_value ("TEXMFLOG"); | |
694 | |
695 if (! log_name.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
696 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
697 log_file = xfopen (log_name.c_str (), "a"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
698 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
699 if (! log_file) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
700 perror (log_name.c_str ()); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
701 } |
4378 | 702 } |
4391 | 703 |
704 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH) || log_file) | |
705 { | |
706 /* FILENAMES should never be null, but safety doesn't hurt. */ | |
707 for (int e = 0; e < filenames.length () && ! filenames[e].empty (); e++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
708 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
709 std::string filename = filenames[e]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
710 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
711 /* Only record absolute filenames, for privacy. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
712 if (log_file && kpse_absolute_p (filename.c_str (), false)) |
10411 | 713 gnulib::fprintf (log_file, "%lu %s\n", |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
714 static_cast<unsigned long> (time (0)), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
715 filename.c_str ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
716 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
717 /* And show them online, if debugging. We've already started |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
718 the debugging line in 'search', where this is called, so |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
719 just print the filename here, don't use DEBUGF. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
720 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) |
10411 | 721 gnulib::fputs (filename.c_str (), stderr); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
722 } |
4378 | 723 } |
724 } | |
4392 | 725 |
4378 | 726 /* Concatenate each element in DIRS with NAME (assume each ends with a |
727 /, to save time). If SEARCH_ALL is false, return the first readable | |
728 regular file. Else continue to search for more. In any case, if | |
729 none, return a list containing just NULL. | |
730 | |
731 We keep a single buffer for the potential filenames and reallocate | |
732 only when necessary. I'm not sure it's noticeably faster, but it | |
733 does seem cleaner. (We do waste a bit of space in the return | |
734 value, though, since we don't shrink it to the final size returned.) */ | |
735 | |
4390 | 736 static string_vector |
737 dir_list_search (str_llist_type *dirs, const std::string& name, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
738 bool search_all) |
4378 | 739 { |
740 str_llist_elt_type *elt; | |
4390 | 741 string_vector ret; |
4378 | 742 |
743 for (elt = *dirs; elt; elt = STR_LLIST_NEXT (*elt)) | |
744 { | |
4390 | 745 const std::string dir = STR_LLIST (*elt); |
4393 | 746 |
747 std::string potential = dir + name; | |
748 | |
749 std::string tmp = kpse_readable_file (potential); | |
750 | |
751 if (! tmp.empty ()) | |
4378 | 752 { |
4393 | 753 ret.append (potential); |
4391 | 754 |
4378 | 755 /* Move this element towards the top of the list. */ |
756 str_llist_float (dirs, elt); | |
4391 | 757 |
758 if (! search_all) | |
4378 | 759 return ret; |
760 } | |
761 } | |
4391 | 762 |
4378 | 763 return ret; |
764 } | |
4392 | 765 |
4378 | 766 /* This is called when NAME is absolute or explicitly relative; if it's |
767 readable, return (a list containing) it; otherwise, return NULL. */ | |
768 | |
4390 | 769 static string_vector |
4393 | 770 absolute_search (const std::string& name) |
4378 | 771 { |
4390 | 772 string_vector ret_list; |
4393 | 773 std::string found = kpse_readable_file (name); |
4391 | 774 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
775 /* Add 'found' to the return list even if it's null; that tells |
4378 | 776 the caller we didn't find anything. */ |
4394 | 777 ret_list.append (found); |
4391 | 778 |
4378 | 779 return ret_list; |
780 } | |
4392 | 781 |
4378 | 782 /* This is the hard case -- look for NAME in PATH. If ALL is false, |
783 return the first file found. Otherwise, search all elements of PATH. */ | |
784 | |
4390 | 785 static string_vector |
4394 | 786 path_search (const std::string& path, const std::string& name, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
787 bool /* must_exist */, bool all) |
4378 | 788 { |
4390 | 789 string_vector ret_list; |
4378 | 790 bool done = false; |
4390 | 791 |
8021 | 792 for (kpse_path_iterator pi (path); ! done && pi != std::string::npos; pi++) |
4390 | 793 { |
4394 | 794 std::string elt = *pi; |
795 | |
4390 | 796 string_vector found; |
797 bool allow_disk_search = true; | |
798 | |
4394 | 799 if (elt.length () > 1 && elt[0] == '!' && elt[1] == '!') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
800 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
801 /* Those magic leading chars in a path element means don't |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
802 search the disk for this elt. And move past the magic to |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
803 get to the name. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
804 allow_disk_search = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
805 elt = elt.substr (2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
806 } |
4390 | 807 |
808 /* Do not touch the device if present */ | |
809 if (NAME_BEGINS_WITH_DEVICE (elt)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
810 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
811 while (elt.length () > 3 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
812 && IS_DIR_SEP (elt[2]) && IS_DIR_SEP (elt[3])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
813 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
814 elt[2] = elt[1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
815 elt[1] = elt[0]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
816 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
817 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
818 } |
4390 | 819 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
820 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
821 /* We never want to search the whole disk. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
822 while (elt.length () > 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
823 && IS_DIR_SEP (elt[0]) && IS_DIR_SEP (elt[1])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
824 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
825 } |
4391 | 826 |
4390 | 827 /* Try ls-R, unless we're searching for texmf.cnf. Our caller |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
828 (search), also tests first_search, and does the resetting. */ |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
829 found = first_search ? string_vector () : kpse_db_search (name, elt, all); |
4390 | 830 |
831 /* Search the filesystem if (1) the path spec allows it, and either | |
4378 | 832 (2a) we are searching for texmf.cnf ; or |
4391 | 833 (2b) no db exists; or |
4378 | 834 (2c) no db's are relevant to this elt; or |
835 (3) MUST_EXIST && NAME was not in the db. | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
836 In (2*), 'found' will be NULL. |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
837 In (3), 'found' will be an empty list. */ |
4390 | 838 |
839 if (allow_disk_search && found.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
840 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
841 str_llist_type *dirs = kpse_element_dirs (elt); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
842 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
843 if (dirs && *dirs) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
844 found = dir_list_search (dirs, name, all); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
845 } |
4390 | 846 |
847 /* Did we find anything anywhere? */ | |
848 if (! found.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
849 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
850 if (all) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
851 ret_list.append (found); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
852 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
853 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
854 ret_list.append (found[0]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
855 done = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
856 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
857 } |
4378 | 858 } |
859 | |
860 return ret_list; | |
4390 | 861 } |
4392 | 862 |
4378 | 863 /* Search PATH for ORIGINAL_NAME. If ALL is false, or ORIGINAL_NAME is |
864 absolute_p, check ORIGINAL_NAME itself. Otherwise, look at each | |
865 element of PATH for the first readable ORIGINAL_NAME. | |
4391 | 866 |
4378 | 867 Always return a list; if no files are found, the list will |
868 contain just NULL. If ALL is true, the list will be | |
869 terminated with NULL. */ | |
870 | |
4390 | 871 static string_vector |
872 search (const std::string& path, const std::string& original_name, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
873 bool must_exist, bool all) |
4378 | 874 { |
4390 | 875 string_vector ret_list; |
4378 | 876 bool absolute_p; |
877 | |
878 /* Make a leading ~ count as an absolute filename, and expand $FOO's. */ | |
4390 | 879 std::string name = kpse_expand (original_name); |
4391 | 880 |
4378 | 881 /* If the first name is absolute or explicitly relative, no need to |
882 consider PATH at all. */ | |
883 absolute_p = kpse_absolute_p (name, true); | |
4391 | 884 |
4378 | 885 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) |
4391 | 886 DEBUGF4 ("start search (file=%s, must_exist=%d, find_all=%d, path=%s).\n", |
4390 | 887 name.c_str (), must_exist, all, path.c_str ()); |
4378 | 888 |
889 /* Find the file(s). */ | |
890 ret_list = absolute_p ? absolute_search (name) | |
891 : path_search (path, name, must_exist, all); | |
4391 | 892 |
4378 | 893 /* The very first search is for texmf.cnf. We can't log that, since |
894 we want to allow setting TEXMFLOG in texmf.cnf. */ | |
4391 | 895 if (first_search) |
896 { | |
897 first_search = false; | |
898 } | |
899 else | |
900 { | |
901 /* Record the filenames we found, if desired. And wrap them in a | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
902 debugging line if we're doing that. */ |
4391 | 903 |
904 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
905 DEBUGF1 ("search (%s) =>", original_name.c_str ()); |
4391 | 906 |
907 log_search (ret_list); | |
908 | |
909 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
10411 | 910 gnulib::putc ('\n', stderr); |
4391 | 911 } |
4378 | 912 |
4390 | 913 return ret_list; |
4378 | 914 } |
4392 | 915 |
4378 | 916 /* Search PATH for the first NAME. */ |
917 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
918 /* Call 'kpse_expand' on NAME. If the result is an absolute or |
4399 | 919 explicitly relative filename, check whether it is a readable |
920 (regular) file. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
921 |
4399 | 922 Otherwise, look in each of the directories specified in PATH (also do |
923 tilde and variable expansion on elements in PATH), using a prebuilt | |
924 db (see db.h) if it's relevant for a given path element. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
925 |
4399 | 926 If the prebuilt db doesn't exist, or if MUST_EXIST is true and NAME |
927 isn't found in the prebuilt db, look on the filesystem. (I.e., if | |
928 MUST_EXIST is false, and NAME isn't found in the db, do *not* look on | |
929 the filesystem.) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
930 |
4399 | 931 The caller must expand PATH. This is because it makes more sense to |
932 do this once, in advance, instead of for every search using it. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
933 |
4399 | 934 In any case, return the complete filename if found, otherwise NULL. */ |
935 | |
936 static std::string | |
4390 | 937 kpse_path_search (const std::string& path, const std::string& name, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
938 bool must_exist) |
4378 | 939 { |
4390 | 940 string_vector ret_list = search (path, name, must_exist, false); |
941 | |
942 return ret_list.empty () ? std::string () : ret_list[0]; | |
4378 | 943 } |
944 | |
945 /* Search all elements of PATH for files named NAME. Not sure if it's | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
946 right to assert 'must_exist' here, but it suffices now. */ |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
947 |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
948 /* Like 'kpse_path_search' with MUST_EXIST true, but return a list of |
4399 | 949 all the filenames (or NULL if none), instead of taking the first. */ |
950 | |
951 static string_vector | |
4390 | 952 kpse_all_path_search (const std::string& path, const std::string& name) |
4378 | 953 { |
4390 | 954 return search (path, name, true, true); |
4378 | 955 } |
4392 | 956 |
4378 | 957 /* This is the hard case -- look in each element of PATH for each |
958 element of NAMES. If ALL is false, return the first file found. | |
959 Otherwise, search all elements of PATH. */ | |
960 | |
4390 | 961 static string_vector |
4394 | 962 path_find_first_of (const std::string& path, const string_vector& names, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
963 bool /* must_exist */, bool all) |
4378 | 964 { |
4390 | 965 string_vector ret_list; |
4378 | 966 bool done = false; |
4390 | 967 |
8021 | 968 for (kpse_path_iterator pi (path); ! done && pi != std::string::npos; pi++) |
4378 | 969 { |
4394 | 970 std::string elt = *pi; |
971 | |
4378 | 972 str_llist_type *dirs; |
973 str_llist_elt_type *dirs_elt; | |
4390 | 974 string_vector found; |
4378 | 975 bool allow_disk_search = true; |
976 | |
4394 | 977 if (elt.length () > 1 && elt[0] == '!' && elt[1] == '!') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
978 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
979 /* Those magic leading chars in a path element means don't |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
980 search the disk for this elt. And move past the magic to |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
981 get to the name. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
982 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
983 allow_disk_search = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
984 elt = elt.substr (2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
985 } |
4378 | 986 |
987 /* Do not touch the device if present */ | |
988 | |
989 if (NAME_BEGINS_WITH_DEVICE (elt)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
990 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
991 while (elt.length () > 3 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
992 && IS_DIR_SEP (elt[2]) && IS_DIR_SEP (elt[3])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
993 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
994 elt[2] = elt[1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
995 elt[1] = elt[0]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
996 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
997 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
998 } |
4378 | 999 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1000 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1001 /* We never want to search the whole disk. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1002 while (elt.length () > 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1003 && IS_DIR_SEP (elt[0]) && IS_DIR_SEP (elt[1])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1004 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1005 } |
4378 | 1006 |
1007 /* We have to search one directory at a time. */ | |
1008 dirs = kpse_element_dirs (elt); | |
1009 for (dirs_elt = *dirs; dirs_elt; dirs_elt = STR_LLIST_NEXT (*dirs_elt)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1010 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1011 const std::string dir = STR_LLIST (*dirs_elt); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1012 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1013 int len = names.length (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1014 for (int i = 0; i < len && !done; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1015 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1016 std::string name = names[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1017 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1018 /* Try ls-R, unless we're searching for texmf.cnf. Our caller |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1019 (find_first_of), also tests first_search, and does the |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1020 resetting. */ |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1021 found = first_search ? string_vector () |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1022 : kpse_db_search (name, dir.c_str (), all); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1023 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1024 /* Search the filesystem if (1) the path spec allows it, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1025 and either |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1026 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1027 (2a) we are searching for texmf.cnf ; or |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1028 (2b) no db exists; or |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1029 (2c) no db's are relevant to this elt; or |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1030 (3) MUST_EXIST && NAME was not in the db. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1031 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1032 In (2*), 'found' will be NULL. |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1033 In (3), 'found' will be an empty list. */ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1034 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1035 if (allow_disk_search && found.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1036 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1037 static str_llist_type *tmp = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1038 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1039 if (! tmp) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1040 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1041 tmp = new str_llist_type; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1042 *tmp = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1043 str_llist_add (tmp, ""); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1044 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1045 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1046 STR_LLIST (*(*tmp)) = dir; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1047 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1048 found = dir_list_search (tmp, name, all); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1049 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1050 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1051 /* Did we find anything anywhere? */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1052 if (! found.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1053 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1054 if (all) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1055 ret_list.append (found); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1056 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1057 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1058 ret_list.append (found[0]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1059 done = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1060 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1061 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1062 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1063 } |
4378 | 1064 } |
1065 | |
1066 return ret_list; | |
4391 | 1067 } |
4378 | 1068 |
4390 | 1069 static string_vector |
1070 find_first_of (const std::string& path, const string_vector& names, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1071 bool must_exist, bool all) |
4378 | 1072 { |
4390 | 1073 string_vector ret_list; |
4378 | 1074 |
1075 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
1076 { | |
10411 | 1077 gnulib::fputs ("start find_first_of ((", stderr); |
4391 | 1078 |
4390 | 1079 int len = names.length (); |
4391 | 1080 |
4390 | 1081 for (int i = 0; i < len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1082 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1083 if (i == 0) |
10411 | 1084 gnulib::fputs (names[i].c_str (), stderr); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1085 else |
10411 | 1086 gnulib::fprintf (stderr, ", %s", names[i].c_str ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1087 } |
4391 | 1088 |
10411 | 1089 gnulib::fprintf (stderr, "), path=%s, must_exist=%d).\n", |
1090 path.c_str (), must_exist); | |
4378 | 1091 } |
1092 | |
4409 | 1093 for (int i = 0; i < names.length (); i++) |
1094 { | |
1095 std::string name = names[i]; | |
1096 | |
1097 if (kpse_absolute_p (name, true)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1098 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1099 /* If the name is absolute or explicitly relative, no need |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1100 to consider PATH at all. If we find something, then we |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1101 are done. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1102 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1103 ret_list = absolute_search (name); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1104 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1105 if (! ret_list.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1106 return ret_list; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1107 } |
4409 | 1108 } |
1109 | |
4378 | 1110 /* Find the file. */ |
1111 ret_list = path_find_first_of (path, names, must_exist, all); | |
1112 | |
1113 /* The very first search is for texmf.cnf. We can't log that, since | |
1114 we want to allow setting TEXMFLOG in texmf.cnf. */ | |
4391 | 1115 if (first_search) |
1116 { | |
1117 first_search = false; | |
1118 } | |
1119 else | |
1120 { | |
1121 /* Record the filenames we found, if desired. And wrap them in a | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1122 debugging line if we're doing that. */ |
4391 | 1123 |
1124 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1125 { |
10411 | 1126 gnulib::fputs ("find_first_of (", stderr); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1127 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1128 int len = names.length (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1129 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1130 for (int i = 0; i < len; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1131 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1132 if (i == 0) |
10411 | 1133 gnulib::fputs (names[i].c_str (), stderr); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1134 else |
10411 | 1135 gnulib::fprintf (stderr, ", %s", names[i].c_str ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1136 } |
10411 | 1137 |
1138 gnulib::fputs (") =>", stderr); | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1139 } |
4391 | 1140 |
1141 log_search (ret_list); | |
1142 | |
1143 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
10411 | 1144 gnulib::putc ('\n', stderr); |
4391 | 1145 } |
4378 | 1146 |
4390 | 1147 return ret_list; |
4378 | 1148 } |
1149 | |
1150 /* Search each element of PATH for each element of NAMES. Return the | |
1151 first one found. */ | |
1152 | |
4399 | 1153 /* Search each element of PATH for each element in the list of NAMES. |
1154 Return the first one found. */ | |
1155 | |
1156 static std::string | |
4390 | 1157 kpse_path_find_first_of (const std::string& path, const string_vector& names, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1158 bool must_exist) |
4378 | 1159 { |
4390 | 1160 string_vector ret_list = find_first_of (path, names, must_exist, false); |
1161 | |
1162 return ret_list.empty () ? std::string () : ret_list[0]; | |
4378 | 1163 } |
1164 | |
1165 /* Search each element of PATH for each element of NAMES and return a | |
1166 list containing everything found, in the order found. */ | |
1167 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1168 /* Like 'kpse_path_find_first_of' with MUST_EXIST true, but return a |
4399 | 1169 list of all the filenames (or NULL if none), instead of taking the |
1170 first. */ | |
1171 | |
1172 static string_vector | |
4390 | 1173 kpse_all_path_find_first_of (const std::string& path, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1174 const string_vector& names) |
4378 | 1175 { |
4390 | 1176 return find_first_of (path, names, true, true); |
4378 | 1177 } |
1178 | |
4399 | 1179 /* General expansion. Some of this file (the brace-expansion |
4378 | 1180 code from bash) is covered by the GPL; this is the only GPL-covered |
1181 code in kpathsea. The part of the file that I wrote (the first | |
1182 couple of functions) is covered by the LGPL. */ | |
1183 | |
1184 /* If NAME has a leading ~ or ~user, Unix-style, expand it to the user's | |
1185 home directory, and return a new malloced string. If no ~, or no | |
1186 <pwd.h>, just return NAME. */ | |
1187 | |
4389 | 1188 static std::string |
1189 kpse_tilde_expand (const std::string& name) | |
4378 | 1190 { |
4389 | 1191 std::string expansion; |
4391 | 1192 |
4378 | 1193 /* If no leading tilde, do nothing. */ |
5137 | 1194 if (name.empty () || name[0] != '~') |
4391 | 1195 { |
1196 expansion = name; | |
1197 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1198 /* If a bare tilde, return the home directory or '.'. (Very |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1199 unlikely that the directory name will do anyone any good, but |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1200 ... */ |
4391 | 1201 } |
1202 else if (name.length () == 1) | |
1203 { | |
20052
4b7b7ac7af2c
use get_home_directory instead of getenv ("HOME") (bug #44694)
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
1204 expansion = octave_env::get_home_directory (); |
4391 | 1205 |
1206 if (expansion.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1207 expansion = "."; |
4391 | 1208 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1209 /* If '~/', remove any trailing / or replace leading // in $HOME. |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1210 Should really check for doubled intermediate slashes, too. */ |
4378 | 1211 } |
4391 | 1212 else if (IS_DIR_SEP (name[1])) |
1213 { | |
1214 unsigned c = 1; | |
20052
4b7b7ac7af2c
use get_home_directory instead of getenv ("HOME") (bug #44694)
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
1215 std::string home = octave_env::get_home_directory (); |
4391 | 1216 |
1217 if (home.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1218 home = "."; |
4391 | 1219 |
1220 size_t home_len = home.length (); | |
1221 | |
1222 /* handle leading // */ | |
1223 if (home_len > 1 && IS_DIR_SEP (home[0]) && IS_DIR_SEP (home[1])) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1224 home = home.substr (1); |
4391 | 1225 |
1226 /* omit / after ~ */ | |
1227 if (IS_DIR_SEP (home[home_len - 1])) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1228 c++; |
4391 | 1229 |
1230 expansion = home + name.substr (c); | |
1231 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1232 /* If '~user' or '~user/', look up user in the passwd database (but |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1233 OS/2 doesn't have this concept. */ |
4378 | 1234 } |
4391 | 1235 else |
4378 | 1236 #ifdef HAVE_PWD_H |
1237 { | |
1238 unsigned c = 2; | |
4391 | 1239 |
1240 /* find user name */ | |
1241 while (name.length () > c && ! IS_DIR_SEP (name[c])) | |
4378 | 1242 c++; |
4391 | 1243 |
1244 std::string user = name.substr (1, c-1); | |
1245 | |
4378 | 1246 /* We only need the cast here for (deficient) systems |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1247 which do not declare 'getpwnam' in <pwd.h>. */ |
4391 | 1248 octave_passwd p = octave_passwd::getpwnam (user); |
4378 | 1249 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1250 /* If no such user, just use '.'. */ |
4391 | 1251 std::string home = p ? p.dir () : std::string ("."); |
1252 | |
1253 if (home.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1254 home = "."; |
4391 | 1255 |
1256 /* handle leading // */ | |
1257 if (home.length () > 1 && IS_DIR_SEP (home[0]) && IS_DIR_SEP (home[1])) | |
1258 home = home.substr (1); | |
1259 | |
1260 /* If HOME ends in /, omit the / after ~user. */ | |
1261 if (name.length () > c && IS_DIR_SEP (home[home.length () - 1])) | |
1262 c++; | |
1263 | |
1264 expansion = name.length () > c ? home : home + name.substr (c); | |
4378 | 1265 } |
1266 #else /* not HAVE_PWD_H */ | |
4391 | 1267 expansion = name; |
4378 | 1268 #endif /* not HAVE_PWD_H */ |
1269 | |
4389 | 1270 return expansion; |
4378 | 1271 } |
1272 | |
1273 /* Do variable expansion first so ~${USER} works. (Besides, it's what the | |
1274 shells do.) */ | |
1275 | |
4399 | 1276 /* Call kpse_var_expand and kpse_tilde_expand (in that order). Result |
1277 is always in fresh memory, even if no expansions were done. */ | |
1278 | |
1279 static std::string | |
4389 | 1280 kpse_expand (const std::string& s) |
4378 | 1281 { |
4389 | 1282 std::string var_expansion = kpse_var_expand (s); |
1283 return kpse_tilde_expand (var_expansion); | |
4378 | 1284 } |
1285 | |
1286 /* Forward declarations of functions from the original expand.c */ | |
4397 | 1287 static string_vector brace_expand (const std::string&); |
4378 | 1288 |
1289 /* If $KPSE_DOT is defined in the environment, prepend it to any relative | |
1290 path components. */ | |
1291 | |
4389 | 1292 static std::string |
1293 kpse_expand_kpse_dot (const std::string& path) | |
4378 | 1294 { |
4389 | 1295 std::string ret; |
4391 | 1296 std::string kpse_dot = octave_env::getenv ("KPSE_DOT"); |
1297 | |
1298 if (kpse_dot.empty ()) | |
4378 | 1299 return path; |
1300 | |
8021 | 1301 for (kpse_path_iterator pi (path); pi != std::string::npos; pi++) |
4391 | 1302 { |
4394 | 1303 std::string elt = *pi; |
1304 | |
4391 | 1305 /* We assume that the !! magic is only used on absolute components. |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1306 Single "." get special treatment, as does "./" or its equivalent. */ |
4391 | 1307 |
4394 | 1308 size_t elt_len = elt.length (); |
1309 | |
1310 if (kpse_absolute_p (elt, false) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1311 || (elt_len > 1 && elt[0] == '!' && elt[1] == '!')) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1312 ret += elt + ENV_SEP_STRING; |
4394 | 1313 else if (elt_len == 1 && elt[0] == '.') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1314 ret += kpse_dot + ENV_SEP_STRING; |
4394 | 1315 else if (elt_len > 1 && elt[0] == '.' && IS_DIR_SEP (elt[1])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1316 ret += kpse_dot + elt.substr (1) + ENV_SEP_STRING; |
4391 | 1317 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1318 ret += kpse_dot + DIR_SEP_STRING + elt + ENV_SEP_STRING; |
4378 | 1319 } |
1320 | |
4389 | 1321 int len = ret.length (); |
1322 if (len > 0) | |
4395 | 1323 ret.resize (len-1); |
4389 | 1324 |
4378 | 1325 return ret; |
1326 } | |
1327 | |
1328 /* Do brace expansion on ELT; then do variable and ~ expansion on each | |
1329 element of the result; then do brace expansion again, in case a | |
1330 variable definition contained braces (e.g., $TEXMF). Return a | |
1331 string comprising all of the results separated by ENV_SEP_STRING. */ | |
1332 | |
4389 | 1333 static std::string |
4394 | 1334 kpse_brace_expand_element (const std::string& elt) |
4378 | 1335 { |
4389 | 1336 std::string ret; |
4378 | 1337 |
4397 | 1338 string_vector expansions = brace_expand (elt); |
1339 | |
1340 for (int i = 0; i < expansions.length (); i++) | |
4391 | 1341 { |
1342 /* Do $ and ~ expansion on each element. */ | |
1343 std::string x = kpse_expand (expansions[i]); | |
1344 | |
1345 if (x != expansions[i]) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1346 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1347 /* If we did any expansions, do brace expansion again. Since |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1348 recursive variable definitions are not allowed, this recursion |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1349 must terminate. (In practice, it's unlikely there will ever be |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1350 more than one level of recursion.) */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1351 x = kpse_brace_expand_element (x); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1352 } |
4391 | 1353 |
1354 ret += x + ENV_SEP_STRING; | |
4378 | 1355 } |
1356 | |
4389 | 1357 ret.resize (ret.length () - 1); |
4391 | 1358 |
4378 | 1359 return ret; |
1360 } | |
1361 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1362 /* Do brace expansion and call 'kpse_expand' on each element of the |
4399 | 1363 result; return the final expansion (always in fresh memory, even if |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1364 no expansions were done). We don't call 'kpse_expand_default' |
4399 | 1365 because there is a whole sequence of defaults to run through; see |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1366 'kpse_init_format'. */ |
4399 | 1367 |
1368 static std::string | |
4397 | 1369 kpse_brace_expand (const std::string& path) |
4378 | 1370 { |
1371 /* Must do variable expansion first because if we have | |
1372 foo = .:~ | |
1373 TEXINPUTS = $foo | |
1374 we want to end up with TEXINPUTS = .:/home/karl. | |
1375 Since kpse_path_element is not reentrant, we must get all | |
1376 the path elements before we start the loop. */ | |
4389 | 1377 std::string tmp = kpse_var_expand (path); |
4394 | 1378 |
4389 | 1379 std::string ret; |
4378 | 1380 |
8021 | 1381 for (kpse_path_iterator pi (tmp); pi != std::string::npos; pi++) |
4391 | 1382 { |
4394 | 1383 std::string elt = *pi; |
1384 | |
4391 | 1385 /* Do brace expansion first, so tilde expansion happens in {~ka,~kb}. */ |
1386 std::string expansion = kpse_brace_expand_element (elt); | |
1387 ret += expansion + ENV_SEP_STRING; | |
1388 } | |
4378 | 1389 |
4394 | 1390 size_t len = ret.length (); |
4389 | 1391 if (len > 0) |
4395 | 1392 ret.resize (len-1); |
4389 | 1393 |
1394 return kpse_expand_kpse_dot (ret); | |
4378 | 1395 } |
4392 | 1396 |
4378 | 1397 /* Expand all special constructs in a path, and include only the actually |
1398 existing directories in the result. */ | |
4399 | 1399 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1400 /* Do brace expansion and call 'kpse_expand' on each argument of the |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1401 result, then expand any '//' constructs. The final expansion (always |
4399 | 1402 in fresh memory) is a path of all the existing directories that match |
1403 the pattern. */ | |
1404 | |
1405 static std::string | |
4397 | 1406 kpse_path_expand (const std::string& path) |
4378 | 1407 { |
4392 | 1408 std::string ret; |
4378 | 1409 unsigned len; |
1410 | |
1411 len = 0; | |
4391 | 1412 |
4378 | 1413 /* Expand variables and braces first. */ |
4389 | 1414 std::string tmp = kpse_brace_expand (path); |
4392 | 1415 |
4378 | 1416 /* Now expand each of the path elements, printing the results */ |
8021 | 1417 for (kpse_path_iterator pi (tmp); pi != std::string::npos; pi++) |
4391 | 1418 { |
4394 | 1419 std::string elt = *pi; |
1420 | |
4391 | 1421 str_llist_type *dirs; |
1422 | |
1423 /* Skip and ignore magic leading chars. */ | |
4394 | 1424 if (elt.length () > 1 && elt[0] == '!' && elt[1] == '!') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1425 elt = elt.substr (2); |
4391 | 1426 |
1427 /* Do not touch the device if present */ | |
1428 if (NAME_BEGINS_WITH_DEVICE (elt)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1429 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1430 while (elt.length () > 3 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1431 && IS_DIR_SEP (elt[2]) && IS_DIR_SEP (elt[3])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1432 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1433 elt[2] = elt[1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1434 elt[1] = elt[0]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1435 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1436 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1437 } |
4391 | 1438 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1439 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1440 /* We never want to search the whole disk. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1441 while (elt.length () > 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1442 && IS_DIR_SEP (elt[0]) && IS_DIR_SEP (elt[1])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1443 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1444 } |
4378 | 1445 |
4394 | 1446 /* Search the disk for all dirs in the component specified. |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1447 Be faster to check the database, but this is more reliable. */ |
4394 | 1448 dirs = kpse_element_dirs (elt); |
1449 | |
1450 if (dirs && *dirs) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1451 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1452 str_llist_elt_type *dir; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1453 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1454 for (dir = *dirs; dir; dir = STR_LLIST_NEXT (*dir)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1455 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1456 const std::string thedir = STR_LLIST (*dir); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1457 unsigned dirlen = thedir.length (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1458 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1459 ret += thedir; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1460 len += dirlen; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1461 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1462 /* Retain trailing slash if that's the root directory. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1463 if (dirlen == 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1464 || (dirlen == 3 && NAME_BEGINS_WITH_DEVICE (thedir) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1465 && IS_DIR_SEP (thedir[2]))) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1466 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1467 ret += ENV_SEP_STRING; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1468 len++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1469 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1470 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1471 ret[len-1] = ENV_SEP; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1472 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1473 } |
4378 | 1474 } |
4391 | 1475 |
4395 | 1476 if (len > 0) |
1477 ret.resize (len-1); | |
4391 | 1478 |
4378 | 1479 return ret; |
1480 } | |
4392 | 1481 |
4378 | 1482 /* braces.c -- code for doing word expansion in curly braces. Taken from |
16768 | 1483 bash 1.14.5. [And subsequently modified for kpatshea.] |
1484 | |
1485 Copyright (C) 1987,1991 Free Software Foundation, Inc. */ | |
4378 | 1486 |
4391 | 1487 #define brace_whitespace(c) (! (c) || (c) == ' ' || (c) == '\t' || (c) == '\n') |
4378 | 1488 |
1489 /* Basic idea: | |
1490 | |
1491 Segregate the text into 3 sections: preamble (stuff before an open brace), | |
1492 postamble (stuff after the matching close brace) and amble (stuff after | |
1493 preamble, and before postamble). Expand amble, and then tack on the | |
1494 expansions to preamble. Expand postamble, and tack on the expansions to | |
4391 | 1495 the result so far. */ |
4378 | 1496 |
4397 | 1497 /* Return a new array of strings which is the result of appending each |
1498 string in ARR2 to each string in ARR1. The resultant array is | |
1499 len (arr1) * len (arr2) long. For convenience, ARR1 (and its contents) | |
1500 are free ()'ed. ARR1 can be NULL, in that case, a new version of ARR2 | |
1501 is returned. */ | |
1502 | |
1503 static string_vector | |
1504 array_concat (const string_vector& arr1, const string_vector& arr2) | |
4378 | 1505 { |
4397 | 1506 string_vector result; |
1507 | |
1508 if (arr1.empty ()) | |
1509 result = arr2; | |
1510 else if (arr2.empty ()) | |
1511 result = arr1; | |
1512 else | |
1513 { | |
1514 int len1 = arr1.length (); | |
1515 int len2 = arr2.length (); | |
1516 | |
1517 result = string_vector (len1 * len2); | |
1518 | |
1519 int k = 0; | |
1520 for (int i = 0; i < len2; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1521 for (int j = 0; j < len1; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1522 result[k++] = arr1[j] + arr2[i]; |
4397 | 1523 } |
1524 | |
1525 return result; | |
4378 | 1526 } |
1527 | |
4397 | 1528 static int brace_gobbler (const std::string&, int&, int); |
1529 static string_vector expand_amble (const std::string&); | |
4378 | 1530 |
1531 /* Return an array of strings; the brace expansion of TEXT. */ | |
4397 | 1532 static string_vector |
1533 brace_expand (const std::string& text) | |
4378 | 1534 { |
1535 /* Find the text of the preamble. */ | |
4397 | 1536 int i = 0; |
1537 int c = brace_gobbler (text, i, '{'); | |
1538 | |
1539 std::string preamble = text.substr (0, i); | |
1540 | |
1541 string_vector result = string_vector (preamble); | |
1542 | |
1543 if (c == '{') | |
4378 | 1544 { |
4397 | 1545 /* Find the amble. This is the stuff inside this set of braces. */ |
1546 int start = ++i; | |
1547 c = brace_gobbler (text, i, '}'); | |
1548 | |
1549 /* What if there isn't a matching close brace? */ | |
1550 if (! c) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1551 { |
19444
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1552 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1553 ("Octave:pathsearch-syntax", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1554 "%s: Unmatched {", text.c_str ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1555 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1556 result = string_vector (text); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1557 } |
4397 | 1558 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1559 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1560 std::string amble = text.substr (start, i-start); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1561 result = array_concat (result, expand_amble (amble)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1562 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1563 std::string postamble = text.substr (i+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1564 result = array_concat (result, brace_expand (postamble)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1565 } |
4378 | 1566 } |
1567 | |
4397 | 1568 return result; |
4378 | 1569 } |
1570 | |
4397 | 1571 /* The character which is used to separate arguments. */ |
1572 static int brace_arg_separator = ','; | |
1573 | |
4378 | 1574 /* Expand the text found inside of braces. We simply try to split the |
1575 text at BRACE_ARG_SEPARATORs into separate strings. We then brace | |
1576 expand each slot which needs it, until there are no more slots which | |
1577 need it. */ | |
4397 | 1578 static string_vector |
1579 expand_amble (const std::string& text) | |
4378 | 1580 { |
4397 | 1581 string_vector result; |
1582 | |
1583 size_t text_len = text.length (); | |
1584 size_t start; | |
1585 int i, c; | |
1586 | |
1587 for (start = 0, i = 0, c = 1; c && start < text_len; start = ++i) | |
4378 | 1588 { |
4397 | 1589 int i0 = i; |
1590 int c0 = brace_gobbler (text, i0, brace_arg_separator); | |
1591 int i1 = i; | |
1592 int c1 = brace_gobbler (text, i1, ENV_SEP); | |
4378 | 1593 c = c0 | c1; |
1594 i = (i0 < i1 ? i0 : i1); | |
1595 | |
4397 | 1596 std::string tem = text.substr (start, i-start); |
1597 | |
1598 string_vector partial = brace_expand (tem); | |
1599 | |
1600 if (result.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1601 result = partial; |
4378 | 1602 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1603 result.append (partial); |
4378 | 1604 } |
4397 | 1605 |
1606 return result; | |
4378 | 1607 } |
1608 | |
1609 /* Start at INDEX, and skip characters in TEXT. Set INDEX to the | |
1610 index of the character matching SATISFY. This understands about | |
1611 quoting. Return the character that caused us to stop searching; | |
1612 this is either the same as SATISFY, or 0. */ | |
1613 static int | |
4397 | 1614 brace_gobbler (const std::string& text, int& indx, int satisfy) |
4378 | 1615 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
1616 int c = 0; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
1617 int level = 0; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
1618 int quoted = 0; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
1619 int pass_next = 0; |
4397 | 1620 |
1621 size_t text_len = text.length (); | |
1622 | |
1623 size_t i = indx; | |
1624 | |
1625 for (; i < text_len; i++) | |
4378 | 1626 { |
4397 | 1627 c = text[i]; |
1628 | |
4378 | 1629 if (pass_next) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1630 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1631 pass_next = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1632 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1633 } |
4378 | 1634 |
1635 /* A backslash escapes the next character. This allows backslash to | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1636 escape the quote character in a double-quoted string. */ |
4378 | 1637 if (c == '\\' && (quoted == 0 || quoted == '"' || quoted == '`')) |
1638 { | |
1639 pass_next = 1; | |
1640 continue; | |
1641 } | |
1642 | |
1643 if (quoted) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1644 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1645 if (c == quoted) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1646 quoted = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1647 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1648 } |
4378 | 1649 |
1650 if (c == '"' || c == '\'' || c == '`') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1651 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1652 quoted = c; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1653 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1654 } |
4391 | 1655 |
4378 | 1656 if (c == satisfy && !level && !quoted) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1657 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1658 /* We ignore an open brace surrounded by whitespace, and also |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1659 an open brace followed immediately by a close brace, that |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1660 was preceded with whitespace. */ |
19898
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
1661 if (c == '{' |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
1662 && ((i == 0 || brace_whitespace (text[i-1])) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
1663 && (i+1 < text_len |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
1664 && (brace_whitespace (text[i+1]) || text[i+1] == '}')))) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1665 continue; |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1666 /* If this is being compiled as part of bash, ignore the '{' |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1667 in a '${ }' construct */ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1668 if ((c != '{') || i == 0 || (text[i-1] != '$')) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1669 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1670 } |
4378 | 1671 |
1672 if (c == '{') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1673 level++; |
4378 | 1674 else if (c == '}' && level) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1675 level--; |
4378 | 1676 } |
1677 | |
4397 | 1678 indx = i; |
1679 return c; | |
4378 | 1680 } |
1681 | |
1682 /* For each file format, we record the following information. The main | |
1683 thing that is not part of this structure is the environment variable | |
1684 lists. They are used directly in tex-file.c. We could incorporate | |
1685 them here, but it would complicate the code a bit. We could also do | |
1686 it via variable expansion, but not now, maybe not ever: | |
1687 ${PKFONTS-${TEXFONTS-/usr/local/lib/texmf/fonts//}}. */ | |
1688 | |
4399 | 1689 struct kpse_format_info_type |
4378 | 1690 { |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1691 kpse_format_info_type (void) |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1692 : type (), path (), raw_path (), path_source (), override_path (), |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1693 client_path (), cnf_path (), default_path (), suffix () |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1694 { } |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1695 |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1696 ~kpse_format_info_type (void) { } |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
1697 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1698 std::string type; /* Human-readable description. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1699 std::string path; /* The search path to use. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1700 std::string raw_path; /* Pre-$~ (but post-default) expansion. */ |
4390 | 1701 std::string path_source; /* Where the path started from. */ |
1702 std::string override_path; /* From client environment variable. */ | |
1703 std::string client_path; /* E.g., from dvips's config.ps. */ | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1704 std::string cnf_path; /* From texmf.cnf. */ |
4390 | 1705 std::string default_path; /* If all else fails. */ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1706 string_vector suffix; /* For kpse_find_file to check for/append. */ |
4399 | 1707 }; |
4378 | 1708 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1709 /* The sole variable of that type, indexed by 'kpse_file_format_type'. |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1710 Initialized by calls to 'kpse_find_file' for 'kpse_init_format'. */ |
4378 | 1711 static kpse_format_info_type kpse_format_info; |
1712 | |
1713 /* And EXPAND_DEFAULT calls kpse_expand_default on try_path and the | |
1714 present info->path. */ | |
4396 | 1715 #define EXPAND_DEFAULT(try_path, source_string) \ |
1716 do \ | |
1717 { \ | |
1718 if (! try_path.empty ()) \ | |
1719 { \ | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1720 info.raw_path = try_path; \ |
4396 | 1721 info.path = kpse_expand_default (try_path, info.path); \ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1722 info.path_source = source_string; \ |
4396 | 1723 } \ |
1724 } \ | |
1725 while (0) | |
4378 | 1726 |
1727 static hash_table_type db; /* The hash table for all the ls-R's. */ | |
4928 | 1728 |
4378 | 1729 static hash_table_type alias_db; |
1730 | |
4390 | 1731 static string_vector db_dir_list; |
4392 | 1732 |
4378 | 1733 /* Return true if FILENAME could be in PATH_ELT, i.e., if the directory |
1734 part of FILENAME matches PATH_ELT. Have to consider // wildcards, but | |
1735 $ and ~ expansion have already been done. */ | |
4391 | 1736 |
4378 | 1737 static bool |
4390 | 1738 match (const std::string& filename_arg, const std::string& path_elt_arg) |
4378 | 1739 { |
4390 | 1740 const char *filename = filename_arg.c_str (); |
1741 const char *path_elt = path_elt_arg.c_str (); | |
1742 | |
4378 | 1743 const char *original_filename = filename; |
1744 bool matched = false; | |
4391 | 1745 |
1746 for (; *filename && *path_elt; filename++, path_elt++) | |
1747 { | |
4394 | 1748 if (*filename == *path_elt) /* normal character match */ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1749 ; |
4391 | 1750 |
1751 else if (IS_DIR_SEP (*path_elt) /* at // */ | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1752 && original_filename < filename && IS_DIR_SEP (path_elt[-1])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1753 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1754 while (IS_DIR_SEP (*path_elt)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1755 path_elt++; /* get past second and any subsequent /'s */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1756 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1757 if (*path_elt == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1758 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1759 /* Trailing //, matches anything. We could make this |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1760 part of the other case, but it seems pointless to do |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1761 the extra work. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1762 matched = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1763 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1764 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1765 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1766 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1767 /* Intermediate //, have to match rest of PATH_ELT. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1768 for (; !matched && *filename; filename++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1769 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1770 /* Try matching at each possible character. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1771 if (IS_DIR_SEP (filename[-1]) && *filename == *path_elt) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1772 matched = match (filename, path_elt); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1773 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1774 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1775 /* Prevent filename++ when *filename='\0'. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1776 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1777 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1778 } |
4391 | 1779 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1780 /* normal character nonmatch, quit */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1781 break; |
4378 | 1782 } |
1783 | |
1784 /* If we've reached the end of PATH_ELT, check that we're at the last | |
1785 component of FILENAME, we've matched. */ | |
4391 | 1786 if (! matched && *path_elt == 0) |
1787 { | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1788 /* Probably PATH_ELT ended with 'vf' or some such, and FILENAME |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1789 ends with 'vf/ptmr.vf'. In that case, we'll be at a |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1790 directory separator. On the other hand, if PATH_ELT ended |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1791 with a / (as in 'vf/'), FILENAME being the same 'vf/ptmr.vf', |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1792 we'll be at the 'p'. Upshot: if we're at a dir separator in |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1793 FILENAME, skip it. But if not, that's ok, as long as there |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1794 are no more dir separators. */ |
4391 | 1795 |
1796 if (IS_DIR_SEP (*filename)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1797 filename++; |
4391 | 1798 |
1799 while (*filename && !IS_DIR_SEP (*filename)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1800 filename++; |
4391 | 1801 |
1802 matched = *filename == 0; | |
1803 } | |
1804 | |
4378 | 1805 return matched; |
1806 } | |
1807 | |
1808 /* If DB_DIR is a prefix of PATH_ELT, return true; otherwise false. | |
1809 That is, the question is whether to try the db for a file looked up | |
1810 in PATH_ELT. If PATH_ELT == ".", for example, the answer is no. If | |
1811 PATH_ELT == "/usr/local/lib/texmf/fonts//tfm", the answer is yes. | |
4391 | 1812 |
4378 | 1813 In practice, ls-R is only needed for lengthy subdirectory |
1814 comparisons, but there's no gain to checking PATH_ELT to see if it is | |
1815 a subdir match, since the only way to do that is to do a string | |
1816 search in it, which is all we do anyway. */ | |
4391 | 1817 |
4378 | 1818 static bool |
4390 | 1819 elt_in_db (const std::string& db_dir, const std::string& path_elt) |
4378 | 1820 { |
1821 bool found = false; | |
1822 | |
4390 | 1823 size_t db_dir_len = db_dir.length (); |
1824 size_t path_elt_len = path_elt.length (); | |
1825 | |
1826 size_t i = 0; | |
1827 | |
4394 | 1828 while (! found && db_dir[i] == path_elt[i]) |
4391 | 1829 { |
1830 i++; | |
1831 /* If we've matched the entire db directory, it's good. */ | |
1832 if (i == db_dir_len) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1833 found = true; |
4391 | 1834 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1835 /* If we've reached the end of PATH_ELT, but not the end of the db |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1836 directory, it's no good. */ |
4391 | 1837 else if (i == path_elt_len) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1838 break; |
4391 | 1839 } |
4378 | 1840 |
1841 return found; | |
1842 } | |
4392 | 1843 |
4378 | 1844 /* Avoid doing anything if this PATH_ELT is irrelevant to the databases. */ |
1845 | |
4399 | 1846 /* Return list of matches for NAME in the ls-R file matching PATH_ELT. If |
1847 ALL is set, return (null-terminated list) of all matches, else just | |
1848 the first. If no matches, return a pointer to an empty list. If no | |
1849 databases can be read, or PATH_ELT is not in any of the databases, | |
1850 return NULL. */ | |
1851 | |
1852 static string_vector | |
4390 | 1853 kpse_db_search (const std::string& name_arg, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1854 const std::string& orig_path_elt, bool all) |
4378 | 1855 { |
1856 bool done; | |
4390 | 1857 string_vector ret; |
1858 string_vector aliases; | |
4378 | 1859 bool relevant = false; |
4390 | 1860 |
4394 | 1861 std::string name = name_arg; |
4391 | 1862 |
4378 | 1863 /* If we failed to build the database (or if this is the recursive |
1864 call to build the db path), quit. */ | |
4398 | 1865 if (! db.buckets) |
4390 | 1866 return ret; |
4391 | 1867 |
4378 | 1868 /* When tex-glyph.c calls us looking for, e.g., dpi600/cmr10.pk, we |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1869 won't find it unless we change NAME to just 'cmr10.pk' and append |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1870 '/dpi600' to PATH_ELT. We are justified in using a literal '/' |
4378 | 1871 here, since that's what tex-glyph.c unconditionally uses in |
1872 DPI_BITMAP_SPEC. But don't do anything if the / begins NAME; that | |
1873 should never happen. */ | |
4394 | 1874 std::string path_elt; |
1875 size_t last_slash = name.rfind ('/'); | |
8021 | 1876 if (last_slash != std::string::npos && last_slash != 0) |
4390 | 1877 { |
4394 | 1878 std::string dir_part = name.substr (0, last_slash); |
1879 name = name.substr (last_slash + 1); | |
4390 | 1880 } |
1881 else | |
4394 | 1882 path_elt = orig_path_elt; |
4378 | 1883 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1884 /* Don't bother doing any lookups if this 'path_elt' isn't covered by |
4378 | 1885 any of database directories. We do this not so much because the |
1886 extra couple of hash lookups matter -- they don't -- but rather | |
1887 because we want to return NULL in this case, so path_search can | |
1888 know to do a disk search. */ | |
4394 | 1889 for (int e = 0; ! relevant && e < db_dir_list.length (); e++) |
4390 | 1890 relevant = elt_in_db (db_dir_list[e], path_elt); |
1891 | |
4391 | 1892 if (! relevant) |
4390 | 1893 return ret; |
4378 | 1894 |
1895 /* If we have aliases for this name, use them. */ | |
1896 if (alias_db.buckets) | |
1897 aliases = hash_lookup (alias_db, name); | |
1898 | |
4390 | 1899 /* Push aliases up by one and insert the original name at the front. */ |
1900 int len = aliases.length (); | |
1901 aliases.resize (len+1); | |
1902 for (int i = len; i > 0; i--) | |
1903 aliases[i] = aliases[i - 1]; | |
1904 aliases[0] = name; | |
4378 | 1905 |
1906 done = false; | |
4390 | 1907 len = aliases.length (); |
1908 for (int i = 0; i < len && !done; i++) | |
1909 { | |
1910 std::string atry = aliases[i]; | |
1911 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1912 /* We have an ls-R db. Look up 'atry'. */ |
4390 | 1913 string_vector db_dirs = hash_lookup (db, atry); |
1914 | |
1915 /* For each filename found, see if it matches the path element. For | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1916 example, if we have .../cx/cmr10.300pk and .../ricoh/cmr10.300pk, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1917 and the path looks like .../cx, we don't want the ricoh file. */ |
4390 | 1918 |
1919 int db_dirs_len = db_dirs.length (); | |
1920 for (int j = 0; j < db_dirs_len && !done; j++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1921 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1922 std::string db_file = db_dirs[j] + atry; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1923 bool matched = match (db_file, path_elt); |
4378 | 1924 |
1925 #ifdef KPSE_DEBUG | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1926 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1927 DEBUGF3 ("db:match (%s,%s) = %d\n", |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1928 db_file.c_str (), path_elt.c_str (), matched); |
4378 | 1929 #endif |
1930 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1931 /* We got a hit in the database. Now see if the file actually |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1932 exists, possibly under an alias. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1933 if (matched) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1934 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1935 std::string found; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1936 std::string tmp = kpse_readable_file (db_file); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1937 if (! tmp.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1938 found = db_file; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1939 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1940 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1941 /* The hit in the DB doesn't exist in disk. Now try |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1942 all its aliases. For example, suppose we have a |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1943 hierarchy on CD, thus 'mf.bas', but ls-R contains |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1944 'mf.base'. Find it anyway. Could probably work |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1945 around this with aliases, but this is pretty easy |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1946 and shouldn't hurt. The upshot is that if one of |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1947 the aliases actually exists, we use that. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1948 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1949 int aliases_len = aliases.length (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1950 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1951 for (int k = 1; k < aliases_len && found.empty (); k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1952 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1953 std::string aatry = db_dirs[j] + aliases[k]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1954 tmp = kpse_readable_file (aatry); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1955 if (! tmp.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1956 found = aatry; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1957 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1958 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1959 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1960 /* If we have a real file, add it to the list, maybe done. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1961 if (! found.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1962 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1963 ret.append (found); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1964 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1965 if (! (all || found.empty ())) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1966 done = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1967 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1968 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1969 } |
4378 | 1970 } |
4391 | 1971 |
4378 | 1972 return ret; |
1973 } | |
1974 | |
4399 | 1975 /* Expand extra colons. */ |
4378 | 1976 |
1977 /* Check for leading colon first, then trailing, then doubled, since | |
1978 that is fastest. Usually it will be leading or trailing. */ | |
1979 | |
4399 | 1980 /* Replace a leading or trailing or doubled : in PATH with DFLT. If |
1981 no extra colons, return PATH. Only one extra colon is replaced. | |
1982 DFLT may not be NULL. */ | |
1983 | |
1984 static std::string | |
4394 | 1985 kpse_expand_default (const std::string& path, const std::string& fallback) |
4378 | 1986 { |
4394 | 1987 std::string expansion; |
1988 | |
1989 size_t path_len = path.length (); | |
1990 | |
1991 if (path_len == 0) | |
1992 expansion = fallback; | |
4378 | 1993 |
1994 /* Solitary or leading :? */ | |
4394 | 1995 else if (IS_ENV_SEP (path[0])) |
4378 | 1996 { |
4394 | 1997 expansion = path_len == 1 ? fallback : fallback + path; |
4378 | 1998 } |
1999 | |
2000 /* Sorry about the assignment in the middle of the expression, but | |
2001 conventions were made to be flouted and all that. I don't see the | |
2002 point of calling strlen twice or complicating the logic just to | |
2003 avoid the assignment (especially now that I've pointed it out at | |
2004 such great length). */ | |
4394 | 2005 else if (IS_ENV_SEP (path[path_len-1])) |
2006 expansion = path + fallback; | |
4378 | 2007 |
2008 /* OK, not leading or trailing. Check for doubled. */ | |
2009 else | |
2010 { | |
2011 /* What we'll return if we find none. */ | |
4394 | 2012 expansion = path; |
2013 | |
2014 for (size_t i = 0; i < path_len; i++) | |
4378 | 2015 { |
4394 | 2016 if (i + 1 < path_len |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2017 && IS_ENV_SEP (path[i]) && IS_ENV_SEP (path[i+1])) |
4394 | 2018 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2019 /* We have a doubled colon. */ |
4391 | 2020 |
4378 | 2021 /* Copy stuff up to and including the first colon. */ |
2022 /* Copy in FALLBACK, and then the rest of PATH. */ | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2023 expansion = path.substr (0, i+1) + fallback + path.substr (i+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2024 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2025 break; |
4378 | 2026 } |
2027 } | |
2028 } | |
4391 | 2029 |
4378 | 2030 return expansion; |
2031 } | |
2032 | |
4399 | 2033 /* Translate a path element to its corresponding director{y,ies}. */ |
4378 | 2034 |
2035 /* To avoid giving prototypes for all the routines and then their real | |
2036 definitions, we give all the subroutines first. The entry point is | |
2037 the last routine in the file. */ | |
4392 | 2038 |
4378 | 2039 /* Make a copy of DIR (unless it's null) and save it in L. Ensure that |
2040 DIR ends with a DIR_SEP for the benefit of later searches. */ | |
2041 | |
2042 static void | |
4390 | 2043 dir_list_add (str_llist_type *l, const std::string& dir) |
4378 | 2044 { |
4390 | 2045 char last_char = dir[dir.length () - 1]; |
4407 | 2046 |
4390 | 2047 std::string saved_dir = dir; |
4407 | 2048 |
2049 if (! (IS_DIR_SEP (last_char) || IS_DEVICE_SEP (last_char))) | |
4390 | 2050 saved_dir += DIR_SEP_STRING; |
4391 | 2051 |
4378 | 2052 str_llist_add (l, saved_dir); |
2053 } | |
2054 | |
4390 | 2055 /* Return true if FN is a directory or a symlink to a directory, |
2056 false if not. */ | |
2057 | |
2058 static bool | |
2059 dir_p (const std::string& fn) | |
2060 { | |
2061 #ifdef WIN32 | |
4391 | 2062 unsigned int fa = GetFileAttributes (fn.c_str ()); |
4390 | 2063 return (fa != 0xFFFFFFFF && (fa & FILE_ATTRIBUTE_DIRECTORY)); |
2064 #else | |
2065 struct stat stats; | |
2066 return stat (fn.c_str (), &stats) == 0 && S_ISDIR (stats.st_mode); | |
2067 #endif | |
2068 } | |
4391 | 2069 |
4378 | 2070 /* If DIR is a directory, add it to the list L. */ |
2071 | |
2072 static void | |
4390 | 2073 checked_dir_list_add (str_llist_type *l, const std::string& dir) |
4378 | 2074 { |
2075 if (dir_p (dir)) | |
2076 dir_list_add (l, dir); | |
2077 } | |
4392 | 2078 |
4378 | 2079 /* The cache. Typically, several paths have the same element; for |
2080 example, /usr/local/lib/texmf/fonts//. We don't want to compute the | |
2081 expansion of such a thing more than once. Even though we also cache | |
2082 the dir_links call, that's not enough -- without this path element | |
2083 caching as well, the execution time doubles. */ | |
2084 | |
4398 | 2085 struct cache_entry |
4378 | 2086 { |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
2087 cache_entry (void) : key (), value (0) { } |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
2088 |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
2089 ~cache_entry (void) { } |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11236
diff
changeset
|
2090 |
4398 | 2091 std::string key; |
4378 | 2092 str_llist_type *value; |
4398 | 2093 }; |
2094 | |
2095 static cache_entry *the_cache = 0; | |
4378 | 2096 static unsigned cache_length = 0; |
2097 | |
2098 /* Associate KEY with VALUE. We implement the cache as a simple linear | |
2099 list, since it's unlikely to ever be more than a dozen or so elements | |
2100 long. We don't bother to check here if PATH has already been saved; | |
2101 we always add it to our list. We copy KEY but not VALUE; not sure | |
2102 that's right, but it seems to be all that's needed. */ | |
2103 | |
2104 static void | |
4398 | 2105 cache (const std::string key, str_llist_type *value) |
4378 | 2106 { |
4398 | 2107 cache_entry *new_cache = new cache_entry [cache_length+1]; |
2108 | |
4399 | 2109 for (unsigned i = 0; i < cache_length; i++) |
4398 | 2110 { |
2111 new_cache[i].key = the_cache[i].key; | |
2112 new_cache[i].value = the_cache[i].value; | |
2113 } | |
2114 | |
2115 delete [] the_cache; | |
2116 | |
2117 the_cache = new_cache; | |
2118 | |
2119 the_cache[cache_length].key = key; | |
2120 the_cache[cache_length].value = value; | |
2121 | |
4378 | 2122 cache_length++; |
2123 } | |
2124 | |
2125 /* To retrieve, just check the list in order. */ | |
2126 | |
2127 static str_llist_type * | |
4398 | 2128 cached (const std::string& key) |
4378 | 2129 { |
2130 unsigned p; | |
4391 | 2131 |
4378 | 2132 for (p = 0; p < cache_length; p++) |
2133 { | |
4398 | 2134 if (key == the_cache[p].key) |
4378 | 2135 return the_cache[p].value; |
2136 } | |
4391 | 2137 |
4398 | 2138 return 0; |
4378 | 2139 } |
4392 | 2140 |
4378 | 2141 /* Handle the magic path constructs. */ |
2142 | |
2143 /* Declare recursively called routine. */ | |
4398 | 2144 static void expand_elt (str_llist_type *, const std::string&, unsigned); |
4378 | 2145 |
2146 /* POST is a pointer into the original element (which may no longer be | |
2147 ELT) to just after the doubled DIR_SEP, perhaps to the null. Append | |
2148 subdirectories of ELT (up to ELT_LENGTH, which must be a /) to | |
2149 STR_LIST_PTR. */ | |
2150 | |
2151 #ifdef WIN32 | |
4398 | 2152 |
4378 | 2153 /* Shared across recursive calls, it acts like a stack. */ |
4398 | 2154 static std::string dirname; |
2155 | |
2156 #else /* WIN32 */ | |
2157 | |
2158 /* Return -1 if FN isn't a directory, else its number of links. | |
2159 Duplicate the call to stat; no need to incur overhead of a function | |
2160 call for that little bit of cleanliness. */ | |
2161 | |
2162 static int | |
2163 dir_links (const std::string& fn) | |
2164 { | |
2165 std::map<std::string, long> link_table; | |
2166 | |
2167 long ret; | |
2168 | |
2169 if (link_table.find (fn) != link_table.end ()) | |
2170 ret = link_table[fn]; | |
2171 else | |
2172 { | |
2173 struct stat stats; | |
2174 | |
2175 ret = stat (fn.c_str (), &stats) == 0 && S_ISDIR (stats.st_mode) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2176 ? stats.st_nlink : static_cast<unsigned> (-1); |
4398 | 2177 |
2178 link_table[fn] = ret; | |
2179 | |
2180 #ifdef KPSE_DEBUG | |
2181 if (KPSE_DEBUG_P (KPSE_DEBUG_STAT)) | |
2182 DEBUGF2 ("dir_links (%s) => %ld\n", fn.c_str (), ret); | |
4378 | 2183 #endif |
4398 | 2184 } |
2185 | |
2186 return ret; | |
2187 } | |
2188 | |
2189 #endif /* WIN32 */ | |
4378 | 2190 |
2191 static void | |
4398 | 2192 do_subdir (str_llist_type *str_list_ptr, const std::string& elt, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2193 unsigned elt_length, const std::string& post) |
4378 | 2194 { |
2195 #ifdef WIN32 | |
2196 WIN32_FIND_DATA find_file_data; | |
2197 HANDLE hnd; | |
2198 int proceed; | |
2199 #else | |
2200 DIR *dir; | |
2201 struct dirent *e; | |
2202 #endif /* not WIN32 */ | |
4389 | 2203 |
4398 | 2204 std::string name = elt.substr (0, elt_length); |
4389 | 2205 |
4378 | 2206 assert (IS_DIR_SEP (elt[elt_length - 1]) |
2207 || IS_DEVICE_SEP (elt[elt_length - 1])); | |
4391 | 2208 |
4378 | 2209 #if defined (WIN32) |
4398 | 2210 |
2211 dirname = name + "/*.*"; /* "*.*" or "*" -- seems equivalent. */ | |
2212 | |
2213 hnd = FindFirstFile (dirname.c_str (), &find_file_data); | |
4378 | 2214 |
4389 | 2215 if (hnd == INVALID_HANDLE_VALUE) |
4378 | 2216 return; |
2217 | |
2218 /* Include top level before subdirectories, if nothing to match. */ | |
4398 | 2219 if (post.empty ()) |
4390 | 2220 dir_list_add (str_list_ptr, name); |
4398 | 2221 else |
2222 { | |
2223 /* If we do have something to match, see if it exists. For | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2224 example, POST might be 'pk/ljfour', and they might have a |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2225 directory '$TEXMF/fonts/pk/ljfour' that we should find. */ |
4398 | 2226 name += post; |
2227 expand_elt (str_list_ptr, name, elt_length); | |
2228 name.resize (elt_length); | |
2229 } | |
2230 | |
4378 | 2231 proceed = 1; |
4398 | 2232 |
4391 | 2233 while (proceed) |
2234 { | |
2235 if (find_file_data.cFileName[0] != '.') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2236 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2237 /* Construct the potential subdirectory name. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2238 name += find_file_data.cFileName; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2239 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2240 if (find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2241 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2242 /* It's a directory, so append the separator. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2243 name += DIR_SEP_STRING; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2244 unsigned potential_len = name.length (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2245 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2246 do_subdir (str_list_ptr, name, potential_len, post); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2247 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2248 name.resize (elt_length); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2249 } |
4398 | 2250 |
4391 | 2251 proceed = FindNextFile (hnd, &find_file_data); |
4378 | 2252 } |
4398 | 2253 |
4391 | 2254 FindClose (hnd); |
4378 | 2255 |
2256 #else /* not WIN32 */ | |
2257 | |
2258 /* If we can't open it, quit. */ | |
10411 | 2259 dir = gnulib::opendir (name.c_str ()); |
4398 | 2260 |
2261 if (! dir) | |
4389 | 2262 return; |
4391 | 2263 |
4378 | 2264 /* Include top level before subdirectories, if nothing to match. */ |
4398 | 2265 if (post.empty ()) |
4390 | 2266 dir_list_add (str_list_ptr, name); |
4378 | 2267 else |
4398 | 2268 { |
2269 /* If we do have something to match, see if it exists. For | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2270 example, POST might be 'pk/ljfour', and they might have a |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2271 directory '$TEXMF/fonts/pk/ljfour' that we should find. */ |
4389 | 2272 name += post; |
4398 | 2273 expand_elt (str_list_ptr, name, elt_length); |
4389 | 2274 name.resize (elt_length); |
4378 | 2275 } |
2276 | |
14155 | 2277 while ((e = gnulib::readdir (dir))) |
4398 | 2278 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2279 /* If it begins with a '.', never mind. (This allows "hidden" |
4378 | 2280 directories that the algorithm won't find.) */ |
4398 | 2281 |
4378 | 2282 if (e->d_name[0] != '.') |
2283 { | |
2284 int links; | |
4391 | 2285 |
4378 | 2286 /* Construct the potential subdirectory name. */ |
4389 | 2287 name += e->d_name; |
4391 | 2288 |
4378 | 2289 /* If we can't stat it, or if it isn't a directory, continue. */ |
4398 | 2290 links = dir_links (name); |
4378 | 2291 |
2292 if (links >= 0) | |
4391 | 2293 { |
4378 | 2294 /* It's a directory, so append the separator. */ |
4389 | 2295 name += DIR_SEP_STRING; |
2296 unsigned potential_len = name.length (); | |
4391 | 2297 |
4378 | 2298 /* Should we recurse? To see if the subdirectory is a |
2299 leaf, check if it has two links (one for . and one for | |
2300 ..). This means that symbolic links to directories do | |
2301 not affect the leaf-ness. This is arguably wrong, but | |
2302 the only alternative I know of is to stat every entry | |
2303 in the directory, and that is unacceptably slow. | |
4391 | 2304 |
4378 | 2305 The #ifdef here makes all this configurable at |
2306 compile-time, so that if we're using VMS directories or | |
2307 some such, we can still find subdirectories, even if it | |
2308 is much slower. */ | |
2309 #ifdef ST_NLINK_TRICK | |
5622 | 2310 if (links != 2) |
4378 | 2311 #endif /* not ST_NLINK_TRICK */ |
2312 /* All criteria are met; find subdirectories. */ | |
4398 | 2313 do_subdir (str_list_ptr, name, potential_len, post); |
4378 | 2314 #ifdef ST_NLINK_TRICK |
4398 | 2315 else if (post.empty ()) |
4378 | 2316 /* Nothing to match, no recursive subdirectories to |
2317 look for: we're done with this branch. Add it. */ | |
4390 | 2318 dir_list_add (str_list_ptr, name); |
4378 | 2319 #endif |
2320 } | |
2321 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2322 /* Remove the directory entry we just checked from 'name'. */ |
4389 | 2323 name.resize (elt_length); |
4378 | 2324 } |
2325 } | |
4391 | 2326 |
4378 | 2327 xclosedir (dir); |
2328 #endif /* not WIN32 */ | |
2329 } | |
2330 | |
2331 /* Assume ELT is non-empty and non-NULL. Return list of corresponding | |
2332 directories (with no terminating NULL entry) in STR_LIST_PTR. Start | |
2333 looking for magic constructs at START. */ | |
2334 | |
2335 static void | |
4398 | 2336 expand_elt (str_llist_type *str_list_ptr, const std::string& elt, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2337 unsigned /* start */) |
4378 | 2338 { |
6306 | 2339 #if 0 |
2340 // We don't want magic constructs. | |
2341 | |
4398 | 2342 size_t elt_len = elt.length (); |
2343 | |
2344 size_t dir = start; | |
2345 | |
2346 | |
2347 while (dir < elt_len) | |
4378 | 2348 { |
4398 | 2349 if (IS_DIR_SEP (elt[dir])) |
4378 | 2350 { |
2351 /* If two or more consecutive /'s, find subdirectories. */ | |
4398 | 2352 if (++dir < elt_len && IS_DIR_SEP (elt[dir])) |
4378 | 2353 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2354 size_t i = dir; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2355 while (i < elt_len && IS_DIR_SEP (elt[i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2356 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2357 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2358 std::string post = elt.substr (i); |
4398 | 2359 |
2360 do_subdir (str_list_ptr, elt, dir, post); | |
2361 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2362 return; |
4378 | 2363 } |
2364 | |
2365 /* No special stuff at this slash. Keep going. */ | |
2366 } | |
4398 | 2367 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2368 dir++; |
4378 | 2369 } |
6306 | 2370 #endif |
4391 | 2371 |
4378 | 2372 /* When we reach the end of ELT, it will be a normal filename. */ |
2373 checked_dir_list_add (str_list_ptr, elt); | |
2374 } | |
4392 | 2375 |
4378 | 2376 /* Here is the entry point. Returns directory list for ELT. */ |
2377 | |
4399 | 2378 /* Given a path element ELT, return a pointer to a NULL-terminated list |
2379 of the corresponding (existing) directory or directories, with | |
2380 trailing slashes, or NULL. If ELT is the empty string, check the | |
2381 current working directory. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
2382 |
4399 | 2383 It's up to the caller to expand ELT. This is because this routine is |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2384 most likely only useful to be called from 'kpse_path_search', which |
4399 | 2385 has already assumed expansion has been done. */ |
2386 | |
2387 static str_llist_type * | |
4398 | 2388 kpse_element_dirs (const std::string& elt) |
4378 | 2389 { |
2390 str_llist_type *ret; | |
2391 | |
2392 /* If given nothing, return nothing. */ | |
4398 | 2393 if (elt.empty ()) |
2394 return 0; | |
4378 | 2395 |
2396 /* If we've already cached the answer for ELT, return it. */ | |
2397 ret = cached (elt); | |
2398 if (ret) | |
2399 return ret; | |
2400 | |
2401 /* We're going to have a real directory list to return. */ | |
4390 | 2402 ret = new str_llist_type; |
4398 | 2403 *ret = 0; |
4378 | 2404 |
2405 /* We handle the hard case in a subroutine. */ | |
2406 expand_elt (ret, elt, 0); | |
2407 | |
2408 /* Remember the directory list we just found, in case future calls are | |
2409 made with the same ELT. */ | |
2410 cache (elt, ret); | |
2411 | |
2412 #ifdef KPSE_DEBUG | |
2413 if (KPSE_DEBUG_P (KPSE_DEBUG_EXPAND)) | |
2414 { | |
4398 | 2415 DEBUGF1 ("path element %s =>", elt.c_str ()); |
4378 | 2416 if (ret) |
2417 { | |
2418 str_llist_elt_type *e; | |
2419 for (e = *ret; e; e = STR_LLIST_NEXT (*e)) | |
10411 | 2420 gnulib::fprintf (stderr, " %s", (STR_LLIST (*e)).c_str ()); |
4378 | 2421 } |
10411 | 2422 gnulib::putc ('\n', stderr); |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2423 gnulib::fflush (stderr); |
4378 | 2424 } |
2425 #endif /* KPSE_DEBUG */ | |
2426 | |
2427 return ret; | |
2428 } | |
2429 | |
4386 | 2430 #ifndef WIN32 |
4385 | 2431 void |
2432 xclosedir (DIR *d) | |
2433 { | |
10411 | 2434 int ret = gnulib::closedir (d); |
4391 | 2435 |
4385 | 2436 if (ret != 0) |
2437 FATAL ("closedir failed"); | |
2438 } | |
4386 | 2439 #endif |
4385 | 2440 |
4399 | 2441 /* Implementation of a linked list of strings. */ |
4385 | 2442 |
2443 /* Add the new string STR to the end of the list L. */ | |
2444 | |
5085 | 2445 static void |
4390 | 2446 str_llist_add (str_llist_type *l, const std::string& str) |
4385 | 2447 { |
2448 str_llist_elt_type *e; | |
4390 | 2449 str_llist_elt_type *new_elt = new str_llist_elt_type; |
4391 | 2450 |
4385 | 2451 /* The new element will be at the end of the list. */ |
2452 STR_LLIST (*new_elt) = str; | |
2453 STR_LLIST_MOVED (*new_elt) = 0; | |
4398 | 2454 STR_LLIST_NEXT (*new_elt) = 0; |
4391 | 2455 |
4385 | 2456 /* Find the current end of the list. */ |
2457 for (e = *l; e && STR_LLIST_NEXT (*e); e = STR_LLIST_NEXT (*e)) | |
2458 ; | |
4391 | 2459 |
2460 if (! e) | |
4385 | 2461 *l = new_elt; |
2462 else | |
2463 STR_LLIST_NEXT (*e) = new_elt; | |
2464 } | |
4392 | 2465 |
4385 | 2466 /* Move an element towards the top. The idea is that when a file is |
2467 found in a given directory, later files will likely be in that same | |
2468 directory, and looking for the file in all the directories in between | |
2469 is thus a waste. */ | |
2470 | |
5085 | 2471 static void |
4385 | 2472 str_llist_float (str_llist_type *l, str_llist_elt_type *mover) |
2473 { | |
2474 str_llist_elt_type *last_moved, *unmoved; | |
4391 | 2475 |
4385 | 2476 /* If we've already moved this element, never mind. */ |
2477 if (STR_LLIST_MOVED (*mover)) | |
2478 return; | |
4391 | 2479 |
4385 | 2480 /* Find the first unmoved element (to insert before). We're |
2481 guaranteed this will terminate, since MOVER itself is currently | |
2482 unmoved, and it must be in L (by hypothesis). */ | |
4398 | 2483 for (last_moved = 0, unmoved = *l; STR_LLIST_MOVED (*unmoved); |
4385 | 2484 last_moved = unmoved, unmoved = STR_LLIST_NEXT (*unmoved)) |
2485 ; | |
2486 | |
2487 /* If we are the first unmoved element, nothing to relink. */ | |
2488 if (unmoved != mover) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2489 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2490 /* Remember 'mover's current successor, so we can relink 'mover's |
4385 | 2491 predecessor to it. */ |
2492 str_llist_elt_type *before_mover; | |
2493 str_llist_elt_type *after_mover = STR_LLIST_NEXT (*mover); | |
4391 | 2494 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2495 /* Find 'mover's predecessor. */ |
4385 | 2496 for (before_mover = unmoved; STR_LLIST_NEXT (*before_mover) != mover; |
2497 before_mover = STR_LLIST_NEXT (*before_mover)) | |
2498 ; | |
4391 | 2499 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2500 /* 'before_mover' now links to 'after_mover'. */ |
4385 | 2501 STR_LLIST_NEXT (*before_mover) = after_mover; |
2502 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2503 /* Insert 'mover' before 'unmoved' and after 'last_moved' (or at |
4385 | 2504 the head of the list). */ |
2505 STR_LLIST_NEXT (*mover) = unmoved; | |
4391 | 2506 if (! last_moved) |
4385 | 2507 *l = mover; |
2508 else | |
2509 STR_LLIST_NEXT (*last_moved) = mover; | |
2510 } | |
2511 | |
2512 /* We've moved it. */ | |
2513 STR_LLIST_MOVED (*mover) = 1; | |
2514 } | |
2515 | |
4399 | 2516 /* Variable expansion. */ |
4385 | 2517 |
2518 /* We have to keep track of variables being expanded, otherwise | |
2519 constructs like TEXINPUTS = $TEXINPUTS result in an infinite loop. | |
2520 (Or indirectly recursive variables, etc.) Our simple solution is to | |
2521 add to a list each time an expansion is started, and check the list | |
2522 before expanding. */ | |
2523 | |
4391 | 2524 static std::map <std::string, bool> expansions; |
4385 | 2525 |
2526 static void | |
4391 | 2527 expanding (const std::string& var, bool xp) |
4385 | 2528 { |
4391 | 2529 expansions[var] = xp; |
4385 | 2530 } |
2531 | |
2532 /* Return whether VAR is currently being expanding. */ | |
2533 | |
4391 | 2534 static bool |
2535 expanding_p (const std::string& var) | |
4385 | 2536 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2537 return (expansions.find (var) != expansions.end ()) ? expansions[var] : false; |
4385 | 2538 } |
4392 | 2539 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2540 /* Append the result of value of 'var' to EXPANSION, where 'var' begins |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2541 at START and ends at END. If 'var' is not set, do not complain. |
4385 | 2542 This is a subroutine for the more complicated expansion function. */ |
2543 | |
2544 static void | |
4391 | 2545 expand (std::string &expansion, const std::string& var) |
4385 | 2546 { |
4391 | 2547 if (expanding_p (var)) |
2548 { | |
19444
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2549 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2550 ("Octave:pathsearch-syntax", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2551 "kpathsea: variable '%s' references itself (eventually)", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2552 var.c_str ()); |
4385 | 2553 } |
4391 | 2554 else |
2555 { | |
2556 /* Check for an environment variable. */ | |
2557 std::string value = octave_env::getenv (var); | |
2558 | |
2559 if (! value.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2560 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2561 expanding (var, true); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2562 std::string tmp = kpse_var_expand (value); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2563 expanding (var, false); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2564 expansion += tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2565 } |
4391 | 2566 } |
4385 | 2567 } |
4392 | 2568 |
4385 | 2569 /* Can't think of when it would be useful to change these (and the |
2570 diagnostic messages assume them), but ... */ | |
2571 #ifndef IS_VAR_START /* starts all variable references */ | |
2572 #define IS_VAR_START(c) ((c) == '$') | |
2573 #endif | |
2574 #ifndef IS_VAR_CHAR /* variable name constituent */ | |
2575 #define IS_VAR_CHAR(c) (isalnum (c) || (c) == '_') | |
2576 #endif | |
2577 #ifndef IS_VAR_BEGIN_DELIMITER /* start delimited variable name (after $) */ | |
2578 #define IS_VAR_BEGIN_DELIMITER(c) ((c) == '{') | |
2579 #endif | |
2580 #ifndef IS_VAR_END_DELIMITER | |
2581 #define IS_VAR_END_DELIMITER(c) ((c) == '}') | |
2582 #endif | |
2583 | |
2584 /* Maybe we should support some or all of the various shell ${...} | |
2585 constructs, especially ${var-value}. */ | |
2586 | |
5085 | 2587 static std::string |
4391 | 2588 kpse_var_expand (const std::string& src) |
4385 | 2589 { |
4389 | 2590 std::string expansion; |
4391 | 2591 |
2592 size_t src_len = src.length (); | |
2593 | |
4385 | 2594 /* Copy everything but variable constructs. */ |
4391 | 2595 for (size_t i = 0; i < src_len; i++) |
2596 { | |
2597 if (IS_VAR_START (src[i])) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2598 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2599 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2600 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
2601 /* Three cases: '$VAR', '${VAR}', '$<anything-else>'. */ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2602 if (IS_VAR_CHAR (src[i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2603 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2604 /* $V: collect name constituents, then expand. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2605 size_t var_end = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2606 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2607 do |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2608 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2609 var_end++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2610 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2611 while (IS_VAR_CHAR (src[var_end])); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2612 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2613 var_end--; /* had to go one past */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2614 expand (expansion, src.substr (i, var_end - i + 1)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2615 i = var_end; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2616 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2617 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2618 else if (IS_VAR_BEGIN_DELIMITER (src[i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2619 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2620 /* ${: scan ahead for matching delimiter, then expand. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2621 size_t var_end = ++i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2622 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2623 while (var_end < src_len && !IS_VAR_END_DELIMITER (src[var_end])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2624 var_end++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2625 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2626 if (var_end == src_len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2627 { |
19444
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2628 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2629 ("Octave:pathsearch-syntax", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2630 "%s: No matching } for ${", src.c_str ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2631 i = var_end - 1; /* will incr to eos at top of loop */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2632 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2633 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2634 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2635 expand (expansion, src.substr (i, var_end - i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2636 i = var_end; /* will incr past } at top of loop*/ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2637 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2638 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2639 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2640 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2641 /* $<something-else>: error. */ |
19444
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2642 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2643 ("Octave:pathsearch-syntax", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
2644 "%s: Unrecognized variable construct '$%c'", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2645 src.c_str (), src[i]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2646 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2647 /* Just ignore those chars and keep going. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2648 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2649 } |
4391 | 2650 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
2651 expansion += src[i]; |
4391 | 2652 } |
4389 | 2653 |
2654 return expansion; | |
4385 | 2655 } |