Mercurial > hg > octave-nkf
changeset 5867:b305874f50ef
[project @ 2006-06-28 22:11:51 by jwe]
author | jwe |
---|---|
date | Wed, 28 Jun 2006 22:11:51 +0000 |
parents | f9ac7ebf0e19 |
children | 84b5cd59e627 |
files | src/ChangeLog src/load-path.cc src/load-path.h |
diffstat | 3 files changed, 126 insertions(+), 127 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,18 @@ 2006-06-28 John W. Eaton <jwe@octave.org> + * load-path.cc (Faddpath): Don't treat "." specially here. + Don't check directory status here. + (Fpath): Handle all args. Don't treat "." specially here. + (Faddpath, Frmpath): Delete unused variable xpath. + (load_path::do_add): New function. + (load_path::do_prepend, load_path::do_append): Use it. + (load_path::do_remove): Really prevent removal of ".". + (load_path::do_clear): Clearing doesn't remove ".". + (load_path::append, load_path::prepend, load_path::do_append, + load_path::do_prepend): New arg, warn. + + * load-path.h: Fix decls. + * DLD-FUNCTIONS/regexp.cc (octregexp_list): Avoid bug in older versions of g++.
--- a/src/load-path.cc +++ b/src/load-path.cc @@ -374,7 +374,7 @@ if (Vsystem_path != ":") xpath += Vsystem_path; - do_set (xpath + ":::"); + do_set (xpath + ":::", false); } void @@ -382,6 +382,8 @@ { dir_info_list.clear (); fcn_map.clear (); + + do_append (".", false); } static std::list<std::string> @@ -418,7 +420,7 @@ } void -load_path::do_set (const std::string& p) +load_path::do_set (const std::string& p, bool warn) { do_clear (); @@ -433,7 +435,7 @@ for (std::list<std::string>::const_iterator i = elts.begin (); i != elts.end (); i++) - do_append (*i); + do_append (*i, warn); // Restore add hook and execute for all newly added directories. @@ -449,64 +451,72 @@ } void -load_path::do_append (const std::string& dir) +load_path::do_append (const std::string& dir, bool warn) { if (! dir.empty ()) - { - dir_info_list_iterator i = find_dir_info (dir); - - if (i != dir_info_list.end ()) - move (i, true); - else - { - dir_info di (dir); + do_add (dir, true, warn); +} - if (! error_state) - { - dir_info_list.push_back (di); - - add_to_fcn_map (di, true); - - if (add_hook) - add_hook (dir); - } - } - } +void +load_path::do_prepend (const std::string& dir, bool warn) +{ + if (! dir.empty ()) + do_add (dir, false, warn); } void -load_path::do_prepend (const std::string& dir) +load_path::do_add (const std::string& dir, bool at_end, bool warn) { - if (! dir.empty ()) + dir_info_list_iterator i = find_dir_info (dir); + + if (i != dir_info_list.end ()) + move (i, at_end); + else { - dir_info_list_iterator i = find_dir_info (dir); + file_stat fs (dir); - if (i != dir_info_list.end ()) - move (i, false); - else + if (fs) { - dir_info di (dir); + if (fs.is_dir ()) + { + dir_info di (dir); - if (! error_state) - { - dir_info_list.push_front (di); + if (! error_state) + { + if (at_end) + dir_info_list.push_back (di); + else + dir_info_list.push_front (di); + + add_to_fcn_map (di, true); - add_to_fcn_map (di, false); - - if (add_hook) - add_hook (dir); + if (add_hook) + add_hook (dir); + } } + else if (warn) + warning ("addpath: %s: not a directory", dir.c_str ()); } + else if (warn) + { + std::string msg = fs.error (); + warning ("addpath: %s: %s", dir.c_str (), msg.c_str ()); + } + } - // FIXME -- is there a better way to do this? + // FIXME -- is there a better way to do this? - i = find_dir_info ("."); + i = find_dir_info ("."); - if (i != dir_info_list.end ()) - move (i, false); - else - panic_impossible (); + if (i != dir_info_list.end ()) + { + if (i != dir_info_list.begin () && warn) + warning ("addpath: \".\" is always first in the path"); + + move (i, false); } + else + panic_impossible (); } bool @@ -517,55 +527,62 @@ if (! dir.empty ()) { if (dir == ".") - warning ("rmpath: can't remove \".\" from path"); + { + warning ("rmpath: can't remove \".\" from path"); - dir_info_list_iterator i = find_dir_info (dir); - - if (i != dir_info_list.end ()) - { + // Avoid additional warnings. retval = true; + } + else + { + dir_info_list_iterator i = find_dir_info (dir); - string_vector fcn_files = i->fcn_files; + if (i != dir_info_list.end ()) + { + retval = true; - dir_info_list.erase (i); + string_vector fcn_files = i->fcn_files; + + dir_info_list.erase (i); - octave_idx_type len = fcn_files.length (); + octave_idx_type len = fcn_files.length (); + + for (octave_idx_type k = 0; k < len; k++) + { + std::string fname = fcn_files[k]; - for (octave_idx_type k = 0; k < len; k++) - { - std::string fname = fcn_files[k]; + std::string ext; + std::string base = fname; + + size_t pos = fname.rfind ('.'); - std::string ext; - std::string base = fname; + if (pos != NPOS) + { + base = fname.substr (0, pos); + ext = fname.substr (pos); + } + + std::list<file_info>& file_info_list = fcn_map[base]; - size_t pos = fname.rfind ('.'); + for (std::list<file_info>::iterator p = file_info_list.begin (); + p != file_info_list.end (); + p++) + { + if (p->dir_name == dir) + { + file_info_list.erase (p); - if (pos != NPOS) - { - base = fname.substr (0, pos); - ext = fname.substr (pos); + if (file_info_list.empty ()) + fcn_map.erase (fname); + + break; + } + } } - std::list<file_info>& file_info_list = fcn_map[base]; - - for (std::list<file_info>::iterator p = file_info_list.begin (); - p != file_info_list.end (); - p++) - { - if (p->dir_name == dir) - { - file_info_list.erase (p); - - if (file_info_list.empty ()) - fcn_map.erase (fname); - - break; - } - } + if (remove_hook) + remove_hook (dir); } - - if (remove_hook) - remove_hook (dir); } } @@ -1289,16 +1306,9 @@ std::string path = argv[1]; for (int i = 2; i < argc; i++) - path += dir_path::path_sep_str; - - size_t plen = path.length (); + path += dir_path::path_sep_str + argv[i]; - if (! ((plen == 1 && path[0] == ':') - || (plen > 1 - && path.substr (0, 2) == ("." + dir_path::path_sep_str)))) - path = "." + dir_path::path_sep_str + path; - - load_path::set (path); + load_path::set (path, true); } if (nargout > 0) @@ -1381,12 +1391,6 @@ } } - std::list<std::string> xpath = load_path::dir_list (); - - // Strip "." for now. Calling path to set the path will restore it. - - xpath.remove ("."); - for (int i = 0; i < nargin; i++) { std::string arg = args(i).string_value (); @@ -1404,28 +1408,10 @@ //dir = regexprep (dir_elts{j}, "//+", "/"); //dir = regexprep (dir, "/$", ""); - if (dir == "." && append) - warning ("addpath: \".\" is always first in the path"); - - file_stat fs (dir); - - if (fs) - { - if (fs.is_dir ()) - { - if (append) - load_path::append (dir); - else - load_path::prepend (dir); - } - else - warning ("addpath: %s: not a directory", dir.c_str ()); - } + if (append) + load_path::append (dir, true); else - { - std::string msg = fs.error (); - warning ("addpath: %s: %s", dir.c_str (), msg.c_str ()); - } + load_path::prepend (dir, true); } } else @@ -1458,8 +1444,6 @@ if (nargin > 0) { - std::list<std::string> xpath = load_path::dir_list (); - for (int i = 0; i < nargin; i++) { std::string arg = args(i).string_value ();
--- a/src/load-path.h +++ b/src/load-path.h @@ -57,22 +57,22 @@ instance->do_clear (); } - static void set (const std::string& p) + static void set (const std::string& p, bool warn = false) { if (instance_ok ()) - instance->do_set (p); + instance->do_set (p, warn); } - static void append (const std::string& dir) + static void append (const std::string& dir, bool warn = false) { if (instance_ok ()) - instance->do_append (dir); + instance->do_append (dir, warn); } - static void prepend (const std::string& dir) + static void prepend (const std::string& dir, bool warn = false) { if (instance_ok ()) - instance->do_prepend (dir); + instance->do_prepend (dir, warn); } static bool remove (const std::string& dir) @@ -298,11 +298,13 @@ void do_clear (void); - void do_set (const std::string& p); + void do_set (const std::string& p, bool warn); + + void do_append (const std::string& dir, bool warn); - void do_append (const std::string& dir); + void do_prepend (const std::string& dir, bool warn); - void do_prepend (const std::string& dir); + void do_add (const std::string& dir, bool at_end, bool warn); bool do_remove (const std::string& dir);