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