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