Mercurial > octave
annotate liboctave/util/kpse.cc @ 21874:7508f3a8e234
more cleanup in kpse.cc
* kpse.cc: Reorder include statements. Indent preprocessor blocks.
Eliminate useless macro definitions. Eliminate unneeded includes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 11 Jun 2016 20:36:01 -0400 |
parents | 40195d04b17c |
children | d8104206e8a9 |
rev | line source |
---|---|
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21732
diff
changeset
|
1 // This file is not compiled to a separate object file. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21732
diff
changeset
|
2 // It is included in pathsearch.cc. |
4399 | 3 |
4 /* Look up a filename in a path. | |
4378 | 5 |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19410
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 |
21690
b6a686543080
Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
29 // This file should not include config.h. It is only included in other |
b6a686543080
Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
30 // C++ source files that should have included config.h before including |
b6a686543080
Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
31 // this file. |
4378 | 32 |
21874 | 33 #include <cctype> |
34 #include <cerrno> | |
35 #include <cstdlib> | |
36 #include <ctime> | |
37 | |
4390 | 38 #include <map> |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
39 #include <fstream> |
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
40 #include <iostream> |
4389 | 41 #include <string> |
42 | |
21874 | 43 #include <sys/types.h> |
44 #include <unistd.h> | |
4399 | 45 |
21874 | 46 #include <dirent.h> |
4378 | 47 |
21865 | 48 #include "file-stat.h" |
4396 | 49 #include "lo-error.h" |
4391 | 50 #include "oct-env.h" |
51 #include "oct-passwd.h" | |
4399 | 52 #include "str-vec.h" |
4385 | 53 |
21874 | 54 #if defined (__WIN32__) && ! defined (__CYGWIN__) |
55 # define WIN32_LEAN_AND_MEAN 1 | |
56 # include <windows.h> | |
57 #endif | |
4385 | 58 |
21874 | 59 // System dependencies that are figured out by 'configure'. If we are |
60 // compiling standalone, we get our c-auto.h. Otherwise, the package | |
61 // containing us must provide this (unless it can somehow generate ours | |
62 // from c-auto.in). We use <...> instead of "..." so that the current | |
63 // cpp directory (i.e., kpathsea/) won't be searched. | |
64 | |
65 // Define the characters which separate components of filenames and | |
66 // environment variable paths. | |
4385 | 67 |
21874 | 68 // What separates filename components? |
69 #if ! defined (DIR_SEP) | |
70 # if defined (__WIN32__) && ! defined (__CYGWIN__) | |
71 // Either \'s or 's work, but use "/". | |
72 # define DIR_SEP '/' | |
73 # define DIR_SEP_STRING "/" | |
74 # define IS_DEVICE_SEP(ch) ((ch) == ':') | |
75 # define NAME_BEGINS_WITH_DEVICE(name) \ | |
76 ((name.length ()>0) && IS_DEVICE_SEP((name)[1])) | |
77 // On Windows, it's good to allow both \ and / between directories. | |
78 # define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\') | |
79 # else | |
80 # define DIR_SEP '/' | |
81 # define DIR_SEP_STRING "/" | |
82 # endif | |
83 #endif | |
21863
a25110491607
eliminate obsolete sysdir.h header file
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
84 |
21874 | 85 #if ! defined (IS_DIR_SEP) |
86 # define IS_DIR_SEP(ch) ((ch) == DIR_SEP) | |
87 #endif | |
88 | |
89 #if ! defined (IS_DEVICE_SEP) | |
90 // No 'devices' on, e.g., Unix. | |
91 # define IS_DEVICE_SEP(ch) 0 | |
92 #endif | |
4385 | 93 |
21874 | 94 #if ! defined (NAME_BEGINS_WITH_DEVICE) |
95 # define NAME_BEGINS_WITH_DEVICE(name) 0 | |
96 #endif | |
97 | |
98 // define NAME_MAX, the maximum length of a single component in a | |
99 // filename. No such limit may exist, or may vary depending on the | |
100 // filesystem. | |
101 | |
102 // Most likely the system will truncate filenames if it is not POSIX, | |
103 // and so we can use the BSD value here. | |
104 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
105 #if ! defined (_POSIX_NAME_MAX) |
21874 | 106 # define _POSIX_NAME_MAX 255 |
4385 | 107 #endif |
108 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
109 #if ! defined (NAME_MAX) |
21874 | 110 # define NAME_MAX _POSIX_NAME_MAX |
4385 | 111 #endif |
112 | |
21874 | 113 // What separates elements in environment variable path lists? */ |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
114 #if ! defined (ENV_SEP) |
21874 | 115 # if defined (SEPCHAR) && defined (SEPCHAR_STR) |
116 # define ENV_SEP SEPCHAR | |
117 # define ENV_SEP_STRING SEPCHAR_STR | |
118 # elif defined (__WIN32__) && ! defined (__CYGWIN__) | |
119 # define ENV_SEP ';' | |
120 # define ENV_SEP_STRING ";" | |
121 # else | |
122 # define ENV_SEP ':' | |
123 # define ENV_SEP_STRING ":" | |
124 # endif | |
125 #endif | |
4385 | 126 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
127 #if ! defined (IS_ENV_SEP) |
21874 | 128 # define IS_ENV_SEP(ch) ((ch) == ENV_SEP) |
4385 | 129 #endif |
130 | |
21874 | 131 // If NO_DEBUG is defined (not recommended), skip all this. |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
132 #if ! defined (NO_DEBUG) |
4385 | 133 |
21874 | 134 // OK, we'll have tracing support. |
135 # define KPSE_DEBUG | |
4385 | 136 |
21874 | 137 // Test if a bit is on. |
138 # define KPSE_DEBUG_P(bit) (kpathsea_debug & (1 << (bit))) | |
4385 | 139 |
21874 | 140 # define KPSE_DEBUG_STAT 0 // stat calls |
141 # define KPSE_DEBUG_EXPAND 1 // path element expansion | |
142 # define KPSE_DEBUG_SEARCH 2 // searches | |
143 # define KPSE_DEBUG_VARS 3 // variable values | |
144 # define KPSE_LAST_DEBUG KPSE_DEBUG_VARS | |
4385 | 145 |
21874 | 146 #endif |
4385 | 147 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
148 #if defined (KPSE_DEBUG) |
4399 | 149 static unsigned int kpathsea_debug = 0; |
150 #endif | |
151 | |
4389 | 152 static std::string kpse_var_expand (const std::string& src); |
4385 | 153 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
154 static std::string kpse_element_dir (const std::string& elt); |
4399 | 155 |
156 static std::string kpse_expand (const std::string& s); | |
157 | |
158 static bool | |
4394 | 159 kpse_is_env_sep (char c) |
160 { | |
161 return IS_ENV_SEP (c); | |
162 } | |
163 | |
21874 | 164 // A way to step through a path, extracting one directory name at a |
165 // time. | |
4399 | 166 |
167 class kpse_path_iterator | |
168 { | |
169 public: | |
170 | |
171 kpse_path_iterator (const std::string& p) | |
172 : path (p), b (0), e (0), len (path.length ()) { set_end (); } | |
173 | |
174 kpse_path_iterator (const kpse_path_iterator& pi) | |
175 : path (pi.path), b (pi.b), e (pi.e), len (pi.len) { } | |
176 | |
177 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
|
178 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
179 kpse_path_iterator retval (*this); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
180 next (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
181 return retval; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
182 } |
4399 | 183 |
184 std::string operator * (void) { return path.substr (b, e-b); } | |
185 | |
186 bool operator != (const size_t sz) { return b != sz; } | |
187 | |
188 private: | |
189 | |
190 const std::string& path; | |
191 size_t b; | |
192 size_t e; | |
193 size_t len; | |
194 | |
195 void set_end (void) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
196 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
197 e = b + 1; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
198 |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
199 if (e == len) |
21874 | 200 ; // OK, we have found the last element. |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
201 else if (e > len) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
202 b = e = std::string::npos; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
203 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
204 { |
21874 | 205 // Find the next colon not enclosed by braces (or the end of the |
206 // path). | |
207 | |
20443
610c74748518
maint: Clean up code based on static analysis suggestions.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
208 while (e < len && ! kpse_is_env_sep (path[e])) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
209 e++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
210 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
211 } |
4399 | 212 |
213 void next (void) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
214 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
215 b = e + 1; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
216 |
21874 | 217 // Skip any consecutive colons. |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
218 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
|
219 b++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
220 |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
221 if (b >= len) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
222 b = e = std::string::npos; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
223 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
224 set_end (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
225 } |
5617 | 226 |
227 // No assignment. | |
228 kpse_path_iterator& operator = (const kpse_path_iterator&); | |
4399 | 229 }; |
230 | |
4391 | 231 /* Truncate any too-long components in NAME, returning the result. It's |
232 too bad this is necessary. See comments in readable.c for why. */ | |
233 | |
4393 | 234 static std::string |
235 kpse_truncate_filename (const std::string& name) | |
4391 | 236 { |
237 unsigned c_len = 0; /* Length of current component. */ | |
238 unsigned ret_len = 0; /* Length of constructed result. */ | |
239 | |
4393 | 240 std::string ret = name; |
241 | |
242 size_t len = name.length (); | |
243 | |
244 for (size_t i = 0; i < len; i++) | |
4391 | 245 { |
4393 | 246 if (IS_DIR_SEP (name[i]) || IS_DEVICE_SEP (name[i])) |
4391 | 247 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
248 /* At a directory delimiter, reset component length. */ |
4391 | 249 c_len = 0; |
250 } | |
251 else if (c_len > NAME_MAX) | |
252 { | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
253 /* If past the max for a component, ignore this character. */ |
4391 | 254 continue; |
255 } | |
256 | |
257 /* Copy this character. */ | |
4393 | 258 ret[ret_len++] = name[i]; |
4391 | 259 c_len++; |
260 } | |
261 | |
4393 | 262 ret.resize (ret_len); |
4391 | 263 |
264 return ret; | |
265 } | |
266 | |
267 /* If access can read FN, run stat (assigning to stat buffer ST) and | |
268 check that fn is not a directory. Don't check for just being a | |
269 regular file, as it is potentially useful to read fifo's or some | |
270 kinds of devices. */ | |
271 | |
21874 | 272 #if defined (__WIN32__) |
4391 | 273 static inline bool |
21865 | 274 READABLE (const std::string& fn) |
4391 | 275 { |
4393 | 276 const char *t = fn.c_str (); |
277 return (GetFileAttributes (t) != 0xFFFFFFFF | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
278 && ! (GetFileAttributes (t) & FILE_ATTRIBUTE_DIRECTORY)); |
4391 | 279 } |
280 #else | |
281 static inline bool | |
21865 | 282 READABLE (const std::string& fn) |
4391 | 283 { |
21865 | 284 bool retval = false; |
285 | |
4393 | 286 const char *t = fn.c_str (); |
21865 | 287 |
288 if (access (t, R_OK) == 0) | |
289 { | |
290 octave::sys::file_stat fs (fn); | |
291 | |
292 retval = fs && ! fs.is_dir (); | |
293 } | |
294 | |
295 return retval; | |
4391 | 296 } |
297 #endif | |
298 | |
299 /* POSIX invented the brain-damage of not necessarily truncating | |
300 filename components; the system's behavior is defined by the value of | |
301 the symbol _POSIX_NO_TRUNC, but you can't change it dynamically! | |
302 | |
303 Generic const return warning. See extend-fname.c. */ | |
304 | |
4393 | 305 static std::string |
306 kpse_readable_file (const std::string& name) | |
4391 | 307 { |
4393 | 308 std::string ret; |
4391 | 309 |
21865 | 310 if (READABLE (name)) |
4391 | 311 { |
4393 | 312 ret = name; |
4391 | 313 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
314 #if defined (ENAMETOOLONG) |
4391 | 315 } |
316 else if (errno == ENAMETOOLONG) | |
317 { | |
318 ret = kpse_truncate_filename (name); | |
319 | |
320 /* 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
|
321 so let's call access again. */ |
4391 | 322 |
21865 | 323 if (! READABLE (ret)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
324 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
325 /* Failed. */ |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
326 ret = ""; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
327 } |
4391 | 328 #endif /* ENAMETOOLONG */ |
329 | |
330 } | |
331 else | |
332 { | |
333 /* Some other error. */ | |
334 if (errno == EACCES) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
335 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
336 /* Maybe warn them if permissions are bad. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
337 perror (name.c_str ()); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
338 } |
4393 | 339 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
340 ret = ""; |
4391 | 341 } |
342 | |
343 return ret; | |
344 } | |
345 | |
346 static bool | |
347 kpse_absolute_p (const std::string& filename, int relative_ok) | |
348 { | |
21865 | 349 return (octave::sys::env::absolute_pathname (filename) |
350 || (relative_ok | |
351 && octave::sys::env::rooted_relative_pathname (filename))); | |
4391 | 352 } |
353 | |
4378 | 354 /* The very first search is for texmf.cnf, called when someone tries to |
355 initialize the TFM path or whatever. init_path calls kpse_cnf_get | |
356 which calls kpse_all_path_search to find all the texmf.cnf's. We | |
357 need to do various special things in this case, since we obviously | |
358 don't yet have the configuration files when we're searching for the | |
359 configuration files. */ | |
360 static bool first_search = true; | |
361 | |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
362 /* This function is called after every search. */ |
4378 | 363 |
364 static void | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
365 log_search (const std::list<std::string>& filenames) |
4378 | 366 { |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
367 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) |
4391 | 368 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
369 for (const auto &filename : filenames) |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
370 std::cerr << time (0) << " " << filename << std::endl; |
4378 | 371 } |
372 } | |
4392 | 373 |
4378 | 374 /* Concatenate each element in DIRS with NAME (assume each ends with a |
375 /, to save time). If SEARCH_ALL is false, return the first readable | |
376 regular file. Else continue to search for more. In any case, if | |
377 none, return a list containing just NULL. | |
378 | |
379 We keep a single buffer for the potential filenames and reallocate | |
380 only when necessary. I'm not sure it's noticeably faster, but it | |
381 does seem cleaner. (We do waste a bit of space in the return | |
382 value, though, since we don't shrink it to the final size returned.) */ | |
383 | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
384 static std::list<std::string> |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
385 dir_search (const std::string& dir, const std::string& name, |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
386 bool search_all) |
4378 | 387 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
388 std::list<std::string> ret; |
4378 | 389 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
390 std::string potential = dir + name; |
4393 | 391 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
392 std::string tmp = kpse_readable_file (potential); |
4393 | 393 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
394 if (! tmp.empty ()) |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
395 { |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
396 ret.push_back (potential); |
4391 | 397 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
398 if (! search_all) |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
399 return ret; |
4378 | 400 } |
4391 | 401 |
4378 | 402 return ret; |
403 } | |
4392 | 404 |
4378 | 405 /* This is called when NAME is absolute or explicitly relative; if it's |
406 readable, return (a list containing) it; otherwise, return NULL. */ | |
407 | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
408 static std::list<std::string> |
4393 | 409 absolute_search (const std::string& name) |
4378 | 410 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
411 std::list<std::string> ret_list; |
4393 | 412 std::string found = kpse_readable_file (name); |
4391 | 413 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
414 /* Add 'found' to the return list even if it's null; that tells |
4378 | 415 the caller we didn't find anything. */ |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
416 ret_list.push_back (found); |
4391 | 417 |
4378 | 418 return ret_list; |
419 } | |
4392 | 420 |
4378 | 421 /* This is the hard case -- look for NAME in PATH. If ALL is false, |
422 return the first file found. Otherwise, search all elements of PATH. */ | |
423 | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
424 static std::list<std::string> |
4394 | 425 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
|
426 bool /* must_exist */, bool all) |
4378 | 427 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
428 std::list<std::string> ret_list; |
4378 | 429 bool done = false; |
4390 | 430 |
8021 | 431 for (kpse_path_iterator pi (path); ! done && pi != std::string::npos; pi++) |
4390 | 432 { |
4394 | 433 std::string elt = *pi; |
434 | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
435 std::list<std::string> found; |
4390 | 436 |
437 /* Do not touch the device if present */ | |
438 if (NAME_BEGINS_WITH_DEVICE (elt)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
439 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
440 while (elt.length () > 3 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
441 && 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
|
442 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
443 elt[2] = elt[1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
444 elt[1] = elt[0]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
445 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
446 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
447 } |
4390 | 448 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
449 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
450 /* We never want to search the whole disk. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
451 while (elt.length () > 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
452 && 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
|
453 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
454 } |
4391 | 455 |
21872 | 456 /* Our caller (search), also tests first_search, and does |
457 the resetting. */ | |
21865 | 458 if (first_search) |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
459 found = std::list<std::string> (); |
21865 | 460 |
461 /* Search the filesystem. */ | |
462 | |
463 if (found.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
464 { |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
465 std::string dir = kpse_element_dir (elt); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
466 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
467 if (! dir.empty ()) |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
468 found = dir_search (dir, name, all); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
469 } |
4390 | 470 |
471 /* Did we find anything anywhere? */ | |
472 if (! found.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
473 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
474 if (all) |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
475 ret_list.splice (ret_list.end (), found); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
476 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
477 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
478 ret_list.push_back (found.front ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
479 done = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
480 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
481 } |
4378 | 482 } |
483 | |
484 return ret_list; | |
4390 | 485 } |
4392 | 486 |
4378 | 487 /* Search PATH for ORIGINAL_NAME. If ALL is false, or ORIGINAL_NAME is |
488 absolute_p, check ORIGINAL_NAME itself. Otherwise, look at each | |
489 element of PATH for the first readable ORIGINAL_NAME. | |
4391 | 490 |
4378 | 491 Always return a list; if no files are found, the list will |
492 contain just NULL. If ALL is true, the list will be | |
493 terminated with NULL. */ | |
494 | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
495 static std::list<std::string> |
4390 | 496 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
|
497 bool must_exist, bool all) |
4378 | 498 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
499 std::list<std::string> ret_list; |
4378 | 500 bool absolute_p; |
501 | |
502 /* Make a leading ~ count as an absolute filename, and expand $FOO's. */ | |
4390 | 503 std::string name = kpse_expand (original_name); |
4391 | 504 |
4378 | 505 /* If the first name is absolute or explicitly relative, no need to |
506 consider PATH at all. */ | |
507 absolute_p = kpse_absolute_p (name, true); | |
4391 | 508 |
4378 | 509 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
510 std::cerr << "kdebug: start search (file=" << name |
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
511 << ", must_exist=" << must_exist |
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
512 << ", find_all=" << all << ", path=" << path << ")." |
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
513 << std::endl; |
4378 | 514 |
515 /* Find the file(s). */ | |
516 ret_list = absolute_p ? absolute_search (name) | |
517 : path_search (path, name, must_exist, all); | |
4391 | 518 |
4378 | 519 /* The very first search is for texmf.cnf. We can't log that, since |
520 we want to allow setting TEXMFLOG in texmf.cnf. */ | |
4391 | 521 if (first_search) |
522 { | |
523 first_search = false; | |
524 } | |
525 else | |
526 { | |
527 /* 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
|
528 debugging line if we're doing that. */ |
4391 | 529 |
530 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
531 std::cerr << "kdebug: search (" << original_name << ") =>"; |
4391 | 532 |
533 log_search (ret_list); | |
534 | |
535 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
536 std::cerr << std::endl; |
4391 | 537 } |
4378 | 538 |
4390 | 539 return ret_list; |
4378 | 540 } |
4392 | 541 |
4378 | 542 /* Search PATH for the first NAME. */ |
543 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
544 /* Call 'kpse_expand' on NAME. If the result is an absolute or |
4399 | 545 explicitly relative filename, check whether it is a readable |
546 (regular) file. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
547 |
4399 | 548 Otherwise, look in each of the directories specified in PATH (also do |
21865 | 549 tilde and variable expansion on elements in PATH). |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
550 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21732
diff
changeset
|
551 The caller must expand PATH. This is because it makes more sense to |
4399 | 552 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
|
553 |
4399 | 554 In any case, return the complete filename if found, otherwise NULL. */ |
555 | |
556 static std::string | |
4390 | 557 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
|
558 bool must_exist) |
4378 | 559 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
560 std::list<std::string> ret_list = search (path, name, must_exist, false); |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
561 |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
562 return ret_list.empty () ? "" : ret_list.front (); |
4378 | 563 } |
564 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
565 /* Like 'kpse_path_search' with MUST_EXIST true, but return a list of |
4399 | 566 all the filenames (or NULL if none), instead of taking the first. */ |
567 | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
568 static std::list<std::string> |
4390 | 569 kpse_all_path_search (const std::string& path, const std::string& name) |
4378 | 570 { |
4390 | 571 return search (path, name, true, true); |
4378 | 572 } |
4392 | 573 |
4378 | 574 /* This is the hard case -- look in each element of PATH for each |
575 element of NAMES. If ALL is false, return the first file found. | |
576 Otherwise, search all elements of PATH. */ | |
577 | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
578 static std::list<std::string> |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
579 path_find_first_of (const std::string& path, |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
580 const std::list<std::string>& names, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
581 bool /* must_exist */, bool all) |
4378 | 582 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
583 std::list<std::string> ret_list; |
4378 | 584 bool done = false; |
4390 | 585 |
8021 | 586 for (kpse_path_iterator pi (path); ! done && pi != std::string::npos; pi++) |
4378 | 587 { |
4394 | 588 std::string elt = *pi; |
589 | |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
590 std::string dir; |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
591 std::list<std::string> found; |
4378 | 592 |
593 /* Do not touch the device if present */ | |
594 | |
595 if (NAME_BEGINS_WITH_DEVICE (elt)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
596 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
597 while (elt.length () > 3 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
598 && 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
|
599 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
600 elt[2] = elt[1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
601 elt[1] = elt[0]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
602 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
603 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
604 } |
4378 | 605 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
606 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
607 /* We never want to search the whole disk. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
608 while (elt.length () > 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
609 && 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
|
610 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
611 } |
4378 | 612 |
613 /* We have to search one directory at a time. */ | |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
614 dir = kpse_element_dir (elt); |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
615 |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
616 if (! dir.empty ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
617 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
618 for (auto it = names.cbegin (); it != names.cend () && ! done; it++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
619 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
620 std::string name = *it; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
621 |
21872 | 622 /* Our caller (find_first_of), also tests first_search, |
623 and does the resetting. */ | |
21865 | 624 if (first_search) |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
625 found = std::list<std::string> (); |
21865 | 626 |
627 /* Search the filesystem. */ | |
628 | |
629 if (found.empty ()) | |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
630 found = dir_search (dir, name, all); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
631 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
632 /* Did we find anything anywhere? */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
633 if (! found.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
634 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
635 if (all) |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
636 ret_list.splice (ret_list.end (), found); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
637 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
638 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
639 ret_list.push_back (found.front ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
640 done = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
641 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
642 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
643 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
644 } |
4378 | 645 } |
646 | |
647 return ret_list; | |
4391 | 648 } |
4378 | 649 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
650 static std::list<std::string> |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
651 find_first_of (const std::string& path, const std::list<std::string>& names, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
652 bool must_exist, bool all) |
4378 | 653 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
654 std::list<std::string> ret_list; |
4378 | 655 |
656 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
657 { | |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
658 std::cerr << "kdebug: start find_first_of (("; |
4391 | 659 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
660 for (auto p = names.cbegin (); p != names.cend (); p++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
661 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
662 if (p == names.cbegin ()) |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
663 std::cerr << *p; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
664 else |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
665 std::cerr << ", " << *p; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
666 } |
4391 | 667 |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
668 std::cerr << "), path=" << path << ", must_exist=" |
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
669 << must_exist << "." << std::endl; |
4378 | 670 } |
671 | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
672 for (const auto &name : names) |
4409 | 673 { |
674 if (kpse_absolute_p (name, true)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
675 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
676 /* 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
|
677 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
|
678 are done. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
679 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
680 ret_list = absolute_search (name); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
681 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
682 if (! ret_list.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
683 return ret_list; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
684 } |
4409 | 685 } |
686 | |
4378 | 687 /* Find the file. */ |
688 ret_list = path_find_first_of (path, names, must_exist, all); | |
689 | |
690 /* The very first search is for texmf.cnf. We can't log that, since | |
691 we want to allow setting TEXMFLOG in texmf.cnf. */ | |
4391 | 692 if (first_search) |
693 { | |
694 first_search = false; | |
695 } | |
696 else | |
697 { | |
698 /* 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
|
699 debugging line if we're doing that. */ |
4391 | 700 |
701 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
702 { |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
703 std::cerr << "kdebug: find_first_of ("; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
704 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
705 for (auto p = names.cbegin (); p != names.cend (); p++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
706 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
707 if (p == names.cbegin ()) |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
708 std:: cerr << *p; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
709 else |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
710 std::cerr << ", " << *p; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
711 } |
10411 | 712 |
21868
e2796ea8feac
* kpse.cc: Use iostream for debug messages.
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
713 std::cerr << ") =>"; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
714 } |
4391 | 715 |
716 log_search (ret_list); | |
717 | |
718 if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) | |
10411 | 719 gnulib::putc ('\n', stderr); |
4391 | 720 } |
4378 | 721 |
4390 | 722 return ret_list; |
4378 | 723 } |
724 | |
725 /* Search each element of PATH for each element of NAMES. Return the | |
726 first one found. */ | |
727 | |
4399 | 728 /* Search each element of PATH for each element in the list of NAMES. |
729 Return the first one found. */ | |
730 | |
731 static std::string | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
732 kpse_path_find_first_of (const std::string& path, |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
733 const std::list<std::string>& names, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
734 bool must_exist) |
4378 | 735 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
736 std::list<std::string> ret_list |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
737 = find_first_of (path, names, must_exist, false); |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
738 |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
739 return ret_list.empty () ? "" : ret_list.front (); |
4378 | 740 } |
741 | |
742 /* Search each element of PATH for each element of NAMES and return a | |
743 list containing everything found, in the order found. */ | |
744 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
745 /* Like 'kpse_path_find_first_of' with MUST_EXIST true, but return a |
4399 | 746 list of all the filenames (or NULL if none), instead of taking the |
747 first. */ | |
748 | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
749 static std::list<std::string> |
4390 | 750 kpse_all_path_find_first_of (const std::string& path, |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
751 const std::list<std::string>& names) |
4378 | 752 { |
4390 | 753 return find_first_of (path, names, true, true); |
4378 | 754 } |
755 | |
4399 | 756 /* General expansion. Some of this file (the brace-expansion |
4378 | 757 code from bash) is covered by the GPL; this is the only GPL-covered |
758 code in kpathsea. The part of the file that I wrote (the first | |
759 couple of functions) is covered by the LGPL. */ | |
760 | |
761 /* If NAME has a leading ~ or ~user, Unix-style, expand it to the user's | |
762 home directory, and return a new malloced string. If no ~, or no | |
763 <pwd.h>, just return NAME. */ | |
764 | |
4389 | 765 static std::string |
766 kpse_tilde_expand (const std::string& name) | |
4378 | 767 { |
4389 | 768 std::string expansion; |
4391 | 769 |
4378 | 770 /* If no leading tilde, do nothing. */ |
5137 | 771 if (name.empty () || name[0] != '~') |
4391 | 772 { |
773 expansion = name; | |
774 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
775 /* 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
|
776 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
|
777 ... */ |
4391 | 778 } |
779 else if (name.length () == 1) | |
780 { | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
781 expansion = octave::sys::env::get_home_directory (); |
4391 | 782 |
783 if (expansion.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
784 expansion = "."; |
4391 | 785 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
786 /* 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
|
787 Should really check for doubled intermediate slashes, too. */ |
4378 | 788 } |
4391 | 789 else if (IS_DIR_SEP (name[1])) |
790 { | |
791 unsigned c = 1; | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
792 std::string home = octave::sys::env::get_home_directory (); |
4391 | 793 |
794 if (home.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
795 home = "."; |
4391 | 796 |
797 size_t home_len = home.length (); | |
798 | |
799 /* handle leading // */ | |
800 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
|
801 home = home.substr (1); |
4391 | 802 |
803 /* omit / after ~ */ | |
804 if (IS_DIR_SEP (home[home_len - 1])) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
805 c++; |
4391 | 806 |
807 expansion = home + name.substr (c); | |
808 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
809 /* 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
|
810 OS/2 doesn't have this concept. */ |
4378 | 811 } |
4391 | 812 else |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
813 #if defined (HAVE_PWD_H) |
4378 | 814 { |
815 unsigned c = 2; | |
4391 | 816 |
817 /* find user name */ | |
818 while (name.length () > c && ! IS_DIR_SEP (name[c])) | |
4378 | 819 c++; |
4391 | 820 |
821 std::string user = name.substr (1, c-1); | |
822 | |
4378 | 823 /* 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
|
824 which do not declare 'getpwnam' in <pwd.h>. */ |
21729
815b2f500fab
use namespace for system password wrapper class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
825 octave::sys::password p = octave::sys::password::getpwnam (user); |
4378 | 826 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
827 /* If no such user, just use '.'. */ |
4391 | 828 std::string home = p ? p.dir () : std::string ("."); |
829 | |
830 if (home.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
831 home = "."; |
4391 | 832 |
833 /* handle leading // */ | |
834 if (home.length () > 1 && IS_DIR_SEP (home[0]) && IS_DIR_SEP (home[1])) | |
835 home = home.substr (1); | |
836 | |
837 /* If HOME ends in /, omit the / after ~user. */ | |
838 if (name.length () > c && IS_DIR_SEP (home[home.length () - 1])) | |
839 c++; | |
840 | |
841 expansion = name.length () > c ? home : home + name.substr (c); | |
4378 | 842 } |
843 #else /* not HAVE_PWD_H */ | |
4391 | 844 expansion = name; |
4378 | 845 #endif /* not HAVE_PWD_H */ |
846 | |
4389 | 847 return expansion; |
4378 | 848 } |
849 | |
850 /* Do variable expansion first so ~${USER} works. (Besides, it's what the | |
851 shells do.) */ | |
852 | |
4399 | 853 /* Call kpse_var_expand and kpse_tilde_expand (in that order). Result |
854 is always in fresh memory, even if no expansions were done. */ | |
855 | |
856 static std::string | |
4389 | 857 kpse_expand (const std::string& s) |
4378 | 858 { |
4389 | 859 std::string var_expansion = kpse_var_expand (s); |
860 return kpse_tilde_expand (var_expansion); | |
4378 | 861 } |
862 | |
863 /* Forward declarations of functions from the original expand.c */ | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
864 static std::list<std::string> brace_expand (const std::string&); |
4378 | 865 |
866 /* If $KPSE_DOT is defined in the environment, prepend it to any relative | |
867 path components. */ | |
868 | |
4389 | 869 static std::string |
870 kpse_expand_kpse_dot (const std::string& path) | |
4378 | 871 { |
4389 | 872 std::string ret; |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
873 std::string kpse_dot = octave::sys::env::getenv ("KPSE_DOT"); |
4391 | 874 |
875 if (kpse_dot.empty ()) | |
4378 | 876 return path; |
877 | |
8021 | 878 for (kpse_path_iterator pi (path); pi != std::string::npos; pi++) |
4391 | 879 { |
4394 | 880 std::string elt = *pi; |
881 | |
21872 | 882 /* Single "." get special treatment, as does "./" or its equivalent. */ |
4391 | 883 |
4394 | 884 size_t elt_len = elt.length (); |
885 | |
21872 | 886 if (kpse_absolute_p (elt, false)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
887 ret += elt + ENV_SEP_STRING; |
4394 | 888 else if (elt_len == 1 && elt[0] == '.') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
889 ret += kpse_dot + ENV_SEP_STRING; |
4394 | 890 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
|
891 ret += kpse_dot + elt.substr (1) + ENV_SEP_STRING; |
4391 | 892 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
893 ret += kpse_dot + DIR_SEP_STRING + elt + ENV_SEP_STRING; |
4378 | 894 } |
895 | |
4389 | 896 int len = ret.length (); |
897 if (len > 0) | |
4395 | 898 ret.resize (len-1); |
4389 | 899 |
4378 | 900 return ret; |
901 } | |
902 | |
903 /* Do brace expansion on ELT; then do variable and ~ expansion on each | |
904 element of the result; then do brace expansion again, in case a | |
905 variable definition contained braces (e.g., $TEXMF). Return a | |
906 string comprising all of the results separated by ENV_SEP_STRING. */ | |
907 | |
4389 | 908 static std::string |
4394 | 909 kpse_brace_expand_element (const std::string& elt) |
4378 | 910 { |
4389 | 911 std::string ret; |
4378 | 912 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
913 std::list<std::string> expansions = brace_expand (elt); |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
914 |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
915 for (const auto &expanded_elt : expansions) |
4391 | 916 { |
917 /* Do $ and ~ expansion on each element. */ | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
918 std::string x = kpse_expand (expanded_elt); |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
919 |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
920 if (x != elt) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
921 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
922 /* 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
|
923 recursive variable definitions are not allowed, this recursion |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
924 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
|
925 more than one level of recursion.) */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
926 x = kpse_brace_expand_element (x); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
927 } |
4391 | 928 |
929 ret += x + ENV_SEP_STRING; | |
4378 | 930 } |
931 | |
4389 | 932 ret.resize (ret.length () - 1); |
4391 | 933 |
4378 | 934 return ret; |
935 } | |
936 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
937 /* Do brace expansion and call 'kpse_expand' on each element of the |
4399 | 938 result; return the final expansion (always in fresh memory, even if |
21874 | 939 no expansions were done). */ |
4399 | 940 |
941 static std::string | |
4397 | 942 kpse_brace_expand (const std::string& path) |
4378 | 943 { |
944 /* Must do variable expansion first because if we have | |
945 foo = .:~ | |
946 TEXINPUTS = $foo | |
947 we want to end up with TEXINPUTS = .:/home/karl. | |
948 Since kpse_path_element is not reentrant, we must get all | |
949 the path elements before we start the loop. */ | |
4389 | 950 std::string tmp = kpse_var_expand (path); |
4394 | 951 |
4389 | 952 std::string ret; |
4378 | 953 |
8021 | 954 for (kpse_path_iterator pi (tmp); pi != std::string::npos; pi++) |
4391 | 955 { |
4394 | 956 std::string elt = *pi; |
957 | |
4391 | 958 /* Do brace expansion first, so tilde expansion happens in {~ka,~kb}. */ |
959 std::string expansion = kpse_brace_expand_element (elt); | |
960 ret += expansion + ENV_SEP_STRING; | |
961 } | |
4378 | 962 |
4394 | 963 size_t len = ret.length (); |
4389 | 964 if (len > 0) |
4395 | 965 ret.resize (len-1); |
4389 | 966 |
967 return kpse_expand_kpse_dot (ret); | |
4378 | 968 } |
4392 | 969 |
4378 | 970 /* Expand all special constructs in a path, and include only the actually |
971 existing directories in the result. */ | |
4399 | 972 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
973 /* Do brace expansion and call 'kpse_expand' on each argument of the |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
974 result. The final expansion (always in fresh memory) is a path of |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
975 all the existing directories that match the pattern. */ |
4399 | 976 |
977 static std::string | |
4397 | 978 kpse_path_expand (const std::string& path) |
4378 | 979 { |
4392 | 980 std::string ret; |
4378 | 981 unsigned len; |
982 | |
983 len = 0; | |
4391 | 984 |
4378 | 985 /* Expand variables and braces first. */ |
4389 | 986 std::string tmp = kpse_brace_expand (path); |
4392 | 987 |
4378 | 988 /* Now expand each of the path elements, printing the results */ |
8021 | 989 for (kpse_path_iterator pi (tmp); pi != std::string::npos; pi++) |
4391 | 990 { |
4394 | 991 std::string elt = *pi; |
992 | |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
993 std::string dir; |
4391 | 994 |
995 /* Do not touch the device if present */ | |
996 if (NAME_BEGINS_WITH_DEVICE (elt)) | |
10314
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 while (elt.length () > 3 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
999 && 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
|
1000 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1001 elt[2] = elt[1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1002 elt[1] = elt[0]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1003 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1004 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1005 } |
4391 | 1006 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1007 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1008 /* We never want to search the whole disk. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1009 while (elt.length () > 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1010 && 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
|
1011 elt = elt.substr (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1012 } |
4378 | 1013 |
4394 | 1014 /* 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
|
1015 Be faster to check the database, but this is more reliable. */ |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1016 dir = kpse_element_dir (elt); |
4394 | 1017 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1018 size_t dirlen = dir.length (); |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1019 |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1020 if (dirlen > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1021 { |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1022 ret += dir; |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1023 len += dirlen; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1024 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1025 /* Retain trailing slash if that's the root directory. */ |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1026 if (dirlen == 1 |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1027 || (dirlen == 3 && NAME_BEGINS_WITH_DEVICE (dir) |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1028 && IS_DIR_SEP (dir[2]))) |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1029 { |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1030 ret += ENV_SEP_STRING; |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1031 len++; |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1032 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1033 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1034 ret[len-1] = ENV_SEP; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1035 } |
4378 | 1036 } |
4391 | 1037 |
4395 | 1038 if (len > 0) |
1039 ret.resize (len-1); | |
4391 | 1040 |
4378 | 1041 return ret; |
1042 } | |
4392 | 1043 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21732
diff
changeset
|
1044 /* braces.c -- code for doing word expansion in curly braces. Taken from |
16768 | 1045 bash 1.14.5. [And subsequently modified for kpatshea.] |
1046 | |
1047 Copyright (C) 1987,1991 Free Software Foundation, Inc. */ | |
4378 | 1048 |
4391 | 1049 #define brace_whitespace(c) (! (c) || (c) == ' ' || (c) == '\t' || (c) == '\n') |
4378 | 1050 |
1051 /* Basic idea: | |
1052 | |
1053 Segregate the text into 3 sections: preamble (stuff before an open brace), | |
1054 postamble (stuff after the matching close brace) and amble (stuff after | |
1055 preamble, and before postamble). Expand amble, and then tack on the | |
1056 expansions to preamble. Expand postamble, and tack on the expansions to | |
4391 | 1057 the result so far. */ |
4378 | 1058 |
4397 | 1059 /* Return a new array of strings which is the result of appending each |
1060 string in ARR2 to each string in ARR1. The resultant array is | |
1061 len (arr1) * len (arr2) long. For convenience, ARR1 (and its contents) | |
1062 are free ()'ed. ARR1 can be NULL, in that case, a new version of ARR2 | |
1063 is returned. */ | |
1064 | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1065 static std::list<std::string> |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1066 array_concat (const std::list<std::string>& arr1, |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1067 const std::list<std::string>& arr2) |
4378 | 1068 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1069 std::list<std::string> result; |
4397 | 1070 |
1071 if (arr1.empty ()) | |
1072 result = arr2; | |
1073 else if (arr2.empty ()) | |
1074 result = arr1; | |
1075 else | |
1076 { | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1077 for (const auto &elt_2 : arr2) |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1078 for (const auto &elt_1 : arr1) |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1079 result.push_back (elt_1 + elt_2); |
4397 | 1080 } |
1081 | |
1082 return result; | |
4378 | 1083 } |
1084 | |
4397 | 1085 static int brace_gobbler (const std::string&, int&, int); |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1086 static std::list<std::string> expand_amble (const std::string&); |
4378 | 1087 |
1088 /* Return an array of strings; the brace expansion of TEXT. */ | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1089 static std::list<std::string> |
4397 | 1090 brace_expand (const std::string& text) |
4378 | 1091 { |
1092 /* Find the text of the preamble. */ | |
4397 | 1093 int i = 0; |
1094 int c = brace_gobbler (text, i, '{'); | |
1095 | |
1096 std::string preamble = text.substr (0, i); | |
1097 | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1098 std::list<std::string> result (1, preamble); |
4397 | 1099 |
1100 if (c == '{') | |
4378 | 1101 { |
4397 | 1102 /* Find the amble. This is the stuff inside this set of braces. */ |
1103 int start = ++i; | |
1104 c = brace_gobbler (text, i, '}'); | |
1105 | |
1106 /* What if there isn't a matching close brace? */ | |
1107 if (! c) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1108 { |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1109 (*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
|
1110 ("Octave:pathsearch-syntax", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1111 "%s: Unmatched {", text.c_str ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1112 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1113 result = std::list<std::string> (1, text); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1114 } |
4397 | 1115 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1116 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1117 std::string amble = text.substr (start, i-start); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1118 result = array_concat (result, expand_amble (amble)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1119 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1120 std::string postamble = text.substr (i+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1121 result = array_concat (result, brace_expand (postamble)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1122 } |
4378 | 1123 } |
1124 | |
4397 | 1125 return result; |
4378 | 1126 } |
1127 | |
4397 | 1128 /* The character which is used to separate arguments. */ |
1129 static int brace_arg_separator = ','; | |
1130 | |
4378 | 1131 /* Expand the text found inside of braces. We simply try to split the |
1132 text at BRACE_ARG_SEPARATORs into separate strings. We then brace | |
1133 expand each slot which needs it, until there are no more slots which | |
1134 need it. */ | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1135 static std::list<std::string> |
4397 | 1136 expand_amble (const std::string& text) |
4378 | 1137 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1138 std::list<std::string> result; |
4397 | 1139 |
1140 size_t text_len = text.length (); | |
1141 size_t start; | |
1142 int i, c; | |
1143 | |
1144 for (start = 0, i = 0, c = 1; c && start < text_len; start = ++i) | |
4378 | 1145 { |
4397 | 1146 int i0 = i; |
1147 int c0 = brace_gobbler (text, i0, brace_arg_separator); | |
1148 int i1 = i; | |
1149 int c1 = brace_gobbler (text, i1, ENV_SEP); | |
4378 | 1150 c = c0 | c1; |
1151 i = (i0 < i1 ? i0 : i1); | |
1152 | |
4397 | 1153 std::string tem = text.substr (start, i-start); |
1154 | |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1155 std::list<std::string> partial = brace_expand (tem); |
4397 | 1156 |
1157 if (result.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1158 result = partial; |
4378 | 1159 else |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21865
diff
changeset
|
1160 result.splice (result.end (), partial); |
4378 | 1161 } |
4397 | 1162 |
1163 return result; | |
4378 | 1164 } |
1165 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21732
diff
changeset
|
1166 /* Start at INDEX, and skip characters in TEXT. Set INDEX to the |
4378 | 1167 index of the character matching SATISFY. This understands about |
1168 quoting. Return the character that caused us to stop searching; | |
1169 this is either the same as SATISFY, or 0. */ | |
1170 static int | |
4397 | 1171 brace_gobbler (const std::string& text, int& indx, int satisfy) |
4378 | 1172 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
1173 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
|
1174 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
|
1175 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
|
1176 int pass_next = 0; |
4397 | 1177 |
1178 size_t text_len = text.length (); | |
1179 | |
1180 size_t i = indx; | |
1181 | |
1182 for (; i < text_len; i++) | |
4378 | 1183 { |
4397 | 1184 c = text[i]; |
1185 | |
4378 | 1186 if (pass_next) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1187 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1188 pass_next = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1189 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1190 } |
4378 | 1191 |
1192 /* 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
|
1193 escape the quote character in a double-quoted string. */ |
4378 | 1194 if (c == '\\' && (quoted == 0 || quoted == '"' || quoted == '`')) |
1195 { | |
1196 pass_next = 1; | |
1197 continue; | |
1198 } | |
1199 | |
1200 if (quoted) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1201 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1202 if (c == quoted) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1203 quoted = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1204 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1205 } |
4378 | 1206 |
1207 if (c == '"' || c == '\'' || c == '`') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1208 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1209 quoted = c; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1210 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1211 } |
4391 | 1212 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
1213 if (c == satisfy && ! level && ! quoted) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1214 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1215 /* 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
|
1216 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
|
1217 was preceded with whitespace. */ |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1218 if (c == '{' |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1219 && ((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:
19697
diff
changeset
|
1220 && (i+1 < text_len |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
1221 && (brace_whitespace (text[i+1]) || text[i+1] == '}')))) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1222 continue; |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1223 /* 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
|
1224 in a '${ }' construct */ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1225 if ((c != '{') || i == 0 || (text[i-1] != '$')) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1226 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1227 } |
4378 | 1228 |
1229 if (c == '{') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1230 level++; |
4378 | 1231 else if (c == '}' && level) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1232 level--; |
4378 | 1233 } |
1234 | |
4397 | 1235 indx = i; |
1236 return c; | |
4378 | 1237 } |
1238 | |
4399 | 1239 /* Expand extra colons. */ |
4378 | 1240 |
1241 /* Check for leading colon first, then trailing, then doubled, since | |
1242 that is fastest. Usually it will be leading or trailing. */ | |
1243 | |
4399 | 1244 /* Replace a leading or trailing or doubled : in PATH with DFLT. If |
1245 no extra colons, return PATH. Only one extra colon is replaced. | |
1246 DFLT may not be NULL. */ | |
1247 | |
1248 static std::string | |
4394 | 1249 kpse_expand_default (const std::string& path, const std::string& fallback) |
4378 | 1250 { |
4394 | 1251 std::string expansion; |
1252 | |
1253 size_t path_len = path.length (); | |
1254 | |
1255 if (path_len == 0) | |
1256 expansion = fallback; | |
4378 | 1257 |
1258 /* Solitary or leading :? */ | |
4394 | 1259 else if (IS_ENV_SEP (path[0])) |
4378 | 1260 { |
4394 | 1261 expansion = path_len == 1 ? fallback : fallback + path; |
4378 | 1262 } |
1263 | |
1264 /* Sorry about the assignment in the middle of the expression, but | |
1265 conventions were made to be flouted and all that. I don't see the | |
1266 point of calling strlen twice or complicating the logic just to | |
1267 avoid the assignment (especially now that I've pointed it out at | |
1268 such great length). */ | |
4394 | 1269 else if (IS_ENV_SEP (path[path_len-1])) |
1270 expansion = path + fallback; | |
4378 | 1271 |
1272 /* OK, not leading or trailing. Check for doubled. */ | |
1273 else | |
1274 { | |
1275 /* What we'll return if we find none. */ | |
4394 | 1276 expansion = path; |
1277 | |
1278 for (size_t i = 0; i < path_len; i++) | |
4378 | 1279 { |
4394 | 1280 if (i + 1 < path_len |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1281 && IS_ENV_SEP (path[i]) && IS_ENV_SEP (path[i+1])) |
4394 | 1282 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1283 /* We have a doubled colon. */ |
4391 | 1284 |
4378 | 1285 /* Copy stuff up to and including the first colon. */ |
1286 /* 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
|
1287 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
|
1288 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1289 break; |
4378 | 1290 } |
1291 } | |
1292 } | |
4391 | 1293 |
4378 | 1294 return expansion; |
1295 } | |
1296 | |
4390 | 1297 /* Return true if FN is a directory or a symlink to a directory, |
1298 false if not. */ | |
1299 | |
1300 static bool | |
1301 dir_p (const std::string& fn) | |
1302 { | |
21865 | 1303 octave::sys::file_stat fs (fn); |
1304 | |
1305 return (fs && fs.is_dir ()); | |
4390 | 1306 } |
4391 | 1307 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1308 /* Given a path element ELT, return a the element with a trailing slash |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1309 or an empty string if the element is not a directory. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
1310 |
4399 | 1311 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
|
1312 most likely only useful to be called from 'kpse_path_search', which |
4399 | 1313 has already assumed expansion has been done. */ |
1314 | |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1315 static std::string |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1316 kpse_element_dir (const std::string& elt) |
4378 | 1317 { |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1318 std::string ret; |
4378 | 1319 |
1320 /* If given nothing, return nothing. */ | |
4398 | 1321 if (elt.empty ()) |
21871
cab605836305
use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents:
21870
diff
changeset
|
1322 return ret; |
4378 | 1323 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1324 if (dir_p (elt)) |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1325 { |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1326 ret = elt; |
4378 | 1327 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1328 char last_char = ret[ret.length () - 1]; |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1329 |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1330 if (! (IS_DIR_SEP (last_char) || IS_DEVICE_SEP (last_char))) |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1331 ret += DIR_SEP_STRING; |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21872
diff
changeset
|
1332 |
4378 | 1333 } |
1334 | |
1335 return ret; | |
1336 } | |
1337 | |
4399 | 1338 /* Variable expansion. */ |
4385 | 1339 |
1340 /* We have to keep track of variables being expanded, otherwise | |
1341 constructs like TEXINPUTS = $TEXINPUTS result in an infinite loop. | |
1342 (Or indirectly recursive variables, etc.) Our simple solution is to | |
1343 add to a list each time an expansion is started, and check the list | |
1344 before expanding. */ | |
1345 | |
4391 | 1346 static std::map <std::string, bool> expansions; |
4385 | 1347 |
1348 static void | |
4391 | 1349 expanding (const std::string& var, bool xp) |
4385 | 1350 { |
4391 | 1351 expansions[var] = xp; |
4385 | 1352 } |
1353 | |
1354 /* Return whether VAR is currently being expanding. */ | |
1355 | |
4391 | 1356 static bool |
1357 expanding_p (const std::string& var) | |
4385 | 1358 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1359 return (expansions.find (var) != expansions.end ()) ? expansions[var] : false; |
4385 | 1360 } |
4392 | 1361 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1362 /* 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
|
1363 at START and ends at END. If 'var' is not set, do not complain. |
4385 | 1364 This is a subroutine for the more complicated expansion function. */ |
1365 | |
1366 static void | |
4391 | 1367 expand (std::string &expansion, const std::string& var) |
4385 | 1368 { |
4391 | 1369 if (expanding_p (var)) |
1370 { | |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1371 (*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
|
1372 ("Octave:pathsearch-syntax", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1373 "kpathsea: variable '%s' references itself (eventually)", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1374 var.c_str ()); |
4385 | 1375 } |
4391 | 1376 else |
1377 { | |
1378 /* Check for an environment variable. */ | |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21729
diff
changeset
|
1379 std::string value = octave::sys::env::getenv (var); |
4391 | 1380 |
1381 if (! value.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1382 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1383 expanding (var, true); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1384 std::string tmp = kpse_var_expand (value); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1385 expanding (var, false); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1386 expansion += tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1387 } |
4391 | 1388 } |
4385 | 1389 } |
4392 | 1390 |
4385 | 1391 /* Can't think of when it would be useful to change these (and the |
1392 diagnostic messages assume them), but ... */ | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
1393 #if ! defined (IS_VAR_START) |
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
1394 /* starts all variable references */ |
4385 | 1395 #define IS_VAR_START(c) ((c) == '$') |
1396 #endif | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
1397 #if ! defined (IS_VAR_CHAR) |
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
1398 /* variable name constituent */ |
4385 | 1399 #define IS_VAR_CHAR(c) (isalnum (c) || (c) == '_') |
1400 #endif | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
1401 #if ! defined (IS_VAR_BEGIN_DELIMITER) |
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
1402 /* start delimited variable name (after $) */ |
4385 | 1403 #define IS_VAR_BEGIN_DELIMITER(c) ((c) == '{') |
1404 #endif | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21690
diff
changeset
|
1405 #if ! defined (IS_VAR_END_DELIMITER) |
4385 | 1406 #define IS_VAR_END_DELIMITER(c) ((c) == '}') |
1407 #endif | |
1408 | |
1409 /* Maybe we should support some or all of the various shell ${...} | |
1410 constructs, especially ${var-value}. */ | |
1411 | |
5085 | 1412 static std::string |
4391 | 1413 kpse_var_expand (const std::string& src) |
4385 | 1414 { |
4389 | 1415 std::string expansion; |
4391 | 1416 |
1417 size_t src_len = src.length (); | |
1418 | |
4385 | 1419 /* Copy everything but variable constructs. */ |
4391 | 1420 for (size_t i = 0; i < src_len; i++) |
1421 { | |
1422 if (IS_VAR_START (src[i])) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1423 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1424 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1425 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14155
diff
changeset
|
1426 /* Three cases: '$VAR', '${VAR}', '$<anything-else>'. */ |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1427 if (IS_VAR_CHAR (src[i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1428 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1429 /* $V: collect name constituents, then expand. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1430 size_t var_end = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1431 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1432 do |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1433 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1434 var_end++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1435 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1436 while (IS_VAR_CHAR (src[var_end])); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1437 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1438 var_end--; /* had to go one past */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1439 expand (expansion, src.substr (i, var_end - i + 1)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1440 i = var_end; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1441 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1442 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1443 else if (IS_VAR_BEGIN_DELIMITER (src[i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1444 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1445 /* ${: scan ahead for matching delimiter, then expand. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1446 size_t var_end = ++i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1447 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
1448 while (var_end < src_len && ! IS_VAR_END_DELIMITER (src[var_end])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1449 var_end++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1450 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1451 if (var_end == src_len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1452 { |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1453 (*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
|
1454 ("Octave:pathsearch-syntax", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1455 "%s: No matching } for ${", src.c_str ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1456 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
|
1457 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1458 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1459 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1460 expand (expansion, src.substr (i, var_end - i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1461 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
|
1462 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1463 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1464 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1465 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1466 /* $<something-else>: error. */ |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1467 (*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
|
1468 ("Octave:pathsearch-syntax", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
1469 "%s: Unrecognized variable construct '$%c'", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1470 src.c_str (), src[i]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1471 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1472 /* Just ignore those chars and keep going. */ |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1473 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1474 } |
4391 | 1475 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
1476 expansion += src[i]; |
4391 | 1477 } |
4389 | 1478 |
1479 return expansion; | |
4385 | 1480 } |