comparison libinterp/corefcn/load-path.cc @ 17856:97e49b588f5d classdef

maint: periodic merge of default to classdef
author John W. Eaton <jwe@octave.org>
date Tue, 05 Nov 2013 12:27:42 -0500
parents 93b3d03b05e7 175b392e91fe
children 181bbce78595
comparison
equal deleted inserted replaced
17746:c4f5c781c3ca 17856:97e49b588f5d
75 // avoid unnecessary calls to stat that can slow 75 // avoid unnecessary calls to stat that can slow
76 // things down tremendously for large directories. 76 // things down tremendously for large directories.
77 77
78 const dir_info& di = p->second; 78 const dir_info& di = p->second;
79 79
80 if (fs.mtime () + fs.time_resolution () > di.dir_time_last_checked) 80 if (fs.mtime () + fs.time_resolution ()
81 > di.dir_time_last_checked)
81 initialize (); 82 initialize ();
82 else 83 else
83 *this = di; 84 *this = di;
84 } 85 }
85 else 86 else
128 129
129 try 130 try
130 { 131 {
131 std::string abs_name = octave_env::make_absolute (dir_name); 132 std::string abs_name = octave_env::make_absolute (dir_name);
132 133
133 // FIXME -- nothing is ever removed from this cache of 134 // FIXME: nothing is ever removed from this cache of
134 // directory information, so there could be some resource 135 // directory information, so there could be some resource
135 // problems. Perhaps it should be pruned from time to time. 136 // problems. Perhaps it should be pruned from time to time.
136 137
137 abs_dir_cache[abs_name] = *this; 138 abs_dir_cache[abs_name] = *this;
138 } 139 }
316 } 317 }
317 318
318 return retval; 319 return retval;
319 } 320 }
320 321
321 // FIXME -- maybe we should also maintain a map to speed up this 322 // FIXME: maybe we should also maintain a map to speed up this method of access.
322 // method of access.
323 323
324 load_path::const_dir_info_list_iterator 324 load_path::const_dir_info_list_iterator
325 load_path::find_dir_info (const std::string& dir_arg) const 325 load_path::find_dir_info (const std::string& dir_arg) const
326 { 326 {
327 std::string dir = file_ops::tilde_expand (dir_arg); 327 std::string dir = file_ops::tilde_expand (dir_arg);
452 if (file_info_list.size () == 1) 452 if (file_info_list.size () == 1)
453 continue; 453 continue;
454 else 454 else
455 { 455 {
456 for (file_info_list_iterator p = file_info_list.begin (); 456 for (file_info_list_iterator p = file_info_list.begin ();
457 p != file_info_list.end (); 457 p != file_info_list.end (); p++)
458 p++)
459 { 458 {
460 if (p->dir_name == full_dir_name) 459 if (p->dir_name == full_dir_name)
461 { 460 {
462 file_info fi = *p; 461 file_info fi = *p;
463 462
767 std::string msg = fs.error (); 766 std::string msg = fs.error ();
768 warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ()); 767 warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ());
769 } 768 }
770 } 769 }
771 770
772 // FIXME -- is there a better way to do this? 771 // FIXME: is there a better way to do this?
773 772
774 i = find_dir_info ("."); 773 i = find_dir_info (".");
775 774
776 if (i != dir_info_list.end ()) 775 if (i != dir_info_list.end ())
777 do_move (i, false); 776 do_move (i, false);
846 if (file_info_list.size () == 1) 845 if (file_info_list.size () == 1)
847 continue; 846 continue;
848 else 847 else
849 { 848 {
850 for (file_info_list_iterator p = file_info_list.begin (); 849 for (file_info_list_iterator p = file_info_list.begin ();
851 p != file_info_list.end (); 850 p != file_info_list.end (); p++)
852 p++)
853 { 851 {
854 if (p->dir_name == full_dir_name) 852 if (p->dir_name == full_dir_name)
855 { 853 {
856 file_info_list.erase (p); 854 file_info_list.erase (p);
857 855
858 // FIXME -- if there are no other elements, we 856 // FIXME: if there are no other elements, we
859 // should remove this element of fm but calling 857 // should remove this element of fm but calling
860 // erase here would invalidate the iterator q. 858 // erase here would invalidate the iterator q.
861 859
862 break; 860 break;
863 } 861 }
1469 } 1467 }
1470 } 1468 }
1471 } 1469 }
1472 } 1470 }
1473 1471
1474 done: 1472 done:
1475 1473
1476 if (! dir_name.empty ()) 1474 if (! dir_name.empty ())
1477 retval = file_ops::concat (dir_name, file_name); 1475 retval = file_ops::concat (dir_name, file_name);
1478 1476
1479 return retval; 1477 return retval;
1526 } 1524 }
1527 1525
1528 rel_flist.resize (rel_flen); 1526 rel_flist.resize (rel_flen);
1529 1527
1530 for (const_dir_info_list_iterator p = dir_info_list.begin (); 1528 for (const_dir_info_list_iterator p = dir_info_list.begin ();
1531 p != dir_info_list.end (); 1529 p != dir_info_list.end (); p++)
1532 p++)
1533 { 1530 {
1534 string_vector all_files = p->all_files; 1531 string_vector all_files = p->all_files;
1535 1532
1536 octave_idx_type len = all_files.length (); 1533 octave_idx_type len = all_files.length ();
1537 1534
1538 for (octave_idx_type i = 0; i < len; i++) 1535 for (octave_idx_type i = 0; i < len; i++)
1539 { 1536 {
1540 for (octave_idx_type j = 0; j < rel_flen; j++) 1537 for (octave_idx_type j = 0; j < rel_flen; j++)
1541 { 1538 {
1542 if (all_files[i] == rel_flist[j]) 1539 if (all_files[i] == rel_flist[j])
1543 retlist.push_back 1540 retlist.push_back (file_ops::concat (p->dir_name,
1544 (file_ops::concat (p->dir_name, rel_flist[j])); 1541 rel_flist[j]));
1545 } 1542 }
1546 } 1543 }
1547 } 1544 }
1548 1545
1549 return retlist; 1546 return retlist;
1741 const dir_info::method_file_map_type& method_file_map 1738 const dir_info::method_file_map_type& method_file_map
1742 = i->method_file_map; 1739 = i->method_file_map;
1743 1740
1744 if (! method_file_map.empty ()) 1741 if (! method_file_map.empty ())
1745 { 1742 {
1746 for (dir_info::const_method_file_map_iterator p = method_file_map.begin (); 1743 for (dir_info::const_method_file_map_iterator
1747 p != method_file_map.end (); 1744 p = method_file_map.begin (); p != method_file_map.end (); p++)
1748 p++)
1749 { 1745 {
1750 os << "\n*** methods in " << i->dir_name 1746 os << "\n*** methods in " << i->dir_name
1751 << "/@" << p->first << ":\n\n"; 1747 << "/@" << p->first << ":\n\n";
1752 1748
1753 const dir_info::class_info& ci = p->second; 1749 const dir_info::class_info& ci = p->second;
1768 1764
1769 // True if a path is contained in a path list separated by path_sep_char 1765 // True if a path is contained in a path list separated by path_sep_char
1770 static bool 1766 static bool
1771 in_path_list (const std::string& path_list, const std::string& path) 1767 in_path_list (const std::string& path_list, const std::string& path)
1772 { 1768 {
1773 size_t ps = path.size (), pls = path_list.size (), pos = path_list.find (path); 1769 size_t ps = path.size ();
1770 size_t pls = path_list.size ();
1771 size_t pos = path_list.find (path);
1774 char psc = dir_path::path_sep_char (); 1772 char psc = dir_path::path_sep_char ();
1775 while (pos != std::string::npos) 1773 while (pos != std::string::npos)
1776 { 1774 {
1777 if ((pos == 0 || path_list[pos-1] == psc) 1775 if ((pos == 0 || path_list[pos-1] == psc)
1778 && (pos + ps == pls || path_list[pos + ps] == psc)) 1776 && (pos + ps == pls || path_list[pos + ps] == psc))
1862 1860
1863 if (! file_info_list.empty ()) 1861 if (! file_info_list.empty ())
1864 { 1862 {
1865 file_info& old = file_info_list.front (); 1863 file_info& old = file_info_list.front ();
1866 1864
1867 // FIXME -- do we need to be more careful about the 1865 // FIXME: do we need to be more careful about the
1868 // way we look for old.dir_name in sys_path to avoid 1866 // way we look for old.dir_name in sys_path to avoid
1869 // partial matches? 1867 // partial matches?
1870 1868
1871 // Don't warn about Contents.m files since we expect 1869 // Don't warn about Contents.m files since we expect
1872 // more than one to exist in the load path. 1870 // more than one to exist in the load path.
1964 else 1962 else
1965 file_info_list.push_front (fi); 1963 file_info_list.push_front (fi);
1966 } 1964 }
1967 else 1965 else
1968 { 1966 {
1969 // FIXME -- is this possible? 1967 // FIXME: is this possible?
1970 1968
1971 file_info& fi = *p2; 1969 file_info& fi = *p2;
1972 1970
1973 fi.types = types; 1971 fi.types = types;
1974 } 1972 }
2147 { 2145 {
2148 execute_pkg_add_or_del (dir, "PKG_DEL"); 2146 execute_pkg_add_or_del (dir, "PKG_DEL");
2149 } 2147 }
2150 2148
2151 DEFUN (genpath, args, , 2149 DEFUN (genpath, args, ,
2152 "-*- texinfo -*-\n\ 2150 "-*- texinfo -*-\n\
2153 @deftypefn {Built-in Function} {} genpath (@var{dir})\n\ 2151 @deftypefn {Built-in Function} {} genpath (@var{dir})\n\
2154 @deftypefnx {Built-in Function} {} genpath (@var{dir}, @var{skip}, @dots{})\n\ 2152 @deftypefnx {Built-in Function} {} genpath (@var{dir}, @var{skip}, @dots{})\n\
2155 Return a path constructed from @var{dir} and all its subdirectories.\n\ 2153 Return a path constructed from @var{dir} and all its subdirectories.\n\
2156 If additional string parameters are given, the resulting path will\n\ 2154 If additional string parameters are given, the resulting path will\n\
2157 exclude directories with those names.\n\ 2155 exclude directories with those names.\n\
2198 static void 2196 static void
2199 rehash_internal (void) 2197 rehash_internal (void)
2200 { 2198 {
2201 load_path::update (); 2199 load_path::update ();
2202 2200
2203 // FIXME -- maybe we should rename this variable since it is being 2201 // FIXME: maybe we should rename this variable since it is being
2204 // used for more than keeping track of the prompt time. 2202 // used for more than keeping track of the prompt time.
2205 2203
2206 // This will force updated functions to be found. 2204 // This will force updated functions to be found.
2207 Vlast_prompt_time.stamp (); 2205 Vlast_prompt_time.stamp ();
2208 } 2206 }
2209 2207
2210 DEFUN (rehash, , , 2208 DEFUN (rehash, , ,
2211 "-*- texinfo -*-\n\ 2209 "-*- texinfo -*-\n\
2212 @deftypefn {Built-in Function} {} rehash ()\n\ 2210 @deftypefn {Built-in Function} {} rehash ()\n\
2213 Reinitialize Octave's load path directory cache.\n\ 2211 Reinitialize Octave's load path directory cache.\n\
2214 @end deftypefn") 2212 @end deftypefn")
2215 { 2213 {
2216 octave_value_list retval; 2214 octave_value_list retval;
2219 2217
2220 return retval; 2218 return retval;
2221 } 2219 }
2222 2220
2223 DEFUN (command_line_path, , , 2221 DEFUN (command_line_path, , ,
2224 "-*- texinfo -*-\n\ 2222 "-*- texinfo -*-\n\
2225 @deftypefn {Built-in Function} {} command_line_path (@dots{})\n\ 2223 @deftypefn {Built-in Function} {} command_line_path (@dots{})\n\
2226 Return the command line path variable.\n\ 2224 Return the command line path variable.\n\
2227 \n\ 2225 \n\
2228 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ 2226 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\
2229 @end deftypefn") 2227 @end deftypefn")
2230 { 2228 {
2231 return octave_value (load_path::get_command_line_path ()); 2229 return octave_value (load_path::get_command_line_path ());
2232 } 2230 }
2233 2231
2234 DEFUN (restoredefaultpath, , , 2232 DEFUN (restoredefaultpath, , ,
2235 "-*- texinfo -*-\n\ 2233 "-*- texinfo -*-\n\
2236 @deftypefn {Built-in Function} {} restoredefaultpath (@dots{})\n\ 2234 @deftypefn {Built-in Function} {} restoredefaultpath (@dots{})\n\
2237 Restore Octave's path to its initial state at startup.\n\ 2235 Restore Octave's path to its initial state at startup.\n\
2238 \n\ 2236 \n\
2239 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ 2237 @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\
2240 @end deftypefn") 2238 @end deftypefn")
2248 // search for function files. This corresponds to the path that 2246 // search for function files. This corresponds to the path that
2249 // exists prior to running the system's octaverc file or the user's 2247 // exists prior to running the system's octaverc file or the user's
2250 // ~/.octaverc file 2248 // ~/.octaverc file
2251 2249
2252 DEFUN (__pathorig__, , , 2250 DEFUN (__pathorig__, , ,
2253 "-*- texinfo -*-\n\ 2251 "-*- texinfo -*-\n\
2254 @deftypefn {Built-in Function} {@var{val} =} __pathorig__ ()\n\ 2252 @deftypefn {Built-in Function} {@var{val} =} __pathorig__ ()\n\
2255 Undocumented internal function.\n\ 2253 Undocumented internal function.\n\
2256 @end deftypefn") 2254 @end deftypefn")
2257 { 2255 {
2258 return octave_value (load_path::system_path ()); 2256 return octave_value (load_path::system_path ());
2259 } 2257 }
2260 2258
2261 DEFUN (path, args, nargout, 2259 DEFUN (path, args, nargout,
2262 "-*- texinfo -*-\n\ 2260 "-*- texinfo -*-\n\
2263 @deftypefn {Built-in Function} {} path (@dots{})\n\ 2261 @deftypefn {Built-in Function} {} path (@dots{})\n\
2264 Modify or display Octave's load path.\n\ 2262 Modify or display Octave's load path.\n\
2265 \n\ 2263 \n\
2266 If @var{nargin} and @var{nargout} are zero, display the elements of\n\ 2264 If @var{nargin} and @var{nargout} are zero, display the elements of\n\
2267 Octave's load path in an easy to read format.\n\ 2265 Octave's load path in an easy to read format.\n\
2299 2297
2300 if (nargout > 0) 2298 if (nargout > 0)
2301 retval = load_path::path (); 2299 retval = load_path::path ();
2302 else if (argc == 1 && nargout == 0) 2300 else if (argc == 1 && nargout == 0)
2303 { 2301 {
2304 octave_stdout << "\nOctave's search path contains the following directories:\n\n"; 2302 octave_stdout <<
2303 "\nOctave's search path contains the following directories:\n\n";
2305 2304
2306 string_vector dirs = load_path::dirs (); 2305 string_vector dirs = load_path::dirs ();
2307 2306
2308 dirs.list_in_columns (octave_stdout); 2307 dirs.list_in_columns (octave_stdout);
2309 2308
2313 2312
2314 return retval; 2313 return retval;
2315 } 2314 }
2316 2315
2317 DEFUN (addpath, args, nargout, 2316 DEFUN (addpath, args, nargout,
2318 "-*- texinfo -*-\n\ 2317 "-*- texinfo -*-\n\
2319 @deftypefn {Built-in Function} {} addpath (@var{dir1}, @dots{})\n\ 2318 @deftypefn {Built-in Function} {} addpath (@var{dir1}, @dots{})\n\
2320 @deftypefnx {Built-in Function} {} addpath (@var{dir1}, @dots{}, @var{option})\n\ 2319 @deftypefnx {Built-in Function} {} addpath (@var{dir1}, @dots{}, @var{option})\n\
2321 Add named directories to the function search path. If\n\ 2320 Add named directories to the function search path. If\n\
2322 @var{option} is @qcode{\"-begin\"} or 0 (the default), prepend the\n\ 2321 @var{option} is @qcode{\"-begin\"} or 0 (the default), prepend the\n\
2323 directory name to the current path. If @var{option} is @qcode{\"-end\"}\n\ 2322 directory name to the current path. If @var{option} is @qcode{\"-end\"}\n\
2429 2428
2430 return retval; 2429 return retval;
2431 } 2430 }
2432 2431
2433 DEFUN (rmpath, args, nargout, 2432 DEFUN (rmpath, args, nargout,
2434 "-*- texinfo -*-\n\ 2433 "-*- texinfo -*-\n\
2435 @deftypefn {Built-in Function} {} rmpath (@var{dir1}, @dots{})\n\ 2434 @deftypefn {Built-in Function} {} rmpath (@var{dir1}, @dots{})\n\
2436 Remove @var{dir1}, @dots{} from the current function search path.\n\ 2435 Remove @var{dir1}, @dots{} from the current function search path.\n\
2437 \n\ 2436 \n\
2438 In addition to accepting individual directory arguments, lists of\n\ 2437 In addition to accepting individual directory arguments, lists of\n\
2439 directory names separated by @code{pathsep} are also accepted. For example:\n\ 2438 directory names separated by @code{pathsep} are also accepted. For example:\n\