# HG changeset patch
# User address@hidden
# Date 1234997149 18000
# Node ID cff08453b6f09b5b8e11744862abf9cc70af1744
# Parent 20dfb885f877be11f33985e69203bd8fc87e977a
Updates to genpath to allow a user to disregard directories (e.g. .hg and .svn).
diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -0,0 +1,3 @@
+2009-02-18 John Swensen
+ * load-path.cc: Allow users of genpath to exclude directories from inclusions.
+
diff --git a/src/defaults.cc b/src/defaults.cc
--- a/src/defaults.cc
+++ b/src/defaults.cc
@@ -271,7 +271,7 @@
if (! tpath.empty ())
VIMAGE_PATH += dir_path::path_sep_str () + tpath;
- tpath = genpath (Vimage_dir, "");
+ tpath = genpath (Vimage_dir, std::list(1,""));
if (! tpath.empty ())
VIMAGE_PATH += dir_path::path_sep_str () + tpath;
diff --git a/src/load-path.cc b/src/load-path.cc
--- a/src/load-path.cc
+++ b/src/load-path.cc
@@ -516,13 +516,13 @@
do_append (".", false);
}
-static std::list
-split_path (const std::string& p)
+static string_vector
+split_string (const std::string& p, char sep_char=dir_path::path_sep_char ())
{
std::list retval;
size_t beg = 0;
- size_t end = p.find (dir_path::path_sep_char ());
+ size_t end = p.find (sep_char);
size_t len = p.length ();
@@ -538,7 +538,7 @@
if (beg == len)
break;
- end = p.find (dir_path::path_sep_char (), beg);
+ end = p.find (sep_char, beg);
}
std::string elt = p.substr (beg);
@@ -546,13 +546,13 @@
if (! elt.empty ())
retval.push_back (elt);
- return retval;
+ return string_vector (retval);
}
void
load_path::do_set (const std::string& p, bool warn)
{
- std::list elts = split_path (p);
+ const string_vector elts = split_string (p);
// Temporarily disable add hook.
@@ -562,10 +562,8 @@
do_clear ();
- for (std::list::const_iterator i = elts.begin ();
- i != elts.end ();
- i++)
- do_append (*i, warn);
+ for (octave_idx_type i = 0; i < elts.length (); i++)
+ do_append (elts (i), warn);
// Restore add hook and execute for all newly added directories.
@@ -1697,31 +1695,19 @@
for (octave_idx_type i = 0; i < len; i++)
{
std::string elt = dirlist[i];
-
- // FIXME -- the caller should be able to specify the list of
- // directories to skip in addition to ".", "..", and
- // directories beginning with "@".
-
+
bool skip_p = (elt == "." || elt == ".." || elt[0] == '@');
+ for (octave_idx_type k = 0; ! skip_p && k < skip.length (); k++)
+ skip_p = elt == skip (k);
if (! skip_p)
{
- for (octave_idx_type j = 0; j < skip.length (); j++)
- {
- skip_p = (elt == skip[j]);
- if (skip_p)
- break;
- }
-
- if (! skip_p)
- {
- std::string nm = file_ops::concat (dirname, elt);
-
- file_stat fs (nm);
-
- if (fs && fs.is_dir ())
- retval += dir_path::path_sep_str () + genpath (nm);
- }
+ std::string nm = file_ops::concat (dirname, elt);
+
+ file_stat fs (nm);
+
+ if (fs && fs.is_dir ())
+ retval += dir_path::path_sep_str () + genpath (nm);
}
}
}
@@ -1766,8 +1752,9 @@
DEFUN (genpath, args, ,
"-*- texinfo -*-\n\
address@hidden {Built-in Function} {} genpath (@var{dir})\n\
-Return a path constructed from @var{dir} and all its subdirectories.\n\
address@hidden {Built-in Function} {} genpath (@var{dir}, @var{exclude})\n\
+Return a path constructed from @var{dir} and all its subdirectories, with\n\
+the exception of the colon-separated list of directories in @var{exclude}.\n\
@end deftypefn")
{
octave_value retval;
@@ -1780,6 +1767,18 @@
retval = genpath (dirname);
else
error ("genpath: expecting argument to be a character string");
+ }
+ else if (args.length() == 2)
+ {
+ std::string dirname = args(0).string_value ();
+ std::string skipstr = args(1).string_value ();
+
+ const string_vector skip = split_string (skipstr, ':');
+
+ if (! error_state)
+ retval = genpath (dirname, skip);
+ else
+ error ("genpath: expecting arguments to be a character strings");
}
else
print_usage ();
@@ -1966,13 +1965,11 @@
if (! error_state)
{
- std::list dir_elts = split_path (arg);
+ const string_vector dir_elts = split_string (arg);
- for (std::list::const_iterator p = dir_elts.begin ();
- p != dir_elts.end ();
- p++)
+ for (octave_idx_type k = 0; k < dir_elts.length (); k++)
{
- std::string dir = *p;
+ std::string dir = dir_elts (k);
//dir = regexprep (dir_elts{j}, "//+", "/");
//dir = regexprep (dir, "/$", "");
@@ -2019,13 +2016,11 @@
if (! error_state)
{
- std::list dir_elts = split_path (arg);
+ const string_vector dir_elts = split_string (arg);
- for (std::list::const_iterator p = dir_elts.begin ();
- p != dir_elts.end ();
- p++)
+ for (octave_idx_type k = 0; k < dir_elts.length (); k++)
{
- std::string dir = *p;
+ std::string dir = dir_elts (k);
//dir = regexprep (dir_elts{j}, "//+", "/");
//dir = regexprep (dir, "/$", "");
diff --git a/src/load-path.h b/src/load-path.h
--- a/src/load-path.h
+++ b/src/load-path.h
@@ -505,6 +505,7 @@
extern std::string
genpath (const std::string& dir, const string_vector& skip = "private");
+
extern void execute_pkg_add (const std::string& dir);
extern void execute_pkg_del (const std::string& dir);