24 #if defined (HAVE_CONFIG_H) 62 static std::list<std::string>
65 std::list<std::string>
retval;
70 size_t len =
p.length ();
72 while (end != std::string::npos)
102 size_t k = dir.length ();
107 if (
k < dir.length ())
136 if (! dir_name.empty ())
173 size_t ps = path.size ();
174 size_t pls = path_list.size ();
175 size_t pos = path_list.find (path);
177 while (pos != std::string::npos)
179 if ((pos == 0 || path_list[pos-1] == psc)
180 && (pos + ps == pls || path_list[pos + ps] == psc))
183 pos = path_list.find (path, pos + 1);
213 if (set_initial_path)
233 if (! tpath.empty ())
243 set (xpath,
false,
true);
263 std::set<std::string> elts_set (elts.begin (), elts.end ());
271 if (elts_set.find (init_dir) == elts_set.end ())
274 "default load path altered. Some built-in functions may not be found. Try restoredefaultpath() to recover it.");
289 for (
const auto& elt : elts)
311 add (dir,
true, warn);
318 add (dir,
false, warn);
326 if (! dir_arg.empty ())
330 warning (R
"(rmpath: can't remove "." from path)"); 377 add (di,
true,
"",
true);
398 std::list<std::string>
401 std::list<std::string>
retval;
408 nm_ldr.second.overloads (meth,
retval);
413 std::list<std::string>
416 std::list<std::string>
retval;
420 if (! only_top_level || dir_ldr.first.find (
'.') == std::string::npos)
421 retval.push_back (dir_ldr.first);
443 if (! tfile.empty ())
448 != std::string::npos)
473 if (all_files[
i] ==
file)
502 size_t dname_len = dname.length ();
504 if (dname.substr (dname_len - 1)
507 dname = dname.substr (0, dname_len - 1);
511 size_t dir_len = dir.length ();
513 if (dname_len > dir_len
515 && dir == dname.substr (dname_len - dir_len))
531 std::list<std::string> retlist;
540 retlist.push_back (dir);
548 size_t dname_len = dname.length ();
550 if (dname.substr (dname_len - 1)
553 dname = dname.substr (0, dname_len - 1);
557 size_t dir_len = dir.length ();
559 if (dname_len > dir_len
561 && dir == dname.substr (dname_len - dir_len))
566 retlist.push_back (di.dir_name);
592 != std::string::npos)
617 rel_flist[rel_flen++] =
file;
620 rel_flist.
resize (rel_flen);
632 if (all_files[
i] == rel_flist[j])
634 dir_name = di.dir_name;
635 file_name = rel_flist[j];
645 if (! dir_name.empty ())
654 std::list<std::string> retlist;
669 != std::string::npos)
677 retlist.push_back (
file);
689 retlist.push_back (tfile);
694 rel_flist[rel_flen++] =
file;
697 rel_flist.
resize (rel_flen);
709 if (all_files[
i] == rel_flist[j])
734 std::list<std::string>
737 std::list<std::string>
retval;
740 retval.push_back (di.dir_name);
763 size_t pos =
fname.rfind (
'.');
765 if (pos != std::string::npos)
804 if (! fcn_files.
empty ())
806 os <<
"\n*** function files in " << di.dir_name <<
":\n\n";
812 = di.method_file_map;
814 if (! method_file_map.empty ())
816 for (
const auto& cls_ci : method_file_map)
818 os <<
"\n*** methods in " << di.dir_name
819 <<
"/@" << cls_ci.first <<
":\n\n";
833 nm_ldr.second.display (
os);
859 if (
retval->dir_name == dir)
877 if (
retval->dir_name == dir)
919 for (
const auto& pkg_di : package_dir_map)
923 if (!
pname.empty ())
924 full_name =
pname +
'.' + full_name;
926 move (pkg_di.second, at_end, full_name);
933 size_t len = dir_arg.length ();
935 if (len > 1 && dir_arg.substr (len-2) ==
"//")
937 "trailing '//' is no longer special in search path elements");
968 warning (
"addpath: %s: not a directory", dir_arg.c_str ());
973 warning (
"addpath: %s: %s", dir_arg.c_str (), msg.c_str ());
994 for (
const auto& pkg_di : package_dir_map)
998 if (!
pname.empty ())
999 full_name =
pname +
'.' + full_name;
1001 remove (pkg_di.second, full_name);
1010 if (di.is_package (
name))
1023 l.
add (di, at_end, updating);
1027 for (
const auto& pkg_di : package_dir_map)
1031 if (!
pname.empty ())
1032 full_name =
pname +
'.' + full_name;
1034 add (pkg_di.second, at_end, full_name);
1047 for (
const auto& nm_typ : lst)
1051 int types = nm_typ.second;
1083 size_t pos =
fname.rfind (
'.');
1085 if (pos != std::string::npos)
1096 else if (ext ==
".oct")
1098 else if (ext ==
".mex")
1118 warning (
"load_path: %s: %s",
d.c_str (), msg.c_str ());
1130 bool has_private_dir = pfs && pfs.
is_dir ();
1201 size_t pos =
name.find (
'.');
1203 if (pos == std::string::npos)
1204 return package_dir_map.find (
name) != package_dir_map.end ();
1212 if (it != package_dir_map.end ())
1213 return it->second.is_package (name_tail);
1224 dir_time_last_checked =
sys::time (static_cast<time_t> (0));
1230 method_file_map.clear ();
1231 package_dir_map.clear ();
1259 warning (
"load_path: %s: %s", dir_name.c_str (), msg.c_str ());
1274 all_files.resize (len);
1275 fcn_files.resize (len);
1292 if (
fname ==
"private")
1293 get_private_file_map (full_name);
1294 else if (
fname[0] ==
'@')
1295 get_method_file_map (full_name,
fname.substr (1));
1296 else if (
fname[0] ==
'+')
1297 get_package_dir (full_name,
fname.substr (1));
1301 all_files[all_files_count++] =
fname;
1303 size_t pos =
fname.rfind (
'.');
1305 if (pos != std::string::npos)
1309 if (ext ==
".m" || ext ==
".oct" || ext ==
".mex")
1314 fcn_files[fcn_files_count++] =
fname;
1321 all_files.resize (all_files_count);
1322 fcn_files.resize (fcn_files_count);
1327 warning (
"load_path: %s: %s",
d.c_str (), msg.c_str ());
1348 method_file_map[class_name].private_file_map =
get_fcn_files (pd);
1355 package_dir_map[package_name] =
dir_info (
d);
1363 std::list<std::string>::iterator
s =
1376 move_fcn_map (dir_name, di.
fcn_files, at_end);
1380 move_method_map (dir_name, at_end);
1392 remove_fcn_map (dir, fcn_files);
1394 remove_private_fcn_map (dir);
1396 remove_method_map (dir);
1402 os <<
"*** package_info: " 1403 << (m_package_name.empty () ?
"<top-level>" : m_package_name)
1410 for (
const auto& dir_fnlst : private_fcn_map)
1412 os <<
"\n*** private functions in " 1416 print_fcn_list (
os, dir_fnlst.second);
1419 #if defined (DEBUG_LOAD_PATH) 1421 for (
const auto& nm_filst : fcn_map)
1423 os << nm_filst.first <<
":\n";
1427 for (
const auto& finfo : file_info_list)
1429 os <<
" " << finfo.dir_name <<
" (";
1431 print_types (
os, finfo.types);
1437 for (
const auto& cls_fnmap : method_map)
1439 os <<
"CLASS " << cls_fnmap.first <<
":\n";
1443 for (
const auto& nm_fnlst : fcn_map)
1445 os <<
" " << nm_fnlst.first <<
":\n";
1449 for (
const auto& finfo : file_info_list)
1451 os <<
" " << finfo.dir_name <<
" (";
1453 print_types (
os, finfo.types);
1474 if (
fcn.length () > 0 &&
fcn[0] ==
'@')
1476 size_t pos =
fcn.find (
'/');
1478 if (pos != std::string::npos)
1494 if (
p != fcn_map.end ())
1498 for (
const auto&
fi : file_info_list)
1503 fcn,
"load_path::find_fcn"))
1505 dir_name =
fi.dir_name;
1528 if (q != private_fcn_map.end ())
1540 "load_path::find_private_fcn"))
1562 if (q != method_map.end ())
1572 for (
const auto&
fi : file_info_list)
1577 meth,
"load_path::find_method");
1581 dir_name =
fi.dir_name;
1593 std::list<std::string>
1596 std::list<std::string>
retval;
1602 if (mtd_map_it != method_map.end ())
1604 for (
const auto& nm_filst : mtd_map_it->second)
1605 retval.push_back (nm_filst.first);
1616 std::list<std::string>& l)
const 1618 for (
const auto& cls_fnmap : method_map)
1622 if (m.find (meth) != m.end ())
1626 if (! m_package_name.empty ())
1627 class_name = m_package_name +
'.' + class_name;
1629 l.push_back (class_name);
1637 size_t len = fcn_map.
size ();
1643 for (
const auto& nm_filst : fcn_map)
1644 retval[count++] = nm_filst.first;
1651 bool at_end,
bool updating)
1666 size_t pos =
fname.rfind (
'.');
1668 if (pos != std::string::npos)
1670 base =
fname.substr (0, pos);
1671 ext =
fname.substr (pos);
1678 while (
p != file_info_list.end ())
1680 if (
p->dir_name == dir_name)
1689 else if (ext ==
".oct")
1691 else if (ext ==
".mex")
1694 if (
p == file_info_list.end ())
1701 if (file_info_list.empty ())
1711 "function %s shadows a built-in function",
1717 file_info& old = file_info_list.front ();
1726 if (
fname !=
"Contents.m" 1733 "function %s shadows a core library function",
1742 file_info_list.push_back (
fi);
1744 file_info_list.push_front (
fi);
1760 if (! private_file_map.empty ())
1761 private_fcn_map[di.
dir_name] = private_file_map;
1772 for (
const auto& cls_ci : method_file_map)
1786 for (
const auto& nm_typ : m)
1789 int types = nm_typ.second;
1794 while (p2 != file_info_list.end ())
1796 if (p2->dir_name == full_dir_name)
1802 if (p2 == file_info_list.end ())
1807 file_info_list.push_back (
fi);
1809 file_info_list.push_front (
fi);
1823 if (! private_file_map.empty ())
1824 private_fcn_map[full_dir_name] = private_file_map;
1841 size_t pos =
fname.rfind (
'.');
1843 if (pos != std::string::npos)
1845 base =
fname.substr (0, pos);
1846 ext =
fname.substr (pos);
1851 if (file_info_list.size () == 1)
1855 for (
auto fi_it = file_info_list.begin ();
1856 fi_it != file_info_list.end ();
1859 if (fi_it->dir_name == dir_name)
1863 file_info_list.erase (fi_it);
1866 file_info_list.push_back (fi_tmp);
1868 file_info_list.push_front (fi_tmp);
1881 for (
auto& cls_fnmap : method_map)
1890 for (
auto& nm_filst : fn_map)
1894 if (file_info_list.size () == 1)
1898 for (
auto fi_it = file_info_list.begin ();
1899 fi_it != file_info_list.end (); fi_it++)
1901 if (fi_it->dir_name == full_dir_name)
1905 file_info_list.erase (fi_it);
1908 file_info_list.push_back (fi_tmp);
1910 file_info_list.push_front (fi_tmp);
1933 size_t pos =
fname.rfind (
'.');
1935 if (pos != std::string::npos)
1937 base =
fname.substr (0, pos);
1938 ext =
fname.substr (pos);
1943 for (
auto fi_it = file_info_list.begin ();
1944 fi_it != file_info_list.end ();
1947 if (fi_it->dir_name == dir)
1949 file_info_list.erase (fi_it);
1951 if (file_info_list.empty ())
1952 fcn_map.erase (
fname);
1965 if (
p != private_fcn_map.end ())
1966 private_fcn_map.erase (
p);
1972 for (
auto& cls_fnmap : method_map)
1981 for (
auto& nm_filst : fn_map)
1985 if (file_info_list.size () == 1)
1989 for (
auto fi_it = file_info_list.begin ();
1990 fi_it != file_info_list.end (); fi_it++)
1992 if (fi_it->dir_name == full_dir_name)
1994 file_info_list.erase (fi_it);
2011 const char *who)
const 2098 error (
"%s: %s: invalid type code = %d", who,
fcn.c_str (),
type);
2106 bool printed_type =
false;
2111 printed_type =
true;
2119 printed_type =
true;
2127 printed_type =
true;
2135 for (
const auto& nm_typ : lst)
2137 os <<
" " << nm_typ.first <<
" (";
2139 print_types (
os, nm_typ.second);
2164 bool skip_p = (elt ==
"." || elt ==
".." || elt[0] ==
'@' 2171 skip_p = (elt == skip[j]);
2208 int nargin = args.length ();
2223 std::string dirname = args(0).xstring_value (
"genpath: all arguments must be strings");
2228 skip[
i-1] = args(
i).xstring_value (
"genpath: all arguments must be strings");
2247 DEFMETHOD (command_line_path, interp, args, ,
2255 if (! args.empty ())
2263 DEFMETHOD (restoredefaultpath, interp, args, ,
2271 if (! args.empty ())
2318 int nargin = args.length ();
2331 lp.
set (path,
true);
2341 "\nOctave's search path contains the following directories:\n\n";
2381 int nargin = args.length ();
2406 else if (
option ==
"-begin")
2411 int val = option_arg.
xint_value (
"addpath: OPTION must be '-begin'/0 or '-end'/1");
2421 error (
"addpath: OPTION must be '-begin'/0 or '-end'/1");
2424 bool need_to_update =
false;
2430 for (
int i = 0;
i < arglist.length ();
i++)
2437 std::reverse (dir_elts.begin (), dir_elts.end ());
2439 for (
auto dir : dir_elts)
2442 std::string::iterator it_start = dir.begin ();
2443 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) 2447 dir.erase (std::unique (it_start, dir.end (),
2456 if (pos == std::string::npos)
2458 if (! dir.empty () && dir[0] ==
'+')
2460 "addpath: package directories should not be added to path: %s\n", dir.c_str ());
2464 if (pos + 1 < dir.length () && dir[pos+1] ==
'+')
2466 "addpath: package directories should not be added to path: %s\n", dir.c_str ());
2474 need_to_update =
true;
2506 int nargin = args.length ();
2518 bool need_to_update =
false;
2525 for (
const auto& dir : dir_elts)
2531 warning (
"rmpath: %s: not found", dir.c_str ());
2533 need_to_update =
true;
2543 DEFMETHOD (__dump_load_path__, interp, , ,
std::string error(void) const
static void maybe_add_path_elts(std::string &path, const std::string &dir)
fcn_file_map_type private_file_map
static char path_sep_char(void)
method_file_map_type method_file_map
file_info_list_type::iterator file_info_list_iterator
void warning_with_id(const char *id, const char *fmt,...)
std::string path(void) const
std::string local_fcn_file_dir(void)
const_dir_info_list_iterator find_dir_info(const std::string &dir) const
static bool in_path_list(const std::string &path_list, const std::string &path)
std::string find_first_of(const string_vector &files) const
void get_file_list(const std::string &d)
For example cd octave end example noindent changes the current working directory to file
is already an absolute the name is checked against the file system instead of Octave s loadpath In this if otherwise an empty string is returned If the first argument is a cell array of 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
bool same_file(const std::string &f, const std::string &g)
void move(dir_info_list_iterator i, bool at_end)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
std::list< std::string > overloads(const std::string &meth) const
std::string string_value(bool force=false) const
sys::time time_resolution(void) const
std::string system_path(void) const
void set(const std::string &p, bool warn=false, bool is_init=false)
void add_to_private_fcn_map(const dir_info &di)
void append(const std::string &dir, bool warn=false)
static void recover_from_exception(void)
static const int OCT_FILE
bool is_built_in_function_name(const std::string &name)
OCTINTERP_API void print_usage(void)
std::string dir_sep_chars(void)
void print_fcn_list(std::ostream &os, const dir_info::fcn_file_map_type &lst) const
identity matrix If supplied two scalar respectively For allows like xample val
static std::string path_sep_str(void)
std::string xstring_value(const char *fmt,...) const
string_vector find_all_first_of(const string_vector &files) const
std::string tilde_expand(const std::string &name)
void get_private_file_map(const std::string &d)
void display(std::ostream &out) const
void add(const std::string &dir, bool at_end, bool warn)
std::string find_fcn(const std::string &fcn, std::string &dir_name, int type=M_FILE|OCT_FILE|MEX_FILE) const
void move(const dir_info &di, bool at_end)
std::string get_command_line_path(void) const
void get_package_dir(const std::string &d, const std::string &package_name)
std::list< std::string > get_all_package_names(bool only_top_level=true) const
private_fcn_map_type::iterator private_fcn_map_iterator
void prepend(const std::string &dir, bool warn=false)
string_vector fcn_names(void) const
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
dir_info_list_type::iterator dir_info_list_iterator
package_info & get_package(const std::string &name) const
std::ostream & list_in_columns(std::ostream &, int width=0, const std::string &prefix="") const
sys::time dir_time_last_checked
std::string dirname(const std::string &path)
static bool rooted_relative_pathname(const std::string &s)
void move_method_map(const std::string &dir, bool at_end)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
symbol_scope __get_current_scope__(const std::string &who)
fcn_file_map_type::iterator fcn_file_map_iterator
std::string find_dir(const std::string &dir) const
static void execute_pkg_add_or_del(const std::string &dir, const std::string &script_file)
std::string find_method(const std::string &class_name, const std::string &meth, std::string &dir_name, const std::string &pack_name="")
static void execute_pkg_del(const std::string &dir)
void add_to_method_map(const dir_info &di, bool at_end)
string_vector fcn_names(void) const
void resize(octave_idx_type n, const std::string &rfv="")
std::string fcn_file_dir(void)
dir_info_list_type::const_iterator const_dir_info_list_iterator
static void rehash_internal(void)
std::string dir_sep_str(void)
std::map< std::string, int > fcn_file_map_type
void add(const dir_info &di, bool at_end, bool updating)
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
int xint_value(const char *fmt,...) const
static std::string getenv(const std::string &name)
std::string m_command_line_path
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 MEX_FILE
void add_to_fcn_map(const dir_info &di, bool at_end, bool updating)
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
std::string concat(const std::string &dir, const std::string &file)
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
symbol_table & __get_symbol_table__(const std::string &who)
nd deftypefn *std::string name
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
void get_method_file_map(const std::string &d, const std::string &class_name)
std::list< file_info > file_info_list_type
std::string local_ver_fcn_file_dir(void)
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)
private_fcn_map_type::const_iterator const_private_fcn_map_iterator
package_map_type package_map
bool valid_identifier(const char *s)
octave_idx_type numel(const octave_value_list &idx)
bool contains(const std::string &dir) const
if(nargin< 2) print_usage()
std::string local_api_fcn_file_dir(void)
octave_value_list & reverse(void)
std::string local_oct_file_dir(void)
void print_types(std::ostream &os, int types) const
fcn_file_map_type method_file_map
static abs_dir_cache_type abs_dir_cache
std::string find_file(const std::string &file) const
static bool absolute_pathname(const std::string &s)
std::list< std::string > dir_list(void) const
size_type size(const size_type d) const
Size of the specified dimension.
std::set< std::string > init_dirs
fcn_map_type::const_iterator const_fcn_map_iterator
void remove_method_map(const std::string &dir)
std::string genpath(const std::string &dirname, const string_vector &skip)
string_vector get_file_list(const dir_info::fcn_file_map_type &lst) const
string_vector & sort(bool make_uniq=false)
void move_fcn_map(const std::string &dir, const string_vector &fcn_files, bool at_end)
void overloads(const std::string &meth, std::list< std::string > &l) const
string_vector files(const std::string &dir, bool omit_exts=false) const
std::string dir_name(void) const
package_dir_map_type::const_iterator const_package_dir_map_iterator
dir_info_list_type dir_info_list
load_path & __get_load_path__(const std::string &who)
std::string oct_file_dir(void)
std::string local_api_oct_file_dir(void)
std::map< std::string, dir_info > abs_dir_cache_type
load_path::dir_info::fcn_file_map_type get_fcn_files(const std::string &d)
bool octave_interpreter_ready
bool is_package(const std::string &name) const
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
void warning(const char *fmt,...)
octave::unwind_protect frame
void remove_fcn_map(const std::string &dir, const string_vector &fcn_files)
package_dir_map_type package_dir_map
std::string local_ver_oct_file_dir(void)
method_map_type::const_iterator const_method_map_iterator
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
static std::string strip_trailing_separators(const std::string &dir_arg)
bool check_file_type(std::string &fname, int type, int possible_types, const std::string &fcn, const char *who) const
string_vector dirs(void) const
static std::list< std::string > split_path(const std::string &p)
std::list< std::string > methods(const std::string &class_name) const
bool is_package(const std::string &name) const
void remove_private_fcn_map(const std::string &dir)
bool remove(const std::string &dir)
std::string error(void) const
package_info top_level_package
friend dir_info::fcn_file_map_type get_fcn_files(const std::string &d)
octave::sys::file_stat fs(filename)
static std::string find_private_file(const std::string &fname)
std::map< std::string, class_info > method_file_map_type
static void execute_pkg_add(const std::string &dir)
void remove(const dir_info &di)
bool is_string(void) const
std::map< std::string, dir_info > package_dir_map_type
void initialize(bool set_initial_path=false)
std::map< std::string, file_info_list_type > fcn_map_type
fcn_file_map_type private_file_map
void display(std::ostream &os) const
fcn_file_map_type::const_iterator const_fcn_file_map_iterator
octave_idx_type numel(void) const
Number of elements in the array.
bool contains_canonical(const std::string &dir_name) const
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
abs_dir_cache_type::const_iterator const_abs_dir_cache_iterator
sys::time mtime(void) const
std::string oct_data_dir(void)
std::string find_private_fcn(const std::string &dir, const std::string &fcn, int type=M_FILE|OCT_FILE|MEX_FILE) const
bool isnumeric(void) const
string_vector find_matching_dirs(const std::string &dir) const
static std::string sys_path
octave_user_function * function(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