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