Mercurial > hg > octave-lyh
annotate src/load-path.cc @ 9401:6c421f2355b5
load-path.cc (Faddpath): preserve order of prepended elements
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 26 Jun 2009 09:15:31 -0400 |
parents | 610bf90fce2a |
children | 0c7d84a65386 |
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 (); | |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
515 parent_map.clear (); |
5867 | 516 |
517 do_append (".", false); | |
5832 | 518 } |
519 | |
520 static std::list<std::string> | |
521 split_path (const std::string& p) | |
522 { | |
523 std::list<std::string> retval; | |
524 | |
525 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
|
526 size_t end = p.find (dir_path::path_sep_char ()); |
5832 | 527 |
528 size_t len = p.length (); | |
529 | |
8021 | 530 while (end != std::string::npos) |
5832 | 531 { |
532 std::string elt = p.substr (beg, end-beg); | |
533 | |
534 if (! elt.empty ()) | |
535 retval.push_back (elt); | |
536 | |
537 beg = end + 1; | |
538 | |
539 if (beg == len) | |
540 break; | |
541 | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
8007
diff
changeset
|
542 end = p.find (dir_path::path_sep_char (), beg); |
5832 | 543 } |
544 | |
545 std::string elt = p.substr (beg); | |
546 | |
547 if (! elt.empty ()) | |
548 retval.push_back (elt); | |
549 | |
550 return retval; | |
551 } | |
552 | |
553 void | |
5867 | 554 load_path::do_set (const std::string& p, bool warn) |
5832 | 555 { |
556 std::list<std::string> elts = split_path (p); | |
557 | |
558 // Temporarily disable add hook. | |
559 | |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9282
diff
changeset
|
560 unwind_protect::protect_var (add_hook); |
5832 | 561 |
562 add_hook = 0; | |
563 | |
8511
a835406e02dd
load_path::do_set: call clear after disabling add_hook
John W. Eaton <jwe@octave.org>
parents:
8331
diff
changeset
|
564 do_clear (); |
a835406e02dd
load_path::do_set: call clear after disabling add_hook
John W. Eaton <jwe@octave.org>
parents:
8331
diff
changeset
|
565 |
5832 | 566 for (std::list<std::string>::const_iterator i = elts.begin (); |
567 i != elts.end (); | |
568 i++) | |
5867 | 569 do_append (*i, warn); |
5832 | 570 |
571 // Restore add hook and execute for all newly added directories. | |
572 | |
573 unwind_protect::run (); | |
574 | |
575 for (dir_info_list_iterator i = dir_info_list.begin (); | |
576 i != dir_info_list.end (); | |
577 i++) | |
578 { | |
579 if (add_hook) | |
580 add_hook (i->dir_name); | |
581 } | |
582 } | |
583 | |
584 void | |
5867 | 585 load_path::do_append (const std::string& dir, bool warn) |
5832 | 586 { |
587 if (! dir.empty ()) | |
5867 | 588 do_add (dir, true, warn); |
589 } | |
5832 | 590 |
5867 | 591 void |
592 load_path::do_prepend (const std::string& dir, bool warn) | |
593 { | |
594 if (! dir.empty ()) | |
595 do_add (dir, false, warn); | |
5832 | 596 } |
597 | |
598 void | |
5919 | 599 load_path::do_add (const std::string& dir_arg, bool at_end, bool warn) |
5832 | 600 { |
5919 | 601 size_t len = dir_arg.length (); |
5911 | 602 |
5919 | 603 if (len > 1 && dir_arg.substr (len-2) == "//") |
5911 | 604 warning_with_id ("Octave:recursive-path-search", |
605 "trailing `//' is no longer special in search path elements"); | |
606 | |
5919 | 607 std::string dir = file_ops::tilde_expand (dir_arg); |
608 | |
5867 | 609 dir_info_list_iterator i = find_dir_info (dir); |
610 | |
611 if (i != dir_info_list.end ()) | |
612 move (i, at_end); | |
613 else | |
5832 | 614 { |
5867 | 615 file_stat fs (dir); |
5832 | 616 |
5867 | 617 if (fs) |
5832 | 618 { |
5867 | 619 if (fs.is_dir ()) |
620 { | |
621 dir_info di (dir); | |
5832 | 622 |
5867 | 623 if (! error_state) |
624 { | |
625 if (at_end) | |
626 dir_info_list.push_back (di); | |
627 else | |
628 dir_info_list.push_front (di); | |
629 | |
630 add_to_fcn_map (di, true); | |
5832 | 631 |
7336 | 632 add_to_private_fcn_map (di); |
633 | |
634 add_to_method_map (di, true); | |
635 | |
5867 | 636 if (add_hook) |
637 add_hook (dir); | |
638 } | |
5832 | 639 } |
5867 | 640 else if (warn) |
5919 | 641 warning ("addpath: %s: not a directory", dir_arg.c_str ()); |
5832 | 642 } |
5867 | 643 else if (warn) |
644 { | |
645 std::string msg = fs.error (); | |
5919 | 646 warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ()); |
5867 | 647 } |
648 } | |
5832 | 649 |
5867 | 650 // FIXME -- is there a better way to do this? |
5832 | 651 |
5867 | 652 i = find_dir_info ("."); |
5832 | 653 |
5867 | 654 if (i != dir_info_list.end ()) |
5871 | 655 move (i, false); |
5867 | 656 else |
657 panic_impossible (); | |
5832 | 658 } |
659 | |
7336 | 660 void |
661 load_path::remove_fcn_map (const std::string& dir, | |
662 const string_vector& fcn_files) | |
663 { | |
664 octave_idx_type len = fcn_files.length (); | |
665 | |
666 for (octave_idx_type k = 0; k < len; k++) | |
667 { | |
668 std::string fname = fcn_files[k]; | |
669 | |
670 std::string ext; | |
671 std::string base = fname; | |
672 | |
673 size_t pos = fname.rfind ('.'); | |
674 | |
8021 | 675 if (pos != std::string::npos) |
7336 | 676 { |
677 base = fname.substr (0, pos); | |
678 ext = fname.substr (pos); | |
679 } | |
680 | |
681 file_info_list_type& file_info_list = fcn_map[base]; | |
682 | |
683 for (file_info_list_iterator p = file_info_list.begin (); | |
684 p != file_info_list.end (); | |
685 p++) | |
686 { | |
687 if (p->dir_name == dir) | |
688 { | |
689 file_info_list.erase (p); | |
690 | |
691 if (file_info_list.empty ()) | |
692 fcn_map.erase (fname); | |
693 | |
694 break; | |
695 } | |
696 } | |
697 } | |
698 } | |
699 | |
700 void | |
701 load_path::remove_private_fcn_map (const std::string& dir) | |
702 { | |
703 private_fcn_map_iterator p = private_fcn_map.find (dir); | |
704 | |
705 if (p != private_fcn_map.end ()) | |
706 private_fcn_map.erase (p); | |
707 } | |
708 | |
709 void | |
710 load_path::remove_method_map (const std::string& dir) | |
711 { | |
712 for (method_map_iterator i = method_map.begin (); | |
713 i != method_map.end (); | |
714 i++) | |
715 { | |
716 std::string class_name = i->first; | |
717 | |
718 fcn_map_type& fm = i->second; | |
719 | |
720 std::string full_dir_name = file_ops::concat (dir, "@" + class_name); | |
721 | |
722 for (fcn_map_iterator q = fm.begin (); q != fm.end (); q++) | |
723 { | |
724 file_info_list_type& file_info_list = q->second; | |
725 | |
726 if (file_info_list.size () == 1) | |
727 continue; | |
728 else | |
729 { | |
730 for (file_info_list_iterator p = file_info_list.begin (); | |
731 p != file_info_list.end (); | |
732 p++) | |
733 { | |
734 if (p->dir_name == full_dir_name) | |
735 { | |
736 file_info_list.erase (p); | |
737 | |
738 // FIXME -- if there are no other elements, we | |
739 // should remove this element of fm but calling | |
740 // erase here would invalidate the iterator q. | |
741 | |
742 break; | |
743 } | |
744 } | |
745 } | |
746 } | |
747 } | |
748 } | |
749 | |
5832 | 750 bool |
5919 | 751 load_path::do_remove (const std::string& dir_arg) |
5832 | 752 { |
753 bool retval = false; | |
754 | |
5919 | 755 if (! dir_arg.empty ()) |
5832 | 756 { |
5919 | 757 if (dir_arg == ".") |
5867 | 758 { |
759 warning ("rmpath: can't remove \".\" from path"); | |
5832 | 760 |
5867 | 761 // Avoid additional warnings. |
5832 | 762 retval = true; |
5867 | 763 } |
764 else | |
765 { | |
5919 | 766 std::string dir = file_ops::tilde_expand (dir_arg); |
767 | |
5867 | 768 dir_info_list_iterator i = find_dir_info (dir); |
5832 | 769 |
5867 | 770 if (i != dir_info_list.end ()) |
771 { | |
772 retval = true; | |
5832 | 773 |
6825 | 774 if (remove_hook) |
775 remove_hook (dir); | |
776 | |
5867 | 777 string_vector fcn_files = i->fcn_files; |
778 | |
779 dir_info_list.erase (i); | |
5832 | 780 |
7336 | 781 remove_fcn_map (dir, fcn_files); |
5867 | 782 |
7336 | 783 remove_private_fcn_map (dir); |
5832 | 784 |
7336 | 785 remove_method_map (dir); |
5832 | 786 } |
787 } | |
788 } | |
789 | |
790 return retval; | |
791 } | |
792 | |
793 void | |
794 load_path::do_update (void) const | |
795 { | |
796 // I don't see a better way to do this because we need to | |
797 // preserve the correct directory ordering for new files that | |
798 // have appeared. | |
799 | |
800 fcn_map.clear (); | |
801 | |
7336 | 802 private_fcn_map.clear (); |
803 | |
804 method_map.clear (); | |
805 | |
5832 | 806 for (dir_info_list_iterator p = dir_info_list.begin (); |
807 p != dir_info_list.end (); | |
808 p++) | |
809 { | |
810 dir_info& di = *p; | |
811 | |
812 di.update (); | |
813 | |
814 add_to_fcn_map (di, true); | |
7336 | 815 |
816 add_to_private_fcn_map (di); | |
817 | |
818 add_to_method_map (di, true); | |
5832 | 819 } |
820 } | |
821 | |
7336 | 822 bool |
823 load_path::check_file_type (std::string& fname, int type, int possible_types, | |
824 const std::string& fcn, const char *who) | |
825 { | |
826 bool retval = false; | |
827 | |
828 if (type == load_path::OCT_FILE) | |
829 { | |
830 if ((type & possible_types) == load_path::OCT_FILE) | |
831 { | |
832 fname += ".oct"; | |
833 retval = true; | |
834 } | |
835 } | |
836 else if (type == load_path::M_FILE) | |
837 { | |
838 if ((type & possible_types) == load_path::M_FILE) | |
839 { | |
840 fname += ".m"; | |
841 retval = true; | |
842 } | |
843 } | |
844 else if (type == load_path::MEX_FILE) | |
845 { | |
846 if ((type & possible_types) == load_path::MEX_FILE) | |
847 { | |
848 fname += ".mex"; | |
849 retval = true; | |
850 } | |
851 } | |
852 else if (type == (load_path::M_FILE | load_path::OCT_FILE)) | |
853 { | |
854 if (possible_types & load_path::OCT_FILE) | |
855 { | |
856 fname += ".oct"; | |
857 retval = true; | |
858 } | |
859 else if (possible_types & load_path::M_FILE) | |
860 { | |
861 fname += ".m"; | |
862 retval = true; | |
863 } | |
864 } | |
865 else if (type == (load_path::M_FILE | load_path::MEX_FILE)) | |
866 { | |
867 if (possible_types & load_path::MEX_FILE) | |
868 { | |
869 fname += ".mex"; | |
870 retval = true; | |
871 } | |
872 else if (possible_types & load_path::M_FILE) | |
873 { | |
874 fname += ".m"; | |
875 retval = true; | |
876 } | |
877 } | |
878 else if (type == (load_path::OCT_FILE | load_path::MEX_FILE)) | |
879 { | |
880 if (possible_types & load_path::OCT_FILE) | |
881 { | |
882 fname += ".oct"; | |
883 retval = true; | |
884 } | |
885 else if (possible_types & load_path::MEX_FILE) | |
886 { | |
887 fname += ".mex"; | |
888 retval = true; | |
889 } | |
890 } | |
891 else if (type == (load_path::M_FILE | load_path::OCT_FILE | |
892 | load_path::MEX_FILE)) | |
893 { | |
894 if (possible_types & load_path::OCT_FILE) | |
895 { | |
896 fname += ".oct"; | |
897 retval = true; | |
898 } | |
899 else if (possible_types & load_path::MEX_FILE) | |
900 { | |
901 fname += ".mex"; | |
902 retval = true; | |
903 } | |
904 else if (possible_types & load_path::M_FILE) | |
905 { | |
906 fname += ".m"; | |
907 retval = true; | |
908 } | |
909 } | |
910 else | |
911 error ("%s: %s: invalid type code = %d", who, fcn.c_str (), type); | |
912 | |
913 return retval; | |
914 } | |
915 | |
5832 | 916 std::string |
7336 | 917 load_path::do_find_fcn (const std::string& fcn, std::string& dir_name, |
918 int type) const | |
5832 | 919 { |
920 std::string retval; | |
7336 | 921 |
922 // update (); | |
5832 | 923 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
924 if (fcn.length () > 0 && fcn[0] == '@') |
5832 | 925 { |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
926 size_t pos = fcn.find ('/'); |
5832 | 927 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
928 if (pos != std::string::npos) |
5832 | 929 { |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
930 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
|
931 std::string meth = fcn.substr (pos+1); |
5832 | 932 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
933 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
|
934 } |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
935 else |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
936 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
|
937 } |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
938 else |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
939 { |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
940 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
|
941 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
942 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
|
943 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
944 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
|
945 { |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
946 const file_info_list_type& file_info_list = p->second; |
5832 | 947 |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
948 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
|
949 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
|
950 i++) |
5832 | 951 { |
8593
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
952 const file_info& fi = *i; |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
953 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
954 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
|
955 |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
956 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
|
957 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
|
958 { |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
959 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
|
960 break; |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
961 } |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
962 else |
4e39b00218d3
load-path.cc (load_path::do_find_fcn): handle @foo/bar
John W. Eaton <jwe@octave.org>
parents:
8586
diff
changeset
|
963 retval = std::string (); |
5832 | 964 } |
7336 | 965 } |
966 } | |
967 | |
968 return retval; | |
969 } | |
970 | |
971 std::string | |
972 load_path::do_find_private_fcn (const std::string& dir, | |
973 const std::string& fcn, int type) const | |
974 { | |
975 std::string retval; | |
976 | |
977 // update (); | |
978 | |
979 const_private_fcn_map_iterator q = private_fcn_map.find (dir); | |
980 | |
981 if (q != private_fcn_map.end ()) | |
982 { | |
983 const dir_info::fcn_file_map_type& m = q->second; | |
984 | |
985 dir_info::const_fcn_file_map_iterator p = m.find (fcn); | |
986 | |
987 if (p != m.end ()) | |
988 { | |
989 std::string fname | |
990 = file_ops::concat (file_ops::concat (dir, "private"), fcn); | |
991 | |
992 if (check_file_type (fname, type, p->second, fcn, | |
993 "load_path::find_private_fcn")) | |
994 retval = fname; | |
995 } | |
996 } | |
997 | |
998 return retval; | |
999 } | |
1000 | |
1001 std::string | |
1002 load_path::do_find_method (const std::string& class_name, | |
1003 const std::string& meth, | |
1004 std::string& dir_name, int type) const | |
1005 { | |
1006 std::string retval; | |
1007 | |
1008 // update (); | |
1009 | |
1010 dir_name = std::string (); | |
1011 | |
1012 const_method_map_iterator q = method_map.find (class_name); | |
1013 | |
1014 if (q != method_map.end ()) | |
1015 { | |
1016 const fcn_map_type& m = q->second; | |
1017 | |
1018 const_fcn_map_iterator p = m.find (meth); | |
1019 | |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1020 if (p == m.end ()) |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1021 { |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1022 // Look in parent classes. |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1023 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1024 const_parent_map_iterator r = parent_map.find (class_name); |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1025 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1026 if (r != parent_map.end ()) |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1027 { |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1028 const std::list<std::string>& plist = r->second; |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1029 std::list<std::string>::const_iterator it = plist.begin (); |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1030 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1031 while (it != plist.end ()) |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1032 { |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1033 retval = do_find_method (*it, meth, dir_name, type); |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1034 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1035 if (retval != "") |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1036 break; |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1037 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1038 it++; |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1039 } |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1040 } |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1041 } |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1042 else |
7336 | 1043 { |
1044 const file_info_list_type& file_info_list = p->second; | |
1045 | |
1046 for (const_file_info_list_iterator i = file_info_list.begin (); | |
1047 i != file_info_list.end (); | |
1048 i++) | |
5864 | 1049 { |
7336 | 1050 const file_info& fi = *i; |
1051 | |
1052 retval = file_ops::concat (fi.dir_name, meth); | |
1053 | |
1054 bool found = check_file_type (retval, type, fi.types, | |
1055 meth, "load_path::do_find_method"); | |
1056 | |
1057 if (found) | |
5864 | 1058 { |
7336 | 1059 dir_name = fi.dir_name; |
5832 | 1060 break; |
1061 } | |
7336 | 1062 else |
1063 retval = std::string (); | |
5864 | 1064 } |
5832 | 1065 } |
1066 } | |
1067 | |
1068 return retval; | |
1069 } | |
1070 | |
7336 | 1071 std::list<std::string> |
1072 load_path::do_methods (const std::string& class_name) const | |
1073 { | |
1074 std::list<std::string> retval; | |
1075 | |
1076 // update (); | |
1077 | |
1078 const_method_map_iterator q = method_map.find (class_name); | |
1079 | |
1080 if (q != method_map.end ()) | |
1081 { | |
1082 const fcn_map_type& m = q->second; | |
1083 | |
1084 for (const_fcn_map_iterator p = m.begin (); p != m.end (); p++) | |
1085 retval.push_back (p->first); | |
1086 } | |
1087 | |
1088 if (! retval.empty ()) | |
1089 retval.sort (); | |
1090 | |
1091 return retval; | |
1092 } | |
1093 | |
5832 | 1094 std::string |
1095 load_path::do_find_file (const std::string& file) const | |
1096 { | |
1097 std::string retval; | |
1098 | |
8021 | 1099 if (file.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos) |
5832 | 1100 { |
6838 | 1101 if (octave_env::absolute_pathname (file) |
1102 || octave_env::rooted_relative_pathname (file)) | |
1103 { | |
1104 file_stat fs (file); | |
5832 | 1105 |
6838 | 1106 if (fs.exists ()) |
1107 return file; | |
1108 } | |
1109 else | |
1110 { | |
1111 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1112 p != dir_info_list.end (); | |
1113 p++) | |
1114 { | |
7272 | 1115 std::string tfile = file_ops::concat (p->dir_name, file); |
5832 | 1116 |
6838 | 1117 file_stat fs (tfile); |
6159 | 1118 |
6838 | 1119 if (fs.exists ()) |
1120 return tfile; | |
5832 | 1121 } |
1122 } | |
1123 } | |
6838 | 1124 else |
1125 { | |
1126 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1127 p != dir_info_list.end (); | |
1128 p++) | |
1129 { | |
1130 string_vector all_files = p->all_files; | |
6159 | 1131 |
6838 | 1132 octave_idx_type len = all_files.length (); |
1133 | |
1134 for (octave_idx_type i = 0; i < len; i++) | |
1135 { | |
1136 if (all_files[i] == file) | |
7272 | 1137 return file_ops::concat (p->dir_name, file); |
6838 | 1138 } |
1139 } | |
1140 } | |
5832 | 1141 |
1142 return retval; | |
1143 } | |
1144 | |
1145 std::string | |
8041
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1146 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
|
1147 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1148 std::string retval; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1149 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1150 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
|
1151 && (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
|
1152 || 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
|
1153 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1154 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
|
1155 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1156 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
|
1157 return dir; |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1158 } |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1159 else |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1160 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1161 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
|
1162 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
|
1163 p++) |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1164 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1165 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
|
1166 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1167 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
|
1168 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1169 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
|
1170 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
|
1171 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1172 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
|
1173 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1174 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
|
1175 && 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
|
1176 && 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
|
1177 { |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1178 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
|
1179 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1180 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
|
1181 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
|
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 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1186 return retval; |
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 |
a14bdf90be55
Add a search for Contents.m files to the help function
David Bateman <dbateman@free.fr>
parents:
8021
diff
changeset
|
1189 std::string |
5832 | 1190 load_path::do_find_first_of (const string_vector& flist) const |
1191 { | |
1192 std::string retval; | |
1193 | |
1194 std::string dir_name; | |
1195 std::string file_name; | |
1196 | |
1197 octave_idx_type flen = flist.length (); | |
1198 octave_idx_type rel_flen = 0; | |
1199 | |
1200 string_vector rel_flist (flen); | |
1201 | |
1202 for (octave_idx_type i = 0; i < flen; i++) | |
1203 { | |
1204 if (octave_env::absolute_pathname (flist[i])) | |
1205 { | |
1206 file_stat fs (flist[i]); | |
1207 | |
1208 if (fs.exists ()) | |
1209 return flist[i]; | |
1210 } | |
1211 else | |
1212 rel_flist[rel_flen++] = flist[i]; | |
1213 } | |
1214 | |
1215 rel_flist.resize (rel_flen); | |
1216 | |
1217 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1218 p != dir_info_list.end (); | |
1219 p++) | |
1220 { | |
1221 string_vector all_files = p->all_files; | |
1222 | |
1223 octave_idx_type len = all_files.length (); | |
1224 | |
1225 for (octave_idx_type i = 0; i < len; i++) | |
1226 { | |
1227 for (octave_idx_type j = 0; j < rel_flen; j++) | |
1228 { | |
1229 if (all_files[i] == rel_flist[j]) | |
1230 { | |
1231 dir_name = p->dir_name; | |
1232 file_name = rel_flist[j]; | |
6159 | 1233 |
1234 goto done; | |
5832 | 1235 } |
1236 } | |
1237 } | |
1238 } | |
1239 | |
6159 | 1240 done: |
1241 | |
5832 | 1242 if (! dir_name.empty ()) |
7272 | 1243 retval = file_ops::concat (dir_name, file_name); |
5832 | 1244 |
1245 return retval; | |
1246 } | |
1247 | |
1248 string_vector | |
1249 load_path::do_find_all_first_of (const string_vector& flist) const | |
1250 { | |
1251 std::list<std::string> retlist; | |
1252 | |
1253 std::string dir_name; | |
1254 std::string file_name; | |
1255 | |
1256 octave_idx_type flen = flist.length (); | |
1257 octave_idx_type rel_flen = 0; | |
1258 | |
1259 string_vector rel_flist (flen); | |
1260 | |
1261 for (octave_idx_type i = 0; i < flen; i++) | |
1262 { | |
1263 if (octave_env::absolute_pathname (flist[i])) | |
1264 { | |
1265 file_stat fs (flist[i]); | |
1266 | |
1267 if (fs.exists ()) | |
1268 retlist.push_back (flist[i]); | |
1269 } | |
1270 else | |
1271 rel_flist[rel_flen++] = flist[i]; | |
1272 } | |
1273 | |
1274 rel_flist.resize (rel_flen); | |
1275 | |
1276 for (const_dir_info_list_iterator p = dir_info_list.begin (); | |
1277 p != dir_info_list.end (); | |
1278 p++) | |
1279 { | |
1280 string_vector all_files = p->all_files; | |
1281 | |
1282 octave_idx_type len = all_files.length (); | |
1283 | |
1284 for (octave_idx_type i = 0; i < len; i++) | |
1285 { | |
1286 for (octave_idx_type j = 0; j < rel_flen; j++) | |
1287 { | |
1288 if (all_files[i] == rel_flist[j]) | |
1289 retlist.push_back | |
7272 | 1290 (file_ops::concat (p->dir_name, rel_flist[j])); |
5832 | 1291 } |
1292 } | |
1293 } | |
1294 | |
1295 size_t retsize = retlist.size (); | |
1296 | |
1297 string_vector retval (retsize); | |
1298 | |
1299 for (size_t i = 0; i < retsize; i++) | |
1300 { | |
1301 retval[i] = retlist.front (); | |
1302 | |
1303 retlist.pop_front (); | |
1304 } | |
1305 | |
1306 return retval; | |
1307 } | |
1308 | |
1309 string_vector | |
1310 load_path::do_dirs (void) const | |
1311 { | |
1312 size_t len = dir_info_list.size (); | |
1313 | |
1314 string_vector retval (len); | |
1315 | |
1316 octave_idx_type k = 0; | |
1317 | |
1318 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1319 i != dir_info_list.end (); | |
1320 i++) | |
1321 retval[k++] = i->dir_name; | |
1322 | |
1323 return retval; | |
1324 } | |
1325 | |
1326 std::list<std::string> | |
1327 load_path::do_dir_list (void) const | |
1328 { | |
1329 std::list<std::string> retval; | |
1330 | |
1331 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1332 i != dir_info_list.end (); | |
1333 i++) | |
1334 retval.push_back (i->dir_name); | |
1335 | |
1336 return retval; | |
1337 } | |
1338 | |
1339 string_vector | |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1340 load_path::do_files (const std::string& dir, bool omit_exts) const |
5832 | 1341 { |
1342 string_vector retval; | |
1343 | |
9282
2ed8d2d92507
load_path::do_files: avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
9261
diff
changeset
|
1344 const_dir_info_list_iterator p = find_dir_info (dir); |
5832 | 1345 |
9282
2ed8d2d92507
load_path::do_files: avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
9261
diff
changeset
|
1346 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
|
1347 retval = p->fcn_files; |
5832 | 1348 |
9261
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1349 if (omit_exts) |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1350 { |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1351 octave_idx_type len = retval.length (); |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1352 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1353 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
|
1354 { |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1355 std::string fname = retval[i]; |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1356 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1357 size_t pos = fname.rfind ('.'); |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1358 |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1359 if (pos != std::string::npos) |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1360 retval[i] = fname.substr (0, pos); |
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 } |
95445f9f5976
omit file extensions from __list_functions__ output
John W. Eaton <jwe@octave.org>
parents:
9105
diff
changeset
|
1363 |
5832 | 1364 return retval; |
1365 } | |
1366 | |
1367 string_vector | |
1368 load_path::do_fcn_names (void) const | |
1369 { | |
1370 size_t len = fcn_map.size (); | |
1371 | |
1372 string_vector retval (len); | |
1373 | |
1374 octave_idx_type count = 0; | |
1375 | |
1376 for (const_fcn_map_iterator p = fcn_map.begin (); | |
1377 p != fcn_map.end (); | |
1378 p++) | |
1379 retval[count++] = p->first; | |
1380 | |
1381 return retval; | |
1382 } | |
1383 | |
1384 std::string | |
1385 load_path::do_path (void) const | |
1386 { | |
1387 std::string xpath; | |
1388 | |
1389 string_vector xdirs = load_path::dirs (); | |
1390 | |
1391 octave_idx_type len = xdirs.length (); | |
1392 | |
1393 if (len > 0) | |
1394 xpath = xdirs[0]; | |
1395 | |
1396 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
|
1397 xpath += dir_path::path_sep_str () + xdirs[i]; |
5832 | 1398 |
1399 return xpath; | |
1400 } | |
1401 | |
1402 void | |
7336 | 1403 print_types (std::ostream& os, int types) |
1404 { | |
1405 bool printed_type = false; | |
1406 | |
1407 if (types & load_path::OCT_FILE) | |
1408 { | |
1409 os << "oct"; | |
1410 printed_type = true; | |
1411 } | |
1412 | |
1413 if (types & load_path::MEX_FILE) | |
1414 { | |
1415 if (printed_type) | |
1416 os << "|"; | |
1417 os << "mex"; | |
1418 printed_type = true; | |
1419 } | |
1420 | |
1421 if (types & load_path::M_FILE) | |
1422 { | |
1423 if (printed_type) | |
1424 os << "|"; | |
1425 os << "m"; | |
1426 printed_type = true; | |
1427 } | |
1428 } | |
1429 | |
1430 void | |
1431 print_fcn_list (std::ostream& os, | |
1432 const load_path::dir_info::fcn_file_map_type& lst) | |
1433 { | |
1434 for (load_path::dir_info::const_fcn_file_map_iterator p = lst.begin (); | |
1435 p != lst.end (); | |
1436 p++) | |
1437 { | |
1438 os << " " << p->first << " ("; | |
1439 | |
1440 print_types (os, p->second); | |
1441 | |
1442 os << ")\n"; | |
1443 } | |
1444 } | |
1445 | |
1446 string_vector | |
1447 get_file_list (const load_path::dir_info::fcn_file_map_type& lst) | |
1448 { | |
1449 octave_idx_type n = lst.size (); | |
1450 | |
1451 string_vector retval (n); | |
1452 | |
1453 octave_idx_type count = 0; | |
1454 | |
1455 for (load_path::dir_info::const_fcn_file_map_iterator p = lst.begin (); | |
1456 p != lst.end (); | |
1457 p++) | |
1458 { | |
1459 std::string nm = p->first; | |
1460 | |
1461 int types = p->second; | |
1462 | |
1463 if (types & load_path::OCT_FILE) | |
1464 nm += ".oct"; | |
1465 else if (types & load_path::MEX_FILE) | |
1466 nm += ".mex"; | |
1467 else | |
1468 nm += ".m"; | |
1469 | |
1470 retval[count++] = nm; | |
1471 } | |
1472 | |
1473 return retval; | |
1474 } | |
1475 | |
1476 void | |
5832 | 1477 load_path::do_display (std::ostream& os) const |
1478 { | |
1479 for (const_dir_info_list_iterator i = dir_info_list.begin (); | |
1480 i != dir_info_list.end (); | |
1481 i++) | |
1482 { | |
1483 string_vector fcn_files = i->fcn_files; | |
1484 | |
1485 if (! fcn_files.empty ()) | |
1486 { | |
1487 os << "\n*** function files in " << i->dir_name << ":\n\n"; | |
1488 | |
1489 fcn_files.list_in_columns (os); | |
1490 } | |
1491 | |
7336 | 1492 const dir_info::method_file_map_type& method_file_map |
1493 = i->method_file_map; | |
5832 | 1494 |
7336 | 1495 if (! method_file_map.empty ()) |
5832 | 1496 { |
7336 | 1497 for (dir_info::const_method_file_map_iterator p = method_file_map.begin (); |
1498 p != method_file_map.end (); | |
5832 | 1499 p++) |
1500 { | |
7336 | 1501 os << "\n*** methods in " << i->dir_name |
1502 << "/@" << p->first << ":\n\n"; | |
5832 | 1503 |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1504 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
|
1505 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1506 string_vector method_files = get_file_list (ci.method_file_map); |
5832 | 1507 |
7336 | 1508 method_files.list_in_columns (os); |
1509 } | |
1510 } | |
1511 } | |
5864 | 1512 |
7336 | 1513 for (const_private_fcn_map_iterator i = private_fcn_map.begin (); |
1514 i != private_fcn_map.end (); i++) | |
1515 { | |
1516 os << "\n*** private functions in " | |
1517 << file_ops::concat (i->first, "private") << ":\n\n"; | |
5832 | 1518 |
7336 | 1519 print_fcn_list (os, i->second); |
5832 | 1520 } |
1521 | |
1522 #if defined (DEBUG_LOAD_PATH) | |
1523 | |
1524 for (const_fcn_map_iterator i = fcn_map.begin (); | |
1525 i != fcn_map.end (); | |
1526 i++) | |
1527 { | |
1528 os << i->first << ":\n"; | |
1529 | |
7336 | 1530 const file_info_list_type& file_info_list = i->second; |
5832 | 1531 |
1532 for (const_file_info_list_iterator p = file_info_list.begin (); | |
1533 p != file_info_list.end (); | |
1534 p++) | |
1535 { | |
1536 os << " " << p->dir_name << " ("; | |
1537 | |
7336 | 1538 print_types (os, p->types); |
5832 | 1539 |
1540 os << ")\n"; | |
1541 } | |
1542 } | |
1543 | |
7336 | 1544 for (const_method_map_iterator i = method_map.begin (); |
1545 i != method_map.end (); | |
1546 i++) | |
1547 { | |
1548 os << "CLASS " << i->first << ":\n"; | |
1549 | |
1550 const fcn_map_type& fm = i->second; | |
1551 | |
1552 for (const_fcn_map_iterator q = fm.begin (); | |
1553 q != fm.end (); | |
1554 q++) | |
1555 { | |
1556 os << " " << q->first << ":\n"; | |
1557 | |
1558 const file_info_list_type& file_info_list = q->second; | |
1559 | |
1560 for (const_file_info_list_iterator p = file_info_list.begin (); | |
1561 p != file_info_list.end (); | |
1562 p++) | |
1563 { | |
1564 os << " " << p->dir_name << " ("; | |
1565 | |
1566 print_types (os, p->types); | |
1567 | |
1568 os << ")\n"; | |
1569 } | |
1570 } | |
1571 } | |
1572 | |
5832 | 1573 os << "\n"; |
1574 | |
1575 #endif | |
1576 } | |
1577 | |
1578 void | |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1579 load_path::do_add_to_parent_map (const std::string& classname, |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1580 const std::list<std::string>& parent_list) const |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1581 { |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1582 parent_map[classname] = parent_list; |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1583 } |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1584 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1585 void |
5832 | 1586 load_path::add_to_fcn_map (const dir_info& di, bool at_end) const |
1587 { | |
1588 std::string dir_name = di.dir_name; | |
1589 | |
1590 string_vector fcn_files = di.fcn_files; | |
1591 | |
1592 octave_idx_type len = fcn_files.length (); | |
1593 | |
1594 for (octave_idx_type i = 0; i < len; i++) | |
1595 { | |
1596 std::string fname = fcn_files[i]; | |
1597 | |
1598 std::string ext; | |
1599 std::string base = fname; | |
1600 | |
1601 size_t pos = fname.rfind ('.'); | |
1602 | |
8021 | 1603 if (pos != std::string::npos) |
5832 | 1604 { |
1605 base = fname.substr (0, pos); | |
1606 ext = fname.substr (pos); | |
1607 } | |
1608 | |
7336 | 1609 file_info_list_type& file_info_list = fcn_map[base]; |
5832 | 1610 |
1611 file_info_list_iterator p = file_info_list.begin (); | |
1612 | |
1613 while (p != file_info_list.end ()) | |
1614 { | |
1615 if (p->dir_name == dir_name) | |
1616 break; | |
1617 | |
1618 p++; | |
1619 } | |
1620 | |
1621 int t = 0; | |
1622 if (ext == ".m") | |
1623 t = load_path::M_FILE; | |
1624 else if (ext == ".oct") | |
1625 t = load_path::OCT_FILE; | |
5864 | 1626 else if (ext == ".mex") |
1627 t = load_path::MEX_FILE; | |
5832 | 1628 |
1629 if (p == file_info_list.end ()) | |
1630 { | |
1631 file_info fi (dir_name, t); | |
1632 | |
1633 if (at_end) | |
1634 file_info_list.push_back (fi); | |
1635 else | |
1636 file_info_list.push_front (fi); | |
1637 } | |
1638 else | |
1639 { | |
1640 file_info& fi = *p; | |
1641 | |
1642 fi.types |= t; | |
1643 } | |
1644 } | |
1645 } | |
1646 | |
7336 | 1647 void |
1648 load_path::add_to_private_fcn_map (const dir_info& di) const | |
1649 { | |
1650 dir_info::fcn_file_map_type private_file_map = di.private_file_map; | |
1651 | |
1652 if (! private_file_map.empty ()) | |
1653 private_fcn_map[di.dir_name] = private_file_map; | |
1654 } | |
1655 | |
1656 void | |
1657 load_path::add_to_method_map (const dir_info& di, bool at_end) const | |
1658 { | |
1659 std::string dir_name = di.dir_name; | |
1660 | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1661 // <CLASS_NAME, CLASS_INFO> |
7336 | 1662 dir_info::method_file_map_type method_file_map = di.method_file_map; |
1663 | |
1664 for (dir_info::const_method_file_map_iterator q = method_file_map.begin (); | |
1665 q != method_file_map.end (); | |
1666 q++) | |
1667 { | |
1668 std::string class_name = q->first; | |
1669 | |
1670 fcn_map_type& fm = method_map[class_name]; | |
1671 | |
1672 std::string full_dir_name | |
1673 = file_ops::concat (dir_name, "@" + class_name); | |
1674 | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1675 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
|
1676 |
7336 | 1677 // <FCN_NAME, TYPES> |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1678 const dir_info::fcn_file_map_type& m = ci.method_file_map; |
7336 | 1679 |
1680 for (dir_info::const_fcn_file_map_iterator p = m.begin (); | |
1681 p != m.end (); | |
1682 p++) | |
1683 { | |
1684 std::string base = p->first; | |
1685 | |
1686 int types = p->second; | |
1687 | |
1688 file_info_list_type& file_info_list = fm[base]; | |
1689 | |
1690 file_info_list_iterator p2 = file_info_list.begin (); | |
1691 | |
1692 while (p2 != file_info_list.end ()) | |
1693 { | |
1694 if (p2->dir_name == full_dir_name) | |
1695 break; | |
1696 | |
1697 p2++; | |
1698 } | |
1699 | |
1700 if (p2 == file_info_list.end ()) | |
1701 { | |
1702 file_info fi (full_dir_name, types); | |
1703 | |
1704 if (at_end) | |
1705 file_info_list.push_back (fi); | |
1706 else | |
1707 file_info_list.push_front (fi); | |
1708 } | |
1709 else | |
1710 { | |
1711 // FIXME -- is this possible? | |
1712 | |
1713 file_info& fi = *p2; | |
1714 | |
1715 fi.types = types; | |
1716 } | |
1717 } | |
7971
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1718 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1719 // <FCN_NAME, TYPES> |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1720 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
|
1721 |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1722 if (! private_file_map.empty ()) |
dd5cc5016487
handle private functions in class directories
John W. Eaton <jwe@octave.org>
parents:
7786
diff
changeset
|
1723 private_fcn_map[full_dir_name] = private_file_map; |
7336 | 1724 } |
1725 } | |
1726 | |
5832 | 1727 std::string |
1728 genpath (const std::string& dirname, const string_vector& skip) | |
1729 { | |
1730 std::string retval; | |
1731 | |
5871 | 1732 dir_entry dir (dirname); |
5832 | 1733 |
1734 if (dir) | |
1735 { | |
1736 retval = dirname; | |
1737 | |
1738 string_vector dirlist = dir.read (); | |
1739 | |
1740 octave_idx_type len = dirlist.length (); | |
1741 | |
1742 for (octave_idx_type i = 0; i < len; i++) | |
1743 { | |
1744 std::string elt = dirlist[i]; | |
1745 | |
1746 // FIXME -- the caller should be able to specify the list of | |
7336 | 1747 // directories to skip in addition to ".", "..", and |
1748 // directories beginning with "@". | |
5832 | 1749 |
7336 | 1750 bool skip_p = (elt == "." || elt == ".." || elt[0] == '@'); |
5832 | 1751 |
1752 if (! skip_p) | |
1753 { | |
1754 for (octave_idx_type j = 0; j < skip.length (); j++) | |
1755 { | |
1756 skip_p = (elt == skip[j]); | |
1757 if (skip_p) | |
1758 break; | |
1759 } | |
1760 | |
1761 if (! skip_p) | |
1762 { | |
7272 | 1763 std::string nm = file_ops::concat (dirname, elt); |
5832 | 1764 |
1765 file_stat fs (nm); | |
1766 | |
1767 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
|
1768 retval += dir_path::path_sep_str () + genpath (nm); |
5832 | 1769 } |
1770 } | |
1771 } | |
1772 } | |
1773 | |
1774 return retval; | |
1775 } | |
1776 | |
1777 static void | |
1778 execute_pkg_add_or_del (const std::string& dir, | |
1779 const std::string& script_file) | |
1780 { | |
1781 if (! octave_interpreter_ready) | |
1782 return; | |
1783 | |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9282
diff
changeset
|
1784 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); |
5832 | 1785 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9282
diff
changeset
|
1786 unwind_protect::protect_var (input_from_startup_file); |
5832 | 1787 |
1788 input_from_startup_file = true; | |
1789 | |
7272 | 1790 std::string file = file_ops::concat (dir, script_file); |
5832 | 1791 |
5978 | 1792 file_stat fs (file); |
5832 | 1793 |
1794 if (fs.exists ()) | |
5975 | 1795 source_file (file, "base"); |
5832 | 1796 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9282
diff
changeset
|
1797 unwind_protect::run_frame (uwp_frame); |
5832 | 1798 } |
1799 | |
1800 void | |
1801 execute_pkg_add (const std::string& dir) | |
1802 { | |
1803 execute_pkg_add_or_del (dir, "PKG_ADD"); | |
1804 } | |
1805 | |
1806 void | |
1807 execute_pkg_del (const std::string& dir) | |
1808 { | |
1809 execute_pkg_add_or_del (dir, "PKG_DEL"); | |
1810 } | |
1811 | |
1812 DEFUN (genpath, args, , | |
1813 "-*- texinfo -*-\n\ | |
1814 @deftypefn {Built-in Function} {} genpath (@var{dir})\n\ | |
8325
b93ac0586e4b
spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents:
8141
diff
changeset
|
1815 Return a path constructed from @var{dir} and all its subdirectories.\n\ |
5832 | 1816 @end deftypefn") |
1817 { | |
1818 octave_value retval; | |
1819 | |
1820 if (args.length () == 1) | |
1821 { | |
1822 std::string dirname = args(0).string_value (); | |
1823 | |
1824 if (! error_state) | |
1825 retval = genpath (dirname); | |
1826 else | |
1827 error ("genpath: expecting argument to be a character string"); | |
1828 } | |
1829 else | |
1830 print_usage (); | |
1831 | |
1832 return retval; | |
1833 } | |
1834 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1835 static void |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1836 rehash_internal (void) |
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 load_path::update (); |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1839 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1840 // 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
|
1841 // 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
|
1842 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1843 // 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
|
1844 Vlast_prompt_time.stamp (); |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1845 } |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1846 |
5832 | 1847 DEFUN (rehash, , , |
1848 "-*- texinfo -*-\n\ | |
1849 @deftypefn {Built-in Function} {} rehash ()\n\ | |
6644 | 1850 Reinitialize Octave's load path directory cache.\n\ |
5832 | 1851 @end deftypefn") |
1852 { | |
1853 octave_value_list retval; | |
1854 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1855 rehash_internal (); |
5832 | 1856 |
1857 return retval; | |
1858 } | |
1859 | |
8609
fcf762ba66cf
load-path.cc (Fcommand_line_path): rename from Fcommandlinepath
John W. Eaton <jwe@octave.org>
parents:
8593
diff
changeset
|
1860 DEFUN (command_line_path, , , |
8586
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1861 "-*- texinfo -*-\n\ |
8609
fcf762ba66cf
load-path.cc (Fcommand_line_path): rename from Fcommandlinepath
John W. Eaton <jwe@octave.org>
parents:
8593
diff
changeset
|
1862 @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
|
1863 Return the command line path variable.\n\ |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1864 \n\ |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1865 @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
|
1866 @end deftypefn") |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1867 { |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1868 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
|
1869 } |
31ab3b83bc8a
savepath: Respect cmd-line and env paths.
Ben Abbott <bpabbott@mac.com>
parents:
8511
diff
changeset
|
1870 |
7391 | 1871 DEFUN (restoredefaultpath, , , |
1872 "-*- texinfo -*-\n\ | |
1873 @deftypefn {Built-in Function} {} restoredefaultpath (@dots{})\n\ | |
1874 Restore Octave's path to it's initial state at startup.\n\ | |
1875 \n\ | |
1876 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
1877 @end deftypefn") | |
1878 { | |
1879 load_path::initialize (true); | |
1880 | |
1881 return octave_value (load_path::system_path ()); | |
1882 } | |
1883 | |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
1884 // 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
|
1885 // 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
|
1886 // 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
|
1887 // ~/.octaverc file |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
1888 |
7391 | 1889 DEFUN (__pathorig__, , , |
5832 | 1890 "-*- texinfo -*-\n\ |
7391 | 1891 @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
|
1892 Undocumented internal function.\n\ |
5832 | 1893 @end deftypefn") |
1894 { | |
6630 | 1895 return octave_value (load_path::system_path ()); |
5832 | 1896 } |
1897 | |
1898 DEFUN (path, args, nargout, | |
1899 "-*- texinfo -*-\n\ | |
6678 | 1900 @deftypefn {Built-in Function} {} path (@dots{})\n\ |
6644 | 1901 Modify or display Octave's load path.\n\ |
5832 | 1902 \n\ |
1903 If @var{nargin} and @var{nargout} are zero, display the elements of\n\ | |
6644 | 1904 Octave's load path in an easy to read format.\n\ |
5832 | 1905 \n\ |
1906 If @var{nargin} is zero and nargout is greater than zero, return the\n\ | |
6644 | 1907 current load path.\n\ |
5832 | 1908 \n\ |
1909 If @var{nargin} is greater than zero, concatenate the arguments,\n\ | |
1910 separating them with @code{pathsep()}. Set the internal search path\n\ | |
1911 to the result and return it.\n\ | |
1912 \n\ | |
1913 No checks are made for duplicate elements.\n\ | |
1914 @seealso{addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
1915 @end deftypefn") | |
1916 { | |
1917 octave_value retval; | |
1918 | |
1919 int argc = args.length () + 1; | |
1920 | |
1921 string_vector argv = args.make_argv ("path"); | |
1922 | |
1923 if (! error_state) | |
1924 { | |
1925 if (argc > 1) | |
1926 { | |
1927 std::string path = argv[1]; | |
1928 | |
1929 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
|
1930 path += dir_path::path_sep_str () + argv[i]; |
5832 | 1931 |
5867 | 1932 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
|
1933 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
1934 rehash_internal (); |
5832 | 1935 } |
1936 | |
1937 if (nargout > 0) | |
1938 retval = load_path::path (); | |
1939 else if (argc == 1 && nargout == 0) | |
1940 { | |
1941 octave_stdout << "\nOctave's search path contains the following directories:\n\n"; | |
1942 | |
1943 string_vector dirs = load_path::dirs (); | |
1944 | |
1945 dirs.list_in_columns (octave_stdout); | |
1946 | |
1947 octave_stdout << "\n"; | |
1948 } | |
1949 } | |
1950 | |
1951 return retval; | |
1952 } | |
1953 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
1954 DEFUN (addpath, args, nargout, |
5832 | 1955 "-*- texinfo -*-\n\ |
6678 | 1956 @deftypefn {Built-in Function} {} addpath (@var{dir1}, @dots{})\n\ |
1957 @deftypefnx {Built-in Function} {} addpath (@var{dir1}, @dots{}, @var{option})\n\ | |
5832 | 1958 Add @var{dir1}, @dots{} to the current function search path. If\n\ |
1959 @var{option} is @samp{\"-begin\"} or 0 (the default), prepend the\n\ | |
1960 directory name to the current path. If @var{option} is @samp{\"-end\"}\n\ | |
1961 or 1, append the directory name to the current path.\n\ | |
1962 Directories added to the path must exist.\n\ | |
1963 @seealso{path, rmpath, genpath, pathdef, savepath, pathsep}\n\ | |
1964 @end deftypefn") | |
1965 { | |
1966 octave_value retval; | |
1967 | |
1968 // Originally written by Bill Denney and Etienne Grossman. Heavily | |
1969 // modified and translated to C++ by jwe. | |
1970 | |
1971 if (nargout > 0) | |
1972 retval = load_path::path (); | |
1973 | |
1974 int nargin = args.length (); | |
1975 | |
1976 if (nargin > 0) | |
1977 { | |
1978 bool append = false; | |
1979 | |
1980 octave_value option_arg = args(nargin-1); | |
1981 | |
1982 if (option_arg.is_string ()) | |
1983 { | |
1984 std::string option = option_arg.string_value (); | |
1985 | |
1986 if (option == "-end") | |
1987 { | |
1988 append = true; | |
1989 nargin--; | |
1990 } | |
1991 else if (option == "-begin") | |
1992 nargin--; | |
1993 } | |
1994 else if (option_arg.is_numeric_type ()) | |
1995 { | |
1996 int val = option_arg.int_value (); | |
1997 | |
1998 if (! error_state) | |
1999 { | |
2000 if (val == 0) | |
2001 append = false; | |
2002 else if (val == 1) | |
2003 append = true; | |
2004 else | |
2005 { | |
2006 error ("addpath: expecting final argument to be 1 or 0"); | |
2007 return retval; | |
2008 } | |
2009 } | |
2010 else | |
2011 { | |
2012 error ("addpath: expecting final argument to be 1 or 0"); | |
2013 return retval; | |
2014 } | |
2015 } | |
2016 | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2017 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
|
2018 |
5832 | 2019 for (int i = 0; i < nargin; i++) |
2020 { | |
2021 std::string arg = args(i).string_value (); | |
2022 | |
2023 if (! error_state) | |
2024 { | |
2025 std::list<std::string> dir_elts = split_path (arg); | |
2026 | |
9401
6c421f2355b5
load-path.cc (Faddpath): preserve order of prepended elements
John W. Eaton <jwe@octave.org>
parents:
9377
diff
changeset
|
2027 if (! append) |
6c421f2355b5
load-path.cc (Faddpath): preserve order of prepended elements
John W. Eaton <jwe@octave.org>
parents:
9377
diff
changeset
|
2028 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
|
2029 |
5832 | 2030 for (std::list<std::string>::const_iterator p = dir_elts.begin (); |
2031 p != dir_elts.end (); | |
2032 p++) | |
2033 { | |
2034 std::string dir = *p; | |
2035 | |
2036 //dir = regexprep (dir_elts{j}, "//+", "/"); | |
2037 //dir = regexprep (dir, "/$", ""); | |
2038 | |
5867 | 2039 if (append) |
2040 load_path::append (dir, true); | |
5832 | 2041 else |
5867 | 2042 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
|
2043 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2044 need_to_update = true; |
5832 | 2045 } |
2046 } | |
2047 else | |
2048 error ("addpath: expecting all args to be character strings"); | |
2049 } | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2050 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2051 if (need_to_update) |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2052 rehash_internal (); |
5832 | 2053 } |
2054 else | |
2055 print_usage (); | |
2056 | |
2057 return retval; | |
2058 } | |
2059 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
2060 DEFUN (rmpath, args, nargout, |
5832 | 2061 "-*- texinfo -*-\n\ |
6678 | 2062 @deftypefn {Built-in Function} {} rmpath (@var{dir1}, @dots{})\n\ |
5832 | 2063 Remove @var{dir1}, @dots{} from the current function search path.\n\ |
2064 \n\ | |
2065 @seealso{path, addpath, genpath, pathdef, savepath, pathsep}\n\ | |
2066 @end deftypefn") | |
2067 { | |
2068 // Originally by Etienne Grossmann. Heavily modified and translated | |
2069 // to C++ by jwe. | |
2070 | |
2071 octave_value retval; | |
2072 | |
2073 if (nargout > 0) | |
2074 retval = load_path::path (); | |
2075 | |
2076 int nargin = args.length (); | |
2077 | |
2078 if (nargin > 0) | |
2079 { | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2080 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
|
2081 |
5832 | 2082 for (int i = 0; i < nargin; i++) |
2083 { | |
2084 std::string arg = args(i).string_value (); | |
2085 | |
2086 if (! error_state) | |
2087 { | |
2088 std::list<std::string> dir_elts = split_path (arg); | |
2089 | |
2090 for (std::list<std::string>::const_iterator p = dir_elts.begin (); | |
2091 p != dir_elts.end (); | |
2092 p++) | |
2093 { | |
2094 std::string dir = *p; | |
2095 | |
2096 //dir = regexprep (dir_elts{j}, "//+", "/"); | |
2097 //dir = regexprep (dir, "/$", ""); | |
2098 | |
2099 if (! load_path::remove (dir)) | |
2100 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
|
2101 else |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2102 need_to_update = true; |
5832 | 2103 } |
2104 } | |
2105 else | |
2106 error ("addpath: expecting all args to be character strings"); | |
2107 } | |
9105
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2108 |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2109 if (need_to_update) |
9b12ed1fbbbd
force rehash if path, addpath, or rmpath modify path
John W. Eaton <jwe@octave.org>
parents:
9010
diff
changeset
|
2110 rehash_internal (); |
5832 | 2111 } |
2112 else | |
2113 print_usage (); | |
2114 | |
2115 return retval; | |
2116 } | |
2117 | |
2118 /* | |
2119 ;;; Local Variables: *** | |
2120 ;;; mode: C++ *** | |
2121 ;;; End: *** | |
2122 */ |