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