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