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