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