5832
|
1 /* |
|
2 |
|
3 Copyright (C) 2006 John W. Eaton |
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <algorithm> |
|
29 |
|
30 #include "dir-ops.h" |
|
31 #include "file-ops.h" |
|
32 #include "file-stat.h" |
|
33 #include "oct-env.h" |
|
34 #include "pathsearch.h" |
|
35 |
|
36 #include "defaults.h" |
|
37 #include "defun.h" |
|
38 #include "input.h" |
|
39 #include "load-path.h" |
|
40 #include "pager.h" |
|
41 #include "parse.h" |
|
42 #include "toplev.h" |
|
43 #include "unwind-prot.h" |
|
44 #include "utils.h" |
|
45 |
|
46 load_path *load_path::instance = 0; |
|
47 load_path::hook_function_ptr load_path::add_hook = execute_pkg_add; |
|
48 load_path::hook_function_ptr load_path::remove_hook = execute_pkg_del; |
|
49 std::string load_path::command_line_path; |
|
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 |
|
84 bool has_private_subdir = get_file_list (dir_name); |
|
85 |
|
86 if (! error_state) |
|
87 { |
|
88 if (has_private_subdir) |
|
89 { |
|
90 std::string pdn = dir_name + file_ops::dir_sep_str + "private"; |
|
91 |
|
92 get_private_function_map (pdn); |
|
93 } |
|
94 } |
|
95 } |
|
96 else |
|
97 { |
|
98 std::string msg = fs.error (); |
|
99 warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ()); |
|
100 } |
|
101 } |
|
102 |
|
103 bool |
|
104 load_path::dir_info::get_file_list (const std::string& d) |
|
105 { |
|
106 bool has_private_subdir = false; |
|
107 |
|
108 dir_entry dir (d); |
|
109 |
|
110 if (dir) |
|
111 { |
|
112 string_vector flist = dir.read (); |
|
113 |
|
114 octave_idx_type len = flist.length (); |
|
115 |
|
116 all_files.resize (len); |
|
117 fcn_files.resize (len); |
|
118 |
|
119 octave_idx_type all_files_count = 0; |
|
120 octave_idx_type fcn_files_count = 0; |
|
121 |
|
122 for (octave_idx_type i = 0; i < len; i++) |
|
123 { |
|
124 std::string fname = flist[i]; |
|
125 |
|
126 std::string full_name = d + file_ops::dir_sep_str + fname; |
|
127 |
|
128 file_stat fs (full_name); |
|
129 |
|
130 if (fs) |
|
131 { |
|
132 if (fs.is_dir ()) |
|
133 { |
|
134 if (! has_private_subdir && fname == "private") |
|
135 has_private_subdir = true; |
|
136 } |
|
137 else |
|
138 { |
|
139 all_files[all_files_count++] = fname; |
|
140 |
|
141 size_t pos = fname.rfind ('.'); |
|
142 |
|
143 if (pos != NPOS) |
|
144 { |
|
145 std::string ext = fname.substr (pos); |
|
146 |
5864
|
147 if (ext == ".m" || ext == ".oct" || ext == ".mex") |
5832
|
148 { |
|
149 std::string base = fname.substr (0, pos); |
|
150 |
|
151 if (valid_identifier (base)) |
|
152 fcn_files[fcn_files_count++] = fname; |
|
153 } |
|
154 } |
|
155 } |
|
156 } |
|
157 } |
|
158 |
|
159 all_files.resize (all_files_count); |
|
160 fcn_files.resize (fcn_files_count); |
|
161 } |
|
162 else |
|
163 { |
|
164 std::string msg = dir.error (); |
|
165 warning ("load_path: %s: %s", d.c_str (), msg.c_str ()); |
|
166 } |
|
167 |
|
168 return has_private_subdir; |
|
169 } |
|
170 |
|
171 void |
|
172 load_path::dir_info::get_private_function_map (const std::string& d) |
|
173 { |
|
174 dir_entry dir (d); |
|
175 |
|
176 if (dir) |
|
177 { |
|
178 string_vector flist = dir.read (); |
|
179 |
|
180 octave_idx_type len = flist.length (); |
|
181 |
|
182 for (octave_idx_type i = 0; i < len; i++) |
|
183 { |
|
184 std::string fname = flist[i]; |
|
185 |
|
186 std::string ext; |
|
187 std::string base = fname; |
|
188 |
|
189 size_t pos = fname.rfind ('.'); |
|
190 |
|
191 if (pos != NPOS) |
|
192 { |
|
193 base = fname.substr (0, pos); |
|
194 ext = fname.substr (pos); |
|
195 |
|
196 if (valid_identifier (base)) |
|
197 { |
|
198 int t = 0; |
|
199 |
|
200 if (ext == ".m") |
|
201 t = load_path::M_FILE; |
|
202 else if (ext == ".oct") |
|
203 t = load_path::OCT_FILE; |
5864
|
204 else if (ext == ".mex") |
|
205 t = load_path::MEX_FILE; |
5832
|
206 |
|
207 private_function_map[base] |= t; |
|
208 } |
|
209 } |
|
210 } |
|
211 } |
|
212 else |
|
213 { |
|
214 std::string msg = dir.error (); |
|
215 warning ("load_path: %s: %s", d.c_str (), msg.c_str ()); |
|
216 } |
|
217 } |
|
218 |
|
219 bool |
|
220 load_path::instance_ok (void) |
|
221 { |
|
222 bool retval = true; |
|
223 |
|
224 if (! instance) |
|
225 instance = new load_path (); |
|
226 |
|
227 if (! instance) |
|
228 { |
|
229 ::error ("unable to create load path object!"); |
|
230 |
|
231 retval = false; |
|
232 } |
|
233 |
|
234 return retval; |
|
235 } |
|
236 |
|
237 load_path::const_dir_info_list_iterator |
5919
|
238 load_path::find_dir_info (const std::string& dir_arg) const |
5832
|
239 { |
5919
|
240 std::string dir = file_ops::tilde_expand (dir_arg); |
|
241 |
5832
|
242 const_dir_info_list_iterator retval = dir_info_list.begin (); |
|
243 |
|
244 while (retval != dir_info_list.end ()) |
|
245 { |
|
246 if (retval->dir_name == dir) |
|
247 break; |
|
248 |
|
249 retval++; |
|
250 } |
|
251 |
|
252 return retval; |
|
253 } |
|
254 |
|
255 load_path::dir_info_list_iterator |
5919
|
256 load_path::find_dir_info (const std::string& dir_arg) |
5832
|
257 { |
5919
|
258 std::string dir = file_ops::tilde_expand (dir_arg); |
|
259 |
5832
|
260 dir_info_list_iterator retval = dir_info_list.begin (); |
|
261 |
|
262 while (retval != dir_info_list.end ()) |
|
263 { |
|
264 if (retval->dir_name == dir) |
|
265 break; |
|
266 |
|
267 retval++; |
|
268 } |
|
269 |
|
270 return retval; |
|
271 } |
|
272 |
|
273 bool |
|
274 load_path::contains (const std::string& dir) const |
|
275 { |
|
276 return find_dir_info (dir) != dir_info_list.end (); |
|
277 } |
|
278 |
|
279 void |
|
280 load_path::move (dir_info_list_iterator i, bool at_end) |
|
281 { |
|
282 if (dir_info_list.size () > 1) |
|
283 { |
|
284 dir_info di = *i; |
|
285 |
|
286 dir_info_list.erase (i); |
|
287 |
|
288 if (at_end) |
|
289 dir_info_list.push_back (di); |
|
290 else |
|
291 dir_info_list.push_front (di); |
|
292 |
|
293 std::string dir = di.dir_name; |
|
294 |
|
295 string_vector fcn_files = di.fcn_files; |
|
296 |
|
297 octave_idx_type len = fcn_files.length (); |
|
298 |
|
299 for (octave_idx_type k = 0; k < len; k++) |
|
300 { |
|
301 std::string fname = fcn_files[k]; |
|
302 |
|
303 std::string ext; |
|
304 std::string base = fname; |
|
305 |
|
306 size_t pos = fname.rfind ('.'); |
|
307 |
|
308 if (pos != NPOS) |
|
309 { |
|
310 base = fname.substr (0, pos); |
|
311 ext = fname.substr (pos); |
|
312 } |
|
313 |
|
314 std::list<file_info>& file_info_list = fcn_map[base]; |
|
315 |
|
316 if (file_info_list.size () == 1) |
|
317 continue; |
|
318 else |
|
319 { |
|
320 for (std::list<file_info>::iterator p = file_info_list.begin (); |
|
321 p != file_info_list.end (); |
|
322 p++) |
|
323 { |
|
324 if (p->dir_name == dir) |
|
325 { |
6149
|
326 file_info fi = *p; |
5832
|
327 |
|
328 file_info_list.erase (p); |
|
329 |
|
330 if (at_end) |
|
331 file_info_list.push_back (fi); |
|
332 else |
|
333 file_info_list.push_front (fi); |
|
334 |
|
335 break; |
|
336 } |
|
337 } |
|
338 } |
|
339 } |
|
340 } |
|
341 } |
|
342 |
|
343 static void |
|
344 maybe_add_path_elts (std::string& path, const std::string& dir) |
|
345 { |
|
346 std::string tpath = genpath (dir); |
|
347 |
|
348 if (! tpath.empty ()) |
|
349 path += dir_path::path_sep_str + tpath; |
|
350 } |
|
351 |
|
352 void |
6365
|
353 load_path::do_initialize (bool set_initial_path) |
5832
|
354 { |
6626
|
355 sys_path = dir_path::path_sep_str; |
5832
|
356 |
6365
|
357 if (set_initial_path) |
|
358 { |
6626
|
359 maybe_add_path_elts (sys_path, Vlocal_ver_oct_file_dir); |
|
360 maybe_add_path_elts (sys_path, Vlocal_api_oct_file_dir); |
|
361 maybe_add_path_elts (sys_path, Vlocal_oct_file_dir); |
|
362 maybe_add_path_elts (sys_path, Vlocal_ver_fcn_file_dir); |
|
363 maybe_add_path_elts (sys_path, Vlocal_api_fcn_file_dir); |
|
364 maybe_add_path_elts (sys_path, Vlocal_fcn_file_dir); |
|
365 maybe_add_path_elts (sys_path, Voct_file_dir); |
|
366 maybe_add_path_elts (sys_path, Vfcn_file_dir); |
6365
|
367 } |
5832
|
368 |
|
369 std::string tpath = load_path::command_line_path; |
|
370 |
|
371 if (tpath.empty ()) |
|
372 tpath = octave_env::getenv ("OCTAVE_LOADPATH"); |
|
373 |
|
374 std::string xpath = "."; |
|
375 |
|
376 if (! tpath.empty ()) |
|
377 xpath += dir_path::path_sep_str + tpath; |
|
378 |
6626
|
379 if (sys_path != dir_path::path_sep_str) |
|
380 xpath += sys_path; |
5832
|
381 |
6119
|
382 do_set (xpath, false); |
5832
|
383 } |
|
384 |
|
385 void |
|
386 load_path::do_clear (void) |
|
387 { |
|
388 dir_info_list.clear (); |
|
389 fcn_map.clear (); |
5867
|
390 |
|
391 do_append (".", false); |
5832
|
392 } |
|
393 |
|
394 static std::list<std::string> |
|
395 split_path (const std::string& p) |
|
396 { |
|
397 std::list<std::string> retval; |
|
398 |
|
399 size_t beg = 0; |
|
400 size_t end = p.find (dir_path::path_sep_char); |
|
401 |
|
402 size_t len = p.length (); |
|
403 |
|
404 while (end != NPOS) |
|
405 { |
|
406 std::string elt = p.substr (beg, end-beg); |
|
407 |
|
408 if (! elt.empty ()) |
|
409 retval.push_back (elt); |
|
410 |
|
411 beg = end + 1; |
|
412 |
|
413 if (beg == len) |
|
414 break; |
|
415 |
|
416 end = p.find (dir_path::path_sep_char, beg); |
|
417 } |
|
418 |
|
419 std::string elt = p.substr (beg); |
|
420 |
|
421 if (! elt.empty ()) |
|
422 retval.push_back (elt); |
|
423 |
|
424 return retval; |
|
425 } |
|
426 |
|
427 void |
5867
|
428 load_path::do_set (const std::string& p, bool warn) |
5832
|
429 { |
|
430 do_clear (); |
|
431 |
|
432 std::list<std::string> elts = split_path (p); |
|
433 |
|
434 // Temporarily disable add hook. |
|
435 |
5854
|
436 unwind_protect_fptr (add_hook); |
5832
|
437 |
|
438 add_hook = 0; |
|
439 |
|
440 for (std::list<std::string>::const_iterator i = elts.begin (); |
|
441 i != elts.end (); |
|
442 i++) |
5867
|
443 do_append (*i, warn); |
5832
|
444 |
|
445 // Restore add hook and execute for all newly added directories. |
|
446 |
|
447 unwind_protect::run (); |
|
448 |
|
449 for (dir_info_list_iterator i = dir_info_list.begin (); |
|
450 i != dir_info_list.end (); |
|
451 i++) |
|
452 { |
|
453 if (add_hook) |
|
454 add_hook (i->dir_name); |
|
455 } |
|
456 } |
|
457 |
|
458 void |
5867
|
459 load_path::do_append (const std::string& dir, bool warn) |
5832
|
460 { |
|
461 if (! dir.empty ()) |
5867
|
462 do_add (dir, true, warn); |
|
463 } |
5832
|
464 |
5867
|
465 void |
|
466 load_path::do_prepend (const std::string& dir, bool warn) |
|
467 { |
|
468 if (! dir.empty ()) |
|
469 do_add (dir, false, warn); |
5832
|
470 } |
|
471 |
|
472 void |
5919
|
473 load_path::do_add (const std::string& dir_arg, bool at_end, bool warn) |
5832
|
474 { |
5919
|
475 size_t len = dir_arg.length (); |
5911
|
476 |
5919
|
477 if (len > 1 && dir_arg.substr (len-2) == "//") |
5911
|
478 warning_with_id ("Octave:recursive-path-search", |
|
479 "trailing `//' is no longer special in search path elements"); |
|
480 |
5919
|
481 std::string dir = file_ops::tilde_expand (dir_arg); |
|
482 |
5867
|
483 dir_info_list_iterator i = find_dir_info (dir); |
|
484 |
|
485 if (i != dir_info_list.end ()) |
|
486 move (i, at_end); |
|
487 else |
5832
|
488 { |
5867
|
489 file_stat fs (dir); |
5832
|
490 |
5867
|
491 if (fs) |
5832
|
492 { |
5867
|
493 if (fs.is_dir ()) |
|
494 { |
|
495 dir_info di (dir); |
5832
|
496 |
5867
|
497 if (! error_state) |
|
498 { |
|
499 if (at_end) |
|
500 dir_info_list.push_back (di); |
|
501 else |
|
502 dir_info_list.push_front (di); |
|
503 |
|
504 add_to_fcn_map (di, true); |
5832
|
505 |
5867
|
506 if (add_hook) |
|
507 add_hook (dir); |
|
508 } |
5832
|
509 } |
5867
|
510 else if (warn) |
5919
|
511 warning ("addpath: %s: not a directory", dir_arg.c_str ()); |
5832
|
512 } |
5867
|
513 else if (warn) |
|
514 { |
|
515 std::string msg = fs.error (); |
5919
|
516 warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ()); |
5867
|
517 } |
|
518 } |
5832
|
519 |
5867
|
520 // FIXME -- is there a better way to do this? |
5832
|
521 |
5867
|
522 i = find_dir_info ("."); |
5832
|
523 |
5867
|
524 if (i != dir_info_list.end ()) |
5871
|
525 move (i, false); |
5867
|
526 else |
|
527 panic_impossible (); |
5832
|
528 } |
|
529 |
|
530 bool |
5919
|
531 load_path::do_remove (const std::string& dir_arg) |
5832
|
532 { |
|
533 bool retval = false; |
|
534 |
5919
|
535 if (! dir_arg.empty ()) |
5832
|
536 { |
5919
|
537 if (dir_arg == ".") |
5867
|
538 { |
|
539 warning ("rmpath: can't remove \".\" from path"); |
5832
|
540 |
5867
|
541 // Avoid additional warnings. |
5832
|
542 retval = true; |
5867
|
543 } |
|
544 else |
|
545 { |
5919
|
546 std::string dir = file_ops::tilde_expand (dir_arg); |
|
547 |
5867
|
548 dir_info_list_iterator i = find_dir_info (dir); |
5832
|
549 |
5867
|
550 if (i != dir_info_list.end ()) |
|
551 { |
|
552 retval = true; |
5832
|
553 |
5867
|
554 string_vector fcn_files = i->fcn_files; |
|
555 |
|
556 dir_info_list.erase (i); |
5832
|
557 |
5867
|
558 octave_idx_type len = fcn_files.length (); |
|
559 |
|
560 for (octave_idx_type k = 0; k < len; k++) |
|
561 { |
|
562 std::string fname = fcn_files[k]; |
5832
|
563 |
5867
|
564 std::string ext; |
|
565 std::string base = fname; |
|
566 |
|
567 size_t pos = fname.rfind ('.'); |
5832
|
568 |
5867
|
569 if (pos != NPOS) |
|
570 { |
|
571 base = fname.substr (0, pos); |
|
572 ext = fname.substr (pos); |
|
573 } |
|
574 |
|
575 std::list<file_info>& file_info_list = fcn_map[base]; |
5832
|
576 |
5867
|
577 for (std::list<file_info>::iterator p = file_info_list.begin (); |
|
578 p != file_info_list.end (); |
|
579 p++) |
|
580 { |
|
581 if (p->dir_name == dir) |
|
582 { |
|
583 file_info_list.erase (p); |
5832
|
584 |
5867
|
585 if (file_info_list.empty ()) |
|
586 fcn_map.erase (fname); |
|
587 |
|
588 break; |
|
589 } |
|
590 } |
5832
|
591 } |
|
592 |
5867
|
593 if (remove_hook) |
|
594 remove_hook (dir); |
5832
|
595 } |
|
596 } |
|
597 } |
|
598 |
|
599 return retval; |
|
600 } |
|
601 |
|
602 void |
|
603 load_path::do_update (void) const |
|
604 { |
|
605 // I don't see a better way to do this because we need to |
|
606 // preserve the correct directory ordering for new files that |
|
607 // have appeared. |
|
608 |
|
609 fcn_map.clear (); |
|
610 |
|
611 for (dir_info_list_iterator p = dir_info_list.begin (); |
|
612 p != dir_info_list.end (); |
|
613 p++) |
|
614 { |
|
615 dir_info& di = *p; |
|
616 |
|
617 di.update (); |
|
618 |
|
619 add_to_fcn_map (di, true); |
|
620 } |
|
621 } |
|
622 |
|
623 std::string |
|
624 load_path::do_find_fcn (const std::string& fcn, int type) const |
|
625 { |
|
626 std::string retval; |
|
627 |
|
628 update (); |
|
629 |
|
630 const_fcn_map_iterator p = fcn_map.find (fcn); |
|
631 |
|
632 if (p != fcn_map.end ()) |
|
633 { |
|
634 const std::list<file_info>& file_info_list = p->second; |
|
635 |
|
636 for (const_file_info_list_iterator i = file_info_list.begin (); |
|
637 i != file_info_list.end (); |
|
638 i++) |
|
639 { |
|
640 const file_info& fi = *i; |
|
641 |
|
642 int t = fi.types; |
|
643 |
|
644 retval = fi.dir_name + file_ops::dir_sep_str + fcn; |
|
645 |
|
646 if (type == load_path::OCT_FILE) |
|
647 { |
|
648 if ((type & t) == load_path::OCT_FILE) |
|
649 { |
|
650 retval += ".oct"; |
|
651 break; |
|
652 } |
|
653 } |
|
654 else if (type == load_path::M_FILE) |
|
655 { |
|
656 if ((type & t) == load_path::M_FILE) |
|
657 { |
|
658 retval += ".m"; |
|
659 break; |
|
660 } |
|
661 } |
5864
|
662 else if (type == load_path::MEX_FILE) |
|
663 { |
|
664 if ((type & t) == load_path::MEX_FILE) |
|
665 { |
|
666 retval += ".mex"; |
|
667 break; |
|
668 } |
|
669 } |
5832
|
670 else if (type == (load_path::M_FILE | load_path::OCT_FILE)) |
|
671 { |
|
672 if (t & load_path::OCT_FILE) |
|
673 { |
|
674 retval += ".oct"; |
|
675 break; |
|
676 } |
|
677 else if (t & load_path::M_FILE) |
|
678 { |
|
679 retval += ".m"; |
|
680 break; |
|
681 } |
|
682 } |
5864
|
683 else if (type == (load_path::M_FILE | load_path::MEX_FILE)) |
|
684 { |
|
685 if (t & load_path::MEX_FILE) |
|
686 { |
|
687 retval += ".mex"; |
|
688 break; |
|
689 } |
|
690 else if (t & load_path::M_FILE) |
|
691 { |
|
692 retval += ".m"; |
|
693 break; |
|
694 } |
|
695 } |
|
696 else if (type == (load_path::OCT_FILE | load_path::MEX_FILE)) |
|
697 { |
|
698 if (t & load_path::OCT_FILE) |
|
699 { |
|
700 retval += ".oct"; |
|
701 break; |
|
702 } |
|
703 else if (t & load_path::MEX_FILE) |
|
704 { |
|
705 retval += ".mex"; |
|
706 break; |
|
707 } |
|
708 } |
|
709 else if (type == (load_path::M_FILE | load_path::OCT_FILE |
|
710 | load_path::MEX_FILE)) |
|
711 { |
|
712 if (t & load_path::OCT_FILE) |
|
713 { |
|
714 retval += ".oct"; |
|
715 break; |
|
716 } |
|
717 else if (t & load_path::MEX_FILE) |
|
718 { |
|
719 retval += ".mex"; |
|
720 break; |
|
721 } |
|
722 else if (t & load_path::M_FILE) |
|
723 { |
|
724 retval += ".m"; |
|
725 break; |
|
726 } |
|
727 } |
5832
|
728 else |
|
729 error ("load_path::do_find_fcn: %s: invalid type code = %d", |
|
730 fcn.c_str (), type); |
6196
|
731 |
|
732 // Reset the return string, in case the above tesst fail. |
|
733 retval = std::string (); |
5832
|
734 } |
|
735 } |
|
736 |
|
737 return retval; |
|
738 } |
|
739 |
|
740 std::string |
|
741 load_path::do_find_file (const std::string& file) const |
|
742 { |
|
743 std::string retval; |
|
744 |
|
745 if (octave_env::absolute_pathname (file)) |
|
746 { |
|
747 file_stat fs (file); |
|
748 |
|
749 if (fs.exists ()) |
|
750 return file; |
|
751 } |
|
752 |
|
753 std::string dir_name; |
|
754 |
|
755 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
|
756 p != dir_info_list.end (); |
|
757 p++) |
|
758 { |
|
759 string_vector all_files = p->all_files; |
|
760 |
|
761 octave_idx_type len = all_files.length (); |
|
762 |
|
763 for (octave_idx_type i = 0; i < len; i++) |
|
764 { |
|
765 if (all_files[i] == file) |
|
766 { |
|
767 dir_name = p->dir_name; |
6159
|
768 |
|
769 goto done; |
5832
|
770 } |
|
771 } |
|
772 } |
|
773 |
6159
|
774 done: |
|
775 |
5832
|
776 if (! dir_name.empty ()) |
|
777 retval = dir_name + file_ops::dir_sep_str + file; |
|
778 |
|
779 return retval; |
|
780 } |
|
781 |
|
782 std::string |
|
783 load_path::do_find_first_of (const string_vector& flist) const |
|
784 { |
|
785 std::string retval; |
|
786 |
|
787 std::string dir_name; |
|
788 std::string file_name; |
|
789 |
|
790 octave_idx_type flen = flist.length (); |
|
791 octave_idx_type rel_flen = 0; |
|
792 |
|
793 string_vector rel_flist (flen); |
|
794 |
|
795 for (octave_idx_type i = 0; i < flen; i++) |
|
796 { |
|
797 if (octave_env::absolute_pathname (flist[i])) |
|
798 { |
|
799 file_stat fs (flist[i]); |
|
800 |
|
801 if (fs.exists ()) |
|
802 return flist[i]; |
|
803 } |
|
804 else |
|
805 rel_flist[rel_flen++] = flist[i]; |
|
806 } |
|
807 |
|
808 rel_flist.resize (rel_flen); |
|
809 |
|
810 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
|
811 p != dir_info_list.end (); |
|
812 p++) |
|
813 { |
|
814 string_vector all_files = p->all_files; |
|
815 |
|
816 octave_idx_type len = all_files.length (); |
|
817 |
|
818 for (octave_idx_type i = 0; i < len; i++) |
|
819 { |
|
820 for (octave_idx_type j = 0; j < rel_flen; j++) |
|
821 { |
|
822 if (all_files[i] == rel_flist[j]) |
|
823 { |
|
824 dir_name = p->dir_name; |
|
825 file_name = rel_flist[j]; |
6159
|
826 |
|
827 goto done; |
5832
|
828 } |
|
829 } |
|
830 } |
|
831 } |
|
832 |
6159
|
833 done: |
|
834 |
5832
|
835 if (! dir_name.empty ()) |
|
836 retval = dir_name + file_ops::dir_sep_str + file_name; |
|
837 |
|
838 return retval; |
|
839 } |
|
840 |
|
841 string_vector |
|
842 load_path::do_find_all_first_of (const string_vector& flist) const |
|
843 { |
|
844 std::list<std::string> retlist; |
|
845 |
|
846 std::string dir_name; |
|
847 std::string file_name; |
|
848 |
|
849 octave_idx_type flen = flist.length (); |
|
850 octave_idx_type rel_flen = 0; |
|
851 |
|
852 string_vector rel_flist (flen); |
|
853 |
|
854 for (octave_idx_type i = 0; i < flen; i++) |
|
855 { |
|
856 if (octave_env::absolute_pathname (flist[i])) |
|
857 { |
|
858 file_stat fs (flist[i]); |
|
859 |
|
860 if (fs.exists ()) |
|
861 retlist.push_back (flist[i]); |
|
862 } |
|
863 else |
|
864 rel_flist[rel_flen++] = flist[i]; |
|
865 } |
|
866 |
|
867 rel_flist.resize (rel_flen); |
|
868 |
|
869 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
|
870 p != dir_info_list.end (); |
|
871 p++) |
|
872 { |
|
873 string_vector all_files = p->all_files; |
|
874 |
|
875 octave_idx_type len = all_files.length (); |
|
876 |
|
877 for (octave_idx_type i = 0; i < len; i++) |
|
878 { |
|
879 for (octave_idx_type j = 0; j < rel_flen; j++) |
|
880 { |
|
881 if (all_files[i] == rel_flist[j]) |
|
882 retlist.push_back |
|
883 (p->dir_name + file_ops::dir_sep_str + rel_flist[j]); |
|
884 } |
|
885 } |
|
886 } |
|
887 |
|
888 size_t retsize = retlist.size (); |
|
889 |
|
890 string_vector retval (retsize); |
|
891 |
|
892 for (size_t i = 0; i < retsize; i++) |
|
893 { |
|
894 retval[i] = retlist.front (); |
|
895 |
|
896 retlist.pop_front (); |
|
897 } |
|
898 |
|
899 return retval; |
|
900 } |
|
901 |
|
902 string_vector |
|
903 load_path::do_dirs (void) const |
|
904 { |
|
905 size_t len = dir_info_list.size (); |
|
906 |
|
907 string_vector retval (len); |
|
908 |
|
909 octave_idx_type k = 0; |
|
910 |
|
911 for (const_dir_info_list_iterator i = dir_info_list.begin (); |
|
912 i != dir_info_list.end (); |
|
913 i++) |
|
914 retval[k++] = i->dir_name; |
|
915 |
|
916 return retval; |
|
917 } |
|
918 |
|
919 std::list<std::string> |
|
920 load_path::do_dir_list (void) const |
|
921 { |
|
922 std::list<std::string> retval; |
|
923 |
|
924 for (const_dir_info_list_iterator i = dir_info_list.begin (); |
|
925 i != dir_info_list.end (); |
|
926 i++) |
|
927 retval.push_back (i->dir_name); |
|
928 |
|
929 return retval; |
|
930 } |
|
931 |
|
932 string_vector |
|
933 load_path::do_files (const std::string& dir) const |
|
934 { |
|
935 string_vector retval; |
|
936 |
|
937 const_dir_info_list_iterator i = find_dir_info (dir); |
|
938 |
|
939 if (i != dir_info_list.end ()) |
|
940 retval = i->fcn_files; |
|
941 |
|
942 return retval; |
|
943 } |
|
944 |
|
945 string_vector |
|
946 load_path::do_fcn_names (void) const |
|
947 { |
|
948 size_t len = fcn_map.size (); |
|
949 |
|
950 string_vector retval (len); |
|
951 |
|
952 octave_idx_type count = 0; |
|
953 |
|
954 for (const_fcn_map_iterator p = fcn_map.begin (); |
|
955 p != fcn_map.end (); |
|
956 p++) |
|
957 retval[count++] = p->first; |
|
958 |
|
959 return retval; |
|
960 } |
|
961 |
|
962 std::string |
|
963 load_path::do_path (void) const |
|
964 { |
|
965 std::string xpath; |
|
966 |
|
967 string_vector xdirs = load_path::dirs (); |
|
968 |
|
969 octave_idx_type len = xdirs.length (); |
|
970 |
|
971 if (len > 0) |
|
972 xpath = xdirs[0]; |
|
973 |
|
974 for (octave_idx_type i = 1; i < len; i++) |
|
975 xpath += dir_path::path_sep_str + xdirs[i]; |
|
976 |
|
977 return xpath; |
|
978 } |
|
979 |
|
980 void |
|
981 load_path::do_display (std::ostream& os) const |
|
982 { |
|
983 for (const_dir_info_list_iterator i = dir_info_list.begin (); |
|
984 i != dir_info_list.end (); |
|
985 i++) |
|
986 { |
|
987 string_vector fcn_files = i->fcn_files; |
|
988 |
|
989 if (! fcn_files.empty ()) |
|
990 { |
|
991 os << "\n*** function files in " << i->dir_name << ":\n\n"; |
|
992 |
|
993 fcn_files.list_in_columns (os); |
|
994 } |
|
995 |
|
996 #if defined (DEBUG_LOAD_PATH) |
|
997 |
|
998 const std::map<std::string, int>& private_function_map |
|
999 = i->private_function_map; |
|
1000 |
|
1001 if (private_function_map.size () > 0) |
|
1002 { |
|
1003 os << "private:\n"; |
|
1004 |
|
1005 for (std::map<std::string, int>::const_iterator p = private_function_map.begin (); |
|
1006 p != private_function_map.end (); |
|
1007 p++) |
|
1008 { |
|
1009 os << " " << p->first << " ("; |
|
1010 |
|
1011 bool printed_type = false; |
|
1012 |
|
1013 int types = p->second; |
|
1014 |
|
1015 if (types & load_path::OCT_FILE) |
|
1016 { |
|
1017 os << "oct"; |
|
1018 printed_type = true; |
|
1019 } |
|
1020 |
5864
|
1021 if (types & load_path::MEX_FILE) |
|
1022 { |
|
1023 if (printed_type) |
|
1024 os << "|"; |
|
1025 os << "mex"; |
|
1026 printed_type = true; |
|
1027 } |
|
1028 |
5832
|
1029 if (types & load_path::M_FILE) |
|
1030 { |
|
1031 if (printed_type) |
|
1032 os << "|"; |
|
1033 os << "m"; |
|
1034 printed_type = true; |
|
1035 } |
|
1036 |
|
1037 os << ")\n"; |
|
1038 } |
|
1039 |
|
1040 os << "\n"; |
|
1041 } |
|
1042 #endif |
|
1043 } |
|
1044 |
|
1045 #if defined (DEBUG_LOAD_PATH) |
|
1046 |
|
1047 for (const_fcn_map_iterator i = fcn_map.begin (); |
|
1048 i != fcn_map.end (); |
|
1049 i++) |
|
1050 { |
|
1051 os << i->first << ":\n"; |
|
1052 |
|
1053 const std::list<file_info>& file_info_list = i->second; |
|
1054 |
|
1055 for (const_file_info_list_iterator p = file_info_list.begin (); |
|
1056 p != file_info_list.end (); |
|
1057 p++) |
|
1058 { |
|
1059 os << " " << p->dir_name << " ("; |
|
1060 |
|
1061 bool printed_type = false; |
|
1062 |
|
1063 if (p->types & load_path::OCT_FILE) |
|
1064 { |
|
1065 os << "oct"; |
|
1066 printed_type = true; |
|
1067 } |
|
1068 |
5864
|
1069 if (p->types & load_path::MEX_FILE) |
|
1070 { |
|
1071 if (printed_type) |
|
1072 os << "|"; |
|
1073 os << "mex"; |
|
1074 printed_type = true; |
|
1075 } |
|
1076 |
5832
|
1077 if (p->types & load_path::M_FILE) |
|
1078 { |
|
1079 if (printed_type) |
|
1080 os << "|"; |
|
1081 os << "m"; |
|
1082 printed_type = true; |
|
1083 } |
|
1084 |
|
1085 os << ")\n"; |
|
1086 } |
|
1087 } |
|
1088 |
|
1089 os << "\n"; |
|
1090 |
|
1091 #endif |
|
1092 } |
|
1093 |
|
1094 void |
|
1095 load_path::add_to_fcn_map (const dir_info& di, bool at_end) const |
|
1096 { |
|
1097 std::string dir_name = di.dir_name; |
|
1098 |
|
1099 string_vector fcn_files = di.fcn_files; |
|
1100 |
|
1101 octave_idx_type len = fcn_files.length (); |
|
1102 |
|
1103 for (octave_idx_type i = 0; i < len; i++) |
|
1104 { |
|
1105 std::string fname = fcn_files[i]; |
|
1106 |
|
1107 std::string ext; |
|
1108 std::string base = fname; |
|
1109 |
|
1110 size_t pos = fname.rfind ('.'); |
|
1111 |
|
1112 if (pos != NPOS) |
|
1113 { |
|
1114 base = fname.substr (0, pos); |
|
1115 ext = fname.substr (pos); |
|
1116 } |
|
1117 |
|
1118 std::list<file_info>& file_info_list = fcn_map[base]; |
|
1119 |
|
1120 file_info_list_iterator p = file_info_list.begin (); |
|
1121 |
|
1122 while (p != file_info_list.end ()) |
|
1123 { |
|
1124 if (p->dir_name == dir_name) |
|
1125 break; |
|
1126 |
|
1127 p++; |
|
1128 } |
|
1129 |
|
1130 int t = 0; |
|
1131 if (ext == ".m") |
|
1132 t = load_path::M_FILE; |
|
1133 else if (ext == ".oct") |
|
1134 t = load_path::OCT_FILE; |
5864
|
1135 else if (ext == ".mex") |
|
1136 t = load_path::MEX_FILE; |
5832
|
1137 |
|
1138 if (p == file_info_list.end ()) |
|
1139 { |
|
1140 file_info fi (dir_name, t); |
|
1141 |
|
1142 if (at_end) |
|
1143 file_info_list.push_back (fi); |
|
1144 else |
|
1145 file_info_list.push_front (fi); |
|
1146 } |
|
1147 else |
|
1148 { |
|
1149 file_info& fi = *p; |
|
1150 |
|
1151 fi.types |= t; |
|
1152 } |
|
1153 } |
|
1154 } |
|
1155 |
|
1156 std::string |
|
1157 genpath (const std::string& dirname, const string_vector& skip) |
|
1158 { |
|
1159 std::string retval; |
|
1160 |
5871
|
1161 dir_entry dir (dirname); |
5832
|
1162 |
|
1163 if (dir) |
|
1164 { |
|
1165 retval = dirname; |
|
1166 |
|
1167 string_vector dirlist = dir.read (); |
|
1168 |
|
1169 octave_idx_type len = dirlist.length (); |
|
1170 |
|
1171 for (octave_idx_type i = 0; i < len; i++) |
|
1172 { |
|
1173 std::string elt = dirlist[i]; |
|
1174 |
|
1175 // FIXME -- the caller should be able to specify the list of |
|
1176 // directories to skip in addition to "." and "..". |
|
1177 |
|
1178 bool skip_p = (elt == "." || elt == ".."); |
|
1179 |
|
1180 if (! skip_p) |
|
1181 { |
|
1182 for (octave_idx_type j = 0; j < skip.length (); j++) |
|
1183 { |
|
1184 skip_p = (elt == skip[j]); |
|
1185 if (skip_p) |
|
1186 break; |
|
1187 } |
|
1188 |
|
1189 if (! skip_p) |
|
1190 { |
5871
|
1191 std::string nm = dirname + file_ops::dir_sep_str + elt; |
5832
|
1192 |
|
1193 file_stat fs (nm); |
|
1194 |
|
1195 if (fs && fs.is_dir ()) |
|
1196 retval += dir_path::path_sep_str + genpath (nm); |
|
1197 } |
|
1198 } |
|
1199 } |
|
1200 } |
|
1201 |
|
1202 return retval; |
|
1203 } |
|
1204 |
|
1205 static void |
|
1206 execute_pkg_add_or_del (const std::string& dir, |
|
1207 const std::string& script_file) |
|
1208 { |
|
1209 if (! octave_interpreter_ready) |
|
1210 return; |
|
1211 |
|
1212 unwind_protect::begin_frame ("execute_pkg_add_or_del"); |
|
1213 |
|
1214 unwind_protect_bool (input_from_startup_file); |
|
1215 |
|
1216 input_from_startup_file = true; |
|
1217 |
|
1218 std::string file = dir + file_ops::dir_sep_str + script_file; |
|
1219 |
5978
|
1220 file_stat fs (file); |
5832
|
1221 |
|
1222 if (fs.exists ()) |
5975
|
1223 source_file (file, "base"); |
5832
|
1224 |
|
1225 unwind_protect::run_frame ("execute_pkg_add_or_del"); |
|
1226 } |
|
1227 |
|
1228 void |
|
1229 execute_pkg_add (const std::string& dir) |
|
1230 { |
|
1231 execute_pkg_add_or_del (dir, "PKG_ADD"); |
|
1232 } |
|
1233 |
|
1234 void |
|
1235 execute_pkg_del (const std::string& dir) |
|
1236 { |
|
1237 execute_pkg_add_or_del (dir, "PKG_DEL"); |
|
1238 } |
|
1239 |
|
1240 DEFUN (genpath, args, , |
|
1241 "-*- texinfo -*-\n\ |
|
1242 @deftypefn {Built-in Function} {} genpath (@var{dir})\n\ |
|
1243 Return a path constructed from @var{dir} and all its subdiretories.\n\ |
|
1244 @end deftypefn") |
|
1245 { |
|
1246 octave_value retval; |
|
1247 |
|
1248 if (args.length () == 1) |
|
1249 { |
|
1250 std::string dirname = args(0).string_value (); |
|
1251 |
|
1252 if (! error_state) |
|
1253 retval = genpath (dirname); |
|
1254 else |
|
1255 error ("genpath: expecting argument to be a character string"); |
|
1256 } |
|
1257 else |
|
1258 print_usage (); |
|
1259 |
|
1260 return retval; |
|
1261 } |
|
1262 |
|
1263 DEFUN (rehash, , , |
|
1264 "-*- texinfo -*-\n\ |
|
1265 @deftypefn {Built-in Function} {} rehash ()\n\ |
|
1266 Reinitialize Octave's @code{LOADPATH} directory cache.\n\ |
|
1267 @end deftypefn") |
|
1268 { |
|
1269 octave_value_list retval; |
|
1270 |
|
1271 load_path::update (); |
|
1272 |
|
1273 // FIXME -- maybe we should rename this variable since it is being |
|
1274 // used for more than keeping track of the prompt time. |
|
1275 |
|
1276 // This will force updated functions to be found. |
|
1277 Vlast_prompt_time.stamp (); |
|
1278 |
|
1279 return retval; |
|
1280 } |
|
1281 |
|
1282 DEFUN (pathdef, , , |
|
1283 "-*- texinfo -*-\n\ |
|
1284 @deftypefn {Built-in Function} {@var{val} =} pathdef ()\n\ |
|
1285 Return the default list of directories in which to search for function\n\ |
|
1286 files.\n\ |
|
1287 @seealso{path, addpath, rmpath, genpath, savepath, pathsep}\n\ |
|
1288 @end deftypefn") |
|
1289 { |
6626
|
1290 return load_path::system_path (); |
5832
|
1291 } |
|
1292 |
|
1293 DEFUN (path, args, nargout, |
|
1294 "-*- texinfo -*-\n\ |
|
1295 @deftypefn {Function File} {} path (@dots{})\n\ |
|
1296 Modify or display Octave's @code{LOADPATH}.\n\ |
|
1297 \n\ |
|
1298 If @var{nargin} and @var{nargout} are zero, display the elements of\n\ |
|
1299 Octave's @code{LOADPATH} in an easy to read format.\n\ |
|
1300 \n\ |
|
1301 If @var{nargin} is zero and nargout is greater than zero, return the\n\ |
|
1302 current value of @code{LOADPATH}.\n\ |
|
1303 \n\ |
|
1304 If @var{nargin} is greater than zero, concatenate the arguments,\n\ |
|
1305 separating them with @code{pathsep()}. Set the internal search path\n\ |
|
1306 to the result and return it.\n\ |
|
1307 \n\ |
|
1308 No checks are made for duplicate elements.\n\ |
|
1309 @seealso{addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ |
|
1310 @end deftypefn") |
|
1311 { |
|
1312 octave_value retval; |
|
1313 |
|
1314 int argc = args.length () + 1; |
|
1315 |
|
1316 string_vector argv = args.make_argv ("path"); |
|
1317 |
|
1318 if (! error_state) |
|
1319 { |
|
1320 if (argc > 1) |
|
1321 { |
|
1322 std::string path = argv[1]; |
|
1323 |
|
1324 for (int i = 2; i < argc; i++) |
5867
|
1325 path += dir_path::path_sep_str + argv[i]; |
5832
|
1326 |
5867
|
1327 load_path::set (path, true); |
5832
|
1328 } |
|
1329 |
|
1330 if (nargout > 0) |
|
1331 retval = load_path::path (); |
|
1332 else if (argc == 1 && nargout == 0) |
|
1333 { |
|
1334 octave_stdout << "\nOctave's search path contains the following directories:\n\n"; |
|
1335 |
|
1336 string_vector dirs = load_path::dirs (); |
|
1337 |
|
1338 dirs.list_in_columns (octave_stdout); |
|
1339 |
|
1340 octave_stdout << "\n"; |
|
1341 } |
|
1342 } |
|
1343 |
|
1344 return retval; |
|
1345 } |
|
1346 |
|
1347 DEFCMD (addpath, args, nargout, |
|
1348 "-*- texinfo -*-\n\ |
|
1349 @deftypefn {Function File} {} addpath (@var{dir1}, @dots{})\n\ |
|
1350 @deftypefnx {Function File} {} addpath (@var{dir1}, @dots{}, @var{option})\n\ |
|
1351 Add @var{dir1}, @dots{} to the current function search path. If\n\ |
|
1352 @var{option} is @samp{\"-begin\"} or 0 (the default), prepend the\n\ |
|
1353 directory name to the current path. If @var{option} is @samp{\"-end\"}\n\ |
|
1354 or 1, append the directory name to the current path.\n\ |
|
1355 Directories added to the path must exist.\n\ |
|
1356 @seealso{path, rmpath, genpath, pathdef, savepath, pathsep}\n\ |
|
1357 @end deftypefn") |
|
1358 { |
|
1359 octave_value retval; |
|
1360 |
|
1361 // Originally written by Bill Denney and Etienne Grossman. Heavily |
|
1362 // modified and translated to C++ by jwe. |
|
1363 |
|
1364 if (nargout > 0) |
|
1365 retval = load_path::path (); |
|
1366 |
|
1367 int nargin = args.length (); |
|
1368 |
|
1369 if (nargin > 0) |
|
1370 { |
|
1371 bool append = false; |
|
1372 |
|
1373 octave_value option_arg = args(nargin-1); |
|
1374 |
|
1375 if (option_arg.is_string ()) |
|
1376 { |
|
1377 std::string option = option_arg.string_value (); |
|
1378 |
|
1379 if (option == "-end") |
|
1380 { |
|
1381 append = true; |
|
1382 nargin--; |
|
1383 } |
|
1384 else if (option == "-begin") |
|
1385 nargin--; |
|
1386 } |
|
1387 else if (option_arg.is_numeric_type ()) |
|
1388 { |
|
1389 int val = option_arg.int_value (); |
|
1390 |
|
1391 if (! error_state) |
|
1392 { |
|
1393 if (val == 0) |
|
1394 append = false; |
|
1395 else if (val == 1) |
|
1396 append = true; |
|
1397 else |
|
1398 { |
|
1399 error ("addpath: expecting final argument to be 1 or 0"); |
|
1400 return retval; |
|
1401 } |
|
1402 } |
|
1403 else |
|
1404 { |
|
1405 error ("addpath: expecting final argument to be 1 or 0"); |
|
1406 return retval; |
|
1407 } |
|
1408 } |
|
1409 |
|
1410 for (int i = 0; i < nargin; i++) |
|
1411 { |
|
1412 std::string arg = args(i).string_value (); |
|
1413 |
|
1414 if (! error_state) |
|
1415 { |
|
1416 std::list<std::string> dir_elts = split_path (arg); |
|
1417 |
|
1418 for (std::list<std::string>::const_iterator p = dir_elts.begin (); |
|
1419 p != dir_elts.end (); |
|
1420 p++) |
|
1421 { |
|
1422 std::string dir = *p; |
|
1423 |
|
1424 //dir = regexprep (dir_elts{j}, "//+", "/"); |
|
1425 //dir = regexprep (dir, "/$", ""); |
|
1426 |
5867
|
1427 if (append) |
|
1428 load_path::append (dir, true); |
5832
|
1429 else |
5867
|
1430 load_path::prepend (dir, true); |
5832
|
1431 } |
|
1432 } |
|
1433 else |
|
1434 error ("addpath: expecting all args to be character strings"); |
|
1435 } |
|
1436 } |
|
1437 else |
|
1438 print_usage (); |
|
1439 |
|
1440 return retval; |
|
1441 } |
|
1442 |
|
1443 DEFCMD (rmpath, args, nargout, |
|
1444 "-*- texinfo -*-\n\ |
|
1445 @deftypefn {Function File} {} rmpath (@var{dir1}, @dots{})\n\ |
|
1446 Remove @var{dir1}, @dots{} from the current function search path.\n\ |
|
1447 \n\ |
|
1448 @seealso{path, addpath, genpath, pathdef, savepath, pathsep}\n\ |
|
1449 @end deftypefn") |
|
1450 { |
|
1451 // Originally by Etienne Grossmann. Heavily modified and translated |
|
1452 // to C++ by jwe. |
|
1453 |
|
1454 octave_value retval; |
|
1455 |
|
1456 if (nargout > 0) |
|
1457 retval = load_path::path (); |
|
1458 |
|
1459 int nargin = args.length (); |
|
1460 |
|
1461 if (nargin > 0) |
|
1462 { |
|
1463 for (int i = 0; i < nargin; i++) |
|
1464 { |
|
1465 std::string arg = args(i).string_value (); |
|
1466 |
|
1467 if (! error_state) |
|
1468 { |
|
1469 std::list<std::string> dir_elts = split_path (arg); |
|
1470 |
|
1471 for (std::list<std::string>::const_iterator p = dir_elts.begin (); |
|
1472 p != dir_elts.end (); |
|
1473 p++) |
|
1474 { |
|
1475 std::string dir = *p; |
|
1476 |
|
1477 //dir = regexprep (dir_elts{j}, "//+", "/"); |
|
1478 //dir = regexprep (dir, "/$", ""); |
|
1479 |
|
1480 if (! load_path::remove (dir)) |
|
1481 warning ("rmpath: %s: not found", dir.c_str ()); |
|
1482 } |
|
1483 } |
|
1484 else |
|
1485 error ("addpath: expecting all args to be character strings"); |
|
1486 } |
|
1487 } |
|
1488 else |
|
1489 print_usage (); |
|
1490 |
|
1491 return retval; |
|
1492 } |
|
1493 |
|
1494 /* |
|
1495 ;;; Local Variables: *** |
|
1496 ;;; mode: C++ *** |
|
1497 ;;; End: *** |
|
1498 */ |