5832
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 2006, 2007 John W. Eaton |
5832
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
5832
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
5832
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include <algorithm> |
|
28 |
|
29 #include "dir-ops.h" |
|
30 #include "file-ops.h" |
|
31 #include "file-stat.h" |
|
32 #include "oct-env.h" |
|
33 #include "pathsearch.h" |
|
34 |
|
35 #include "defaults.h" |
|
36 #include "defun.h" |
|
37 #include "input.h" |
|
38 #include "load-path.h" |
|
39 #include "pager.h" |
|
40 #include "parse.h" |
|
41 #include "toplev.h" |
|
42 #include "unwind-prot.h" |
|
43 #include "utils.h" |
|
44 |
|
45 load_path *load_path::instance = 0; |
|
46 load_path::hook_function_ptr load_path::add_hook = execute_pkg_add; |
|
47 load_path::hook_function_ptr load_path::remove_hook = execute_pkg_del; |
|
48 std::string load_path::command_line_path; |
6630
|
49 std::string load_path::sys_path; |
5832
|
50 |
|
51 void |
|
52 load_path::dir_info::update (void) |
|
53 { |
|
54 if (is_relative) |
|
55 initialize (); |
|
56 else |
|
57 { |
|
58 file_stat fs (dir_name); |
|
59 |
|
60 if (fs) |
|
61 { |
|
62 if (fs.mtime () != dir_mtime) |
|
63 initialize (); |
|
64 } |
|
65 else |
|
66 { |
|
67 std::string msg = fs.error (); |
|
68 warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ()); |
|
69 } |
|
70 } |
|
71 } |
|
72 |
|
73 void |
|
74 load_path::dir_info::initialize (void) |
|
75 { |
|
76 is_relative = ! octave_env::absolute_pathname (dir_name); |
|
77 |
|
78 file_stat fs (dir_name); |
|
79 |
|
80 if (fs) |
|
81 { |
|
82 dir_mtime = fs.mtime (); |
|
83 |
|
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 |
6825
|
554 if (remove_hook) |
|
555 remove_hook (dir); |
|
556 |
5867
|
557 string_vector fcn_files = i->fcn_files; |
|
558 |
|
559 dir_info_list.erase (i); |
5832
|
560 |
5867
|
561 octave_idx_type len = fcn_files.length (); |
|
562 |
|
563 for (octave_idx_type k = 0; k < len; k++) |
|
564 { |
|
565 std::string fname = fcn_files[k]; |
5832
|
566 |
5867
|
567 std::string ext; |
|
568 std::string base = fname; |
|
569 |
|
570 size_t pos = fname.rfind ('.'); |
5832
|
571 |
5867
|
572 if (pos != NPOS) |
|
573 { |
|
574 base = fname.substr (0, pos); |
|
575 ext = fname.substr (pos); |
|
576 } |
|
577 |
|
578 std::list<file_info>& file_info_list = fcn_map[base]; |
5832
|
579 |
5867
|
580 for (std::list<file_info>::iterator p = file_info_list.begin (); |
|
581 p != file_info_list.end (); |
|
582 p++) |
|
583 { |
|
584 if (p->dir_name == dir) |
|
585 { |
|
586 file_info_list.erase (p); |
5832
|
587 |
5867
|
588 if (file_info_list.empty ()) |
|
589 fcn_map.erase (fname); |
|
590 |
|
591 break; |
|
592 } |
|
593 } |
5832
|
594 } |
|
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 |
6850
|
745 if (file.find_first_of (file_ops::dir_sep_chars) != NPOS) |
5832
|
746 { |
6838
|
747 if (octave_env::absolute_pathname (file) |
|
748 || octave_env::rooted_relative_pathname (file)) |
|
749 { |
|
750 file_stat fs (file); |
5832
|
751 |
6838
|
752 if (fs.exists ()) |
|
753 return file; |
|
754 } |
|
755 else |
|
756 { |
|
757 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
|
758 p != dir_info_list.end (); |
|
759 p++) |
|
760 { |
|
761 std::string tfile = p->dir_name + file_ops::dir_sep_str + file; |
5832
|
762 |
6838
|
763 file_stat fs (tfile); |
6159
|
764 |
6838
|
765 if (fs.exists ()) |
|
766 return tfile; |
5832
|
767 } |
|
768 } |
|
769 } |
6838
|
770 else |
|
771 { |
|
772 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
|
773 p != dir_info_list.end (); |
|
774 p++) |
|
775 { |
|
776 string_vector all_files = p->all_files; |
6159
|
777 |
6838
|
778 octave_idx_type len = all_files.length (); |
|
779 |
|
780 for (octave_idx_type i = 0; i < len; i++) |
|
781 { |
|
782 if (all_files[i] == file) |
|
783 return p->dir_name + file_ops::dir_sep_str + file; |
|
784 } |
|
785 } |
|
786 } |
5832
|
787 |
|
788 return retval; |
|
789 } |
|
790 |
|
791 std::string |
|
792 load_path::do_find_first_of (const string_vector& flist) const |
|
793 { |
|
794 std::string retval; |
|
795 |
|
796 std::string dir_name; |
|
797 std::string file_name; |
|
798 |
|
799 octave_idx_type flen = flist.length (); |
|
800 octave_idx_type rel_flen = 0; |
|
801 |
|
802 string_vector rel_flist (flen); |
|
803 |
|
804 for (octave_idx_type i = 0; i < flen; i++) |
|
805 { |
|
806 if (octave_env::absolute_pathname (flist[i])) |
|
807 { |
|
808 file_stat fs (flist[i]); |
|
809 |
|
810 if (fs.exists ()) |
|
811 return flist[i]; |
|
812 } |
|
813 else |
|
814 rel_flist[rel_flen++] = flist[i]; |
|
815 } |
|
816 |
|
817 rel_flist.resize (rel_flen); |
|
818 |
|
819 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
|
820 p != dir_info_list.end (); |
|
821 p++) |
|
822 { |
|
823 string_vector all_files = p->all_files; |
|
824 |
|
825 octave_idx_type len = all_files.length (); |
|
826 |
|
827 for (octave_idx_type i = 0; i < len; i++) |
|
828 { |
|
829 for (octave_idx_type j = 0; j < rel_flen; j++) |
|
830 { |
|
831 if (all_files[i] == rel_flist[j]) |
|
832 { |
|
833 dir_name = p->dir_name; |
|
834 file_name = rel_flist[j]; |
6159
|
835 |
|
836 goto done; |
5832
|
837 } |
|
838 } |
|
839 } |
|
840 } |
|
841 |
6159
|
842 done: |
|
843 |
5832
|
844 if (! dir_name.empty ()) |
|
845 retval = dir_name + file_ops::dir_sep_str + file_name; |
|
846 |
|
847 return retval; |
|
848 } |
|
849 |
|
850 string_vector |
|
851 load_path::do_find_all_first_of (const string_vector& flist) const |
|
852 { |
|
853 std::list<std::string> retlist; |
|
854 |
|
855 std::string dir_name; |
|
856 std::string file_name; |
|
857 |
|
858 octave_idx_type flen = flist.length (); |
|
859 octave_idx_type rel_flen = 0; |
|
860 |
|
861 string_vector rel_flist (flen); |
|
862 |
|
863 for (octave_idx_type i = 0; i < flen; i++) |
|
864 { |
|
865 if (octave_env::absolute_pathname (flist[i])) |
|
866 { |
|
867 file_stat fs (flist[i]); |
|
868 |
|
869 if (fs.exists ()) |
|
870 retlist.push_back (flist[i]); |
|
871 } |
|
872 else |
|
873 rel_flist[rel_flen++] = flist[i]; |
|
874 } |
|
875 |
|
876 rel_flist.resize (rel_flen); |
|
877 |
|
878 for (const_dir_info_list_iterator p = dir_info_list.begin (); |
|
879 p != dir_info_list.end (); |
|
880 p++) |
|
881 { |
|
882 string_vector all_files = p->all_files; |
|
883 |
|
884 octave_idx_type len = all_files.length (); |
|
885 |
|
886 for (octave_idx_type i = 0; i < len; i++) |
|
887 { |
|
888 for (octave_idx_type j = 0; j < rel_flen; j++) |
|
889 { |
|
890 if (all_files[i] == rel_flist[j]) |
|
891 retlist.push_back |
|
892 (p->dir_name + file_ops::dir_sep_str + rel_flist[j]); |
|
893 } |
|
894 } |
|
895 } |
|
896 |
|
897 size_t retsize = retlist.size (); |
|
898 |
|
899 string_vector retval (retsize); |
|
900 |
|
901 for (size_t i = 0; i < retsize; i++) |
|
902 { |
|
903 retval[i] = retlist.front (); |
|
904 |
|
905 retlist.pop_front (); |
|
906 } |
|
907 |
|
908 return retval; |
|
909 } |
|
910 |
|
911 string_vector |
|
912 load_path::do_dirs (void) const |
|
913 { |
|
914 size_t len = dir_info_list.size (); |
|
915 |
|
916 string_vector retval (len); |
|
917 |
|
918 octave_idx_type k = 0; |
|
919 |
|
920 for (const_dir_info_list_iterator i = dir_info_list.begin (); |
|
921 i != dir_info_list.end (); |
|
922 i++) |
|
923 retval[k++] = i->dir_name; |
|
924 |
|
925 return retval; |
|
926 } |
|
927 |
|
928 std::list<std::string> |
|
929 load_path::do_dir_list (void) const |
|
930 { |
|
931 std::list<std::string> retval; |
|
932 |
|
933 for (const_dir_info_list_iterator i = dir_info_list.begin (); |
|
934 i != dir_info_list.end (); |
|
935 i++) |
|
936 retval.push_back (i->dir_name); |
|
937 |
|
938 return retval; |
|
939 } |
|
940 |
|
941 string_vector |
|
942 load_path::do_files (const std::string& dir) const |
|
943 { |
|
944 string_vector retval; |
|
945 |
|
946 const_dir_info_list_iterator i = find_dir_info (dir); |
|
947 |
|
948 if (i != dir_info_list.end ()) |
|
949 retval = i->fcn_files; |
|
950 |
|
951 return retval; |
|
952 } |
|
953 |
|
954 string_vector |
|
955 load_path::do_fcn_names (void) const |
|
956 { |
|
957 size_t len = fcn_map.size (); |
|
958 |
|
959 string_vector retval (len); |
|
960 |
|
961 octave_idx_type count = 0; |
|
962 |
|
963 for (const_fcn_map_iterator p = fcn_map.begin (); |
|
964 p != fcn_map.end (); |
|
965 p++) |
|
966 retval[count++] = p->first; |
|
967 |
|
968 return retval; |
|
969 } |
|
970 |
|
971 std::string |
|
972 load_path::do_path (void) const |
|
973 { |
|
974 std::string xpath; |
|
975 |
|
976 string_vector xdirs = load_path::dirs (); |
|
977 |
|
978 octave_idx_type len = xdirs.length (); |
|
979 |
|
980 if (len > 0) |
|
981 xpath = xdirs[0]; |
|
982 |
|
983 for (octave_idx_type i = 1; i < len; i++) |
|
984 xpath += dir_path::path_sep_str + xdirs[i]; |
|
985 |
|
986 return xpath; |
|
987 } |
|
988 |
|
989 void |
|
990 load_path::do_display (std::ostream& os) const |
|
991 { |
|
992 for (const_dir_info_list_iterator i = dir_info_list.begin (); |
|
993 i != dir_info_list.end (); |
|
994 i++) |
|
995 { |
|
996 string_vector fcn_files = i->fcn_files; |
|
997 |
|
998 if (! fcn_files.empty ()) |
|
999 { |
|
1000 os << "\n*** function files in " << i->dir_name << ":\n\n"; |
|
1001 |
|
1002 fcn_files.list_in_columns (os); |
|
1003 } |
|
1004 |
|
1005 #if defined (DEBUG_LOAD_PATH) |
|
1006 |
|
1007 const std::map<std::string, int>& private_function_map |
|
1008 = i->private_function_map; |
|
1009 |
|
1010 if (private_function_map.size () > 0) |
|
1011 { |
|
1012 os << "private:\n"; |
|
1013 |
|
1014 for (std::map<std::string, int>::const_iterator p = private_function_map.begin (); |
|
1015 p != private_function_map.end (); |
|
1016 p++) |
|
1017 { |
|
1018 os << " " << p->first << " ("; |
|
1019 |
|
1020 bool printed_type = false; |
|
1021 |
|
1022 int types = p->second; |
|
1023 |
|
1024 if (types & load_path::OCT_FILE) |
|
1025 { |
|
1026 os << "oct"; |
|
1027 printed_type = true; |
|
1028 } |
|
1029 |
5864
|
1030 if (types & load_path::MEX_FILE) |
|
1031 { |
|
1032 if (printed_type) |
|
1033 os << "|"; |
|
1034 os << "mex"; |
|
1035 printed_type = true; |
|
1036 } |
|
1037 |
5832
|
1038 if (types & load_path::M_FILE) |
|
1039 { |
|
1040 if (printed_type) |
|
1041 os << "|"; |
|
1042 os << "m"; |
|
1043 printed_type = true; |
|
1044 } |
|
1045 |
|
1046 os << ")\n"; |
|
1047 } |
|
1048 |
|
1049 os << "\n"; |
|
1050 } |
|
1051 #endif |
|
1052 } |
|
1053 |
|
1054 #if defined (DEBUG_LOAD_PATH) |
|
1055 |
|
1056 for (const_fcn_map_iterator i = fcn_map.begin (); |
|
1057 i != fcn_map.end (); |
|
1058 i++) |
|
1059 { |
|
1060 os << i->first << ":\n"; |
|
1061 |
|
1062 const std::list<file_info>& file_info_list = i->second; |
|
1063 |
|
1064 for (const_file_info_list_iterator p = file_info_list.begin (); |
|
1065 p != file_info_list.end (); |
|
1066 p++) |
|
1067 { |
|
1068 os << " " << p->dir_name << " ("; |
|
1069 |
|
1070 bool printed_type = false; |
|
1071 |
|
1072 if (p->types & load_path::OCT_FILE) |
|
1073 { |
|
1074 os << "oct"; |
|
1075 printed_type = true; |
|
1076 } |
|
1077 |
5864
|
1078 if (p->types & load_path::MEX_FILE) |
|
1079 { |
|
1080 if (printed_type) |
|
1081 os << "|"; |
|
1082 os << "mex"; |
|
1083 printed_type = true; |
|
1084 } |
|
1085 |
5832
|
1086 if (p->types & load_path::M_FILE) |
|
1087 { |
|
1088 if (printed_type) |
|
1089 os << "|"; |
|
1090 os << "m"; |
|
1091 printed_type = true; |
|
1092 } |
|
1093 |
|
1094 os << ")\n"; |
|
1095 } |
|
1096 } |
|
1097 |
|
1098 os << "\n"; |
|
1099 |
|
1100 #endif |
|
1101 } |
|
1102 |
|
1103 void |
|
1104 load_path::add_to_fcn_map (const dir_info& di, bool at_end) const |
|
1105 { |
|
1106 std::string dir_name = di.dir_name; |
|
1107 |
|
1108 string_vector fcn_files = di.fcn_files; |
|
1109 |
|
1110 octave_idx_type len = fcn_files.length (); |
|
1111 |
|
1112 for (octave_idx_type i = 0; i < len; i++) |
|
1113 { |
|
1114 std::string fname = fcn_files[i]; |
|
1115 |
|
1116 std::string ext; |
|
1117 std::string base = fname; |
|
1118 |
|
1119 size_t pos = fname.rfind ('.'); |
|
1120 |
|
1121 if (pos != NPOS) |
|
1122 { |
|
1123 base = fname.substr (0, pos); |
|
1124 ext = fname.substr (pos); |
|
1125 } |
|
1126 |
|
1127 std::list<file_info>& file_info_list = fcn_map[base]; |
|
1128 |
|
1129 file_info_list_iterator p = file_info_list.begin (); |
|
1130 |
|
1131 while (p != file_info_list.end ()) |
|
1132 { |
|
1133 if (p->dir_name == dir_name) |
|
1134 break; |
|
1135 |
|
1136 p++; |
|
1137 } |
|
1138 |
|
1139 int t = 0; |
|
1140 if (ext == ".m") |
|
1141 t = load_path::M_FILE; |
|
1142 else if (ext == ".oct") |
|
1143 t = load_path::OCT_FILE; |
5864
|
1144 else if (ext == ".mex") |
|
1145 t = load_path::MEX_FILE; |
5832
|
1146 |
|
1147 if (p == file_info_list.end ()) |
|
1148 { |
|
1149 file_info fi (dir_name, t); |
|
1150 |
|
1151 if (at_end) |
|
1152 file_info_list.push_back (fi); |
|
1153 else |
|
1154 file_info_list.push_front (fi); |
|
1155 } |
|
1156 else |
|
1157 { |
|
1158 file_info& fi = *p; |
|
1159 |
|
1160 fi.types |= t; |
|
1161 } |
|
1162 } |
|
1163 } |
|
1164 |
|
1165 std::string |
|
1166 genpath (const std::string& dirname, const string_vector& skip) |
|
1167 { |
|
1168 std::string retval; |
|
1169 |
5871
|
1170 dir_entry dir (dirname); |
5832
|
1171 |
|
1172 if (dir) |
|
1173 { |
|
1174 retval = dirname; |
|
1175 |
|
1176 string_vector dirlist = dir.read (); |
|
1177 |
|
1178 octave_idx_type len = dirlist.length (); |
|
1179 |
|
1180 for (octave_idx_type i = 0; i < len; i++) |
|
1181 { |
|
1182 std::string elt = dirlist[i]; |
|
1183 |
|
1184 // FIXME -- the caller should be able to specify the list of |
|
1185 // directories to skip in addition to "." and "..". |
|
1186 |
|
1187 bool skip_p = (elt == "." || elt == ".."); |
|
1188 |
|
1189 if (! skip_p) |
|
1190 { |
|
1191 for (octave_idx_type j = 0; j < skip.length (); j++) |
|
1192 { |
|
1193 skip_p = (elt == skip[j]); |
|
1194 if (skip_p) |
|
1195 break; |
|
1196 } |
|
1197 |
|
1198 if (! skip_p) |
|
1199 { |
5871
|
1200 std::string nm = dirname + file_ops::dir_sep_str + elt; |
5832
|
1201 |
|
1202 file_stat fs (nm); |
|
1203 |
|
1204 if (fs && fs.is_dir ()) |
|
1205 retval += dir_path::path_sep_str + genpath (nm); |
|
1206 } |
|
1207 } |
|
1208 } |
|
1209 } |
|
1210 |
|
1211 return retval; |
|
1212 } |
|
1213 |
|
1214 static void |
|
1215 execute_pkg_add_or_del (const std::string& dir, |
|
1216 const std::string& script_file) |
|
1217 { |
|
1218 if (! octave_interpreter_ready) |
|
1219 return; |
|
1220 |
|
1221 unwind_protect::begin_frame ("execute_pkg_add_or_del"); |
|
1222 |
|
1223 unwind_protect_bool (input_from_startup_file); |
|
1224 |
|
1225 input_from_startup_file = true; |
|
1226 |
|
1227 std::string file = dir + file_ops::dir_sep_str + script_file; |
|
1228 |
5978
|
1229 file_stat fs (file); |
5832
|
1230 |
|
1231 if (fs.exists ()) |
5975
|
1232 source_file (file, "base"); |
5832
|
1233 |
|
1234 unwind_protect::run_frame ("execute_pkg_add_or_del"); |
|
1235 } |
|
1236 |
|
1237 void |
|
1238 execute_pkg_add (const std::string& dir) |
|
1239 { |
|
1240 execute_pkg_add_or_del (dir, "PKG_ADD"); |
|
1241 } |
|
1242 |
|
1243 void |
|
1244 execute_pkg_del (const std::string& dir) |
|
1245 { |
|
1246 execute_pkg_add_or_del (dir, "PKG_DEL"); |
|
1247 } |
|
1248 |
|
1249 DEFUN (genpath, args, , |
|
1250 "-*- texinfo -*-\n\ |
|
1251 @deftypefn {Built-in Function} {} genpath (@var{dir})\n\ |
|
1252 Return a path constructed from @var{dir} and all its subdiretories.\n\ |
|
1253 @end deftypefn") |
|
1254 { |
|
1255 octave_value retval; |
|
1256 |
|
1257 if (args.length () == 1) |
|
1258 { |
|
1259 std::string dirname = args(0).string_value (); |
|
1260 |
|
1261 if (! error_state) |
|
1262 retval = genpath (dirname); |
|
1263 else |
|
1264 error ("genpath: expecting argument to be a character string"); |
|
1265 } |
|
1266 else |
|
1267 print_usage (); |
|
1268 |
|
1269 return retval; |
|
1270 } |
|
1271 |
|
1272 DEFUN (rehash, , , |
|
1273 "-*- texinfo -*-\n\ |
|
1274 @deftypefn {Built-in Function} {} rehash ()\n\ |
6644
|
1275 Reinitialize Octave's load path directory cache.\n\ |
5832
|
1276 @end deftypefn") |
|
1277 { |
|
1278 octave_value_list retval; |
|
1279 |
|
1280 load_path::update (); |
|
1281 |
|
1282 // FIXME -- maybe we should rename this variable since it is being |
|
1283 // used for more than keeping track of the prompt time. |
|
1284 |
|
1285 // This will force updated functions to be found. |
|
1286 Vlast_prompt_time.stamp (); |
|
1287 |
|
1288 return retval; |
|
1289 } |
|
1290 |
|
1291 DEFUN (pathdef, , , |
|
1292 "-*- texinfo -*-\n\ |
|
1293 @deftypefn {Built-in Function} {@var{val} =} pathdef ()\n\ |
|
1294 Return the default list of directories in which to search for function\n\ |
|
1295 files.\n\ |
|
1296 @seealso{path, addpath, rmpath, genpath, savepath, pathsep}\n\ |
|
1297 @end deftypefn") |
|
1298 { |
6630
|
1299 return octave_value (load_path::system_path ()); |
5832
|
1300 } |
|
1301 |
|
1302 DEFUN (path, args, nargout, |
|
1303 "-*- texinfo -*-\n\ |
6678
|
1304 @deftypefn {Built-in Function} {} path (@dots{})\n\ |
6644
|
1305 Modify or display Octave's load path.\n\ |
5832
|
1306 \n\ |
|
1307 If @var{nargin} and @var{nargout} are zero, display the elements of\n\ |
6644
|
1308 Octave's load path in an easy to read format.\n\ |
5832
|
1309 \n\ |
|
1310 If @var{nargin} is zero and nargout is greater than zero, return the\n\ |
6644
|
1311 current load path.\n\ |
5832
|
1312 \n\ |
|
1313 If @var{nargin} is greater than zero, concatenate the arguments,\n\ |
|
1314 separating them with @code{pathsep()}. Set the internal search path\n\ |
|
1315 to the result and return it.\n\ |
|
1316 \n\ |
|
1317 No checks are made for duplicate elements.\n\ |
|
1318 @seealso{addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ |
|
1319 @end deftypefn") |
|
1320 { |
|
1321 octave_value retval; |
|
1322 |
|
1323 int argc = args.length () + 1; |
|
1324 |
|
1325 string_vector argv = args.make_argv ("path"); |
|
1326 |
|
1327 if (! error_state) |
|
1328 { |
|
1329 if (argc > 1) |
|
1330 { |
|
1331 std::string path = argv[1]; |
|
1332 |
|
1333 for (int i = 2; i < argc; i++) |
5867
|
1334 path += dir_path::path_sep_str + argv[i]; |
5832
|
1335 |
5867
|
1336 load_path::set (path, true); |
5832
|
1337 } |
|
1338 |
|
1339 if (nargout > 0) |
|
1340 retval = load_path::path (); |
|
1341 else if (argc == 1 && nargout == 0) |
|
1342 { |
|
1343 octave_stdout << "\nOctave's search path contains the following directories:\n\n"; |
|
1344 |
|
1345 string_vector dirs = load_path::dirs (); |
|
1346 |
|
1347 dirs.list_in_columns (octave_stdout); |
|
1348 |
|
1349 octave_stdout << "\n"; |
|
1350 } |
|
1351 } |
|
1352 |
|
1353 return retval; |
|
1354 } |
|
1355 |
|
1356 DEFCMD (addpath, args, nargout, |
|
1357 "-*- texinfo -*-\n\ |
6678
|
1358 @deftypefn {Built-in Function} {} addpath (@var{dir1}, @dots{})\n\ |
|
1359 @deftypefnx {Built-in Function} {} addpath (@var{dir1}, @dots{}, @var{option})\n\ |
5832
|
1360 Add @var{dir1}, @dots{} to the current function search path. If\n\ |
|
1361 @var{option} is @samp{\"-begin\"} or 0 (the default), prepend the\n\ |
|
1362 directory name to the current path. If @var{option} is @samp{\"-end\"}\n\ |
|
1363 or 1, append the directory name to the current path.\n\ |
|
1364 Directories added to the path must exist.\n\ |
|
1365 @seealso{path, rmpath, genpath, pathdef, savepath, pathsep}\n\ |
|
1366 @end deftypefn") |
|
1367 { |
|
1368 octave_value retval; |
|
1369 |
|
1370 // Originally written by Bill Denney and Etienne Grossman. Heavily |
|
1371 // modified and translated to C++ by jwe. |
|
1372 |
|
1373 if (nargout > 0) |
|
1374 retval = load_path::path (); |
|
1375 |
|
1376 int nargin = args.length (); |
|
1377 |
|
1378 if (nargin > 0) |
|
1379 { |
|
1380 bool append = false; |
|
1381 |
|
1382 octave_value option_arg = args(nargin-1); |
|
1383 |
|
1384 if (option_arg.is_string ()) |
|
1385 { |
|
1386 std::string option = option_arg.string_value (); |
|
1387 |
|
1388 if (option == "-end") |
|
1389 { |
|
1390 append = true; |
|
1391 nargin--; |
|
1392 } |
|
1393 else if (option == "-begin") |
|
1394 nargin--; |
|
1395 } |
|
1396 else if (option_arg.is_numeric_type ()) |
|
1397 { |
|
1398 int val = option_arg.int_value (); |
|
1399 |
|
1400 if (! error_state) |
|
1401 { |
|
1402 if (val == 0) |
|
1403 append = false; |
|
1404 else if (val == 1) |
|
1405 append = true; |
|
1406 else |
|
1407 { |
|
1408 error ("addpath: expecting final argument to be 1 or 0"); |
|
1409 return retval; |
|
1410 } |
|
1411 } |
|
1412 else |
|
1413 { |
|
1414 error ("addpath: expecting final argument to be 1 or 0"); |
|
1415 return retval; |
|
1416 } |
|
1417 } |
|
1418 |
|
1419 for (int i = 0; i < nargin; i++) |
|
1420 { |
|
1421 std::string arg = args(i).string_value (); |
|
1422 |
|
1423 if (! error_state) |
|
1424 { |
|
1425 std::list<std::string> dir_elts = split_path (arg); |
|
1426 |
|
1427 for (std::list<std::string>::const_iterator p = dir_elts.begin (); |
|
1428 p != dir_elts.end (); |
|
1429 p++) |
|
1430 { |
|
1431 std::string dir = *p; |
|
1432 |
|
1433 //dir = regexprep (dir_elts{j}, "//+", "/"); |
|
1434 //dir = regexprep (dir, "/$", ""); |
|
1435 |
5867
|
1436 if (append) |
|
1437 load_path::append (dir, true); |
5832
|
1438 else |
5867
|
1439 load_path::prepend (dir, true); |
5832
|
1440 } |
|
1441 } |
|
1442 else |
|
1443 error ("addpath: expecting all args to be character strings"); |
|
1444 } |
|
1445 } |
|
1446 else |
|
1447 print_usage (); |
|
1448 |
|
1449 return retval; |
|
1450 } |
|
1451 |
|
1452 DEFCMD (rmpath, args, nargout, |
|
1453 "-*- texinfo -*-\n\ |
6678
|
1454 @deftypefn {Built-in Function} {} rmpath (@var{dir1}, @dots{})\n\ |
5832
|
1455 Remove @var{dir1}, @dots{} from the current function search path.\n\ |
|
1456 \n\ |
|
1457 @seealso{path, addpath, genpath, pathdef, savepath, pathsep}\n\ |
|
1458 @end deftypefn") |
|
1459 { |
|
1460 // Originally by Etienne Grossmann. Heavily modified and translated |
|
1461 // to C++ by jwe. |
|
1462 |
|
1463 octave_value retval; |
|
1464 |
|
1465 if (nargout > 0) |
|
1466 retval = load_path::path (); |
|
1467 |
|
1468 int nargin = args.length (); |
|
1469 |
|
1470 if (nargin > 0) |
|
1471 { |
|
1472 for (int i = 0; i < nargin; i++) |
|
1473 { |
|
1474 std::string arg = args(i).string_value (); |
|
1475 |
|
1476 if (! error_state) |
|
1477 { |
|
1478 std::list<std::string> dir_elts = split_path (arg); |
|
1479 |
|
1480 for (std::list<std::string>::const_iterator p = dir_elts.begin (); |
|
1481 p != dir_elts.end (); |
|
1482 p++) |
|
1483 { |
|
1484 std::string dir = *p; |
|
1485 |
|
1486 //dir = regexprep (dir_elts{j}, "//+", "/"); |
|
1487 //dir = regexprep (dir, "/$", ""); |
|
1488 |
|
1489 if (! load_path::remove (dir)) |
|
1490 warning ("rmpath: %s: not found", dir.c_str ()); |
|
1491 } |
|
1492 } |
|
1493 else |
|
1494 error ("addpath: expecting all args to be character strings"); |
|
1495 } |
|
1496 } |
|
1497 else |
|
1498 print_usage (); |
|
1499 |
|
1500 return retval; |
|
1501 } |
|
1502 |
|
1503 /* |
|
1504 ;;; Local Variables: *** |
|
1505 ;;; mode: C++ *** |
|
1506 ;;; End: *** |
|
1507 */ |