93 catch (octave_execution_exception)
106 std::string msg = fs.
error ();
116 dir_time_last_checked =
octave_time (static_cast<time_t> (0));
122 method_file_map.clear ();
124 dir_mtime = fs.
mtime ();
139 catch (octave_execution_exception)
146 std::string msg = fs.
error ();
147 warning (
"load_path: %s: %s", dir_name.c_str (), msg.c_str ());
162 all_files.resize (len);
163 fcn_files.resize (len);
170 std::string fname = flist[i];
180 if (fname ==
"private")
181 get_private_file_map (full_name);
182 else if (fname[0] ==
'@')
183 get_method_file_map (full_name, fname.substr (1));
187 all_files[all_files_count++] = fname;
189 size_t pos = fname.rfind (
'.');
191 if (pos != std::string::npos)
193 std::string ext = fname.substr (pos);
195 if (ext ==
".m" || ext ==
".oct" || ext ==
".mex")
197 std::string base = fname.substr (0, pos);
200 fcn_files[fcn_files_count++] = fname;
207 all_files.resize (all_files_count);
208 fcn_files.resize (fcn_files_count);
212 std::string msg = dir.
error ();
213 warning (
"load_path: %s: %s", d.c_str (), msg.c_str ());
232 std::string fname = flist[i];
235 std::string base = fname;
237 size_t pos = fname.rfind (
'.');
239 if (pos != std::string::npos)
241 base = fname.substr (0, pos);
242 ext = fname.substr (pos);
250 else if (ext ==
".oct")
252 else if (ext ==
".mex")
262 std::string msg = dir.
error ();
263 warning (
"load_path: %s: %s", d.c_str (), msg.c_str ());
277 const std::string& class_name)
279 method_file_map[class_name].method_file_map =
get_fcn_files (d);
286 method_file_map[class_name].private_file_map =
get_fcn_files (pd);
304 ::error (
"unable to create load path object!");
323 if (retval->dir_name == dir)
341 if (retval->dir_name == dir)
383 std::string fname = fcn_files[k];
386 std::string base = fname;
388 size_t pos = fname.rfind (
'.');
390 if (pos != std::string::npos)
392 base = fname.substr (0, pos);
393 ext = fname.substr (pos);
398 if (file_info_list.size () == 1)
403 p != file_info_list.end ();
406 if (p->dir_name == dir_name)
410 file_info_list.erase (p);
413 file_info_list.push_back (fi);
415 file_info_list.push_front (fi);
431 std::string class_name = i->first;
435 std::string full_dir_name
442 if (file_info_list.size () == 1)
447 p != file_info_list.end (); p++)
449 if (p->dir_name == full_dir_name)
453 file_info_list.erase (p);
456 file_info_list.push_back (fi);
458 file_info_list.push_front (fi);
495 std::string tpath =
genpath (dir);
497 if (! tpath.empty ())
511 if (set_initial_path)
530 if (! tpath.empty ())
540 do_set (xpath,
false,
true);
552 static std::list<std::string>
555 std::list<std::string> retval;
560 size_t len = p.length ();
562 while (end != std::string::npos)
564 std::string elt = p.substr (beg, end-beg);
567 retval.push_back (elt);
577 std::string elt = p.substr (beg);
580 retval.push_back (elt);
592 std::set<std::string> elts_set (elts.begin (), elts.end ());
598 for (std::set<std::string>::const_iterator it =
init_dirs.begin ();
601 if (elts_set.find (*it) == elts_set.end ())
604 "default load path altered. Some built-in functions may not be found. Try restoredefaultpath() to recover it.");
619 for (std::list<std::string>::const_iterator i = elts.begin ();
620 i != elts.end (); i++)
649 do_add (dir,
false, warn);
657 std::string dir = dir_arg;
659 size_t k = dir.length ();
664 if (k < dir.length ())
673 size_t len = dir_arg.length ();
675 if (len > 1 && dir_arg.substr (len-2) ==
"//")
677 "trailing '//' is no longer special in search path elements");
715 warning (
"addpath: %s: not a directory", dir_arg.c_str ());
719 std::string msg = fs.
error ();
720 warning (
"addpath: %s: %s", dir_arg.c_str (), msg.c_str ());
740 std::string fname = fcn_files[k];
743 std::string base = fname;
745 size_t pos = fname.rfind (
'.');
747 if (pos != std::string::npos)
749 base = fname.substr (0, pos);
750 ext = fname.substr (pos);
756 p != file_info_list.end ();
759 if (p->dir_name == dir)
761 file_info_list.erase (p);
763 if (file_info_list.empty ())
788 std::string class_name = i->first;
798 if (file_info_list.size () == 1)
803 p != file_info_list.end (); p++)
805 if (p->dir_name == full_dir_name)
807 file_info_list.erase (p);
826 if (! dir_arg.empty ())
830 warning (
"rmpath: can't remove \".\" from path");
897 const std::string& fcn,
const char *who)
984 error (
"%s: %s: invalid type code = %d", who, fcn.c_str (),
type);
997 if (fcn.length () > 0 && fcn[0] ==
'@')
999 size_t pos = fcn.find (
'/');
1001 if (pos != std::string::npos)
1003 std::string class_name = fcn.substr (1, pos-1);
1004 std::string meth = fcn.substr (pos+1);
1009 retval = std::string ();
1013 dir_name = std::string ();
1022 i != file_info_list.end ();
1030 fcn,
"load_path::do_find_fcn"))
1036 retval = std::string ();
1046 const std::string& fcn,
int type)
const
1066 "load_path::find_private_fcn"))
1076 const std::string& meth,
1077 std::string& dir_name,
int type)
const
1083 dir_name = std::string ();
1098 i != file_info_list.end ();
1106 meth,
"load_path::do_find_method");
1114 retval = std::string ();
1122 std::list<std::string>
1125 std::list<std::string> retval;
1136 retval.push_back (p->first);
1139 if (! retval.empty ())
1145 std::list<std::string>
1148 std::list<std::string> retval;
1157 if (m.find (meth) != m.end ())
1158 retval.push_back (q->first);
1206 if (all_files[i] == file)
1237 size_t dname_len = dname.length ();
1241 dname = dname.substr (0, dname_len - 1);
1245 size_t dir_len = dir.length ();
1247 if (dname_len >= dir_len
1249 && dir.compare (dname.substr (dname_len - dir_len)) == 0)
1265 std::list<std::string> retlist;
1274 retlist.push_back (dir);
1284 size_t dname_len = dname.length ();
1288 dname = dname.substr (0, dname_len - 1);
1292 size_t dir_len = dir.length ();
1294 if (dname_len >= dir_len
1296 && dir.compare (dname.substr (dname_len - dir_len)) == 0)
1301 retlist.push_back (p->dir_name);
1314 std::string dir_name;
1315 std::string file_name;
1324 std::string file = flist[i];
1352 rel_flist[rel_flen++] = file;
1355 rel_flist.
resize (rel_flen);
1369 if (all_files[i] == rel_flist[j])
1371 dir_name = p->dir_name;
1372 file_name = rel_flist[j];
1382 if (! dir_name.empty ())
1391 std::list<std::string> retlist;
1393 std::string dir_name;
1394 std::string file_name;
1403 std::string file = flist[i];
1413 retlist.push_back (file);
1426 retlist.push_back (tfile);
1431 rel_flist[rel_flen++] = file;
1434 rel_flist.
resize (rel_flen);
1447 if (all_files[i] == rel_flist[j])
1469 retval[k++] = i->dir_name;
1474 std::list<std::string>
1477 std::list<std::string> retval;
1482 retval.push_back (i->dir_name);
1495 retval = p->fcn_files;
1503 std::string fname = retval[i];
1505 size_t pos = fname.rfind (
'.');
1507 if (pos != std::string::npos)
1508 retval[i] = fname.substr (0, pos);
1527 retval[count++] = p->first;
1553 bool printed_type =
false;
1558 printed_type =
true;
1566 printed_type =
true;
1574 printed_type =
true;
1586 os <<
" " << p->first <<
" (";
1607 std::string nm = p->first;
1609 int types = p->second;
1618 retval[count++] = nm;
1633 if (! fcn_files.
empty ())
1635 os <<
"\n*** function files in " << i->dir_name <<
":\n\n";
1641 = i->method_file_map;
1643 if (! method_file_map.empty ())
1646 p = method_file_map.begin (); p != method_file_map.end (); p++)
1648 os <<
"\n*** methods in " << i->dir_name
1649 <<
"/@" << p->first <<
":\n\n";
1663 os <<
"\n*** private functions in "
1669 #if defined (DEBUG_LOAD_PATH)
1675 os << i->first <<
":\n";
1680 p != file_info_list.end ();
1683 os <<
" " << p->dir_name <<
" (";
1695 os <<
"CLASS " << i->first <<
":\n";
1703 os <<
" " << q->first <<
":\n";
1708 p != file_info_list.end ();
1711 os <<
" " << p->dir_name <<
" (";
1729 size_t ps = path.size ();
1730 size_t pls = path_list.size ();
1731 size_t pos = path_list.find (path);
1733 while (pos != std::string::npos)
1735 if ((pos == 0 || path_list[pos-1] == psc)
1736 && (pos + ps == pls || path_list[pos + ps] == psc))
1739 pos = path_list.find (path, pos + 1);
1748 std::string dir_name = di.
dir_name;
1756 std::string fname = fcn_files[i];
1759 std::string base = fname;
1761 size_t pos = fname.rfind (
'.');
1763 if (pos != std::string::npos)
1765 base = fname.substr (0, pos);
1766 ext = fname.substr (pos);
1773 while (p != file_info_list.end ())
1775 if (p->dir_name == dir_name)
1784 else if (ext ==
".oct")
1786 else if (ext ==
".mex")
1789 if (p == file_info_list.end ())
1794 file_info_list.push_back (fi);
1799 if (! file_info_list.empty ())
1801 file_info& old = file_info_list.front ();
1810 if (fname !=
"Contents.m"
1817 "function %s shadows a core library function",
1825 "function %s shadows a built-in function",
1829 file_info_list.push_front (fi);
1846 if (! private_file_map.empty ())
1853 std::string dir_name = di.
dir_name;
1859 q != method_file_map.end ();
1862 std::string class_name = q->first;
1866 std::string full_dir_name
1878 std::string base = p->first;
1880 int types = p->second;
1886 while (p2 != file_info_list.end ())
1888 if (p2->dir_name == full_dir_name)
1894 if (p2 == file_info_list.end ())
1899 file_info_list.push_back (fi);
1901 file_info_list.push_front (fi);
1916 if (! private_file_map.empty ())
1938 std::string elt = dirlist[i];
1940 bool skip_p = (elt ==
"." || elt ==
".." || elt[0] ==
'@');
1946 skip_p = (elt == skip[j]);
1969 const std::string& script_file)
1998 @deftypefn {Built-in Function} {} genpath (@var{dir})\n\
1999 @deftypefnx {Built-in Function} {} genpath (@var{dir}, @var{skip}, @dots{})\n\
2000 Return a path constructed from @var{dir} and all its subdirectories.\n\
2001 If additional string parameters are given, the resulting path will\n\
2002 exclude directories with those names.\n\
2011 std::string dirname = args(0).string_value ();
2016 error (
"genpath: DIR must be a character string");
2018 else if (nargin > 1)
2020 std::string dirname = args(0).string_value ();
2026 skip[i-1] = args(i).string_value ();
2033 retval =
genpath (dirname, skip);
2035 error (
"genpath: all arguments must be character strings");
2057 @deftypefn {Built-in Function} {} rehash ()\n\
2058 Reinitialize Octave's load path directory cache.\n\
2070 @deftypefn {Built-in Function} {} command_line_path (@dots{})\n\
2071 Return the command line path variable.\n\
2073 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\
2079 DEFUN (restoredefaultpath, , ,
2081 @deftypefn {Built-in Function} {} restoredefaultpath (@dots{})\n\
2082 Restore Octave's path to its initial state at startup.\n\
2084 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\
2097 DEFUN (__pathorig__, , ,
2099 @deftypefn {Built-in Function} {@var{val} =} __pathorig__ ()\n\
2100 Undocumented internal function.\n\
2108 @deftypefn {Built-in Function} {} path (@dots{})\n\
2109 Modify or display Octave's load path.\n\
2111 If @var{nargin} and @var{nargout} are zero, display the elements of\n\
2112 Octave's load path in an easy to read format.\n\
2114 If @var{nargin} is zero and nargout is greater than zero, return the\n\
2115 current load path.\n\
2117 If @var{nargin} is greater than zero, concatenate the arguments,\n\
2118 separating them with @code{pathsep}. Set the internal search path\n\
2119 to the result and return it.\n\
2121 No checks are made for duplicate elements.\n\
2122 @seealso{addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\
2127 int argc = args.
length () + 1;
2135 std::string
path = argv[1];
2137 for (
int i = 2; i < argc; i++)
2147 else if (argc == 1 && nargout == 0)
2150 "\nOctave's search path contains the following directories:\n\n";
2163 DEFUN (addpath, args, nargout,
2165 @deftypefn {Built-in Function} {} addpath (@var{dir1}, @dots{})\n\
2166 @deftypefnx {Built-in Function} {} addpath (@var{dir1}, @dots{}, @var{option})\n\
2167 Add named directories to the function search path. If\n\
2168 @var{option} is @qcode{\"-begin\"} or 0 (the default), prepend the\n\
2169 directory name to the current path. If @var{option} is @qcode{\"-end\"}\n\
2170 or 1, append the directory name to the current path.\n\
2171 Directories added to the path must exist.\n\
2173 In addition to accepting individual directory arguments, lists of\n\
2174 directory names separated by @code{pathsep} are also accepted. For example:\n\
2177 addpath (\"dir1:/dir2:~/dir3\")\n\
2179 @seealso{path, rmpath, genpath, pathdef, savepath, pathsep}\n\
2190 int nargin = args.length ();
2202 if (option ==
"-end")
2207 else if (option ==
"-begin")
2225 error (
"addpath: expecting final argument to be 1 or 0");
2231 error (
"addpath: expecting final argument to be 1 or 0");
2236 bool need_to_update =
false;
2238 for (
int i = 0; i < nargin; i++)
2240 std::string
arg = args(i).string_value ();
2244 std::list<std::string> dir_elts =
split_path (arg);
2247 std::reverse (dir_elts.begin (), dir_elts.end ());
2249 for (std::list<std::string>::const_iterator p = dir_elts.begin ();
2250 p != dir_elts.end ();
2253 std::string dir = *p;
2263 need_to_update =
true;
2267 error (
"addpath: all arguments must be character strings");
2279 DEFUN (rmpath, args, nargout,
2281 @deftypefn {Built-in Function} {} rmpath (@var{dir1}, @dots{})\n\
2282 Remove @var{dir1}, @dots{} from the current function search path.\n\
2284 In addition to accepting individual directory arguments, lists of\n\
2285 directory names separated by @code{pathsep} are also accepted. For example:\n\
2288 rmpath (\"dir1:/dir2:~/dir3\")\n\
2290 @seealso{path, addpath, genpath, pathdef, savepath, pathsep}\n\
2301 int nargin = args.length ();
2305 bool need_to_update =
false;
2307 for (
int i = 0; i < nargin; i++)
2309 std::string
arg = args(i).string_value ();
2313 std::list<std::string> dir_elts =
split_path (arg);
2315 for (std::list<std::string>::const_iterator p = dir_elts.begin ();
2316 p != dir_elts.end ();
2319 std::string dir = *p;
2325 warning (
"rmpath: %s: not found", dir.c_str ());
2327 need_to_update =
true;
2331 error (
"addpath: all arguments must be character strings");