changeset 10971:386aa01ca84c

genpath: accept additional arguments as names of directories to skip
author Jordi Gutiérrez Hermoso <jordigh@gmail.com>
date Tue, 14 Sep 2010 02:18:38 -0400
parents 795400289d1c
children 14d16530ad59
files src/ChangeLog src/load-path.cc
diffstat 2 files changed, 31 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Sep 14 01:59:03 2010 -0400
+++ b/src/ChangeLog	Tue Sep 14 02:18:38 2010 -0400
@@ -1,3 +1,8 @@
+2010-09-14  Jordi GutiƩrrez Hermoso <jordigh@gmail.com>
+
+	* load-path.cc (genpath): Pass SKIP in recursive call.
+	(Fgenpath): Accept list of directories to skip.
+
 2010-09-14  John W. Eaton  <jwe@octave.org>
 
 	* oct-stream.cc (BEGIN_CHAR_CLASS_CONVERSION): If we hit EOF but
--- a/src/load-path.cc	Tue Sep 14 01:59:03 2010 -0400
+++ b/src/load-path.cc	Tue Sep 14 02:18:38 2010 -0400
@@ -1829,10 +1829,6 @@
         {
           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] == '@');
 
           if (! skip_p)
@@ -1851,7 +1847,7 @@
                   file_stat fs (nm);
 
                   if (fs && fs.is_dir ())
-                    retval += dir_path::path_sep_str () + genpath (nm);
+                    retval += dir_path::path_sep_str () + genpath (nm, skip);
                 }
             }
         }
@@ -1896,12 +1892,17 @@
 DEFUN (genpath, args, ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} genpath (@var{dir})\n\
+@deftypefnx {Built-in Function} {} genpath (@var{dir}, @var{skip}, @dots{})\n\
 Return a path constructed from @var{dir} and all its subdirectories.\n\
+If additional string parameters are given, the resulting path will \n\
+exclude directories with those names.\
 @end deftypefn")
 {
   octave_value retval;
 
-  if (args.length () == 1)
+  octave_idx_type nargin = args.length ();
+
+  if (nargin == 1)
     {
       std::string dirname = args(0).string_value ();
 
@@ -1910,6 +1911,25 @@
       else
         error ("genpath: expecting argument to be a character string");
     }
+  else if (nargin > 1)
+    {
+      std::string dirname = args(0).string_value ();
+
+      string_vector skip (nargin - 1);
+
+      for (octave_idx_type i = 1; i < nargin; i++)
+        {
+          skip[i-1] = args(i).string_value ();
+
+          if (error_state)
+            break;
+        }
+
+      if (! error_state)
+        retval = genpath (dirname, skip);
+      else
+        error ("genpath: expecting all arguments to be character strings");
+    }
   else
     print_usage ();