Mercurial > octave
annotate src/load-path.cc @ 10250:2d47356a7a1a
use gnulib getcwd module
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 03 Feb 2010 03:07:06 -0500 |
parents | 4acae5e46738 |
children | 57a59eae83cc |
rev | line source |
---|---|
5832 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2006, 2007, 2008, 2009 John W. Eaton |
5832 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
5832 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
5832 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <algorithm> | |
28 | |
29 #include "dir-ops.h" | |
30 #include "file-ops.h" | |
31 #include "file-stat.h" | |
32 #include "oct-env.h" | |
33 #include "pathsearch.h" | |
34 | |
35 #include "defaults.h" | |
36 #include "defun.h" | |
37 #include "input.h" | |
38 #include "load-path.h" | |
39 #include "pager.h" | |
40 #include "parse.h" | |
41 #include "toplev.h" | |
42 #include "unwind-prot.h" | |
43 #include "utils.h" | |
44 | |
45 load_path *load_path::instance = 0; | |
7336 | 46 load_path::hook_fcn_ptr load_path::add_hook = execute_pkg_add; |
47 load_path::hook_fcn_ptr load_path::remove_hook = execute_pkg_del; | |
5832 | 48 std::string load_path::command_line_path; |
6630 | 49 std::string load_path::sys_path; |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
50 load_path::abs_dir_cache_type load_path::abs_dir_cache; |
5832 | 51 |
52 void | |
53 load_path::dir_info::update (void) | |
54 { | |
8330
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
55 file_stat fs (dir_name); |
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
56 |
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
57 if (fs) |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
58 { |
8330
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
59 if (is_relative) |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
60 { |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
61 try |
8330
8303f0e912bc
load-path.cc (load_path::dir_info::update): simplify previous change
John W. Eaton <jwe@octave.org>
parents:
8329
diff
changeset
|
62 { |
10250 | 63 std::string abs_name = octave_env::make_absolute (dir_name); |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
64 |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
65 abs_dir_cache_iterator p = abs_dir_cache.find (abs_name); |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
66 |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
67 if (p != abs_dir_cache.end ()) |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
68 { |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
69 // The directory is in the cache of all directories |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
70 // we have visited (indexed by its absolute name). |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
71 // If it is out of date, initialize it. Otherwise, |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
72 // copy the info from the cache. By doing that, we |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
73 // avoid unnecessary calls to stat that can slow |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
74 // things down tremendously for large directories. |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
75 |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
76 const dir_info& di = p->second; |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
77 |
9748
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
9581
diff
changeset
|
78 if (fs.mtime () + fs.time_resolution () > di.dir_time_last_checked) |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
79 initialize (); |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
80 else |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
81 *this = di; |
9764
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
82 } |
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
83 else |
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
84 { |
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
85 // We haven't seen this directory before. |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
86 |
9764
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
87 initialize (); |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
88 } |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
89 } |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
90 catch (octave_execution_exception) |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
91 { |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
92 // Skip updating if we don't know where we are, but |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
93 // don't treat it as an error. |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
94 |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
95 error_state = 0; |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
96 } |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
97 } |
9764
7922a24f78c0
fix relative directory caching
John W. Eaton <jwe@octave.org>
parents:
9748
diff
changeset
|
98 else if (fs.mtime () + fs.time_resolution () > dir_time_last_checked) |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
99 initialize (); |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
100 } |
5832 | 101 else |
102 { | |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
103 std::string msg = fs.error (); |
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
104 warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ()); |
5832 | 105 } |
106 } | |
107 | |
108 void | |
109 load_path::dir_info::initialize (void) | |
110 { | |
111 is_relative = ! octave_env::absolute_pathname (dir_name); | |
112 | |
9748
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
9581
diff
changeset
|
113 dir_time_last_checked = octave_time (static_cast<time_t> (0)); |
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
9581
diff
changeset
|
114 |
5832 | 115 file_stat fs (dir_name); |
116 | |
117 if (fs) | |
118 { | |
119 dir_mtime = fs.mtime (); | |
9748
d6b2b708b6b0
load-path: compare directory timestamps with tolerance
John W. Eaton <jwe@octave.org>
parents:
9581
diff
changeset
|
120 dir_time_last_checked = octave_time (); |
5832 | 121 |
7336 | 122 get_file_list (dir_name); |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
123 |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
124 try |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
125 { |
10250 | 126 std::string abs_name = octave_env::make_absolute (dir_name); |
8329
c91b59532f32
load-path.cc (load_path::dir_info::update): smarter handling of relative names
John W. Eaton <jwe@octave.org>
parents:
8325
diff
changeset
|
127 |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
128 // FIXME -- nothing is ever removed from this cache of |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
129 // directory information, so there could be some resource |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
130 // problems. Perhaps it should be pruned from time to time. |
8331 | 131 |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
132 abs_dir_cache[abs_name] = *this; |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
133 } |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
134 catch (octave_execution_exception) |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
135 { |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
136 // Skip updating if we don't know where we are. |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8609
diff
changeset
|
137 } |
5832 | 138 } |
139 else | |
140 { | |
141 std::string msg = fs.error (); | |
142 warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ()); | |
143 } | |
144 } | |
145 | |
7336 | 146 void |
5832 | 147 load_path::dir_info::get_file_list (const std::string& d) |
148 { | |
149 dir_entry dir (d); | |
150 | |
151 if (dir) | |
152 { | |
153 string_vector flist = dir.read (); | |
154 | |
155 octave_idx_type len = flist.length (); | |
156 | |
157 all_files.resize (len); | |
158 fcn_files.resize (len); | |
159 | |
160 octave_idx_type all_files_count = 0; | |
161 octave_idx_type fcn_files_count = 0; | |
162 | |
163 for (octave_idx_type i = 0; i < len; i++) | |
164 { | |
165 std::string fname = flist[i]; | |
166 | |
7272 | 167 std::string full_name = file_ops::concat (d, fname); |
5832 | 168 |
169 file_stat fs (full_name); | |
170 | |
171 if (fs) | |
172 { | |
173 if (fs.is_dir ()) | |
174 { | |
7336 | 175 if (fname == "private") |
176 get_private_file_map (full_name); | |
177 else if (fname[0] == '@') | |
178 get_method_file_map (full_name, fname.substr (1)); | |
5832 | 179 } |
180 else | |
181 { | |
182 all_files[all_files_count++] = fname; | |
183 | |
184 size_t pos = fname.rfind ('.'); | |
185 | |
8021 | 186 if (pos != std::string::npos) |
5832 | 187 { |
188 std::string ext = fname.substr (pos); | |
189 | |
5864 | 190 if (ext == ".m" || ext == ".oct" || ext == ".mex") |
5832 | 191 { |
192 std::string base = fname.substr (0, pos); | |
193 | |
194 if (valid_identifier (base)) | |
195 fcn_files[fcn_files_count++] = fname; | |
196 } | |
197 } | |
198 } | |
199 } | |
200 } | |
201 | |
202 all_files.resize (all_files_count); | |
203 fcn_files.resize (fcn_files_count); | |
204 } | |
205 else | |
206 { | |
207 std::string msg = dir.error (); | |
208 warning ("load_path: %s: %s", d.c_str (), msg.c_str ()); | |
209 } | |
210 } | |
211 | |
7336 | 212 load_path::dir_info::fcn_file_map_type |
213 get_fcn_files (const std::string& d) | |
5832 | 214 { |
7336 | 215 load_path::dir_info::fcn_file_map_type retval; |
216 | |
5832 | 217 dir_entry dir (d); |
218 | |
219 if (dir) | |
220 { | |
221 string_vector flist = dir.read (); | |
222 | |
223 octave_idx_type len = flist.length (); | |
224 | |
225 for (octave_idx_type i = 0; i < len; i++) | |
226 { | |
227 std::string fname = flist[i]; | |
228 | |
229 std::string ext; | |
230 std::string base = fname; | |
231 | |
232 size_t pos = fname.rfind ('.'); | |
233 | |
8021 | 234 if (pos != std::string::npos) |
5832 | 235 { |
236 base = fname.substr (0, pos); | |
237 ext = fname.substr (pos); | |
238 | |
239 if (valid_identifier (base)) | |
240 { | |
241 int t = 0; | |
242 | |
243 if (ext == ".m") | |
244 t = load_path::M_FILE; | |
245 else if (ext == ".oct") | |
246 t = load_path::OCT_FILE; | |
5864 | 247 else if (ext == ".mex") |
248 t = load_path::MEX_FILE; | |
5832 | 249 |
7336 | 250 retval[base] |= t; |
5832 | 251 } |
252 } | |
253 } | |
254 } | |
255 else | |
256 { | |
257 std::string msg = dir.error (); | |
258 warning ("load_path: %s: %s", d.c_str (), msg.c_str ()); | |
259 } | |
7336 | 260 |
261 return retval; | |
262 } | |
263 | |
264 void | |
265 load_path::dir_info::get_private_file_map (const std::string& d) | |
266 { | |
267 private_file_map = get_fcn_files (d); | |
268 } | |
269 | |
270 void | |
271 load_path::dir_info::get_method_file_map (const std::string& d, | |
272 const std::string& class_name) | |
273 { | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
274 method_file_map[class_name].method_file_map = get_fcn_files (d); |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
275 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
276 std::string pd = file_ops::concat (d, "private"); |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
277 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
278 file_stat fs (pd); |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
279 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
280 if (fs && fs.is_dir ()) |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
281 method_file_map[class_name].private_file_map = get_fcn_files (pd); |
5832 | 282 } |
283 | |
284 bool | |
285 load_path::instance_ok (void) | |
286 { | |
287 bool retval = true; | |
288 | |
289 if (! instance) | |
290 instance = new load_path (); | |
291 | |
292 if (! instance) | |
293 { | |
294 ::error ("unable to create load path object!"); | |
295 | |
296 retval = false; | |
297 } | |
298 | |
299 return retval; | |
300 } | |
301 | |
7336 | 302 // FIXME -- maybe we should also maintain a map to speed up this |
303 // method of access. | |
304 | |
5832 | 305 load_path::const_dir_info_list_iterator |
5919 | 306 load_path::find_dir_info (const std::string& dir_arg) const |
5832 | 307 { |
5919 | 308 std::string dir = file_ops::tilde_expand (dir_arg); |
309 | |
5832 | 310 const_dir_info_list_iterator retval = dir_info_list.begin (); |
311 | |
312 while (retval != dir_info_list.end ()) | |
313 { | |
314 if (retval->dir_name == dir) | |
315 break; | |
316 | |
317 retval++; | |
318 } | |
319 | |
320 return retval; | |
321 } | |
322 | |
323 load_path::dir_info_list_iterator | |
5919 | 324 load_path::find_dir_info (const std::string& dir_arg) |
5832 | 325 { |
5919 | 326 std::string dir = file_ops::tilde_expand (dir_arg); |
327 | |
5832 | 328 dir_info_list_iterator retval = dir_info_list.begin (); |
329 | |
330 while (retval != dir_info_list.end ()) | |
331 { | |
332 if (retval->dir_name == dir) | |
333 break; | |
334 | |
335 retval++; | |
336 } | |
337 | |
338 return retval; | |
339 } | |
340 | |
341 bool | |
342 load_path::contains (const std::string& dir) const | |
343 { | |
344 return find_dir_info (dir) != dir_info_list.end (); | |
345 } | |
346 | |
347 void | |
7336 | 348 load_path::move_fcn_map (const std::string& dir_name, |
349 const string_vector& fcn_files, bool at_end) | |
5832 | 350 { |
7336 | 351 octave_idx_type len = fcn_files.length (); |
352 | |
353 for (octave_idx_type k = 0; k < len; k++) | |
5832 | 354 { |
7336 | 355 std::string fname = fcn_files[k]; |
5832 | 356 |
7336 | 357 std::string ext; |
358 std::string base = fname; | |
359 | |
360 size_t pos = fname.rfind ('.'); | |
5832 | 361 |
8021 | 362 if (pos != std::string::npos) |
7336 | 363 { |
364 base = fname.substr (0, pos); | |
365 ext = fname.substr (pos); | |
366 } | |
5832 | 367 |
7336 | 368 file_info_list_type& file_info_list = fcn_map[base]; |
5832 | 369 |
7336 | 370 if (file_info_list.size () == 1) |
371 continue; | |
372 else | |
5832 | 373 { |
7336 | 374 for (file_info_list_iterator p = file_info_list.begin (); |
375 p != file_info_list.end (); | |
376 p++) | |
377 { | |
378 if (p->dir_name == dir_name) | |
379 { | |
380 file_info fi = *p; | |
5832 | 381 |
7336 | 382 file_info_list.erase (p); |
383 | |
384 if (at_end) | |
385 file_info_list.push_back (fi); | |
386 else | |
387 file_info_list.push_front (fi); | |
5832 | 388 |
7336 | 389 break; |
390 } | |
391 } | |
392 } | |
393 } | |
394 } | |
5832 | 395 |
7336 | 396 void |
397 load_path::move_method_map (const std::string& dir_name, bool at_end) | |
398 { | |
399 for (method_map_iterator i = method_map.begin (); | |
400 i != method_map.end (); | |
401 i++) | |
402 { | |
403 std::string class_name = i->first; | |
5832 | 404 |
7336 | 405 fcn_map_type& fm = i->second; |
406 | |
407 std::string full_dir_name | |
408 = file_ops::concat (dir_name, "@" + class_name); | |
409 | |
410 for (fcn_map_iterator q = fm.begin (); q != fm.end (); q++) | |
411 { | |
412 file_info_list_type& file_info_list = q->second; | |
5832 | 413 |
414 if (file_info_list.size () == 1) | |
415 continue; | |
416 else | |
417 { | |
7336 | 418 for (file_info_list_iterator p = file_info_list.begin (); |
419 p != file_info_list.end (); | |
420 p++) | |
5832 | 421 { |
7336 | 422 if (p->dir_name == full_dir_name) |
5832 | 423 { |
6149 | 424 file_info fi = *p; |
5832 | 425 |
426 file_info_list.erase (p); | |
427 | |
428 if (at_end) | |
429 file_info_list.push_back (fi); | |
430 else | |
431 file_info_list.push_front (fi); | |
432 | |
433 break; | |
434 } | |
435 } | |
436 } | |
437 } | |
438 } | |
439 } | |
440 | |
7336 | 441 void |
442 load_path::move (dir_info_list_iterator i, bool at_end) | |
443 { | |
444 if (dir_info_list.size () > 1) | |
445 { | |
446 dir_info di = *i; | |
447 | |
448 dir_info_list.erase (i); | |
449 | |
450 if (at_end) | |
451 dir_info_list.push_back (di); | |
452 else | |
453 dir_info_list.push_front (di); | |
454 | |
455 std::string dir_name = di.dir_name; | |
456 | |
457 move_fcn_map (dir_name, di.fcn_files, at_end); | |
458 | |
459 // No need to move elements of private function map. | |
460 | |
461 move_method_map (dir_name, at_end); | |
462 } | |
463 } | |
464 | |
5832 | 465 static void |
466 maybe_add_path_elts (std::string& path, const std::string& dir) | |
467 { | |
468 std::string tpath = genpath (dir); | |
469 | |
470 if (! tpath.empty ()) | |
7374 | 471 { |
472 if (path.empty ()) | |
473 path = tpath; | |
474 else | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
475 path += dir_path::path_sep_str () + tpath; |
7374 | 476 } |
5832 | 477 } |
478 | |
479 void | |
6365 | 480 load_path::do_initialize (bool set_initial_path) |
5832 | 481 { |
7374 | 482 sys_path = ""; |
5832 | 483 |
6365 | 484 if (set_initial_path) |
485 { | |
6626 | 486 maybe_add_path_elts (sys_path, Vlocal_ver_oct_file_dir); |
487 maybe_add_path_elts (sys_path, Vlocal_api_oct_file_dir); | |
488 maybe_add_path_elts (sys_path, Vlocal_oct_file_dir); | |
489 maybe_add_path_elts (sys_path, Vlocal_ver_fcn_file_dir); | |
490 maybe_add_path_elts (sys_path, Vlocal_api_fcn_file_dir); | |
491 maybe_add_path_elts (sys_path, Vlocal_fcn_file_dir); | |
492 maybe_add_path_elts (sys_path, Voct_file_dir); | |
493 maybe_add_path_elts (sys_path, Vfcn_file_dir); | |
6365 | 494 } |
5832 | 495 |
496 std::string tpath = load_path::command_line_path; | |
497 | |
498 if (tpath.empty ()) | |
8141
31d7885d9869
load-path.cc (load_path::do_initialize): look for OCTAVE_PATH in the environment, not OCTAVE_LOADPATH
John W. Eaton <jwe@octave.org>
parents:
8041
diff
changeset
|
499 tpath = octave_env::getenv ("OCTAVE_PATH"); |
5832 | 500 |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
501 std::string xpath; |
5832 | 502 |
503 if (! tpath.empty ()) | |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
504 { |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
505 xpath = tpath; |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
506 |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
507 if (! sys_path.empty ()) |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
508 xpath += dir_path::path_sep_str () + sys_path; |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
509 } |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
510 else |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
511 xpath = sys_path; |
5832 | 512 |
6119 | 513 do_set (xpath, false); |
5832 | 514 } |
515 | |
516 void | |
517 load_path::do_clear (void) | |
518 { | |
519 dir_info_list.clear (); | |
520 fcn_map.clear (); | |
7336 | 521 private_fcn_map.clear (); |
522 method_map.clear (); | |
5832 | 523 } |
524 | |
525 static std::list<std::string> | |
526 split_path (const std::string& p) | |
527 { | |
528 std::list<std::string> retval; | |
529 | |
530 size_t beg = 0; | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
531 size_t end = p.find (dir_path::path_sep_char ()); |
5832 | 532 |
533 size_t len = p.length (); | |
534 | |
8021 | 535 while (end != std::string::npos) |
5832 | 536 { |
537 std::string elt = p.substr (beg, end-beg); | |
538 | |
539 if (! elt.empty ()) | |
540 retval.push_back (elt); | |
541 | |
542 beg = end + 1; | |
543 | |
544 if (beg == len) | |
545 break; | |
546 | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
547 end = p.find (dir_path::path_sep_char (), beg); |
5832 | 548 } |
549 | |
550 std::string elt = p.substr (beg); | |
551 | |
552 if (! elt.empty ()) | |
553 retval.push_back (elt); | |
554 | |
555 return retval; | |
556 } | |
557 | |
558 void | |
5867 | 559 load_path::do_set (const std::string& p, bool warn) |
5832 | 560 { |
561 std::list<std::string> elts = split_path (p); | |
562 | |
563 // Temporarily disable add hook. | |
564 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9807
diff
changeset
|
565 unwind_protect frame; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9807
diff
changeset
|
566 frame.protect_var (add_hook); |
5832 | 567 |
568 add_hook = 0; | |
569 | |
8511
a835406e02dd
load_path::do_set: call clear after disabling add_hook
John W. Eaton <jwe@octave.org>
parents:
8331
diff
changeset
|
570 do_clear (); |
a835406e02dd
load_path::do_set: call clear after disabling add_hook
John W. Eaton <jwe@octave.org>
parents:
8331
diff
changeset
|
571 |
5832 | 572 for (std::list<std::string>::const_iterator i = elts.begin (); |
573 i != elts.end (); | |
574 i++) | |
5867 | 575 do_append (*i, warn); |
5832 | 576 |
577 // Restore add hook and execute for all newly added directories. | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9807
diff
changeset
|
578 frame.run_top (); |
5832 | 579 |
580 for (dir_info_list_iterator i = dir_info_list.begin (); | |
581 i != dir_info_list.end (); | |
582 i++) | |
583 { | |
584 if (add_hook) | |
585 add_hook (i->dir_name); | |
586 } | |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
587 |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
588 // Always prepend current directory. |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
589 do_prepend (".", warn); |
5832 | 590 } |
591 | |
592 void | |
5867 | 593 load_path::do_append (const std::string& dir, bool warn) |
5832 | 594 { |
595 if (! dir.empty ()) | |
5867 | 596 do_add (dir, true, warn); |
597 } | |
5832 | 598 |
5867 | 599 void |
600 load_path::do_prepend (const std::string& dir, bool warn) | |
601 { | |
602 if (! dir.empty ()) | |
603 do_add (dir, false, warn); | |
5832 | 604 } |
605 | |
606 void | |
5919 | 607 load_path::do_add (const std::string& dir_arg, bool at_end, bool warn) |
5832 | 608 { |
5919 | 609 size_t len = dir_arg.length (); |
5911 | 610 |
5919 | 611 if (len > 1 && dir_arg.substr (len-2) == "//") |
5911 | 612 warning_with_id ("Octave:recursive-path-search", |
613 "trailing `//' is no longer special in search path elements"); | |
614 | |
5919 | 615 std::string dir = file_ops::tilde_expand (dir_arg); |
616 | |
5867 | 617 dir_info_list_iterator i = find_dir_info (dir); |
618 | |
619 if (i != dir_info_list.end ()) | |
620 move (i, at_end); | |
621 else | |
5832 | 622 { |
5867 | 623 file_stat fs (dir); |
5832 | 624 |
5867 | 625 if (fs) |
5832 | 626 { |
5867 | 627 if (fs.is_dir ()) |
628 { | |
629 dir_info di (dir); | |
5832 | 630 |
5867 | 631 if (! error_state) |
632 { | |
633 if (at_end) | |
634 dir_info_list.push_back (di); | |
635 else | |
636 dir_info_list.push_front (di); | |
637 | |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
638 add_to_fcn_map (di, at_end); |
5832 | 639 |
7336 | 640 add_to_private_fcn_map (di); |
641 | |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
642 add_to_method_map (di, at_end); |
7336 | 643 |
5867 | 644 if (add_hook) |
645 add_hook (dir); | |
646 } | |
5832 | 647 } |
5867 | 648 else if (warn) |
5919 | 649 warning ("addpath: %s: not a directory", dir_arg.c_str ()); |
5832 | 650 } |
5867 | 651 else if (warn) |
652 { | |
653 std::string msg = fs.error (); | |
5919 | 654 warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ()); |
5867 | 655 } |
656 } | |
5832 | 657 |
5867 | 658 // FIXME -- is there a better way to do this? |
5832 | 659 |
5867 | 660 i = find_dir_info ("."); |
5832 | 661 |
5867 | 662 if (i != dir_info_list.end ()) |
5871 | 663 move (i, false); |
5832 | 664 } |
665 | |
7336 | 666 void |
667 load_path::remove_fcn_map (const std::string& dir, | |
668 const string_vector& fcn_files) | |
669 { | |
670 octave_idx_type len = fcn_files.length (); | |
671 | |
672 for (octave_idx_type k = 0; k < len; k++) | |
673 { | |
674 std::string fname = fcn_files[k]; | |
675 | |
676 std::string ext; | |
677 std::string base = fname; | |
678 | |
679 size_t pos = fname.rfind ('.'); | |
680 | |
8021 | 681 if (pos != std::string::npos) |
7336 | 682 { |
683 base = fname.substr (0, pos); | |
684 ext = fname.substr (pos); | |
685 } | |
686 | |
687 file_info_list_type& file_info_list = fcn_map[base]; | |
688 | |
689 for (file_info_list_iterator p = file_info_list.begin (); | |
690 p != file_info_list.end (); | |
691 p++) | |
692 { | |
693 if (p->dir_name == dir) | |
694 { | |
695 file_info_list.erase (p); | |
696 | |
697 if (file_info_list.empty ()) | |
698 fcn_map.erase (fname); | |
699 | |
700 break; | |
701 } | |
702 } | |
703 } | |
704 } | |
705 | |
706 void | |
707 load_path::remove_private_fcn_map (const std::string& dir) | |
708 { | |
709 private_fcn_map_iterator p = private_fcn_map.find (dir); | |
710 | |
711 if (p != private_fcn_map.end ()) | |
712 private_fcn_map.erase (p); | |
713 } | |
714 | |
715 void | |
716 load_path::remove_method_map (const std::string& dir) | |
717 { | |
718 for (method_map_iterator i = method_map.begin (); | |
719 i != method_map.end (); | |
720 i++) | |
721 { | |
722 std::string class_name = i->first; | |
723 | |
724 fcn_map_type& fm = i->second; | |
725 | |
726 std::string full_dir_name = file_ops::concat (dir, "@" + class_name); | |
727 | |
728 for (fcn_map_iterator q = fm.begin (); q != fm.end (); q++) | |
729 { | |
730 file_info_list_type& file_info_list = q->second; | |
731 | |
732 if (file_info_list.size () == 1) | |
733 continue; | |
734 else | |
735 { | |
736 for (file_info_list_iterator p = file_info_list.begin (); | |
737 p != file_info_list.end (); | |
738 p++) | |
739 { | |
740 if (p->dir_name == full_dir_name) | |
741 { | |
742 file_info_list.erase (p); | |
743 | |
744 // FIXME -- if there are no other elements, we | |
745 // should remove this element of fm but calling | |
746 // erase here would invalidate the iterator q. | |
747 | |
748 break; | |
749 } | |
750 } | |
751 } | |
752 } | |
753 } | |
754 } | |
755 | |
5832 | 756 bool |
5919 | 757 load_path::do_remove (const std::string& dir_arg) |
5832 | 758 { |
759 bool retval = false; | |
760 | |
5919 | 761 if (! dir_arg.empty ()) |
5832 | 762 { |
5919 | 763 if (dir_arg == ".") |
5867 | 764 { |
765 warning ("rmpath: can't remove \".\" from path"); | |
5832 | 766 |
5867 | 767 // Avoid additional warnings. |
5832 | 768 retval = true; |
5867 | 769 } |
770 else | |
771 { | |
5919 | 772 std::string dir = file_ops::tilde_expand (dir_arg); |
773 | |
5867 | 774 dir_info_list_iterator i = find_dir_info (dir); |
5832 | 775 |
5867 | 776 if (i != dir_info_list.end ()) |
777 { | |
778 retval = true; | |
5832 | 779 |
6825 | 780 if (remove_hook) |
781 remove_hook (dir); | |
782 | |
5867 | 783 string_vector fcn_files = i->fcn_files; |
784 | |
785 dir_info_list.erase (i); | |
5832 | 786 |
7336 | 787 remove_fcn_map (dir, fcn_files); |
5867 | 788 |
7336 | 789 remove_private_fcn_map (dir); |
5832 | 790 |
7336 | 791 remove_method_map (dir); |
5832 | 792 } |
793 } | |
794 } | |
795 | |
796 return retval; | |
797 } | |
798 | |
799 void | |
800 load_path::do_update (void) const | |
801 { | |
802 // I don't see a better way to do this because we need to | |
803 // preserve the correct directory ordering for new files that | |
804 // have appeared. | |
805 | |
806 fcn_map.clear (); | |
807 | |
7336 | 808 private_fcn_map.clear (); |
809 | |
810 method_map.clear (); | |
811 | |
5832 | 812 for (dir_info_list_iterator p = dir_info_list.begin (); |
813 p != dir_info_list.end (); | |
814 p++) | |
815 { | |
816 dir_info& di = *p; | |
817 | |
818 di.update (); | |
819 | |
820 add_to_fcn_map (di, true); | |
7336 | 821 |
822 add_to_private_fcn_map (di); | |
823 | |
824 add_to_method_map (di, true); | |
5832 | 825 } |
826 } | |
827 | |
7336 | 828 bool |
829 load_path::check_file_type (std::string& fname, int type, int possible_types, | |
830 const std::string& fcn, const char *who) | |
831 { | |
832 bool retval = false; | |
833 | |
834 if (type == load_path::OCT_FILE) | |
835 { | |
836 if ((type & possible_types) == load_path::OCT_FILE) | |
837 { | |
838 fname += ".oct"; | |
839 retval = true; | |
840 } | |
841 } | |
842 else if (type == load_path::M_FILE) | |
843 { | |
844 if ((type & possible_types) == load_path::M_FILE) | |
845 { | |
846 fname += ".m"; | |
847 retval = true; | |
848 } | |
849 } | |
850 else if (type == load_path::MEX_FILE) | |
851 { | |
852 if ((type & possible_types) == load_path::MEX_FILE) | |
853 { | |
854 fname += ".mex"; | |
855 retval = true; | |
856 } | |
857 } | |
858 else if (type == (load_path::M_FILE | load_path::OCT_FILE)) | |
859 { | |
860 if (possible_types & load_path::OCT_FILE) | |
861 { | |
862 fname += ".oct"; | |
863 retval = true; | |
864 } | |
865 else if (possible_types & load_path::M_FILE) | |
866 { | |
867 fname += ".m"; | |
868 retval = true; | |
869 } | |
870 } | |
871 else if (type == (load_path::M_FILE | load_path::MEX_FILE)) | |
872 { | |
873 if (possible_types & load_path::MEX_FILE) | |
874 { | |
875 fname += ".mex"; | |
876 retval = true; | |
877 } | |
878 else if (possible_types & load_path::M_FILE) | |
879 { | |
880 fname += ".m"; | |
881 retval = true; | |
882 } | |
883 } | |
884 else if (type == (load_path::OCT_FILE | load_path::MEX_FILE)) | |
885 { | |
886 if (possible_types & load_path::OCT_FILE) | |
887 { | |
888 fname += ".oct"; | |
889 retval = true; | |
890 } | |
891 else if (possible_types & load_path::MEX_FILE) | |
892 { | |
893 fname += ".mex"; | |
894 retval = true; | |
895 } | |
896 } | |
897 else if (type == (load_path::M_FILE | load_path::OCT_FILE | |
898 | load_path::MEX_FILE)) | |
899 { | |
900 if (possible_types & load_path::OCT_FILE) | |
901 { | |
902 fname += ".oct"; | |
903 retval = true; | |
904 } | |
905 else if (possible_types & load_path::MEX_FILE) | |
906 { | |
907 fname += ".mex"; | |
908 retval = true; | |
909 } | |
910 else if (possible_types & load_path::M_FILE) | |
911 { | |
912 fname += ".m"; | |
913 retval = true; | |
914 } | |
915 } | |
916 else | |
917 error ("%s: %s: invalid type code = %d", who, fcn.c_str (), type); | |
918 | |
919 return retval; | |
920 } | |
921 | |
5832 | 922 std::string |
7336 | 923 load_path::do_find_fcn (const std::string& fcn, std::string& dir_name, |
924 int type) const | |
5832 | 925 { |
926 std::string retval; | |
7336 | 927 |
928 // update (); | |
5832 | 929 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
930 if (fcn.length () > 0 && fcn[0] == '@') |
5832 | 931 { |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
932 size_t pos = fcn.find ('/'); |
5832 | 933 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
934 if (pos != std::string::npos) |
5832 | 935 { |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
936 std::string class_name = fcn.substr (1, pos-1); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
937 std::string meth = fcn.substr (pos+1); |
5832 | 938 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
939 retval = do_find_method (class_name, meth, dir_name); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
940 } |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
941 else |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
942 retval = std::string (); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
943 } |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
944 else |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
945 { |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
946 dir_name = std::string (); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
947 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
948 const_fcn_map_iterator p = fcn_map.find (fcn); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
949 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
950 if (p != fcn_map.end ()) |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
951 { |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
952 const file_info_list_type& file_info_list = p->second; |
5832 | 953 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
954 for (const_file_info_list_iterator i = file_info_list.begin (); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
955 i != file_info_list.end (); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
956 i++) |
5832 | 957 { |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
958 const file_info& fi = *i; |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
959 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
960 retval = file_ops::concat (fi.dir_name, fcn); |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
961 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
962 if (check_file_type (retval, type, fi.types, |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
963 fcn, "load_path::do_find_fcn")) |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
964 { |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
965 dir_name = fi.dir_name; |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
966 break; |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
967 } |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
968 else |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
969 retval = std::string (); |
5832 | 970 } |
7336 | 971 } |
972 } | |
973 | |
974 return retval; | |
975 } | |
976 | |
977 std::string | |
978 load_path::do_find_private_fcn (const std::string& dir, | |
979 const std::string& fcn, int type) const | |
980 { | |
981 std::string retval; | |
982 | |
983 // update (); | |
984 | |
985 const_private_fcn_map_iterator q = private_fcn_map.find (dir); | |
986 | |
987 if (q != private_fcn_map.end ()) | |
988 { | |
989 const dir_info::fcn_file_map_type& m = q->second; | |
990 | |
991 dir_info::const_fcn_file_map_iterator p = m.find (fcn); | |
992 | |
993 if (p != m.end ()) | |
994 { | |
995 std::string fname | |
996 = file_ops::concat (file_ops::concat (dir, "private"), fcn); | |
997 | |
998 if (check_file_type (fname, type, p->second, fcn, | |
999 "load_path::find_private_fcn")) | |
1000 retval = fname; | |
1001 } | |
1002 } | |
1003 | |
1004 return retval; | |
1005 } | |
1006 | |
1007 std::string | |
1008 load_path::do_find_method (const std::string& class_name, | |
1009 const std::string& meth, | |
1010 std::string& dir_name, int type) const | |
1011 { | |
1012 std::string retval; | |
1013 | |
1014 // update (); | |
1015 | |
1016 dir_name = std::string (); | |
1017 | |
1018 const_method_map_iterator q = method_map.find (class_name); | |
1019 | |
1020 if (q != method_map.end ()) | |
1021 { | |
1022 const fcn_map_type& m = q->second; | |
1023 | |
1024 const_fcn_map_iterator p = m.find (meth); | |
1025 | |
9581
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1026 if (p != m.end ()) |
7336 | 1027 { |
1028 const file_info_list_type& file_info_list = p->second; | |
1029 | |
1030 for (const_file_info_list_iterator i = file_info_list.begin (); | |
1031 i != file_info_list.end (); | |
1032 i++) | |
5864 | 1033 { |
7336 | 1034 const file_info& fi = *i; |
1035 | |
1036 retval = file_ops::concat (fi.dir_name, meth); | |
1037 | |
1038 bool found = check_file_type (retval, type, fi.types, | |
1039 meth, "load_path::do_find_method"); | |
1040 | |
1041 if (found) | |
5864 | 1042 { |
7336 | 1043 dir_name = fi.dir_name; |
5832 | 1044 break; |
1045 } | |
7336 | 1046 else |
1047 retval = std::string (); | |
5864 | 1048 } |
5832 | 1049 } |
1050 } | |
1051 | |
1052 return retval; | |
1053 } | |
1054 | |
7336 | 1055 std::list<std::string> |
1056 load_path::do_methods (const std::string& class_name) const | |
1057 { | |
1058 std::list<std::string> retval; | |
1059 | |
1060 // update (); | |
1061 | |
1062 const_method_map_iterator q = method_map.find (class_name); | |
1063 | |
1064 if (q != method_map.end ()) | |
1065 { | |
1066 const fcn_map_type& m = q->second; | |
1067 | |
1068 for (const_fcn_map_iterator p = m.begin (); p != m.end (); p++) | |
1069 retval.push_back (p->first); | |
1070 } | |
1071 | |
1072 if (! retval.empty ()) | |
1073 retval.sort (); | |
1074 | |
1075 return retval; | |
1076 } | |
1077 | |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1078 bool |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1079 load_path::do_any_class_method (const std::string& meth) const |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1080 { |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1081 bool retval = false; |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1082 |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1083 // update (); |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1084 |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1085 for (const_method_map_iterator q = method_map.begin (); |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1086 q != method_map.end (); q++) |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1087 { |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1088 const fcn_map_type& m = q->second; |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1089 |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1090 if (m.find (meth) != m.end ()) |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1091 { |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1092 retval = true; |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1093 break; |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1094 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1095 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1096 |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1097 return retval; |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1098 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9401
diff
changeset
|
1099 |
5832 | 1100 std::string |
1101 load_path::do_find_file (const std::string& file) const | |
1102 { | |
1103 std::string retval; | |
1104 | |
8021 | 1105 if (file.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos) |
5832 | 1106 { |
6838 | 1107 if (octave_env::absolute_pathname (file) |
1108 || octave_env::rooted_relative_pathname (file)) | |
1109 { | |
1110 file_stat fs (file); | |
5832 | 1111 |
6838 | 1112 if (fs.exists ()) |
1113 return file; | |
1114 } | |
1115 else | |
1116 { | |
1117 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1118 p != dir_info_list.end (); | |
1119 p++) | |
1120 { | |
7272 | 1121 std::string tfile = file_ops::concat (p->dir_name, file); |
5832 | 1122 |
6838 | 1123 file_stat fs (tfile); |
6159 | 1124 |
6838 | 1125 if (fs.exists ()) |
1126 return tfile; | |
5832 | 1127 } |
1128 } | |
1129 } | |
6838 | 1130 else |
1131 { | |
1132 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1133 p != dir_info_list.end (); | |
1134 p++) | |
1135 { | |
1136 string_vector all_files = p->all_files; | |
6159 | 1137 |
6838 | 1138 octave_idx_type len = all_files.length (); |
1139 | |
1140 for (octave_idx_type i = 0; i < len; i++) | |
1141 { | |
1142 if (all_files[i] == file) | |
7272 | 1143 return file_ops::concat (p->dir_name, file); |
6838 | 1144 } |
1145 } | |
1146 } | |
5832 | 1147 |
1148 return retval; | |
1149 } | |
1150 | |
1151 std::string | |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1152 load_path::do_find_dir (const std::string& dir) const |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1153 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1154 std::string retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1155 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1156 if (dir.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1157 && (octave_env::absolute_pathname (dir) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1158 || octave_env::rooted_relative_pathname (dir))) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1159 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1160 file_stat fs (dir); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1161 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1162 if (fs.exists () && fs.is_dir ()) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1163 return dir; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1164 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1165 else |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1166 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1167 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1168 p != dir_info_list.end (); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1169 p++) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1170 { |
10250 | 1171 std::string dname = octave_env::make_absolute (p->dir_name); |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1172 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1173 size_t dname_len = dname.length (); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1174 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1175 if (dname.substr (dname_len - 1) == file_ops::dir_sep_str ()) |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1176 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1177 dname = dname.substr (0, dname_len - 1); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1178 dname_len--; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1179 } |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1180 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1181 size_t dir_len = dir.length (); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1182 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1183 if (dname_len >= dir_len |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1184 && file_ops::is_dir_sep (dname[dname_len - dir_len - 1]) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1185 && dir.compare (dname.substr (dname_len - dir_len)) == 0) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1186 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1187 file_stat fs (p->dir_name); |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1188 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1189 if (fs.exists () && fs.is_dir ()) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1190 return p->dir_name; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1191 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1192 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1193 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1194 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1195 return retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1196 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1197 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1198 string_vector |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1199 load_path::do_find_matching_dirs (const std::string& dir) const |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1200 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1201 std::list<std::string> retlist; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1202 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1203 if (dir.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1204 && (octave_env::absolute_pathname (dir) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1205 || octave_env::rooted_relative_pathname (dir))) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1206 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1207 file_stat fs (dir); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1208 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1209 if (fs.exists () && fs.is_dir ()) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1210 retlist.push_back (dir); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1211 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1212 else |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1213 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1214 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1215 p != dir_info_list.end (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1216 p++) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1217 { |
10250 | 1218 std::string dname = octave_env::make_absolute (p->dir_name); |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1219 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1220 size_t dname_len = dname.length (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1221 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1222 if (dname.substr (dname_len - 1) == file_ops::dir_sep_str ()) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1223 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1224 dname = dname.substr (0, dname_len - 1); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1225 dname_len--; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1226 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1227 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1228 size_t dir_len = dir.length (); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1229 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1230 if (dname_len >= dir_len |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1231 && file_ops::is_dir_sep (dname[dname_len - dir_len - 1]) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1232 && dir.compare (dname.substr (dname_len - dir_len)) == 0) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1233 { |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1234 file_stat fs (p->dir_name); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1235 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1236 if (fs.exists () && fs.is_dir ()) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1237 retlist.push_back (p->dir_name); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1238 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1239 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1240 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1241 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1242 return retlist; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1243 } |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9764
diff
changeset
|
1244 |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1245 std::string |
5832 | 1246 load_path::do_find_first_of (const string_vector& flist) const |
1247 { | |
1248 std::string retval; | |
1249 | |
1250 std::string dir_name; | |
1251 std::string file_name; | |
1252 | |
1253 octave_idx_type flen = flist.length (); | |
1254 octave_idx_type rel_flen = 0; | |
1255 | |
1256 string_vector rel_flist (flen); | |
1257 | |
1258 for (octave_idx_type i = 0; i < flen; i++) | |
1259 { | |
1260 if (octave_env::absolute_pathname (flist[i])) | |
1261 { | |
1262 file_stat fs (flist[i]); | |
1263 | |
1264 if (fs.exists ()) | |
1265 return flist[i]; | |
1266 } | |
1267 else | |
1268 rel_flist[rel_flen++] = flist[i]; | |
1269 } | |
1270 | |
1271 rel_flist.resize (rel_flen); | |
1272 | |
1273 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1274 p != dir_info_list.end (); | |
1275 p++) | |
1276 { | |
1277 string_vector all_files = p->all_files; | |
1278 | |
1279 octave_idx_type len = all_files.length (); | |
1280 | |
1281 for (octave_idx_type i = 0; i < len; i++) | |
1282 { | |
1283 for (octave_idx_type j = 0; j < rel_flen; j++) | |
1284 { | |
1285 if (all_files[i] == rel_flist[j]) | |
1286 { | |
1287 dir_name = p->dir_name; | |
1288 file_name = rel_flist[j]; | |
6159 | 1289 |
1290 goto done; | |
5832 | 1291 } |
1292 } | |
1293 } | |
1294 } | |
1295 | |
6159 | 1296 done: |
1297 | |
5832 | 1298 if (! dir_name.empty ()) |
7272 | 1299 retval = file_ops::concat (dir_name, file_name); |
5832 | 1300 |
1301 return retval; | |
1302 } | |
1303 | |
1304 string_vector | |
1305 load_path::do_find_all_first_of (const string_vector& flist) const | |
1306 { | |
1307 std::list<std::string> retlist; | |
1308 | |
1309 std::string dir_name; | |
1310 std::string file_name; | |
1311 | |
1312 octave_idx_type flen = flist.length (); | |
1313 octave_idx_type rel_flen = 0; | |
1314 | |
1315 string_vector rel_flist (flen); | |
1316 | |
1317 for (octave_idx_type i = 0; i < flen; i++) | |
1318 { | |
1319 if (octave_env::absolute_pathname (flist[i])) | |
1320 { | |
1321 file_stat fs (flist[i]); | |
1322 | |
1323 if (fs.exists ()) | |
1324 retlist.push_back (flist[i]); | |
1325 } | |
1326 else | |
1327 rel_flist[rel_flen++] = flist[i]; | |
1328 } | |
1329 | |
1330 rel_flist.resize (rel_flen); | |
1331 | |
1332 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1333 p != dir_info_list.end (); | |
1334 p++) | |
1335 { | |
1336 string_vector all_files = p->all_files; | |
1337 | |
1338 octave_idx_type len = all_files.length (); | |
1339 | |
1340 for (octave_idx_type i = 0; i < len; i++) | |
1341 { | |
1342 for (octave_idx_type j = 0; j < rel_flen; j++) | |
1343 { | |
1344 if (all_files[i] == rel_flist[j]) | |
1345 retlist.push_back | |
7272 | 1346 (file_ops::concat (p->dir_name, rel_flist[j])); |
5832 | 1347 } |
1348 } | |
1349 } | |
1350 | |
9807
645c478aa89d
load-path.cc (load_path::do_find_all_first_of): take advantage of string_vector (std::list<std:string>) constructor
John W. Eaton <jwe@octave.org>
parents:
9806
diff
changeset
|
1351 return retlist; |
5832 | 1352 } |
1353 | |
1354 string_vector | |
1355 load_path::do_dirs (void) const | |
1356 { | |
1357 size_t len = dir_info_list.size (); | |
1358 | |
1359 string_vector retval (len); | |
1360 | |
1361 octave_idx_type k = 0; | |
1362 | |
1363 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1364 i != dir_info_list.end (); | |
1365 i++) | |
1366 retval[k++] = i->dir_name; | |
1367 | |
1368 return retval; | |
1369 } | |
1370 | |
1371 std::list<std::string> | |
1372 load_path::do_dir_list (void) const | |
1373 { | |
1374 std::list<std::string> retval; | |
1375 | |
1376 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1377 i != dir_info_list.end (); | |
1378 i++) | |
1379 retval.push_back (i->dir_name); | |
1380 | |
1381 return retval; | |
1382 } | |
1383 | |
1384 string_vector | |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1385 load_path::do_files (const std::string& dir, bool omit_exts) const |
5832 | 1386 { |
1387 string_vector retval; | |
1388 | |
9282
2ed8d2d92507
load_path::do_files: avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
9261
diff
changeset
|
1389 const_dir_info_list_iterator p = find_dir_info (dir); |
5832 | 1390 |
9282
2ed8d2d92507
load_path::do_files: avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
9261
diff
changeset
|
1391 if (p != dir_info_list.end ()) |
2ed8d2d92507
load_path::do_files: avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
9261
diff
changeset
|
1392 retval = p->fcn_files; |
5832 | 1393 |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1394 if (omit_exts) |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1395 { |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1396 octave_idx_type len = retval.length (); |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1397 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1398 for (octave_idx_type i = 0; i < len; i++) |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1399 { |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1400 std::string fname = retval[i]; |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1401 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1402 size_t pos = fname.rfind ('.'); |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1403 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1404 if (pos != std::string::npos) |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1405 retval[i] = fname.substr (0, pos); |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1406 } |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1407 } |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1408 |
5832 | 1409 return retval; |
1410 } | |
1411 | |
1412 string_vector | |
1413 load_path::do_fcn_names (void) const | |
1414 { | |
1415 size_t len = fcn_map.size (); | |
1416 | |
1417 string_vector retval (len); | |
1418 | |
1419 octave_idx_type count = 0; | |
1420 | |
1421 for (const_fcn_map_iterator p = fcn_map.begin (); | |
1422 p != fcn_map.end (); | |
1423 p++) | |
1424 retval[count++] = p->first; | |
1425 | |
1426 return retval; | |
1427 } | |
1428 | |
1429 std::string | |
1430 load_path::do_path (void) const | |
1431 { | |
1432 std::string xpath; | |
1433 | |
1434 string_vector xdirs = load_path::dirs (); | |
1435 | |
1436 octave_idx_type len = xdirs.length (); | |
1437 | |
1438 if (len > 0) | |
1439 xpath = xdirs[0]; | |
1440 | |
1441 for (octave_idx_type i = 1; i < len; i++) | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
1442 xpath += dir_path::path_sep_str () + xdirs[i]; |
5832 | 1443 |
1444 return xpath; | |
1445 } | |
1446 | |
1447 void | |
7336 | 1448 print_types (std::ostream& os, int types) |
1449 { | |
1450 bool printed_type = false; | |
1451 | |
1452 if (types & load_path::OCT_FILE) | |
1453 { | |
1454 os << "oct"; | |
1455 printed_type = true; | |
1456 } | |
1457 | |
1458 if (types & load_path::MEX_FILE) | |
1459 { | |
1460 if (printed_type) | |
1461 os << "|"; | |
1462 os << "mex"; | |
1463 printed_type = true; | |
1464 } | |
1465 | |
1466 if (types & load_path::M_FILE) | |
1467 { | |
1468 if (printed_type) | |
1469 os << "|"; | |
1470 os << "m"; | |
1471 printed_type = true; | |
1472 } | |
1473 } | |
1474 | |
1475 void | |
1476 print_fcn_list (std::ostream& os, | |
1477 const load_path::dir_info::fcn_file_map_type& lst) | |
1478 { | |
1479 for (load_path::dir_info::const_fcn_file_map_iterator p = lst.begin (); | |
1480 p != lst.end (); | |
1481 p++) | |
1482 { | |
1483 os << " " << p->first << " ("; | |
1484 | |
1485 print_types (os, p->second); | |
1486 | |
1487 os << ")\n"; | |
1488 } | |
1489 } | |
1490 | |
1491 string_vector | |
1492 get_file_list (const load_path::dir_info::fcn_file_map_type& lst) | |
1493 { | |
1494 octave_idx_type n = lst.size (); | |
1495 | |
1496 string_vector retval (n); | |
1497 | |
1498 octave_idx_type count = 0; | |
1499 | |
1500 for (load_path::dir_info::const_fcn_file_map_iterator p = lst.begin (); | |
1501 p != lst.end (); | |
1502 p++) | |
1503 { | |
1504 std::string nm = p->first; | |
1505 | |
1506 int types = p->second; | |
1507 | |
1508 if (types & load_path::OCT_FILE) | |
1509 nm += ".oct"; | |
1510 else if (types & load_path::MEX_FILE) | |
1511 nm += ".mex"; | |
1512 else | |
1513 nm += ".m"; | |
1514 | |
1515 retval[count++] = nm; | |
1516 } | |
1517 | |
1518 return retval; | |
1519 } | |
1520 | |
1521 void | |
5832 | 1522 load_path::do_display (std::ostream& os) const |
1523 { | |
1524 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1525 i != dir_info_list.end (); | |
1526 i++) | |
1527 { | |
1528 string_vector fcn_files = i->fcn_files; | |
1529 | |
1530 if (! fcn_files.empty ()) | |
1531 { | |
1532 os << "\n*** function files in " << i->dir_name << ":\n\n"; | |
1533 | |
1534 fcn_files.list_in_columns (os); | |
1535 } | |
1536 | |
7336 | 1537 const dir_info::method_file_map_type& method_file_map |
1538 = i->method_file_map; | |
5832 | 1539 |
7336 | 1540 if (! method_file_map.empty ()) |
5832 | 1541 { |
7336 | 1542 for (dir_info::const_method_file_map_iterator p = method_file_map.begin (); |
1543 p != method_file_map.end (); | |
5832 | 1544 p++) |
1545 { | |
7336 | 1546 os << "\n*** methods in " << i->dir_name |
1547 << "/@" << p->first << ":\n\n"; | |
5832 | 1548 |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1549 const dir_info::class_info& ci = p->second; |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1550 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1551 string_vector method_files = get_file_list (ci.method_file_map); |
5832 | 1552 |
7336 | 1553 method_files.list_in_columns (os); |
1554 } | |
1555 } | |
1556 } | |
5864 | 1557 |
7336 | 1558 for (const_private_fcn_map_iterator i = private_fcn_map.begin (); |
1559 i != private_fcn_map.end (); i++) | |
1560 { | |
1561 os << "\n*** private functions in " | |
1562 << file_ops::concat (i->first, "private") << ":\n\n"; | |
5832 | 1563 |
7336 | 1564 print_fcn_list (os, i->second); |
5832 | 1565 } |
1566 | |
1567 #if defined (DEBUG_LOAD_PATH) | |
1568 | |
1569 for (const_fcn_map_iterator i = fcn_map.begin (); | |
1570 i != fcn_map.end (); | |
1571 i++) | |
1572 { | |
1573 os << i->first << ":\n"; | |
1574 | |
7336 | 1575 const file_info_list_type& file_info_list = i->second; |
5832 | 1576 |
1577 for (const_file_info_list_iterator p = file_info_list.begin (); | |
1578 p != file_info_list.end (); | |
1579 p++) | |
1580 { | |
1581 os << " " << p->dir_name << " ("; | |
1582 | |
7336 | 1583 print_types (os, p->types); |
5832 | 1584 |
1585 os << ")\n"; | |
1586 } | |
1587 } | |
1588 | |
7336 | 1589 for (const_method_map_iterator i = method_map.begin (); |
1590 i != method_map.end (); | |
1591 i++) | |
1592 { | |
1593 os << "CLASS " << i->first << ":\n"; | |
1594 | |
1595 const fcn_map_type& fm = i->second; | |
1596 | |
1597 for (const_fcn_map_iterator q = fm.begin (); | |
1598 q != fm.end (); | |
1599 q++) | |
1600 { | |
1601 os << " " << q->first << ":\n"; | |
1602 | |
1603 const file_info_list_type& file_info_list = q->second; | |
1604 | |
1605 for (const_file_info_list_iterator p = file_info_list.begin (); | |
1606 p != file_info_list.end (); | |
1607 p++) | |
1608 { | |
1609 os << " " << p->dir_name << " ("; | |
1610 | |
1611 print_types (os, p->types); | |
1612 | |
1613 os << ")\n"; | |
1614 } | |
1615 } | |
1616 } | |
1617 | |
5832 | 1618 os << "\n"; |
1619 | |
1620 #endif | |
1621 } | |
1622 | |
1623 void | |
1624 load_path::add_to_fcn_map (const dir_info& di, bool at_end) const | |
1625 { | |
1626 std::string dir_name = di.dir_name; | |
1627 | |
1628 string_vector fcn_files = di.fcn_files; | |
1629 | |
1630 octave_idx_type len = fcn_files.length (); | |
1631 | |
1632 for (octave_idx_type i = 0; i < len; i++) | |
1633 { | |
1634 std::string fname = fcn_files[i]; | |
1635 | |
1636 std::string ext; | |
1637 std::string base = fname; | |
1638 | |
1639 size_t pos = fname.rfind ('.'); | |
1640 | |
8021 | 1641 if (pos != std::string::npos) |
5832 | 1642 { |
1643 base = fname.substr (0, pos); | |
1644 ext = fname.substr (pos); | |
1645 } | |
1646 | |
7336 | 1647 file_info_list_type& file_info_list = fcn_map[base]; |
5832 | 1648 |
1649 file_info_list_iterator p = file_info_list.begin (); | |
1650 | |
1651 while (p != file_info_list.end ()) | |
1652 { | |
1653 if (p->dir_name == dir_name) | |
1654 break; | |
1655 | |
1656 p++; | |
1657 } | |
1658 | |
1659 int t = 0; | |
1660 if (ext == ".m") | |
1661 t = load_path::M_FILE; | |
1662 else if (ext == ".oct") | |
1663 t = load_path::OCT_FILE; | |
5864 | 1664 else if (ext == ".mex") |
1665 t = load_path::MEX_FILE; | |
5832 | 1666 |
1667 if (p == file_info_list.end ()) | |
1668 { | |
1669 file_info fi (dir_name, t); | |
1670 | |
1671 if (at_end) | |
1672 file_info_list.push_back (fi); | |
1673 else | |
10242
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1674 { |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1675 // Warn if a built-in or library function is being shadowed. |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1676 if (! file_info_list.empty ()) |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1677 { |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1678 file_info& old = file_info_list.front (); |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1679 if (sys_path.find (old.dir_name) != std::string::npos) |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1680 { |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1681 std::string fcn_path = file_ops::concat (dir_name, fname); |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1682 warning_with_id ("Octave:shadowed-function", |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1683 "function %s shadows a core library function", |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1684 fcn_path.c_str ()); |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1685 } |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1686 } |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1687 else if (symbol_table::is_built_in_function_name (base)) |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1688 { |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1689 std::string fcn_path = file_ops::concat (dir_name, fname); |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1690 warning_with_id ("Octave:shadowed-function", |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1691 "function %s shadows a built-in function", |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1692 fcn_path.c_str ()); |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1693 } |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1694 |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1695 file_info_list.push_front (fi); |
4acae5e46738
warn when core functions are shadowed
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1696 } |
5832 | 1697 } |
1698 else | |
1699 { | |
1700 file_info& fi = *p; | |
1701 | |
1702 fi.types |= t; | |
1703 } | |
1704 } | |
1705 } | |
1706 | |
7336 | 1707 void |
1708 load_path::add_to_private_fcn_map (const dir_info& di) const | |
1709 { | |
1710 dir_info::fcn_file_map_type private_file_map = di.private_file_map; | |
1711 | |
1712 if (! private_file_map.empty ()) | |
1713 private_fcn_map[di.dir_name] = private_file_map; | |
1714 } | |
1715 | |
1716 void | |
1717 load_path::add_to_method_map (const dir_info& di, bool at_end) const | |
1718 { | |
1719 std::string dir_name = di.dir_name; | |
1720 | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1721 // <CLASS_NAME, CLASS_INFO> |
7336 | 1722 dir_info::method_file_map_type method_file_map = di.method_file_map; |
1723 | |
1724 for (dir_info::const_method_file_map_iterator q = method_file_map.begin (); | |
1725 q != method_file_map.end (); | |
1726 q++) | |
1727 { | |
1728 std::string class_name = q->first; | |
1729 | |
1730 fcn_map_type& fm = method_map[class_name]; | |
1731 | |
1732 std::string full_dir_name | |
1733 = file_ops::concat (dir_name, "@" + class_name); | |
1734 | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1735 const dir_info::class_info& ci = q->second; |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1736 |
7336 | 1737 // <FCN_NAME, TYPES> |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1738 const dir_info::fcn_file_map_type& m = ci.method_file_map; |
7336 | 1739 |
1740 for (dir_info::const_fcn_file_map_iterator p = m.begin (); | |
1741 p != m.end (); | |
1742 p++) | |
1743 { | |
1744 std::string base = p->first; | |
1745 | |
1746 int types = p->second; | |
1747 | |
1748 file_info_list_type& file_info_list = fm[base]; | |
1749 | |
1750 file_info_list_iterator p2 = file_info_list.begin (); | |
1751 | |
1752 while (p2 != file_info_list.end ()) | |
1753 { | |
1754 if (p2->dir_name == full_dir_name) | |
1755 break; | |
1756 | |
1757 p2++; | |
1758 } | |
1759 | |
1760 if (p2 == file_info_list.end ()) | |
1761 { | |
1762 file_info fi (full_dir_name, types); | |
1763 | |
1764 if (at_end) | |
1765 file_info_list.push_back (fi); | |
1766 else | |
1767 file_info_list.push_front (fi); | |
1768 } | |
1769 else | |
1770 { | |
1771 // FIXME -- is this possible? | |
1772 | |
1773 file_info& fi = *p2; | |
1774 | |
1775 fi.types = types; | |
1776 } | |
1777 } | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1778 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1779 // <FCN_NAME, TYPES> |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1780 dir_info::fcn_file_map_type private_file_map = ci.private_file_map; |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1781 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1782 if (! private_file_map.empty ()) |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1783 private_fcn_map[full_dir_name] = private_file_map; |
7336 | 1784 } |
1785 } | |
1786 | |
5832 | 1787 std::string |
1788 genpath (const std::string& dirname, const string_vector& skip) | |
1789 { | |
1790 std::string retval; | |
1791 | |
5871 | 1792 dir_entry dir (dirname); |
5832 | 1793 |
1794 if (dir) | |
1795 { | |
1796 retval = dirname; | |
1797 | |
1798 string_vector dirlist = dir.read (); | |
1799 | |
1800 octave_idx_type len = dirlist.length (); | |
1801 | |
1802 for (octave_idx_type i = 0; i < len; i++) | |
1803 { | |
1804 std::string elt = dirlist[i]; | |
1805 | |
1806 // FIXME -- the caller should be able to specify the list of | |
7336 | 1807 // directories to skip in addition to ".", "..", and |
1808 // directories beginning with "@". | |
5832 | 1809 |
7336 | 1810 bool skip_p = (elt == "." || elt == ".." || elt[0] == '@'); |
5832 | 1811 |
1812 if (! skip_p) | |
1813 { | |
1814 for (octave_idx_type j = 0; j < skip.length (); j++) | |
1815 { | |
1816 skip_p = (elt == skip[j]); | |
1817 if (skip_p) | |
1818 break; | |
1819 } | |
1820 | |
1821 if (! skip_p) | |
1822 { | |
7272 | 1823 std::string nm = file_ops::concat (dirname, elt); |
5832 | 1824 |
1825 file_stat fs (nm); | |
1826 | |
1827 if (fs && fs.is_dir ()) | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
1828 retval += dir_path::path_sep_str () + genpath (nm); |
5832 | 1829 } |
1830 } | |
1831 } | |
1832 } | |
1833 | |
1834 return retval; | |
1835 } | |
1836 | |
1837 static void | |
1838 execute_pkg_add_or_del (const std::string& dir, | |
1839 const std::string& script_file) | |
1840 { | |
1841 if (! octave_interpreter_ready) | |
1842 return; | |
1843 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9807
diff
changeset
|
1844 unwind_protect frame; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9807
diff
changeset
|
1845 |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9807
diff
changeset
|
1846 frame.protect_var (input_from_startup_file); |
5832 | 1847 |
1848 input_from_startup_file = true; | |
1849 | |
7272 | 1850 std::string file = file_ops::concat (dir, script_file); |
5832 | 1851 |
5978 | 1852 file_stat fs (file); |
5832 | 1853 |
1854 if (fs.exists ()) | |
5975 | 1855 source_file (file, "base"); |
5832 | 1856 } |
1857 | |
1858 void | |
1859 execute_pkg_add (const std::string& dir) | |
1860 { | |
1861 execute_pkg_add_or_del (dir, "PKG_ADD"); | |
1862 } | |
1863 | |
1864 void | |
1865 execute_pkg_del (const std::string& dir) | |
1866 { | |
1867 execute_pkg_add_or_del (dir, "PKG_DEL"); | |
1868 } | |
1869 | |
1870 DEFUN (genpath, args, , | |
1871 "-*- texinfo -*-\n\ | |
1872 @deftypefn {Built-in Function} {} genpath (@var{dir})\n\ | |
8325
b93ac0586e4b
spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents:
8141
diff
changeset
|
1873 Return a path constructed from @var{dir} and all its subdirectories.\n\ |
5832 | 1874 @end deftypefn") |
1875 { | |
1876 octave_value retval; | |
1877 | |
1878 if (args.length () == 1) | |
1879 { | |
1880 std::string dirname = args(0).string_value (); | |
1881 | |
1882 if (! error_state) | |
1883 retval = genpath (dirname); | |
1884 else | |
1885 error ("genpath: expecting argument to be a character string"); | |
1886 } | |
1887 else | |
1888 print_usage (); | |
1889 | |
1890 return retval; | |
1891 } | |
1892 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1893 static void |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1894 rehash_internal (void) |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1895 { |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1896 load_path::update (); |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1897 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1898 // FIXME -- maybe we should rename this variable since it is being |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1899 // used for more than keeping track of the prompt time. |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1900 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1901 // This will force updated functions to be found. |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1902 Vlast_prompt_time.stamp (); |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1903 } |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1904 |
5832 | 1905 DEFUN (rehash, , , |
1906 "-*- texinfo -*-\n\ | |
1907 @deftypefn {Built-in Function} {} rehash ()\n\ | |
6644 | 1908 Reinitialize Octave's load path directory cache.\n\ |
5832 | 1909 @end deftypefn") |
1910 { | |
1911 octave_value_list retval; | |
1912 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1913 rehash_internal (); |
5832 | 1914 |
1915 return retval; | |
1916 } | |
1917 | |
8609
fcf762ba66cf
load-path.cc (Fcommand_line_path): rename from Fcommandlinepath
John W. Eaton <jwe@octave.org>
parents:
8593
diff
changeset
|
1918 DEFUN (command_line_path, , , |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1919 "-*- texinfo -*-\n\ |
8609
fcf762ba66cf
load-path.cc (Fcommand_line_path): rename from Fcommandlinepath
John W. Eaton <jwe@octave.org>
parents:
8593
diff
changeset
|
1920 @deftypefn {Built-in Function} {} command_line_path (@dots{})\n\ |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1921 Return the command line path variable.\n\ |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1922 \n\ |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1923 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1924 @end deftypefn") |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1925 { |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1926 return octave_value (load_path::get_command_line_path ()); |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1927 } |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1928 |
7391 | 1929 DEFUN (restoredefaultpath, , , |
1930 "-*- texinfo -*-\n\ | |
1931 @deftypefn {Built-in Function} {} restoredefaultpath (@dots{})\n\ | |
1932 Restore Octave's path to it's initial state at startup.\n\ | |
1933 \n\ | |
1934 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
1935 @end deftypefn") | |
1936 { | |
1937 load_path::initialize (true); | |
1938 | |
1939 return octave_value (load_path::system_path ()); | |
1940 } | |
1941 | |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
1942 // Return Octave's original default list of directories in which to |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
1943 // search for function files. This corresponds to the path that |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
1944 // exists prior to running the system's octaverc file or the user's |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
1945 // ~/.octaverc file |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
1946 |
7391 | 1947 DEFUN (__pathorig__, , , |
5832 | 1948 "-*- texinfo -*-\n\ |
7391 | 1949 @deftypefn {Built-in Function} {@var{val} =} __pathorig__ ()\n\ |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
1950 Undocumented internal function.\n\ |
5832 | 1951 @end deftypefn") |
1952 { | |
6630 | 1953 return octave_value (load_path::system_path ()); |
5832 | 1954 } |
1955 | |
1956 DEFUN (path, args, nargout, | |
1957 "-*- texinfo -*-\n\ | |
6678 | 1958 @deftypefn {Built-in Function} {} path (@dots{})\n\ |
6644 | 1959 Modify or display Octave's load path.\n\ |
5832 | 1960 \n\ |
1961 If @var{nargin} and @var{nargout} are zero, display the elements of\n\ | |
6644 | 1962 Octave's load path in an easy to read format.\n\ |
5832 | 1963 \n\ |
1964 If @var{nargin} is zero and nargout is greater than zero, return the\n\ | |
6644 | 1965 current load path.\n\ |
5832 | 1966 \n\ |
1967 If @var{nargin} is greater than zero, concatenate the arguments,\n\ | |
1968 separating them with @code{pathsep()}. Set the internal search path\n\ | |
1969 to the result and return it.\n\ | |
1970 \n\ | |
1971 No checks are made for duplicate elements.\n\ | |
1972 @seealso{addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
1973 @end deftypefn") | |
1974 { | |
1975 octave_value retval; | |
1976 | |
1977 int argc = args.length () + 1; | |
1978 | |
1979 string_vector argv = args.make_argv ("path"); | |
1980 | |
1981 if (! error_state) | |
1982 { | |
1983 if (argc > 1) | |
1984 { | |
1985 std::string path = argv[1]; | |
1986 | |
1987 for (int i = 2; i < argc; i++) | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
1988 path += dir_path::path_sep_str () + argv[i]; |
5832 | 1989 |
5867 | 1990 load_path::set (path, true); |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1991 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1992 rehash_internal (); |
5832 | 1993 } |
1994 | |
1995 if (nargout > 0) | |
1996 retval = load_path::path (); | |
1997 else if (argc == 1 && nargout == 0) | |
1998 { | |
1999 octave_stdout << "\nOctave's search path contains the following directories:\n\n"; | |
2000 | |
2001 string_vector dirs = load_path::dirs (); | |
2002 | |
2003 dirs.list_in_columns (octave_stdout); | |
2004 | |
2005 octave_stdout << "\n"; | |
2006 } | |
2007 } | |
2008 | |
2009 return retval; | |
2010 } | |
2011 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
2012 DEFUN (addpath, args, nargout, |
5832 | 2013 "-*- texinfo -*-\n\ |
6678 | 2014 @deftypefn {Built-in Function} {} addpath (@var{dir1}, @dots{})\n\ |
2015 @deftypefnx {Built-in Function} {} addpath (@var{dir1}, @dots{}, @var{option})\n\ | |
5832 | 2016 Add @var{dir1}, @dots{} to the current function search path. If\n\ |
2017 @var{option} is @samp{\"-begin\"} or 0 (the default), prepend the\n\ | |
2018 directory name to the current path. If @var{option} is @samp{\"-end\"}\n\ | |
2019 or 1, append the directory name to the current path.\n\ | |
2020 Directories added to the path must exist.\n\ | |
2021 @seealso{path, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
2022 @end deftypefn") | |
2023 { | |
2024 octave_value retval; | |
2025 | |
2026 // Originally written by Bill Denney and Etienne Grossman. Heavily | |
2027 // modified and translated to C++ by jwe. | |
2028 | |
2029 if (nargout > 0) | |
2030 retval = load_path::path (); | |
2031 | |
2032 int nargin = args.length (); | |
2033 | |
2034 if (nargin > 0) | |
2035 { | |
2036 bool append = false; | |
2037 | |
2038 octave_value option_arg = args(nargin-1); | |
2039 | |
2040 if (option_arg.is_string ()) | |
2041 { | |
2042 std::string option = option_arg.string_value (); | |
2043 | |
2044 if (option == "-end") | |
2045 { | |
2046 append = true; | |
2047 nargin--; | |
2048 } | |
2049 else if (option == "-begin") | |
2050 nargin--; | |
2051 } | |
2052 else if (option_arg.is_numeric_type ()) | |
2053 { | |
2054 int val = option_arg.int_value (); | |
2055 | |
2056 if (! error_state) | |
2057 { | |
2058 if (val == 0) | |
2059 append = false; | |
2060 else if (val == 1) | |
2061 append = true; | |
2062 else | |
2063 { | |
2064 error ("addpath: expecting final argument to be 1 or 0"); | |
2065 return retval; | |
2066 } | |
2067 } | |
2068 else | |
2069 { | |
2070 error ("addpath: expecting final argument to be 1 or 0"); | |
2071 return retval; | |
2072 } | |
2073 } | |
2074 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2075 bool need_to_update = false; |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2076 |
5832 | 2077 for (int i = 0; i < nargin; i++) |
2078 { | |
2079 std::string arg = args(i).string_value (); | |
2080 | |
2081 if (! error_state) | |
2082 { | |
2083 std::list<std::string> dir_elts = split_path (arg); | |
2084 | |
9401
6c421f2355b5
load-path.cc (Faddpath): preserve order of prepended elements
John W. Eaton <jwe@octave.org>
parents:
9377
diff
changeset
|
2085 if (! append) |
6c421f2355b5
load-path.cc (Faddpath): preserve order of prepended elements
John W. Eaton <jwe@octave.org>
parents:
9377
diff
changeset
|
2086 std::reverse (dir_elts.begin (), dir_elts.end ()); |
6c421f2355b5
load-path.cc (Faddpath): preserve order of prepended elements
John W. Eaton <jwe@octave.org>
parents:
9377
diff
changeset
|
2087 |
5832 | 2088 for (std::list<std::string>::const_iterator p = dir_elts.begin (); |
2089 p != dir_elts.end (); | |
2090 p++) | |
2091 { | |
2092 std::string dir = *p; | |
2093 | |
2094 //dir = regexprep (dir_elts{j}, "//+", "/"); | |
2095 //dir = regexprep (dir, "/$", ""); | |
2096 | |
5867 | 2097 if (append) |
2098 load_path::append (dir, true); | |
5832 | 2099 else |
5867 | 2100 load_path::prepend (dir, true); |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2101 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2102 need_to_update = true; |
5832 | 2103 } |
2104 } | |
2105 else | |
2106 error ("addpath: expecting all args to be character strings"); | |
2107 } | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2108 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2109 if (need_to_update) |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2110 rehash_internal (); |
5832 | 2111 } |
2112 else | |
2113 print_usage (); | |
2114 | |
2115 return retval; | |
2116 } | |
2117 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
2118 DEFUN (rmpath, args, nargout, |
5832 | 2119 "-*- texinfo -*-\n\ |
6678 | 2120 @deftypefn {Built-in Function} {} rmpath (@var{dir1}, @dots{})\n\ |
5832 | 2121 Remove @var{dir1}, @dots{} from the current function search path.\n\ |
2122 \n\ | |
2123 @seealso{path, addpath, genpath, pathdef, savepath, pathsep}\n\ | |
2124 @end deftypefn") | |
2125 { | |
2126 // Originally by Etienne Grossmann. Heavily modified and translated | |
2127 // to C++ by jwe. | |
2128 | |
2129 octave_value retval; | |
2130 | |
2131 if (nargout > 0) | |
2132 retval = load_path::path (); | |
2133 | |
2134 int nargin = args.length (); | |
2135 | |
2136 if (nargin > 0) | |
2137 { | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2138 bool need_to_update = false; |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2139 |
5832 | 2140 for (int i = 0; i < nargin; i++) |
2141 { | |
2142 std::string arg = args(i).string_value (); | |
2143 | |
2144 if (! error_state) | |
2145 { | |
2146 std::list<std::string> dir_elts = split_path (arg); | |
2147 | |
2148 for (std::list<std::string>::const_iterator p = dir_elts.begin (); | |
2149 p != dir_elts.end (); | |
2150 p++) | |
2151 { | |
2152 std::string dir = *p; | |
2153 | |
2154 //dir = regexprep (dir_elts{j}, "//+", "/"); | |
2155 //dir = regexprep (dir, "/$", ""); | |
2156 | |
2157 if (! load_path::remove (dir)) | |
2158 warning ("rmpath: %s: not found", dir.c_str ()); | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2159 else |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2160 need_to_update = true; |
5832 | 2161 } |
2162 } | |
2163 else | |
2164 error ("addpath: expecting all args to be character strings"); | |
2165 } | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2166 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2167 if (need_to_update) |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2168 rehash_internal (); |
5832 | 2169 } |
2170 else | |
2171 print_usage (); | |
2172 | |
2173 return retval; | |
2174 } |