GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
load-path.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2006-2017 John W. Eaton
4 Copyright (C) 2010 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (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 #include "singleton-cleanup.h"
36 
37 #include "defaults.h"
38 #include "defun.h"
39 #include "input.h"
40 #include "interpreter.h"
41 #include "load-path.h"
42 #include "ov-usr-fcn.h"
43 #include "pager.h"
44 #include "parse.h"
45 #include "unwind-prot.h"
46 #include "utils.h"
47 
54 
55 void
57 {
59 
60  if (! fs)
61  {
62  std::string msg = fs.error ();
63  warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ());
64  }
65  else
66  {
67  if (is_relative)
68  {
69  try
70  {
72 
73  abs_dir_cache_iterator p = abs_dir_cache.find (abs_name);
74 
75  if (p != abs_dir_cache.end ())
76  {
77  // The directory is in the cache of all directories we have
78  // visited (indexed by absolute name). If it is out of date,
79  // initialize it. Otherwise, copy the info from the cache.
80  // By doing that, we avoid unnecessary calls to stat that can
81  // slow things down tremendously for large directories.
82  const dir_info& di = p->second;
83 
84  if (fs.mtime () + fs.time_resolution ()
86  initialize ();
87  else
88  {
89  // Copy over info from cache, but leave dir_name and
90  // is_relative unmodified.
91  this->abs_dir_name = di.abs_dir_name;
92  this->dir_mtime = di.dir_mtime;
94  this->all_files = di.all_files;
95  this->fcn_files = di.fcn_files;
99  }
100  }
101  else
102  {
103  // We haven't seen this directory before.
104  initialize ();
105  }
106  }
107  catch (const octave::execution_exception&)
108  {
109  // Skip updating if we don't know where we are,
110  // but don't treat it as an error.
112  }
113  }
114  // Absolute path, check timestamp to see whether it requires re-caching
115  else if (fs.mtime () + fs.time_resolution () > dir_time_last_checked)
116  initialize ();
117  }
118 }
119 
120 bool
122 {
123  size_t pos = name.find ('.');
124 
125  if (pos == std::string::npos)
126  return package_dir_map.find (name) != package_dir_map.end ();
127  else
128  {
129  std::string name_head = name.substr (0, pos);
130  std::string name_tail = name.substr (pos + 1);
131 
132  const_package_dir_map_iterator it = package_dir_map.find (name_head);
133 
134  if (it != package_dir_map.end ())
135  return it->second.is_package (name_tail);
136  else
137  return false;
138  }
139 }
140 
141 void
143 {
144  is_relative = ! octave::sys::env::absolute_pathname (dir_name);
145 
146  dir_time_last_checked = octave::sys::time (static_cast<time_t> (0));
147 
148  octave::sys::file_stat fs (dir_name);
149 
150  if (fs)
151  {
152  method_file_map.clear ();
153  package_dir_map.clear ();
154 
155  dir_mtime = fs.mtime ();
156  dir_time_last_checked = octave::sys::time ();
157 
158  get_file_list (dir_name);
159 
160  try
161  {
162  std::string abs_name = octave::sys::env::make_absolute (dir_name);
163 
164  // FIXME: nothing is ever removed from this cache of
165  // directory information, so there could be some resource
166  // problems. Perhaps it should be pruned from time to time.
167 
168  abs_dir_cache[abs_name] = *this;
169  }
170  catch (const octave::execution_exception&)
171  {
172  // Skip updating if we don't know where we are but don't treat
173  // it as an error.
174 
176  }
177  }
178  else
179  {
180  std::string msg = fs.error ();
181  warning ("load_path: %s: %s", dir_name.c_str (), msg.c_str ());
182  }
183 }
184 
185 void
187 {
188  octave::sys::dir_entry dir (d);
189 
190  if (dir)
191  {
192  string_vector flist = dir.read ();
193 
194  octave_idx_type len = flist.numel ();
195 
196  all_files.resize (len);
197  fcn_files.resize (len);
198 
199  octave_idx_type all_files_count = 0;
200  octave_idx_type fcn_files_count = 0;
201 
202  for (octave_idx_type i = 0; i < len; i++)
203  {
204  std::string fname = flist[i];
205 
206  std::string full_name = octave::sys::file_ops::concat (d, fname);
207 
208  octave::sys::file_stat fs (full_name);
209 
210  if (fs)
211  {
212  if (fs.is_dir ())
213  {
214  if (fname == "private")
215  get_private_file_map (full_name);
216  else if (fname[0] == '@')
217  get_method_file_map (full_name, fname.substr (1));
218  else if (fname[0] == '+')
219  get_package_dir (full_name, fname.substr (1));
220  }
221  else
222  {
223  all_files[all_files_count++] = fname;
224 
225  size_t pos = fname.rfind ('.');
226 
227  if (pos != std::string::npos)
228  {
229  std::string ext = fname.substr (pos);
230 
231  if (ext == ".m" || ext == ".oct" || ext == ".mex")
232  {
233  std::string base = fname.substr (0, pos);
234 
235  if (valid_identifier (base))
236  fcn_files[fcn_files_count++] = fname;
237  }
238  }
239  }
240  }
241  }
242 
243  all_files.resize (all_files_count);
244  fcn_files.resize (fcn_files_count);
245  }
246  else
247  {
248  std::string msg = dir.error ();
249  warning ("load_path: %s: %s", d.c_str (), msg.c_str ());
250  }
251 }
252 
255 {
257 
258  octave::sys::dir_entry dir (d);
259 
260  if (dir)
261  {
262  string_vector flist = dir.read ();
263 
264  octave_idx_type len = flist.numel ();
265 
266  for (octave_idx_type i = 0; i < len; i++)
267  {
268  std::string fname = flist[i];
269 
270  size_t pos = fname.rfind ('.');
271 
272  if (pos != std::string::npos)
273  {
274  std::string base = fname.substr (0, pos);
275  std::string ext = fname.substr (pos);
276 
277  if (valid_identifier (base))
278  {
279  int t = 0;
280 
281  if (ext == ".m")
282  t = load_path::M_FILE;
283  else if (ext == ".oct")
285  else if (ext == ".mex")
287 
288  if (t)
289  retval[base] = t;
290  }
291  }
292  }
293  }
294  else
295  {
296  std::string msg = dir.error ();
297  warning ("load_path: %s: %s", d.c_str (), msg.c_str ());
298  }
299 
300  return retval;
301 }
302 
303 void
305 {
306  private_file_map = get_fcn_files (d);
307 }
308 
309 void
311  const std::string& class_name)
312 {
313  method_file_map[class_name].method_file_map = get_fcn_files (d);
314 
315  std::string pd = octave::sys::file_ops::concat (d, "private");
316 
318 
319  if (fs && fs.is_dir ())
320  method_file_map[class_name].private_file_map = get_fcn_files (pd);
321 }
322 
323 void
325  const std::string& package_name)
326 {
327  package_dir_map[package_name] = dir_info (d);
328 }
329 
330 bool
332 {
333  bool retval = true;
334 
335  if (! instance)
336  {
337  instance = new load_path ();
338 
339  if (instance)
341  }
342 
343  if (! instance)
344  error ("unable to create load path object!");
345 
346  return retval;
347 }
348 
349 // FIXME: maybe we should also maintain a map to speed up this method of access.
350 
352 load_path::find_dir_info (const std::string& dir_arg) const
353 {
355 
357 
358  while (retval != dir_info_list.end ())
359  {
360  if (retval->dir_name == dir)
361  break;
362 
363  retval++;
364  }
365 
366  return retval;
367 }
368 
371 {
373 
375 
376  while (retval != dir_info_list.end ())
377  {
378  if (retval->dir_name == dir)
379  break;
380 
381  retval++;
382  }
383 
384  return retval;
385 }
386 
387 bool
389 {
390  return find_dir_info (dir) != dir_info_list.end ();
391 }
392 
393 bool
395 {
396  bool retval = false;
397 
399  i != dir_info_list.end ();
400  i++)
401  {
402  if (same_file (dir, i->dir_name))
403  {
404  retval = true;
405  break;
406  }
407  }
408 
409  return retval;
410 }
411 
412 void
414  const string_vector& fcn_files, bool at_end)
415 {
416  octave_idx_type len = fcn_files.numel ();
417 
418  for (octave_idx_type k = 0; k < len; k++)
419  {
420  std::string fname = fcn_files[k];
421 
422  std::string ext;
423  std::string base = fname;
424 
425  size_t pos = fname.rfind ('.');
426 
427  if (pos != std::string::npos)
428  {
429  base = fname.substr (0, pos);
430  ext = fname.substr (pos);
431  }
432 
433  file_info_list_type& file_info_list = fcn_map[base];
434 
435  if (file_info_list.size () == 1)
436  continue;
437  else
438  {
439  for (file_info_list_iterator p = file_info_list.begin ();
440  p != file_info_list.end ();
441  p++)
442  {
443  if (p->dir_name == dir_name)
444  {
445  file_info fi = *p;
446 
447  file_info_list.erase (p);
448 
449  if (at_end)
450  file_info_list.push_back (fi);
451  else
452  file_info_list.push_front (fi);
453 
454  break;
455  }
456  }
457  }
458  }
459 }
460 
461 void
462 load_path::loader::move_method_map (const std::string& dir_name, bool at_end)
463 {
464  for (method_map_iterator i = method_map.begin ();
465  i != method_map.end ();
466  i++)
467  {
468  std::string class_name = i->first;
469 
470  fcn_map_type& fm = i->second;
471 
472  std::string full_dir_name
473  = octave::sys::file_ops::concat (dir_name, "@" + class_name);
474 
475  for (fcn_map_iterator q = fm.begin (); q != fm.end (); q++)
476  {
477  file_info_list_type& file_info_list = q->second;
478 
479  if (file_info_list.size () == 1)
480  continue;
481  else
482  {
483  for (file_info_list_iterator p = file_info_list.begin ();
484  p != file_info_list.end (); p++)
485  {
486  if (p->dir_name == full_dir_name)
487  {
488  file_info fi = *p;
489 
490  file_info_list.erase (p);
491 
492  if (at_end)
493  file_info_list.push_back (fi);
494  else
495  file_info_list.push_front (fi);
496 
497  break;
498  }
499  }
500  }
501  }
502  }
503 }
504 
505 void
507 {
508  if (dir_info_list.size () > 1)
509  {
510  dir_info di = *i;
511 
512  dir_info_list.erase (i);
513 
514  if (at_end)
515  dir_info_list.push_back (di);
516  else
517  dir_info_list.push_front (di);
518 
519  move (di, at_end);
520  }
521 }
522 
523 void
524 load_path::move (const dir_info& di, bool at_end, const std::string& pname)
525 {
526  loader& l = get_loader (pname);
527 
528  l.move (di, at_end);
529 
530  dir_info::package_dir_map_type package_dir_map = di.package_dir_map;
531 
532  for (dir_info::const_package_dir_map_iterator p = package_dir_map.begin ();
533  p != package_dir_map.end (); ++p)
534  {
535  std::string full_name = p->first;
536 
537  if (! pname.empty ())
538  full_name = pname + "." + full_name;
539 
540  move (p->second, at_end, full_name);
541  }
542 }
543 
544 void
545 load_path::loader::move (const dir_info& di, bool at_end)
546 {
547  std::string dir_name = di.dir_name;
548 
549  std::list<std::string>::iterator s =
550  std::find (dir_list.begin (), dir_list.end (), dir_name);
551 
552  if (s != dir_list.end ())
553  {
554  dir_list.erase (s);
555 
556  if (at_end)
557  dir_list.push_back (dir_name);
558  else
559  dir_list.push_front (dir_name);
560  }
561 
562  move_fcn_map (dir_name, di.fcn_files, at_end);
563 
564  // No need to move elements of private function map.
565 
566  move_method_map (dir_name, at_end);
567 }
568 
569 static void
571 {
572  std::string tpath = genpath (dir);
573 
574  if (! tpath.empty ())
575  {
576  if (path.empty ())
577  path = tpath;
578  else
579  path += octave::directory_path::path_sep_str () + tpath;
580  }
581 }
582 
583 void
584 load_path::do_initialize (bool set_initial_path)
585 {
586  sys_path = "";
587 
588  if (set_initial_path)
589  {
599  }
600 
602 
603  if (tpath.empty ())
604  tpath = octave::sys::env::getenv ("OCTAVE_PATH");
605 
606  std::string xpath;
607 
608  if (! tpath.empty ())
609  {
610  xpath = tpath;
611 
612  if (! sys_path.empty ())
614  }
615  else
616  xpath = sys_path;
617 
618  do_set (xpath, false, true);
619 }
620 
621 void
623 {
624  dir_info_list.clear ();
625 
627 
628  loader_map.clear ();
629 }
630 
631 static std::list<std::string>
633 {
634  std::list<std::string> retval;
635 
636  size_t beg = 0;
637  size_t end = p.find (octave::directory_path::path_sep_char ());
638 
639  size_t len = p.length ();
640 
641  while (end != std::string::npos)
642  {
643  std::string elt = p.substr (beg, end-beg);
644 
645  if (! elt.empty ())
646  retval.push_back (elt);
647 
648  beg = end + 1;
649 
650  if (beg == len)
651  break;
652 
653  end = p.find (octave::directory_path::path_sep_char (), beg);
654  }
655 
656  std::string elt = p.substr (beg);
657 
658  if (! elt.empty ())
659  retval.push_back (elt);
660 
661  return retval;
662 }
663 
664 void
665 load_path::do_set (const std::string& p, bool warn, bool is_init)
666 {
667  // Use a list when we need to preserve order.
668  std::list<std::string> elts = split_path (p);
669 
670  // Use a set when we need to search and order is not important.
671  std::set<std::string> elts_set (elts.begin (), elts.end ());
672 
673  if (is_init)
674  init_dirs = elts_set;
675  else
676  {
677  for (std::set<std::string>::const_iterator it = init_dirs.begin ();
678  it != init_dirs.end (); it++)
679  {
680  if (elts_set.find (*it) == elts_set.end ())
681  {
682  warning_with_id ("Octave:remove-init-dir",
683  "default load path altered. Some built-in functions may not be found. Try restoredefaultpath() to recover it.");
684  break;
685  }
686  }
687  }
688 
689  // Temporarily disable add hook.
690 
692  frame.protect_var (add_hook);
693 
694  add_hook = 0;
695 
696  do_clear ();
697 
698  for (std::list<std::string>::const_iterator i = elts.begin ();
699  i != elts.end (); i++)
700  do_append (*i, warn);
701 
702  // Restore add hook and execute for all newly added directories.
703  frame.run_first ();
704 
705  for (dir_info_list_iterator i = dir_info_list.begin ();
706  i != dir_info_list.end ();
707  i++)
708  {
709  if (add_hook)
710  add_hook (i->dir_name);
711  }
712 
713  // Always prepend current directory.
714  do_prepend (".", warn);
715 }
716 
717 void
718 load_path::do_append (const std::string& dir, bool warn)
719 {
720  if (! dir.empty ())
721  do_add (dir, true, warn);
722 }
723 
724 void
725 load_path::do_prepend (const std::string& dir, bool warn)
726 {
727  if (! dir.empty ())
728  do_add (dir, false, warn);
729 }
730 
731 // Strip trailing directory separators.
732 
733 static std::string
735 {
736  std::string dir = dir_arg;
737 
738  size_t k = dir.length ();
739 
740  while (k > 1 && octave::sys::file_ops::is_dir_sep (dir[k-1]))
741  k--;
742 
743  if (k < dir.length ())
744  dir.resize (k);
745 
746  return dir;
747 }
748 
749 void
750 load_path::do_add (const std::string& dir_arg, bool at_end, bool warn)
751 {
752  size_t len = dir_arg.length ();
753 
754  if (len > 1 && dir_arg.substr (len-2) == "//")
755  warning_with_id ("Octave:recursive-path-search",
756  "trailing '//' is no longer special in search path elements");
757 
759 
760  dir = strip_trailing_separators (dir);
761 
763 
764  if (i != dir_info_list.end ())
765  do_move (i, at_end);
766  else
767  {
769 
770  if (fs)
771  {
772  if (fs.is_dir ())
773  {
774  dir_info di (dir);
775 
776  if (at_end)
777  dir_info_list.push_back (di);
778  else
779  dir_info_list.push_front (di);
780 
781  add (di, at_end);
782 
783  if (add_hook)
784  add_hook (dir);
785  }
786  else if (warn)
787  warning ("addpath: %s: not a directory", dir_arg.c_str ());
788  }
789  else if (warn)
790  {
791  std::string msg = fs.error ();
792  warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ());
793  }
794  }
795 
796  // FIXME: is there a better way to do this?
797 
798  i = find_dir_info (".");
799 
800  if (i != dir_info_list.end ())
801  do_move (i, false);
802 }
803 
804 void
806  const string_vector& fcn_files)
807 {
808  octave_idx_type len = fcn_files.numel ();
809 
810  for (octave_idx_type k = 0; k < len; k++)
811  {
812  std::string fname = fcn_files[k];
813 
814  std::string ext;
815  std::string base = fname;
816 
817  size_t pos = fname.rfind ('.');
818 
819  if (pos != std::string::npos)
820  {
821  base = fname.substr (0, pos);
822  ext = fname.substr (pos);
823  }
824 
825  file_info_list_type& file_info_list = fcn_map[base];
826 
827  for (file_info_list_iterator p = file_info_list.begin ();
828  p != file_info_list.end ();
829  p++)
830  {
831  if (p->dir_name == dir)
832  {
833  file_info_list.erase (p);
834 
835  if (file_info_list.empty ())
836  fcn_map.erase (fname);
837 
838  break;
839  }
840  }
841  }
842 }
843 
844 void
846 {
847  private_fcn_map_iterator p = private_fcn_map.find (dir);
848 
849  if (p != private_fcn_map.end ())
850  private_fcn_map.erase (p);
851 }
852 
853 void
855 {
856  for (method_map_iterator i = method_map.begin ();
857  i != method_map.end ();
858  i++)
859  {
860  std::string class_name = i->first;
861 
862  fcn_map_type& fm = i->second;
863 
864  std::string full_dir_name
865  = octave::sys::file_ops::concat (dir, "@" + class_name);
866 
867  for (fcn_map_iterator q = fm.begin (); q != fm.end (); q++)
868  {
869  file_info_list_type& file_info_list = q->second;
870 
871  if (file_info_list.size () == 1)
872  continue;
873  else
874  {
875  for (file_info_list_iterator p = file_info_list.begin ();
876  p != file_info_list.end (); p++)
877  {
878  if (p->dir_name == full_dir_name)
879  {
880  file_info_list.erase (p);
881 
882  // FIXME: if there are no other elements, we
883  // should remove this element of fm but calling
884  // erase here would invalidate the iterator q.
885 
886  break;
887  }
888  }
889  }
890  }
891  }
892 }
893 
894 bool
896 {
897  bool retval = false;
898 
899  if (! dir_arg.empty ())
900  {
901  if (dir_arg == ".")
902  {
903  warning ("rmpath: can't remove \".\" from path");
904 
905  // Avoid additional warnings.
906  retval = true;
907  }
908  else
909  {
911 
912  dir = strip_trailing_separators (dir);
913 
915 
916  if (i != dir_info_list.end ())
917  {
918  retval = true;
919 
920  if (remove_hook)
921  remove_hook (dir);
922 
923  dir_info& di = *i;
924 
925  remove (di);
926 
927  dir_info_list.erase (i);
928  }
929  }
930  }
931 
932  return retval;
933 }
934 
935 void
937 {
938  loader& l = get_loader (pname);
939 
940  l.remove (di);
941 
942  dir_info::package_dir_map_type package_dir_map = di.package_dir_map;
943 
944  for (dir_info::const_package_dir_map_iterator p = package_dir_map.begin ();
945  p != package_dir_map.end (); ++p)
946  {
947  std::string full_name = p->first;
948 
949  if (! pname.empty ())
950  full_name = pname + "." + full_name;
951 
952  remove (p->second, full_name);
953  }
954 }
955 
956 void
958 {
959  std::string dir = di.dir_name;
960 
961  string_vector fcn_files = di.fcn_files;
962 
963  dir_list.remove (dir);
964 
965  remove_fcn_map (dir, fcn_files);
966 
967  remove_private_fcn_map (dir);
968 
969  remove_method_map (dir);
970 }
971 
972 void
974 {
975  // I don't see a better way to do this because we need to
976  // preserve the correct directory ordering for new files that
977  // have appeared.
978 
980 
981  loader_map.clear ();
982 
983  for (dir_info_list_iterator p = dir_info_list.begin ();
984  p != dir_info_list.end ();
985  p++)
986  {
987  dir_info& di = *p;
988 
989  di.update ();
990 
991  add (di, true, "", true);
992  }
993 }
994 
995 bool
997  const std::string& fcn, const char *who)
998 {
999  bool retval = false;
1000 
1001  if (type == load_path::OCT_FILE)
1002  {
1003  if ((type & possible_types) == load_path::OCT_FILE)
1004  {
1005  fname += ".oct";
1006  retval = true;
1007  }
1008  }
1009  else if (type == load_path::M_FILE)
1010  {
1011  if ((type & possible_types) == load_path::M_FILE)
1012  {
1013  fname += ".m";
1014  retval = true;
1015  }
1016  }
1017  else if (type == load_path::MEX_FILE)
1018  {
1019  if ((type & possible_types) == load_path::MEX_FILE)
1020  {
1021  fname += ".mex";
1022  retval = true;
1023  }
1024  }
1025  else if (type == (load_path::M_FILE | load_path::OCT_FILE))
1026  {
1027  if (possible_types & load_path::OCT_FILE)
1028  {
1029  fname += ".oct";
1030  retval = true;
1031  }
1032  else if (possible_types & load_path::M_FILE)
1033  {
1034  fname += ".m";
1035  retval = true;
1036  }
1037  }
1038  else if (type == (load_path::M_FILE | load_path::MEX_FILE))
1039  {
1040  if (possible_types & load_path::MEX_FILE)
1041  {
1042  fname += ".mex";
1043  retval = true;
1044  }
1045  else if (possible_types & load_path::M_FILE)
1046  {
1047  fname += ".m";
1048  retval = true;
1049  }
1050  }
1051  else if (type == (load_path::OCT_FILE | load_path::MEX_FILE))
1052  {
1053  if (possible_types & load_path::OCT_FILE)
1054  {
1055  fname += ".oct";
1056  retval = true;
1057  }
1058  else if (possible_types & load_path::MEX_FILE)
1059  {
1060  fname += ".mex";
1061  retval = true;
1062  }
1063  }
1064  else if (type == (load_path::M_FILE | load_path::OCT_FILE
1066  {
1067  if (possible_types & load_path::OCT_FILE)
1068  {
1069  fname += ".oct";
1070  retval = true;
1071  }
1072  else if (possible_types & load_path::MEX_FILE)
1073  {
1074  fname += ".mex";
1075  retval = true;
1076  }
1077  else if (possible_types & load_path::M_FILE)
1078  {
1079  fname += ".m";
1080  retval = true;
1081  }
1082  }
1083  else
1084  error ("%s: %s: invalid type code = %d", who, fcn.c_str (), type);
1085 
1086  return retval;
1087 }
1088 
1091  int type) const
1092 {
1094 
1095  // update ();
1096 
1097  if (fcn.length () > 0 && fcn[0] == '@')
1098  {
1099  size_t pos = fcn.find ('/');
1100 
1101  if (pos != std::string::npos)
1102  {
1103  std::string class_name = fcn.substr (1, pos-1);
1104  std::string meth = fcn.substr (pos+1);
1105 
1106  retval = find_method (class_name, meth, dir_name);
1107  }
1108  else
1109  retval = "";
1110  }
1111  else
1112  {
1113  dir_name = "";
1114 
1115  const_fcn_map_iterator p = fcn_map.find (fcn);
1116 
1117  if (p != fcn_map.end ())
1118  {
1119  const file_info_list_type& file_info_list = p->second;
1120 
1121  for (const_file_info_list_iterator i = file_info_list.begin ();
1122  i != file_info_list.end ();
1123  i++)
1124  {
1125  const file_info& fi = *i;
1126 
1127  retval = octave::sys::file_ops::concat (fi.dir_name, fcn);
1128 
1129  if (check_file_type (retval, type, fi.types,
1130  fcn, "load_path::do_find_fcn"))
1131  {
1132  dir_name = fi.dir_name;
1133  break;
1134  }
1135  else
1136  retval = "";
1137  }
1138  }
1139  }
1140 
1141  return retval;
1142 }
1143 
1146  const std::string& fcn, int type) const
1147 {
1149 
1150  // update ();
1151 
1152  const_private_fcn_map_iterator q = private_fcn_map.find (dir);
1153 
1154  if (q != private_fcn_map.end ())
1155  {
1156  const dir_info::fcn_file_map_type& m = q->second;
1157 
1159 
1160  if (p != m.end ())
1161  {
1164 
1165  if (check_file_type (fname, type, p->second, fcn,
1166  "load_path::find_private_fcn"))
1167  retval = fname;
1168  }
1169  }
1170 
1171  return retval;
1172 }
1173 
1176  const std::string& meth,
1177  std::string& dir_name, int type) const
1178 {
1180 
1181  // update ();
1182 
1183  dir_name = "";
1184 
1185  const_method_map_iterator q = method_map.find (class_name);
1186 
1187  if (q != method_map.end ())
1188  {
1189  const fcn_map_type& m = q->second;
1190 
1191  const_fcn_map_iterator p = m.find (meth);
1192 
1193  if (p != m.end ())
1194  {
1195  const file_info_list_type& file_info_list = p->second;
1196 
1197  for (const_file_info_list_iterator i = file_info_list.begin ();
1198  i != file_info_list.end ();
1199  i++)
1200  {
1201  const file_info& fi = *i;
1202 
1203  retval = octave::sys::file_ops::concat (fi.dir_name, meth);
1204 
1205  bool found = check_file_type (retval, type, fi.types,
1206  meth, "load_path::do_find_method");
1207 
1208  if (found)
1209  {
1210  dir_name = fi.dir_name;
1211  break;
1212  }
1213  else
1214  retval = "";
1215  }
1216  }
1217  }
1218 
1219  return retval;
1220 }
1221 
1222 std::list<std::string>
1223 load_path::loader::methods (const std::string& class_name) const
1224 {
1225  std::list<std::string> retval;
1226 
1227  // update ();
1228 
1229  const_method_map_iterator q = method_map.find (class_name);
1230 
1231  if (q != method_map.end ())
1232  {
1233  const fcn_map_type& m = q->second;
1234 
1235  for (const_fcn_map_iterator p = m.begin (); p != m.end (); p++)
1236  retval.push_back (p->first);
1237  }
1238 
1239  if (! retval.empty ())
1240  retval.sort ();
1241 
1242  return retval;
1243 }
1244 
1245 bool
1247 {
1249  p != dir_info_list.end ();
1250  p++)
1251  {
1252  if (p->is_package (name))
1253  return true;
1254  }
1255 
1256  return false;
1257 }
1258 
1259 std::list<std::string>
1261 {
1262  std::list<std::string> retval;
1263 
1264  // update ();
1265 
1266  default_loader.overloads (meth, retval);
1267 
1268  for (const_loader_map_iterator l = loader_map.begin ();
1269  l != loader_map.end (); ++l)
1270  l->second.overloads (meth, retval);
1271 
1272  return retval;
1273 }
1274 
1275 void
1277  std::list<std::string>& l) const
1278 {
1279  for (const_method_map_iterator q = method_map.begin ();
1280  q != method_map.end (); q++)
1281  {
1282  const fcn_map_type& m = q->second;
1283 
1284  if (m.find (meth) != m.end ())
1285  {
1286  std::string class_name = q->first;
1287 
1288  if (! prefix.empty ())
1289  class_name = prefix + "." + class_name;
1290 
1291  l.push_back (class_name);
1292  }
1293  }
1294 }
1295 
1296 // Should we cache all files in private directories, or is it OK to just
1297 // look them up each time as needed?
1298 
1301 {
1303 
1304  // Look in private directory corresponding to current function (if
1305  // any).
1306 
1308 
1309  if (curr_fcn)
1310  {
1311  // Even for private functions, dir_name doesn't contain the
1312  // "private" directory component so we append it here in all
1313  // cases.
1314 
1315  std::string dir_name = curr_fcn->dir_name ();
1316 
1317  if (! dir_name.empty ())
1318  {
1319  std::string pfname = dir_name + octave::sys::file_ops::dir_sep_str ()
1320  + "private" + octave::sys::file_ops::dir_sep_str () + fname;
1321 
1322  octave::sys::file_stat fs (pfname);
1323 
1324  if (fs.exists () && fs.is_reg ())
1325  retval = pfname;
1326  }
1327  }
1328 
1329  return retval;
1330 }
1331 
1334 {
1336 
1339  {
1340  octave::sys::file_stat fs (file);
1341 
1342  return fs.exists () ? file : retval;
1343  }
1344  else
1345  {
1346  std::string tfile = find_private_file (file);
1347 
1348  if (! tfile.empty ())
1349  return tfile;
1350  }
1351 
1352  if (file.find_first_of (octave::sys::file_ops::dir_sep_chars ())
1353  != std::string::npos)
1354  {
1355  // Given name has a directory separator, so append it to each
1356  // element of the load path in turn.
1357 
1359  p != dir_info_list.end ();
1360  p++)
1361  {
1362  std::string tfile = octave::sys::file_ops::concat (p->dir_name, file);
1363 
1364  octave::sys::file_stat fs (tfile);
1365 
1366  if (fs.exists ())
1367  return tfile;
1368  }
1369  }
1370  else
1371  {
1372  // Look in cache.
1373 
1375  p != dir_info_list.end ();
1376  p++)
1377  {
1378  string_vector all_files = p->all_files;
1379 
1380  octave_idx_type len = all_files.numel ();
1381 
1382  for (octave_idx_type i = 0; i < len; i++)
1383  {
1384  if (all_files[i] == file)
1385  return octave::sys::file_ops::concat (p->dir_name, file);
1386  }
1387  }
1388  }
1389 
1390  return retval;
1391 }
1392 
1395 {
1397 
1398  if (dir.find_first_of (octave::sys::file_ops::dir_sep_chars ()) != std::string::npos
1401  {
1402  octave::sys::file_stat fs (dir);
1403 
1404  if (fs.exists () && fs.is_dir ())
1405  return dir;
1406  }
1407  else
1408  {
1410  p != dir_info_list.end ();
1411  p++)
1412  {
1413  std::string dname = octave::sys::env::make_absolute (p->dir_name);
1414 
1415  size_t dname_len = dname.length ();
1416 
1417  if (dname.substr (dname_len - 1) == octave::sys::file_ops::dir_sep_str ())
1418  {
1419  dname = dname.substr (0, dname_len - 1);
1420  dname_len--;
1421  }
1422 
1423  size_t dir_len = dir.length ();
1424 
1425  if (dname_len > dir_len
1426  && octave::sys::file_ops::is_dir_sep (dname[dname_len - dir_len - 1])
1427  && dir == dname.substr (dname_len - dir_len))
1428  {
1429  octave::sys::file_stat fs (p->dir_name);
1430 
1431  if (fs.exists () && fs.is_dir ())
1432  return p->dir_name;
1433  }
1434  }
1435  }
1436 
1437  return retval;
1438 }
1439 
1442 {
1443  std::list<std::string> retlist;
1444 
1445  if (dir.find_first_of (octave::sys::file_ops::dir_sep_chars ()) != std::string::npos
1448  {
1449  octave::sys::file_stat fs (dir);
1450 
1451  if (fs.exists () && fs.is_dir ())
1452  retlist.push_back (dir);
1453  }
1454  else
1455  {
1457  p != dir_info_list.end ();
1458  p++)
1459  {
1460  std::string dname = octave::sys::env::make_absolute (p->dir_name);
1461 
1462  size_t dname_len = dname.length ();
1463 
1464  if (dname.substr (dname_len - 1) == octave::sys::file_ops::dir_sep_str ())
1465  {
1466  dname = dname.substr (0, dname_len - 1);
1467  dname_len--;
1468  }
1469 
1470  size_t dir_len = dir.length ();
1471 
1472  if (dname_len > dir_len
1473  && octave::sys::file_ops::is_dir_sep (dname[dname_len - dir_len - 1])
1474  && dir == dname.substr (dname_len - dir_len))
1475  {
1476  octave::sys::file_stat fs (p->dir_name);
1477 
1478  if (fs.exists () && fs.is_dir ())
1479  retlist.push_back (p->dir_name);
1480  }
1481  }
1482  }
1483 
1484  return retlist;
1485 }
1486 
1489 {
1491 
1492  std::string dir_name;
1493  std::string file_name;
1494 
1495  octave_idx_type flen = flist.numel ();
1496  octave_idx_type rel_flen = 0;
1497 
1498  string_vector rel_flist (flen);
1499 
1500  for (octave_idx_type i = 0; i < flen; i++)
1501  {
1502  std::string file = flist[i];
1503 
1504  if (file.find_first_of (octave::sys::file_ops::dir_sep_chars ())
1505  != std::string::npos)
1506  {
1509  {
1510  octave::sys::file_stat fs (file);
1511 
1512  if (fs.exists ())
1513  return file;
1514  }
1515  else
1516  {
1518  p != dir_info_list.end ();
1519  p++)
1520  {
1521  std::string tfile = octave::sys::file_ops::concat (p->dir_name, file);
1522 
1523  octave::sys::file_stat fs (tfile);
1524 
1525  if (fs.exists ())
1526  return tfile;
1527  }
1528  }
1529  }
1530  else
1531  rel_flist[rel_flen++] = file;
1532  }
1533 
1534  rel_flist.resize (rel_flen);
1535 
1537  p != dir_info_list.end ();
1538  p++)
1539  {
1540  string_vector all_files = p->all_files;
1541 
1542  octave_idx_type len = all_files.numel ();
1543 
1544  for (octave_idx_type i = 0; i < len; i++)
1545  {
1546  for (octave_idx_type j = 0; j < rel_flen; j++)
1547  {
1548  if (all_files[i] == rel_flist[j])
1549  {
1550  dir_name = p->dir_name;
1551  file_name = rel_flist[j];
1552 
1553  goto done;
1554  }
1555  }
1556  }
1557  }
1558 
1559 done:
1560 
1561  if (! dir_name.empty ())
1562  retval = octave::sys::file_ops::concat (dir_name, file_name);
1563 
1564  return retval;
1565 }
1566 
1569 {
1570  std::list<std::string> retlist;
1571 
1572  std::string dir_name;
1573  std::string file_name;
1574 
1575  octave_idx_type flen = flist.numel ();
1576  octave_idx_type rel_flen = 0;
1577 
1578  string_vector rel_flist (flen);
1579 
1580  for (octave_idx_type i = 0; i < flen; i++)
1581  {
1582  std::string file = flist[i];
1583 
1584  if (file.find_first_of (octave::sys::file_ops::dir_sep_chars ())
1585  != std::string::npos)
1586  {
1589  {
1590  octave::sys::file_stat fs (file);
1591 
1592  if (fs.exists ())
1593  retlist.push_back (file);
1594  }
1595  else
1596  {
1598  p != dir_info_list.end ();
1599  p++)
1600  {
1601  std::string tfile = octave::sys::file_ops::concat (p->dir_name, file);
1602 
1603  octave::sys::file_stat fs (tfile);
1604 
1605  if (fs.exists ())
1606  retlist.push_back (tfile);
1607  }
1608  }
1609  }
1610  else
1611  rel_flist[rel_flen++] = file;
1612  }
1613 
1614  rel_flist.resize (rel_flen);
1615 
1617  p != dir_info_list.end (); p++)
1618  {
1619  string_vector all_files = p->all_files;
1620 
1621  octave_idx_type len = all_files.numel ();
1622 
1623  for (octave_idx_type i = 0; i < len; i++)
1624  {
1625  for (octave_idx_type j = 0; j < rel_flen; j++)
1626  {
1627  if (all_files[i] == rel_flist[j])
1628  retlist.push_back (octave::sys::file_ops::concat (p->dir_name,
1629  rel_flist[j]));
1630  }
1631  }
1632  }
1633 
1634  return retlist;
1635 }
1636 
1639 {
1640  size_t len = dir_info_list.size ();
1641 
1642  string_vector retval (len);
1643 
1644  octave_idx_type k = 0;
1645 
1647  i != dir_info_list.end ();
1648  i++)
1649  retval[k++] = i->dir_name;
1650 
1651  return retval;
1652 }
1653 
1654 std::list<std::string>
1656 {
1657  std::list<std::string> retval;
1658 
1660  i != dir_info_list.end ();
1661  i++)
1662  retval.push_back (i->dir_name);
1663 
1664  return retval;
1665 }
1666 
1668 load_path::do_files (const std::string& dir, bool omit_exts) const
1669 {
1671 
1673 
1674  if (p != dir_info_list.end ())
1675  retval = p->fcn_files;
1676 
1677  if (omit_exts)
1678  {
1679  octave_idx_type len = retval.numel ();
1680 
1681  for (octave_idx_type i = 0; i < len; i++)
1682  {
1683  std::string fname = retval[i];
1684 
1685  size_t pos = fname.rfind ('.');
1686 
1687  if (pos != std::string::npos)
1688  retval[i] = fname.substr (0, pos);
1689  }
1690  }
1691 
1692  return retval;
1693 }
1694 
1697 {
1698  return default_loader.fcn_names ();
1699 }
1700 
1703 {
1704  size_t len = fcn_map.size ();
1705 
1706  string_vector retval (len);
1707 
1708  octave_idx_type count = 0;
1709 
1710  for (const_fcn_map_iterator p = fcn_map.begin ();
1711  p != fcn_map.end ();
1712  p++)
1713  retval[count++] = p->first;
1714 
1715  return retval;
1716 }
1717 
1720 {
1721  std::string xpath;
1722 
1723  string_vector xdirs = load_path::dirs ();
1724 
1725  octave_idx_type len = xdirs.numel ();
1726 
1727  if (len > 0)
1728  xpath = xdirs[0];
1729 
1730  for (octave_idx_type i = 1; i < len; i++)
1731  xpath += octave::directory_path::path_sep_str () + xdirs[i];
1732 
1733  return xpath;
1734 }
1735 
1736 void
1737 print_types (std::ostream& os, int types)
1738 {
1739  bool printed_type = false;
1740 
1741  if (types & load_path::OCT_FILE)
1742  {
1743  os << "oct";
1744  printed_type = true;
1745  }
1746 
1747  if (types & load_path::MEX_FILE)
1748  {
1749  if (printed_type)
1750  os << "|";
1751  os << "mex";
1752  printed_type = true;
1753  }
1754 
1755  if (types & load_path::M_FILE)
1756  {
1757  if (printed_type)
1758  os << "|";
1759  os << "m";
1760  printed_type = true;
1761  }
1762 }
1763 
1764 void
1765 print_fcn_list (std::ostream& os,
1767 {
1769  p != lst.end ();
1770  p++)
1771  {
1772  os << " " << p->first << " (";
1773 
1774  print_types (os, p->second);
1775 
1776  os << ")\n";
1777  }
1778 }
1779 
1782 {
1783  octave_idx_type n = lst.size ();
1784 
1785  string_vector retval (n);
1786 
1787  octave_idx_type count = 0;
1788 
1790  p != lst.end ();
1791  p++)
1792  {
1793  std::string nm = p->first;
1794 
1795  int types = p->second;
1796 
1797  if (types & load_path::OCT_FILE)
1798  nm += ".oct";
1799  else if (types & load_path::MEX_FILE)
1800  nm += ".mex";
1801  else
1802  nm += ".m";
1803 
1804  retval[count++] = nm;
1805  }
1806 
1807  return retval;
1808 }
1809 
1810 void
1811 load_path::do_display (std::ostream& os) const
1812 {
1814  i != dir_info_list.end ();
1815  i++)
1816  {
1817  string_vector fcn_files = i->fcn_files;
1818 
1819  if (! fcn_files.empty ())
1820  {
1821  os << "\n*** function files in " << i->dir_name << ":\n\n";
1822 
1823  fcn_files.list_in_columns (os);
1824  }
1825 
1826  const dir_info::method_file_map_type& method_file_map
1827  = i->method_file_map;
1828 
1829  if (! method_file_map.empty ())
1830  {
1832  p = method_file_map.begin (); p != method_file_map.end (); p++)
1833  {
1834  os << "\n*** methods in " << i->dir_name
1835  << "/@" << p->first << ":\n\n";
1836 
1837  const dir_info::class_info& ci = p->second;
1838 
1839  string_vector method_files = get_file_list (ci.method_file_map);
1840 
1841  method_files.list_in_columns (os);
1842  }
1843  }
1844  }
1845 
1846  default_loader.display (os);
1847 
1848  for (const_loader_map_iterator l = loader_map.begin ();
1849  l != loader_map.end (); ++l)
1850  l->second.display (os);
1851 }
1852 
1853 // True if a path is contained in a path list separated by path_sep_char
1854 static bool
1855 in_path_list (const std::string& path_list, const std::string& path)
1856 {
1857  size_t ps = path.size ();
1858  size_t pls = path_list.size ();
1859  size_t pos = path_list.find (path);
1861  while (pos != std::string::npos)
1862  {
1863  if ((pos == 0 || path_list[pos-1] == psc)
1864  && (pos + ps == pls || path_list[pos + ps] == psc))
1865  return true;
1866  else
1867  pos = path_list.find (path, pos + 1);
1868  }
1869 
1870  return false;
1871 }
1872 
1873 void
1874 load_path::add (const dir_info& di, bool at_end,
1875  const std::string& pname, bool updating) const
1876 {
1877  loader& l = get_loader (pname);
1878 
1879  l.add (di, at_end, updating);
1880 
1881  dir_info::package_dir_map_type package_dir_map = di.package_dir_map;
1882 
1883  for (dir_info::const_package_dir_map_iterator p = package_dir_map.begin ();
1884  p != package_dir_map.end (); ++p)
1885  {
1886  std::string full_name = p->first;
1887 
1888  if (! pname.empty ())
1889  full_name = pname + "." + full_name;
1890 
1891  add (p->second, at_end, full_name);
1892  }
1893 }
1894 
1895 void
1897  bool updating)
1898 {
1899  std::string dir_name = di.dir_name;
1900 
1901  string_vector fcn_files = di.fcn_files;
1902 
1903  octave_idx_type len = fcn_files.numel ();
1904 
1905  for (octave_idx_type i = 0; i < len; i++)
1906  {
1907  std::string fname = fcn_files[i];
1908 
1909  std::string ext;
1910  std::string base = fname;
1911 
1912  size_t pos = fname.rfind ('.');
1913 
1914  if (pos != std::string::npos)
1915  {
1916  base = fname.substr (0, pos);
1917  ext = fname.substr (pos);
1918  }
1919 
1920  file_info_list_type& file_info_list = fcn_map[base];
1921 
1922  file_info_list_iterator p = file_info_list.begin ();
1923 
1924  while (p != file_info_list.end ())
1925  {
1926  if (p->dir_name == dir_name)
1927  break;
1928 
1929  p++;
1930  }
1931 
1932  int t = 0;
1933  if (ext == ".m")
1934  t = load_path::M_FILE;
1935  else if (ext == ".oct")
1936  t = load_path::OCT_FILE;
1937  else if (ext == ".mex")
1938  t = load_path::MEX_FILE;
1939 
1940  if (p == file_info_list.end ())
1941  {
1942  // Warn if a built-in or library function is being shadowed,
1943  // but not if we are just updating (rehashing) the list.
1944 
1945  if (! updating)
1946  {
1947  if (file_info_list.empty ())
1948  {
1950  {
1951  std::string fcn_path = octave::sys::file_ops::concat (dir_name, fname);
1952 
1953  warning_with_id ("Octave:shadowed-function",
1954  "function %s shadows a built-in function",
1955  fcn_path.c_str ());
1956  }
1957  }
1958  else if (! at_end)
1959  {
1960  file_info& old = file_info_list.front ();
1961 
1962  // FIXME: do we need to be more careful about the
1963  // way we look for old.dir_name in sys_path to avoid
1964  // partial matches?
1965 
1966  // Don't warn about Contents.m files since we expect
1967  // more than one to exist in the load path.
1968 
1969  if (fname != "Contents.m"
1970  && sys_path.find (old.dir_name) != std::string::npos
1971  && in_path_list (sys_path, old.dir_name))
1972  {
1973  std::string fcn_path = octave::sys::file_ops::concat (dir_name, fname);
1974 
1975  warning_with_id ("Octave:shadowed-function",
1976  "function %s shadows a core library function",
1977  fcn_path.c_str ());
1978  }
1979  }
1980  }
1981 
1982  file_info fi (dir_name, t);
1983 
1984  if (at_end)
1985  file_info_list.push_back (fi);
1986  else
1987  file_info_list.push_front (fi);
1988  }
1989  else
1990  {
1991  file_info& fi = *p;
1992 
1993  fi.types |= t;
1994  }
1995  }
1996 }
1997 
1998 void
2000 {
2001  dir_info::fcn_file_map_type private_file_map = di.private_file_map;
2002 
2003  if (! private_file_map.empty ())
2004  private_fcn_map[di.dir_name] = private_file_map;
2005 }
2006 
2007 void
2009 {
2010  std::string dir_name = di.dir_name;
2011 
2012  // <CLASS_NAME, CLASS_INFO>
2013  dir_info::method_file_map_type method_file_map = di.method_file_map;
2014 
2015  for (dir_info::const_method_file_map_iterator q = method_file_map.begin ();
2016  q != method_file_map.end ();
2017  q++)
2018  {
2019  std::string class_name = q->first;
2020 
2021  fcn_map_type& fm = method_map[class_name];
2022 
2023  std::string full_dir_name
2024  = octave::sys::file_ops::concat (dir_name, "@" + class_name);
2025 
2026  const dir_info::class_info& ci = q->second;
2027 
2028  // <FCN_NAME, TYPES>
2030 
2031  for (dir_info::const_fcn_file_map_iterator p = m.begin ();
2032  p != m.end ();
2033  p++)
2034  {
2035  std::string base = p->first;
2036 
2037  int types = p->second;
2038 
2039  file_info_list_type& file_info_list = fm[base];
2040 
2041  file_info_list_iterator p2 = file_info_list.begin ();
2042 
2043  while (p2 != file_info_list.end ())
2044  {
2045  if (p2->dir_name == full_dir_name)
2046  break;
2047 
2048  p2++;
2049  }
2050 
2051  if (p2 == file_info_list.end ())
2052  {
2053  file_info fi (full_dir_name, types);
2054 
2055  if (at_end)
2056  file_info_list.push_back (fi);
2057  else
2058  file_info_list.push_front (fi);
2059  }
2060  else
2061  {
2062  // FIXME: is this possible?
2063 
2064  file_info& fi = *p2;
2065 
2066  fi.types = types;
2067  }
2068  }
2069 
2070  // <FCN_NAME, TYPES>
2071  dir_info::fcn_file_map_type private_file_map = ci.private_file_map;
2072 
2073  if (! private_file_map.empty ())
2074  private_fcn_map[full_dir_name] = private_file_map;
2075  }
2076 }
2077 
2078 void
2079 load_path::loader::display (std::ostream& os) const
2080 {
2081  os << "*** loader: " << (prefix.empty () ? "<top-level>" : prefix) << "\n\n";
2082 
2083  for (std::list<std::string>::const_iterator s = dir_list.begin ();
2084  s != dir_list.end (); ++s)
2085  os << *s << "\n";
2086  os << "\n";
2087 
2088  for (const_private_fcn_map_iterator i = private_fcn_map.begin ();
2089  i != private_fcn_map.end (); i++)
2090  {
2091  os << "\n*** private functions in "
2092  << octave::sys::file_ops::concat (i->first, "private") << ":\n\n";
2093 
2094  print_fcn_list (os, i->second);
2095  }
2096 
2097 #if defined (DEBUG_LOAD_PATH)
2098 
2099  for (const_fcn_map_iterator i = fcn_map.begin ();
2100  i != fcn_map.end ();
2101  i++)
2102  {
2103  os << i->first << ":\n";
2104 
2105  const file_info_list_type& file_info_list = i->second;
2106 
2107  for (const_file_info_list_iterator p = file_info_list.begin ();
2108  p != file_info_list.end ();
2109  p++)
2110  {
2111  os << " " << p->dir_name << " (";
2112 
2113  print_types (os, p->types);
2114 
2115  os << ")\n";
2116  }
2117  }
2118 
2119  for (const_method_map_iterator i = method_map.begin ();
2120  i != method_map.end ();
2121  i++)
2122  {
2123  os << "CLASS " << i->first << ":\n";
2124 
2125  const fcn_map_type& fm = i->second;
2126 
2127  for (const_fcn_map_iterator q = fm.begin ();
2128  q != fm.end ();
2129  q++)
2130  {
2131  os << " " << q->first << ":\n";
2132 
2133  const file_info_list_type& file_info_list = q->second;
2134 
2135  for (const_file_info_list_iterator p = file_info_list.begin ();
2136  p != file_info_list.end ();
2137  p++)
2138  {
2139  os << " " << p->dir_name << " (";
2140 
2141  print_types (os, p->types);
2142 
2143  os << ")\n";
2144  }
2145  }
2146  }
2147 
2148  os << "\n";
2149 
2150 #endif
2151 }
2152 
2154 genpath (const std::string& dirname, const string_vector& skip)
2155 {
2157 
2158  octave::sys::dir_entry dir (dirname);
2159 
2160  if (dir)
2161  {
2162  retval = dirname;
2163 
2164  string_vector dirlist = dir.read ().sort (false);
2165 
2166  octave_idx_type len = dirlist.numel ();
2167 
2168  for (octave_idx_type i = 0; i < len; i++)
2169  {
2170  std::string elt = dirlist[i];
2171 
2172  bool skip_p = (elt == "." || elt == ".." || elt[0] == '@'
2173  || elt[0] == '+');
2174 
2175  if (! skip_p)
2176  {
2177  for (octave_idx_type j = 0; j < skip.numel (); j++)
2178  {
2179  skip_p = (elt == skip[j]);
2180  if (skip_p)
2181  break;
2182  }
2183 
2184  if (! skip_p)
2185  {
2186  std::string nm = octave::sys::file_ops::concat (dirname, elt);
2187 
2189 
2190  if (fs && fs.is_dir ())
2191  retval += octave::directory_path::path_sep_str () + genpath (nm, skip);
2192  }
2193  }
2194  }
2195  }
2196 
2197  return retval;
2198 }
2199 
2200 std::list<std::string>
2201 load_path::do_get_all_package_names (bool only_top_level) const
2202 {
2203  std::list<std::string> retval;
2204 
2205  for (const_loader_map_iterator l = loader_map.begin ();
2206  l != loader_map.end (); ++l)
2207  {
2208  if (! only_top_level || l->first.find ('.') == std::string::npos)
2209  retval.push_back (l->first);
2210  }
2211 
2212  return retval;
2213 }
2214 
2215 static void
2217  const std::string& script_file)
2218 {
2220  return;
2221 
2223 
2224  std::string file = octave::sys::file_ops::concat (dir, script_file);
2225 
2226  octave::sys::file_stat fs (file);
2227 
2228  if (fs.exists ())
2229  source_file (file, "base");
2230 }
2231 
2232 void
2234 {
2235  execute_pkg_add_or_del (dir, "PKG_ADD");
2236 }
2237 
2238 void
2240 {
2241  execute_pkg_add_or_del (dir, "PKG_DEL");
2242 }
2243 
2244 DEFUN (genpath, args, ,
2245  doc: /* -*- texinfo -*-
2246 @deftypefn {} {} genpath (@var{dir})
2247 @deftypefnx {} {} genpath (@var{dir}, @var{skip}, @dots{})
2248 Return a path constructed from @var{dir} and all its subdirectories.
2249 
2250 If additional string parameters are given, the resulting path will exclude
2251 directories with those names.
2252 @end deftypefn */)
2253 {
2254  int nargin = args.length ();
2255 
2256  if (nargin == 0)
2257  print_usage ();
2258 
2260 
2261  if (nargin == 1)
2262  {
2263  std::string dirname = args(0).xstring_value ("genpath: DIR must be a string");
2264 
2265  retval = genpath (dirname);
2266  }
2267  else
2268  {
2269  std::string dirname = args(0).xstring_value ("genpath: all arguments must be strings");
2270 
2271  string_vector skip (nargin - 1);
2272 
2273  for (octave_idx_type i = 1; i < nargin; i++)
2274  skip[i-1] = args(i).xstring_value ("genpath: all arguments must be strings");
2275 
2276  retval = genpath (dirname, skip);
2277  }
2278 
2279  return retval;
2280 }
2281 
2282 static void
2284 {
2285  load_path::update ();
2286 
2287  // FIXME: maybe we should rename this variable since it is being
2288  // used for more than keeping track of the prompt time.
2289 
2290  // This will force updated functions to be found.
2292 }
2293 
2294 DEFUN (rehash, , ,
2295  doc: /* -*- texinfo -*-
2296 @deftypefn {} {} rehash ()
2297 Reinitialize Octave's load path directory cache.
2298 @end deftypefn */)
2299 {
2300  rehash_internal ();
2301 
2302  return ovl ();
2303 }
2304 
2306  doc: /* -*- texinfo -*-
2307 @deftypefn {} {} command_line_path (@dots{})
2308 Return the command line path variable.
2309 
2310 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}
2311 @end deftypefn */)
2312 {
2314 }
2316 DEFUN (restoredefaultpath, , ,
2317  doc: /* -*- texinfo -*-
2318 @deftypefn {} {} restoredefaultpath (@dots{})
2319 Restore Octave's path to its initial state at startup.
2320 
2321 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}
2322 @end deftypefn */)
2323 {
2324  load_path::initialize (true);
2325 
2326  return ovl (load_path::system_path ());
2327 }
2328 
2329 // Return Octave's original default list of directories in which to
2330 // search for function files. This corresponds to the path that
2331 // exists prior to running the system's octaverc file or the user's
2332 // ~/.octaverc file
2333 
2334 DEFUN (__pathorig__, , ,
2335  doc: /* -*- texinfo -*-
2336 @deftypefn {} {@var{val} =} __pathorig__ ()
2337 Undocumented internal function.
2338 @end deftypefn */)
2340  return ovl (load_path::system_path ());
2341 }
2342 
2343 DEFUN (path, args, nargout,
2344  doc: /* -*- texinfo -*-
2345 @deftypefn {} {} path ()
2346 @deftypefnx {} {@var{str} =} path ()
2347 @deftypefnx {} {@var{str} =} path (@var{path1}, @dots{})
2348 Modify or display Octave's load path.
2349 
2350 If @var{nargin} and @var{nargout} are zero, display the elements of
2351 Octave's load path in an easy to read format.
2352 
2353 If @var{nargin} is zero and nargout is greater than zero, return the
2354 current load path.
2355 
2356 If @var{nargin} is greater than zero, concatenate the arguments,
2357 separating them with @code{pathsep}. Set the internal search path
2358 to the result and return it.
2359 
2360 No checks are made for duplicate elements.
2361 @seealso{addpath, rmpath, genpath, pathdef, savepath, pathsep}
2362 @end deftypefn */)
2363 {
2364  int nargin = args.length ();
2365 
2366  string_vector argv = args.make_argv ("path");
2367 
2368  if (nargin > 0)
2369  {
2370  std::string path = argv[1];
2371 
2372  for (int i = 2; i <= nargin; i++)
2373  path += octave::directory_path::path_sep_str () + argv[i];
2374 
2375  load_path::set (path, true);
2376 
2377  rehash_internal ();
2378  }
2379 
2380  if (nargout > 0)
2381  return ovl (load_path::path ());
2382  else if (nargin == 0 && nargout == 0)
2383  {
2384  octave_stdout <<
2385  "\nOctave's search path contains the following directories:\n\n";
2386 
2388 
2390 
2391  octave_stdout << "\n";
2392  }
2393 
2394  return ovl ();
2395 }
2396 
2397 DEFUN (addpath, args, nargout,
2398  doc: /* -*- texinfo -*-
2399 @deftypefn {} {} addpath (@var{dir1}, @dots{})
2400 @deftypefnx {} {} addpath (@var{dir1}, @dots{}, @var{option})
2401 Add named directories to the function search path.
2402 
2403 If @var{option} is @qcode{"-begin"} or 0 (the default), prepend the
2404 directory name to the current path. If @var{option} is @qcode{"-end"}
2405 or 1, append the directory name to the current path.
2406 Directories added to the path must exist.
2407 
2408 In addition to accepting individual directory arguments, lists of
2409 directory names separated by @code{pathsep} are also accepted. For example:
2410 
2411 @example
2412 addpath ("dir1:/dir2:~/dir3")
2413 @end example
2414 
2415 For each directory that is added, and that was not already in the path,
2416 @code{addpath} checks for the existence of a file named @file{PKG_ADD}
2417 (note lack of .m extension) and runs it if it exists.
2418 
2419 @seealso{path, rmpath, genpath, pathdef, savepath, pathsep}
2420 @end deftypefn */)
2421 {
2422  // Originally written by Bill Denney and Etienne Grossman.
2423  // Heavily modified and translated to C++ by jwe.
2424 
2425  int nargin = args.length ();
2426 
2427  if (nargin == 0)
2428  print_usage ();
2429 
2431 
2432  if (nargout > 0)
2433  retval = load_path::path ();
2434 
2435  bool append = false;
2436 
2437  octave_value option_arg = args(nargin-1);
2438 
2439  if (option_arg.is_string ())
2440  {
2441  std::string option = option_arg.string_value ();
2442 
2443  if (option == "-end")
2444  {
2445  append = true;
2446  nargin--;
2447  }
2448  else if (option == "-begin")
2449  nargin--;
2450  }
2451  else if (option_arg.is_numeric_type ())
2452  {
2453  int val = option_arg.xint_value ("addpath: OPTION must be '-begin'/0 or '-end'/1");
2454 
2455  if (val == 0)
2456  nargin--;
2457  else if (val == 1)
2458  {
2459  append = true;
2460  nargin--;
2461  }
2462  else
2463  error ("addpath: OPTION must be '-begin'/0 or '-end'/1");
2464  }
2465 
2466  bool need_to_update = false;
2467 
2468  octave_value_list arglist (args.slice (0, nargin));
2469  if (! append)
2470  arglist.reverse ();
2471 
2472  for (int i = 0; i < arglist.length (); i++)
2473  {
2474  std::string arg = arglist(i).xstring_value ("addpath: all arguments must be strings");
2475 
2476  std::list<std::string> dir_elts = split_path (arg);
2477 
2478  if (! append)
2479  std::reverse (dir_elts.begin (), dir_elts.end ());
2480 
2481  for (const auto& p : dir_elts)
2482  {
2483  std::string dir = p;
2484 
2485  // Remove duplicate directory separators
2486  dir.erase (std::unique (dir.begin (), dir.end (),
2487  [](char l, char r)
2488  {
2489  return l == r &&
2491  }),
2492  dir.end ());
2493 
2494  if (append)
2495  load_path::append (dir, true);
2496  else
2497  load_path::prepend (dir, true);
2498 
2499  need_to_update = true;
2500  }
2501  }
2502 
2503  if (need_to_update)
2504  rehash_internal ();
2505 
2506  return retval;
2507 }
2508 
2510  doc: /* -*- texinfo -*-
2511 @deftypefn {} {} rmpath (@var{dir1}, @dots{})
2512 Remove @var{dir1}, @dots{} from the current function search path.
2513 
2514 In addition to accepting individual directory arguments, lists of
2515 directory names separated by @code{pathsep} are also accepted. For example:
2516 
2517 @example
2518 rmpath ("dir1:/dir2:~/dir3")
2519 @end example
2520 
2521 For each directory that is removed, @code{rmpath} checks for the
2522 existence of a file named @file{PKG_DEL} (note lack of .m extension)
2523 and runs it if it exists.
2524 
2525 @seealso{path, addpath, genpath, pathdef, savepath, pathsep}
2526 @end deftypefn */)
2527 {
2528  // Originally written by Etienne Grossmann. Heavily modified and translated
2529  // to C++ by jwe.
2530 
2531  int nargin = args.length ();
2532 
2533  if (nargin == 0)
2534  print_usage ();
2535 
2537 
2538  if (nargout > 0)
2539  retval = load_path::path ();
2540 
2541  bool need_to_update = false;
2542 
2543  for (int i = 0; i < nargin; i++)
2544  {
2545  std::string arg = args(i).xstring_value ("rmpath: all arguments must be strings");
2546  std::list<std::string> dir_elts = split_path (arg);
2547 
2548  for (std::list<std::string>::const_iterator p = dir_elts.begin ();
2549  p != dir_elts.end ();
2550  p++)
2551  {
2552  std::string dir = *p;
2553 
2554  //dir = regexprep (dir_elts{j}, '//+', "/");
2555  //dir = regexprep (dir, '/$', "");
2556 
2557  if (! load_path::remove (dir))
2558  warning ("rmpath: %s: not found", dir.c_str ());
2559  else
2560  need_to_update = true;
2561  }
2562  }
2563 
2564  if (need_to_update)
2565  rehash_internal ();
2566 
2567  return retval;
2568 }
2569 
2570 DEFUN (__dump_load_path__, , ,
2571  doc: /* -*- texinfo -*-
2572 @deftypefn {} {} __dump_load_path__ ()
2573 Undocumented internal function.
2574 @end deftypefn */)
2575 {
2577 
2578  return ovl ();
2579 }
fcn_map_type::iterator fcn_map_iterator
Definition: load-path.h:483
static void maybe_add_path_elts(std::string &path, const std::string &dir)
Definition: load-path.cc:570
static std::string dir_sep_str(void)
Definition: file-ops.h:80
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:803
void update(void)
Definition: load-path.cc:56
option
Definition: sighandlers.cc:767
void remove_private_fcn_map(const std::string &dir)
Definition: load-path.cc:845
static std::string system_path(void)
Definition: load-path.h:286
static bool in_path_list(const std::string &path_list, const std::string &path)
Definition: load-path.cc:1855
void do_update(void) const
Definition: load-path.cc:973
friend void print_types(std::ostream &os, int types)
Definition: load-path.cc:1737
std::set< std::string > init_dirs
Definition: load-path.h:618
method_file_map_type method_file_map
Definition: load-path.h:403
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:120
std::string find_private_file(const std::string &fname)
Definition: load-path.cc:1300
bool same_file(const std::string &f, const std::string &g)
Definition: utils.cc:130
std::string Vlocal_oct_file_dir
Definition: defaults.cc:68
fcn_file_map_type private_file_map
Definition: load-path.h:402
octave::sys::time mtime(void) const
Definition: file-stat.h:128
method_map_type::iterator method_map_iterator
Definition: load-path.h:496
static void display(std::ostream &os)
Definition: load-path.h:257
void get_package_dir(const std::string &d, const std::string &package_name)
Definition: load-path.cc:324
fname
Definition: load-save.cc:754
void get_file_list(const std::string &d)
Definition: load-path.cc:186
void move(const dir_info &di, bool at_end, const std::string &pname="")
Definition: load-path.cc:524
std::string do_find_dir(const std::string &dir) const
Definition: load-path.cc:1394
std::string Vlocal_fcn_file_dir
Definition: defaults.cc:72
static void prepend(const std::string &dir, bool warn=false)
Definition: load-path.h:77
string_vector do_find_matching_dirs(const std::string &dir) const
Definition: load-path.cc:1441
std::map< std::string, int > fcn_file_map_type
Definition: load-path.h:302
static std::string command_line_path
Definition: load-path.h:628
OCTINTERP_API void print_usage(void)
Definition: defun.cc:52
std::string Vlocal_ver_fcn_file_dir
Definition: defaults.cc:70
dir_info_list_type::iterator dir_info_list_iterator
Definition: load-path.h:467
static void append(const std::string &dir, bool warn=false)
Definition: load-path.h:71
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
static std::string dir_sep_chars(void)
Definition: file-ops.h:85
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
std::map< std::string, dir_info > package_dir_map_type
Definition: load-path.h:338
octave::sys::time dir_time_last_checked
Definition: load-path.h:399
void get_private_file_map(const std::string &d)
Definition: load-path.cc:304
int xint_value(const char *fmt,...) const
Definition: ov.cc:2047
bool is_numeric_type(void) const
Definition: ov.h:679
loader & get_loader(const std::string &name) const
Definition: load-path.h:673
bool empty(void) const
Definition: str-vec.h:79
for large enough k
Definition: lu.cc:606
string_vector do_find_all_first_of(const string_vector &files) const
Definition: load-path.cc:1568
file_info_list_type::const_iterator const_file_info_list_iterator
Definition: load-path.h:476
fcn_file_map_type private_file_map
Definition: load-path.h:328
octave::sys::time dir_mtime
Definition: load-path.h:398
void add(const dir_info &di, bool at_end, bool updating)
Definition: load-path.h:525
dir_info_list_type dir_info_list
Definition: load-path.h:616
void protect_var(T &var)
void remove(const dir_info &di)
Definition: load-path.cc:957
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
void error(const char *fmt,...)
Definition: error.cc:570
private_fcn_map_type::const_iterator const_private_fcn_map_iterator
Definition: load-path.h:489
void move_method_map(const std::string &dir, bool at_end)
Definition: load-path.cc:462
std::string Vfcn_file_dir
Definition: defaults.cc:79
static abs_dir_cache_type abs_dir_cache
Definition: load-path.h:632
size_type size(const size_type d) const
Size of the specified dimension.
Definition: Array.h:428
static double fi[256]
Definition: randmtzig.cc:440
private_fcn_map_type::iterator private_fcn_map_iterator
Definition: load-path.h:490
void(* hook_fcn_ptr)(const std::string &dir)
Definition: load-path.h:49
std::string find_fcn(const std::string &fcn, std::string &dir_name, int type=M_FILE|OCT_FILE|MEX_FILE) const
Definition: load-path.cc:1090
octave::sys::time Vlast_prompt_time
Definition: input.cc:96
std::string do_find_first_of(const string_vector &files) const
Definition: load-path.cc:1488
static bool rooted_relative_pathname(const std::string &s)
Definition: oct-env.cc:115
void overloads(const std::string &meth, std::list< std::string > &l) const
Definition: load-path.cc:1276
string_vector do_fcn_names(void) const
Definition: load-path.cc:1696
void do_initialize(bool set_initial_path)
Definition: load-path.cc:584
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:935
static std::string find_method(const std::string &class_name, const std::string &meth, std::string &dir_name, const std::string &pack_name="")
Definition: load-path.h:99
static const int MEX_FILE
Definition: load-path.h:295
std::string dir_name
Definition: load-path.h:395
method_map_type::const_iterator const_method_map_iterator
Definition: load-path.h:495
std::string xstring_value(const char *fmt,...) const
Definition: ov.cc:2122
Definition: dir-ops.h:36
s
Definition: file-io.cc:2682
static void execute_pkg_add_or_del(const std::string &dir, const std::string &script_file)
Definition: load-path.cc:2216
static std::string tilde_expand(const std::string &)
Definition: file-ops.cc:301
void resize(octave_idx_type n, const std::string &rfv="")
Definition: str-vec.h:97
octave_value arg
Definition: pr-output.cc:3440
load_path(void)
Definition: load-path.h:44
static void rehash_internal(void)
Definition: load-path.cc:2283
octave_function * fcn
Definition: ov-class.cc:1743
std::string Voct_data_dir
Definition: defaults.cc:74
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
bool is_reg(void) const
Definition: file-stat.cc:75
static std::string getenv(const std::string &name)
Definition: oct-env.cc:235
string_vector argv
Definition: load-save.cc:635
void remove_fcn_map(const std::string &dir, const string_vector &fcn_files)
Definition: load-path.cc:805
void do_append(const std::string &dir, bool warn)
Definition: load-path.cc:718
string_vector fcn_files
Definition: load-path.h:401
string_vector read(void)
Definition: dir-ops.cc:70
OCTAVE_EXPORT octave_value_list search each directory of the loadpath for element of the cell array and return the first that matches If the second optional argument return a cell array containing the list of all files that have the same name in the path If no files are found
Definition: utils.cc:302
static hook_fcn_ptr remove_hook
Definition: load-path.h:626
JNIEnv void * args
Definition: ov-java.cc:67
std::list< file_info > file_info_list_type
Definition: load-path.h:474
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
Definition: oct-env.cc:129
static void cleanup_instance(void)
Definition: load-path.h:622
bool is_dir(void) const
Definition: file-stat.cc:57
std::list< std::string > methods(const std::string &class_name) const
Definition: load-path.cc:1223
done
Definition: syscalls.cc:248
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
void add(const dir_info &di, bool at_end, const std::string &pname="", bool updating=false) const
Definition: load-path.cc:1874
std::map< std::string, file_info_list_type > fcn_map_type
Definition: load-path.h:480
std::string do_find_file(const std::string &file) const
Definition: load-path.cc:1333
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
static hook_fcn_ptr add_hook
Definition: load-path.h:624
bool valid_identifier(const char *s)
Definition: utils.cc:74
std::string Vlocal_api_fcn_file_dir
Definition: defaults.cc:71
std::string string_value(bool force=false) const
Definition: ov.h:908
fcn_file_map_type::const_iterator const_fcn_file_map_iterator
Definition: load-path.h:304
if(nargin< 2) print_usage()
Definition: cellfun.cc:405
string_vector do_files(const std::string &dir, bool omit_exts) const
Definition: load-path.cc:1668
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
octave_value_list & reverse(void)
Definition: ovl.cc:111
static void add(fptr f)
std::string find_method(const std::string &class_name, const std::string &meth, std::string &dir_name, int type=M_FILE|OCT_FILE|MEX_FILE) const
Definition: load-path.cc:1175
static bool instance_ok(void)
Definition: load-path.cc:331
static void execute_pkg_add(const std::string &dir)
Definition: load-path.cc:2233
static std::string sys_path
Definition: load-path.h:630
int nargin
Definition: graphics.cc:10115
std::string dir_name
Definition: load-path.h:447
bool is_string(void) const
Definition: ov.h:578
std::map< std::string, dir_info > abs_dir_cache_type
Definition: load-path.h:469
friend dir_info::fcn_file_map_type get_fcn_files(const std::string &d)
Definition: load-path.cc:254
void add_to_private_fcn_map(const dir_info &di)
Definition: load-path.cc:1999
static bool absolute_pathname(const std::string &s)
Definition: oct-env.cc:108
void do_prepend(const std::string &dir, bool warn)
Definition: load-path.cc:725
static void initialize(bool set_initial_path=false)
Definition: load-path.h:53
static char path_sep_char(void)
Definition: pathsearch.h:99
std::list< std::string > do_overloads(const std::string &meth) const
Definition: load-path.cc:1260
std::list< std::string > do_get_all_package_names(bool only_top_level) const
Definition: load-path.cc:2201
octave_value retval
Definition: data.cc:6294
loader default_loader
Definition: load-path.h:614
std::string find_private_fcn(const std::string &dir, const std::string &fcn, int type=M_FILE|OCT_FILE|MEX_FILE) const
Definition: load-path.cc:1145
std::list< std::string > do_dir_list(void) const
Definition: load-path.cc:1655
dir_info_list_type::const_iterator const_dir_info_list_iterator
Definition: load-path.h:466
OCTAVE_EXPORT octave_value_list genpath
Definition: load-path.cc:2298
friend string_vector get_file_list(const dir_info::fcn_file_map_type &lst)
Definition: load-path.cc:1781
string_vector & sort(bool make_uniq=false)
Definition: str-vec.cc:74
octave_idx_type length(void) const
Definition: ov.cc:1623
idx type
Definition: ov.cc:3129
std::ostream & list_in_columns(std::ostream &, int width=0, const std::string &prefix="") const
Definition: str-vec.cc:195
string_vector do_dirs(void) const
Definition: load-path.cc:1638
bool exists(void) const
Definition: file-stat.h:144
void move(const dir_info &di, bool at_end)
Definition: load-path.cc:545
std::string do_path(void) const
Definition: load-path.cc:1719
file_info_list_type::iterator file_info_list_iterator
Definition: load-path.h:477
void get_method_file_map(const std::string &d, const std::string &class_name)
Definition: load-path.cc:310
static octave_user_function * get_curr_fcn(scope_id scope=xcurrent_scope)
Definition: symtab.h:2316
void move_fcn_map(const std::string &dir, const string_vector &fcn_files, bool at_end)
Definition: load-path.cc:413
std::string pname
Definition: graphics.cc:11207
abs_dir_cache_type::iterator abs_dir_cache_iterator
Definition: load-path.h:472
package_dir_map_type::const_iterator const_package_dir_map_iterator
Definition: load-path.h:340
std::string Vlocal_ver_oct_file_dir
Definition: defaults.cc:66
static load_path * instance
Definition: load-path.h:620
const_dir_info_list_iterator find_dir_info(const std::string &dir) const
Definition: load-path.cc:352
static std::string concat(const std::string &, const std::string &)
Definition: file-ops.cc:375
bool octave_interpreter_ready
Definition: interpreter.cc:79
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
Definition: colamd.cc:112
method_file_map_type::const_iterator const_method_file_map_iterator
Definition: load-path.h:334
void warning(const char *fmt,...)
Definition: error.cc:788
std::string dir_name(void) const
Definition: ov-fcn.h:125
OCTAVE_EXPORT octave_value_list rmpath
Definition: load-path.cc:2298
octave::unwind_protect frame
Definition: graphics.cc:11584
void recover_from_exception(void)
Definition: interpreter.cc:200
void do_set(const std::string &p, bool warn, bool is_init=false)
Definition: load-path.cc:665
virtual void run_first(void)=0
static std::string path_sep_str(void)
Definition: pathsearch.h:109
octave::sys::time time_resolution(void) const
Definition: file-stat.h:86
#define octave_stdout
Definition: pager.h:146
std::string Voct_file_dir
Definition: defaults.cc:78
static void update(void)
Definition: load-path.h:88
static std::string strip_trailing_separators(const std::string &dir_arg)
Definition: load-path.cc:734
void remove_method_map(const std::string &dir)
Definition: load-path.cc:854
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
void do_clear(void)
Definition: load-path.cc:622
string_vector fcn_names(void) const
Definition: load-path.cc:1702
fcn_map_type::const_iterator const_fcn_map_iterator
Definition: load-path.h:482
p
Definition: lu.cc:138
void add_to_method_map(const dir_info &di, bool at_end)
Definition: load-path.cc:2008
std::string abs_dir_name
Definition: load-path.h:396
static std::list< std::string > split_path(const std::string &p)
Definition: load-path.cc:632
fcn_file_map_type method_file_map
Definition: load-path.h:327
static const int M_FILE
Definition: load-path.h:293
static string_vector dirs(void)
Definition: load-path.h:230
void do_add(const std::string &dir, bool at_end, bool warn)
Definition: load-path.cc:750
static std::list< std::string > dir_list(void)
Definition: load-path.h:235
octave::sys::file_stat fs(filename)
string_vector all_files
Definition: load-path.h:400
void do_move(dir_info_list_iterator i, bool at_end)
Definition: load-path.cc:506
bool contains(const std::string &dir) const
Definition: load-path.cc:388
package_dir_map_type package_dir_map
Definition: load-path.h:404
bool is_package(const std::string &name) const
Definition: load-path.cc:1246
loader_map_type::const_iterator const_loader_map_iterator
Definition: load-path.h:609
bool do_remove(const std::string &dir)
Definition: load-path.cc:895
static void set(const std::string &p, bool warn=false)
Definition: load-path.h:65
std::string error(void) const
Definition: file-stat.h:146
static bool is_built_in_function_name(const std::string &name)
Definition: symtab.h:1487
static std::string get_command_line_path(void)
Definition: load-path.h:280
friend void print_fcn_list(std::ostream &os, const dir_info::fcn_file_map_type &lst)
Definition: load-path.cc:1765
bool is_package(const std::string &name) const
Definition: load-path.cc:121
void display(std::ostream &out) const
Definition: load-path.cc:2079
OCTAVE_EXPORT octave_value_list pathsep end deftypefn *return ovl(load_path::system_path())
static bool check_file_type(std::string &fname, int type, int possible_types, const std::string &fcn, const char *who)
Definition: load-path.cc:996
loader_map_type loader_map
Definition: load-path.h:612
void clear(void)
Definition: load-path.h:543
OCTINTERP_API void source_file(const std::string &file_name, const std::string &context="", bool verbose=false, bool require_file=true, const std::string &warn_for="")
static const int OCT_FILE
Definition: load-path.h:294
void initialize(void)
Definition: load-path.cc:142
std::string error(void) const
Definition: dir-ops.h:77
static std::string path(void)
Definition: load-path.h:252
std::map< std::string, class_info > method_file_map_type
Definition: load-path.h:332
void stamp(void)
Definition: oct-time.cc:92
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
static void execute_pkg_del(const std::string &dir)
Definition: load-path.cc:2239
static bool remove(const std::string &dir)
Definition: load-path.h:83
void add_to_fcn_map(const dir_info &di, bool at_end, bool updating)
Definition: load-path.cc:1896
bool do_contains_canonical(const std::string &dir) const
Definition: load-path.cc:394
static bool is_dir_sep(char c)
Definition: file-ops.h:90
void do_display(std::ostream &os) const
Definition: load-path.cc:1811
std::string Vlocal_api_oct_file_dir
Definition: defaults.cc:67