24 #if defined (HAVE_CONFIG_H)
107 catch (
const octave::execution_exception&)
123 size_t pos = name.find (
'.');
125 if (pos == std::string::npos)
126 return package_dir_map.find (name) != package_dir_map.end ();
134 if (it != package_dir_map.end ())
135 return it->second.is_package (name_tail);
152 method_file_map.clear ();
153 package_dir_map.clear ();
155 dir_mtime = fs.
mtime ();
170 catch (
const octave::execution_exception&)
181 warning (
"load_path: %s: %s", dir_name.c_str (), msg.c_str ());
196 all_files.resize (len);
197 fcn_files.resize (len);
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));
223 all_files[all_files_count++] =
fname;
225 size_t pos = fname.rfind (
'.');
227 if (pos != std::string::npos)
231 if (ext ==
".m" || ext ==
".oct" || ext ==
".mex")
236 fcn_files[fcn_files_count++] =
fname;
243 all_files.resize (all_files_count);
244 fcn_files.resize (fcn_files_count);
249 warning (
"load_path: %s: %s", d.c_str (), msg.c_str ());
270 size_t pos = fname.rfind (
'.');
272 if (pos != std::string::npos)
283 else if (ext ==
".oct")
285 else if (ext ==
".mex")
297 warning (
"load_path: %s: %s", d.c_str (), msg.c_str ());
313 method_file_map[class_name].method_file_map =
get_fcn_files (d);
320 method_file_map[class_name].private_file_map =
get_fcn_files (pd);
327 package_dir_map[package_name] =
dir_info (d);
344 error (
"unable to create load path object!");
360 if (retval->dir_name == dir)
378 if (retval->dir_name == dir)
425 size_t pos = fname.rfind (
'.');
427 if (pos != std::string::npos)
429 base = fname.substr (0, pos);
430 ext = fname.substr (pos);
435 if (file_info_list.size () == 1)
440 p != file_info_list.end ();
443 if (
p->dir_name == dir_name)
447 file_info_list.erase (
p);
450 file_info_list.push_back (fi);
452 file_info_list.push_front (fi);
465 i != method_map.end ();
479 if (file_info_list.size () == 1)
484 p != file_info_list.end ();
p++)
486 if (
p->dir_name == full_dir_name)
490 file_info_list.erase (
p);
493 file_info_list.push_back (fi);
495 file_info_list.push_front (fi);
533 p != package_dir_map.end (); ++
p)
537 if (! pname.empty ())
538 full_name = pname +
"." + full_name;
540 move (
p->second, at_end, full_name);
549 std::list<std::string>::iterator
s =
562 move_fcn_map (dir_name, di.
fcn_files, at_end);
566 move_method_map (dir_name, at_end);
574 if (! tpath.empty ())
588 if (set_initial_path)
608 if (! tpath.empty ())
618 do_set (xpath,
false,
true);
631 static std::list<std::string>
634 std::list<std::string>
retval;
641 while (end != std::string::npos)
646 retval.push_back (elt);
659 retval.push_back (elt);
671 std::set<std::string> elts_set (elts.begin (), elts.end ());
677 for (std::set<std::string>::const_iterator it =
init_dirs.begin ();
680 if (elts_set.find (*it) == elts_set.end ())
683 "default load path altered. Some built-in functions may not be found. Try restoredefaultpath() to recover it.");
698 for (std::list<std::string>::const_iterator
i = elts.begin ();
699 i != elts.end ();
i++)
728 do_add (dir,
false, warn);
738 size_t k = dir.length ();
743 if (k < dir.length ())
752 size_t len = dir_arg.length ();
754 if (len > 1 && dir_arg.substr (len-2) ==
"//")
756 "trailing '//' is no longer special in search path elements");
787 warning (
"addpath: %s: not a directory", dir_arg.c_str ());
792 warning (
"addpath: %s: %s", dir_arg.c_str (), msg.c_str ());
817 size_t pos = fname.rfind (
'.');
819 if (pos != std::string::npos)
821 base = fname.substr (0, pos);
822 ext = fname.substr (pos);
828 p != file_info_list.end ();
831 if (
p->dir_name == dir)
833 file_info_list.erase (
p);
835 if (file_info_list.empty ())
836 fcn_map.erase (fname);
849 if (p != private_fcn_map.end ())
850 private_fcn_map.erase (p);
857 i != method_map.end ();
871 if (file_info_list.size () == 1)
876 p != file_info_list.end ();
p++)
878 if (
p->dir_name == full_dir_name)
880 file_info_list.erase (
p);
899 if (! dir_arg.empty ())
903 warning (
"rmpath: can't remove \".\" from path");
945 p != package_dir_map.end (); ++
p)
949 if (! pname.empty ())
950 full_name = pname +
"." + full_name;
952 remove (
p->second, full_name);
965 remove_fcn_map (dir, fcn_files);
967 remove_private_fcn_map (dir);
969 remove_method_map (dir);
991 add (di,
true,
"",
true);
1084 error (
"%s: %s: invalid type code = %d", who, fcn.c_str (),
type);
1097 if (fcn.length () > 0 && fcn[0] ==
'@')
1099 size_t pos = fcn.find (
'/');
1101 if (pos != std::string::npos)
1106 retval =
find_method (class_name, meth, dir_name);
1117 if (p != fcn_map.end ())
1122 i != file_info_list.end ();
1130 fcn,
"load_path::do_find_fcn"))
1154 if (q != private_fcn_map.end ())
1166 "load_path::find_private_fcn"))
1187 if (q != method_map.end ())
1198 i != file_info_list.end ();
1206 meth,
"load_path::do_find_method");
1222 std::list<std::string>
1225 std::list<std::string>
retval;
1231 if (q != method_map.end ())
1236 retval.push_back (
p->first);
1239 if (! retval.empty ())
1252 if (
p->is_package (name))
1259 std::list<std::string>
1262 std::list<std::string>
retval;
1270 l->second.overloads (meth, retval);
1277 std::list<std::string>& l)
const
1280 q != method_map.end (); q++)
1284 if (m.find (meth) != m.end ())
1288 if (! prefix.empty ())
1289 class_name = prefix +
"." + class_name;
1291 l.push_back (class_name);
1317 if (! dir_name.empty ())
1348 if (! tfile.empty ())
1353 != std::string::npos)
1384 if (all_files[
i] == file)
1415 size_t dname_len = dname.length ();
1419 dname = dname.substr (0, dname_len - 1);
1423 size_t dir_len = dir.length ();
1425 if (dname_len > dir_len
1427 && dir == dname.substr (dname_len - dir_len))
1443 std::list<std::string> retlist;
1452 retlist.push_back (dir);
1462 size_t dname_len = dname.length ();
1466 dname = dname.substr (0, dname_len - 1);
1470 size_t dir_len = dir.length ();
1472 if (dname_len > dir_len
1474 && dir == dname.substr (dname_len - dir_len))
1479 retlist.push_back (
p->dir_name);
1505 != std::string::npos)
1531 rel_flist[rel_flen++] =
file;
1534 rel_flist.
resize (rel_flen);
1548 if (all_files[
i] == rel_flist[j])
1550 dir_name =
p->dir_name;
1551 file_name = rel_flist[j];
1561 if (! dir_name.empty ())
1570 std::list<std::string> retlist;
1585 != std::string::npos)
1593 retlist.push_back (file);
1606 retlist.push_back (tfile);
1611 rel_flist[rel_flen++] =
file;
1614 rel_flist.
resize (rel_flen);
1627 if (all_files[
i] == rel_flist[j])
1649 retval[k++] =
i->dir_name;
1654 std::list<std::string>
1657 std::list<std::string>
retval;
1662 retval.push_back (
i->dir_name);
1675 retval = p->fcn_files;
1685 size_t pos = fname.rfind (
'.');
1687 if (pos != std::string::npos)
1688 retval[
i] = fname.substr (0, pos);
1704 size_t len = fcn_map.
size ();
1711 p != fcn_map.end ();
1713 retval[count++] =
p->first;
1739 bool printed_type =
false;
1744 printed_type =
true;
1752 printed_type =
true;
1760 printed_type =
true;
1772 os <<
" " <<
p->first <<
" (";
1795 int types =
p->second;
1804 retval[count++] =
nm;
1819 if (! fcn_files.
empty ())
1821 os <<
"\n*** function files in " <<
i->dir_name <<
":\n\n";
1827 =
i->method_file_map;
1829 if (! method_file_map.empty ())
1832 p = method_file_map.begin ();
p != method_file_map.end ();
p++)
1834 os <<
"\n*** methods in " <<
i->dir_name
1835 <<
"/@" <<
p->first <<
":\n\n";
1850 l->second.display (os);
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)
1863 if ((pos == 0 || path_list[pos-1] == psc)
1864 && (pos + ps == pls || path_list[pos + ps] == psc))
1867 pos = path_list.find (path, pos + 1);
1879 l.
add (di, at_end, updating);
1884 p != package_dir_map.end (); ++
p)
1888 if (! pname.empty ())
1889 full_name = pname +
"." + full_name;
1891 add (
p->second, at_end, full_name);
1912 size_t pos = fname.rfind (
'.');
1914 if (pos != std::string::npos)
1916 base = fname.substr (0, pos);
1917 ext = fname.substr (pos);
1924 while (p != file_info_list.end ())
1926 if (p->dir_name == dir_name)
1935 else if (ext ==
".oct")
1937 else if (ext ==
".mex")
1940 if (p == file_info_list.end ())
1947 if (file_info_list.empty ())
1954 "function %s shadows a built-in function",
1960 file_info& old = file_info_list.front ();
1969 if (fname !=
"Contents.m"
1976 "function %s shadows a core library function",
1985 file_info_list.push_back (fi);
1987 file_info_list.push_front (fi);
2003 if (! private_file_map.empty ())
2004 private_fcn_map[di.
dir_name] = private_file_map;
2016 q != method_file_map.end ();
2037 int types =
p->second;
2043 while (p2 != file_info_list.end ())
2045 if (p2->dir_name == full_dir_name)
2051 if (p2 == file_info_list.end ())
2056 file_info_list.push_back (fi);
2058 file_info_list.push_front (fi);
2073 if (! private_file_map.empty ())
2074 private_fcn_map[full_dir_name] = private_file_map;
2081 os <<
"*** loader: " << (prefix.empty () ?
"<top-level>" : prefix) <<
"\n\n";
2083 for (std::list<std::string>::const_iterator
s =
dir_list.begin ();
2089 i != private_fcn_map.end ();
i++)
2091 os <<
"\n*** private functions in "
2097 #if defined (DEBUG_LOAD_PATH)
2100 i != fcn_map.end ();
2103 os <<
i->first <<
":\n";
2108 p != file_info_list.end ();
2111 os <<
" " <<
p->dir_name <<
" (";
2120 i != method_map.end ();
2123 os <<
"CLASS " <<
i->first <<
":\n";
2131 os <<
" " << q->first <<
":\n";
2136 p != file_info_list.end ();
2139 os <<
" " <<
p->dir_name <<
" (";
2172 bool skip_p = (elt ==
"." || elt ==
".." || elt[0] ==
'@'
2179 skip_p = (elt == skip[j]);
2200 std::list<std::string>
2203 std::list<std::string>
retval;
2208 if (! only_top_level || l->first.find (
'.') == std::string::npos)
2209 retval.push_back (l->first);
2263 std::string dirname =
args(0).xstring_value (
"genpath: DIR must be a string");
2269 std::string dirname =
args(0).xstring_value (
"genpath: all arguments must be strings");
2274 skip[
i-1] =
args(
i).xstring_value (
"genpath: all arguments must be strings");
2276 retval =
genpath (dirname, skip);
2316 DEFUN (restoredefaultpath, , ,
2334 DEFUN (__pathorig__, , ,
2382 else if (nargin == 0 &&
nargout == 0)
2385 "\nOctave's search path contains the following directories:\n\n";
2425 int nargin =
args.length ();
2443 if (option ==
"-end")
2448 else if (option ==
"-begin")
2453 int val = option_arg.
xint_value (
"addpath: OPTION must be '-begin'/0 or '-end'/1");
2463 error (
"addpath: OPTION must be '-begin'/0 or '-end'/1");
2466 bool need_to_update =
false;
2472 for (
int i = 0;
i < arglist.length ();
i++)
2476 std::list<std::string> dir_elts =
split_path (arg);
2479 std::reverse (dir_elts.begin (), dir_elts.end ());
2481 for (
const auto&
p : dir_elts)
2486 dir.erase (std::unique (dir.begin (), dir.end (),
2499 need_to_update =
true;
2531 int nargin =
args.length ();
2541 bool need_to_update =
false;
2545 std::string arg =
args(
i).xstring_value (
"rmpath: all arguments must be strings");
2546 std::list<std::string> dir_elts =
split_path (arg);
2548 for (std::list<std::string>::const_iterator
p = dir_elts.begin ();
2549 p != dir_elts.end ();
2558 warning (
"rmpath: %s: not found", dir.c_str ());
2560 need_to_update =
true;
2570 DEFUN (__dump_load_path__, , ,
fcn_map_type::iterator fcn_map_iterator
static void maybe_add_path_elts(std::string &path, const std::string &dir)
static std::string dir_sep_str(void)
void warning_with_id(const char *id, const char *fmt,...)
void remove_private_fcn_map(const std::string &dir)
static std::string system_path(void)
static bool in_path_list(const std::string &path_list, const std::string &path)
void do_update(void) const
friend void print_types(std::ostream &os, int types)
std::set< std::string > init_dirs
method_file_map_type method_file_map
For example cd octave end example noindent changes the current working directory to file
std::string find_private_file(const std::string &fname)
bool same_file(const std::string &f, const std::string &g)
std::string Vlocal_oct_file_dir
fcn_file_map_type private_file_map
octave::sys::time mtime(void) const
method_map_type::iterator method_map_iterator
static void display(std::ostream &os)
void get_package_dir(const std::string &d, const std::string &package_name)
void get_file_list(const std::string &d)
void move(const dir_info &di, bool at_end, const std::string &pname="")
std::string do_find_dir(const std::string &dir) const
std::string Vlocal_fcn_file_dir
static void prepend(const std::string &dir, bool warn=false)
string_vector do_find_matching_dirs(const std::string &dir) const
std::map< std::string, int > fcn_file_map_type
static std::string command_line_path
OCTINTERP_API void print_usage(void)
std::string Vlocal_ver_fcn_file_dir
dir_info_list_type::iterator dir_info_list_iterator
static void append(const std::string &dir, bool warn=false)
octave_idx_type numel(void) const
Number of elements in the array.
static std::string dir_sep_chars(void)
identity matrix If supplied two scalar respectively For allows like xample val
std::map< std::string, dir_info > package_dir_map_type
octave::sys::time dir_time_last_checked
void get_private_file_map(const std::string &d)
int xint_value(const char *fmt,...) const
bool is_numeric_type(void) const
loader & get_loader(const std::string &name) const
string_vector do_find_all_first_of(const string_vector &files) const
file_info_list_type::const_iterator const_file_info_list_iterator
fcn_file_map_type private_file_map
octave::sys::time dir_mtime
void add(const dir_info &di, bool at_end, bool updating)
dir_info_list_type dir_info_list
void remove(const dir_info &di)
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
private_fcn_map_type::const_iterator const_private_fcn_map_iterator
void move_method_map(const std::string &dir, bool at_end)
std::string Vfcn_file_dir
static abs_dir_cache_type abs_dir_cache
size_type size(const size_type d) const
Size of the specified dimension.
private_fcn_map_type::iterator private_fcn_map_iterator
void(* hook_fcn_ptr)(const std::string &dir)
std::string find_fcn(const std::string &fcn, std::string &dir_name, int type=M_FILE|OCT_FILE|MEX_FILE) const
std::string do_find_first_of(const string_vector &files) const
static bool rooted_relative_pathname(const std::string &s)
void overloads(const std::string &meth, std::list< std::string > &l) const
string_vector do_fcn_names(void) const
void do_initialize(bool set_initial_path)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
static std::string find_method(const std::string &class_name, const std::string &meth, std::string &dir_name, const std::string &pack_name="")
static const int MEX_FILE
method_map_type::const_iterator const_method_map_iterator
std::string xstring_value(const char *fmt,...) const
static void execute_pkg_add_or_del(const std::string &dir, const std::string &script_file)
static std::string tilde_expand(const std::string &)
void resize(octave_idx_type n, const std::string &rfv="")
static void rehash_internal(void)
std::string Voct_data_dir
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
static std::string getenv(const std::string &name)
void remove_fcn_map(const std::string &dir, const string_vector &fcn_files)
void do_append(const std::string &dir, bool warn)
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
static hook_fcn_ptr remove_hook
std::list< file_info > file_info_list_type
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
static void cleanup_instance(void)
std::list< std::string > methods(const std::string &class_name) const
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
void add(const dir_info &di, bool at_end, const std::string &pname="", bool updating=false) const
std::map< std::string, file_info_list_type > fcn_map_type
std::string do_find_file(const std::string &file) const
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)
static hook_fcn_ptr add_hook
bool valid_identifier(const char *s)
std::string Vlocal_api_fcn_file_dir
std::string string_value(bool force=false) const
fcn_file_map_type::const_iterator const_fcn_file_map_iterator
if(nargin< 2) print_usage()
string_vector do_files(const std::string &dir, bool omit_exts) const
nd deftypefn *octave_map m
octave_value_list & reverse(void)
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
static bool instance_ok(void)
static void execute_pkg_add(const std::string &dir)
static std::string sys_path
bool is_string(void) const
std::map< std::string, dir_info > abs_dir_cache_type
friend dir_info::fcn_file_map_type get_fcn_files(const std::string &d)
void add_to_private_fcn_map(const dir_info &di)
static bool absolute_pathname(const std::string &s)
void do_prepend(const std::string &dir, bool warn)
static void initialize(bool set_initial_path=false)
static char path_sep_char(void)
std::list< std::string > do_overloads(const std::string &meth) const
std::list< std::string > do_get_all_package_names(bool only_top_level) const
std::string find_private_fcn(const std::string &dir, const std::string &fcn, int type=M_FILE|OCT_FILE|MEX_FILE) const
std::list< std::string > do_dir_list(void) const
dir_info_list_type::const_iterator const_dir_info_list_iterator
OCTAVE_EXPORT octave_value_list genpath
friend string_vector get_file_list(const dir_info::fcn_file_map_type &lst)
string_vector & sort(bool make_uniq=false)
octave_idx_type length(void) const
std::ostream & list_in_columns(std::ostream &, int width=0, const std::string &prefix="") const
string_vector do_dirs(void) const
void move(const dir_info &di, bool at_end)
std::string do_path(void) const
file_info_list_type::iterator file_info_list_iterator
void get_method_file_map(const std::string &d, const std::string &class_name)
static octave_user_function * get_curr_fcn(scope_id scope=xcurrent_scope)
void move_fcn_map(const std::string &dir, const string_vector &fcn_files, bool at_end)
abs_dir_cache_type::iterator abs_dir_cache_iterator
package_dir_map_type::const_iterator const_package_dir_map_iterator
std::string Vlocal_ver_oct_file_dir
static load_path * instance
const_dir_info_list_iterator find_dir_info(const std::string &dir) const
static std::string concat(const std::string &, const std::string &)
bool octave_interpreter_ready
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
method_file_map_type::const_iterator const_method_file_map_iterator
void warning(const char *fmt,...)
std::string dir_name(void) const
OCTAVE_EXPORT octave_value_list rmpath
octave::unwind_protect frame
void recover_from_exception(void)
void do_set(const std::string &p, bool warn, bool is_init=false)
virtual void run_first(void)=0
static std::string path_sep_str(void)
octave::sys::time time_resolution(void) const
std::string Voct_file_dir
static std::string strip_trailing_separators(const std::string &dir_arg)
void remove_method_map(const std::string &dir)
=val(i)}if ode{val(i)}occurs in table i
string_vector fcn_names(void) const
fcn_map_type::const_iterator const_fcn_map_iterator
void add_to_method_map(const dir_info &di, bool at_end)
static std::list< std::string > split_path(const std::string &p)
fcn_file_map_type method_file_map
static string_vector dirs(void)
void do_add(const std::string &dir, bool at_end, bool warn)
static std::list< std::string > dir_list(void)
octave::sys::file_stat fs(filename)
void do_move(dir_info_list_iterator i, bool at_end)
bool contains(const std::string &dir) const
package_dir_map_type package_dir_map
bool is_package(const std::string &name) const
loader_map_type::const_iterator const_loader_map_iterator
bool do_remove(const std::string &dir)
static void set(const std::string &p, bool warn=false)
std::string error(void) const
static bool is_built_in_function_name(const std::string &name)
static std::string get_command_line_path(void)
friend void print_fcn_list(std::ostream &os, const dir_info::fcn_file_map_type &lst)
bool is_package(const std::string &name) const
void display(std::ostream &out) const
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)
loader_map_type loader_map
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
std::string error(void) const
static std::string path(void)
std::map< std::string, class_info > method_file_map_type
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
static void execute_pkg_del(const std::string &dir)
static bool remove(const std::string &dir)
void add_to_fcn_map(const dir_info &di, bool at_end, bool updating)
bool do_contains_canonical(const std::string &dir) const
static bool is_dir_sep(char c)
void do_display(std::ostream &os) const
std::string Vlocal_api_oct_file_dir