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