changeset 4216:e613ffa9f0e6

[project @ 2002-12-04 17:37:09 by jwe]
author jwe
date Wed, 04 Dec 2002 17:37:09 +0000
parents bc6059c5ddc7
children 301cc4cf87e9
files src/Cell.cc src/Cell.h src/ChangeLog src/oct-map.cc src/oct-obj.cc src/oct-obj.h src/utils.cc src/utils.h
diffstat 8 files changed, 101 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/Cell.cc	Wed Dec 04 05:21:08 2002 +0000
+++ b/src/Cell.cc	Wed Dec 04 17:37:09 2002 +0000
@@ -30,6 +30,19 @@
 
 #include "Cell.h"
 
+Cell::Cell (const string_vector& sv)
+  : Array2<octave_value> ()
+{
+  int n = sv.length ();
+
+  if (n > 0)
+    {
+      resize (n, 1);
+
+      for (int i = 0; i < n; i++)
+	elem(i,0) = sv[i];
+    }
+}
 
 /*
 ;;; Local Variables: ***
--- a/src/Cell.h	Wed Dec 04 05:21:08 2002 +0000
+++ b/src/Cell.h	Wed Dec 04 17:37:09 2002 +0000
@@ -55,6 +55,8 @@
   Cell (const Array<octave_value>& c, int nr, int nc)
     : Array2<octave_value> (c, nr, nc) { }
 
+  Cell (const string_vector& sv);
+
   Cell (const Cell& c)
     : Array2<octave_value> (c) { }
 
--- a/src/ChangeLog	Wed Dec 04 05:21:08 2002 +0000
+++ b/src/ChangeLog	Wed Dec 04 17:37:09 2002 +0000
@@ -1,3 +1,16 @@
+2002-12-04  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* utils.cc (search_path_for_all_files): New function.
+	(Ffile_in_loadpath, Ffile_in_path): Allow search to return all
+	files in the path.
+
+	* Cell.cc (Cell (const string_vector&)): New constructor.
+
+	* oct-obj.cc (octave_value_list::assign): Allow optional fill
+	value for resizing.
+	* oct-map.cc (Octave_map::assign): Pass fill_value in initial
+	assignment too.
+
 2002-12-03  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* TEMPLATE-INST/Map-tc.cc, TEMPLATE-INST/Map-fnc.cc: Delete.
--- a/src/oct-map.cc	Wed Dec 04 05:21:08 2002 +0000
+++ b/src/oct-map.cc	Wed Dec 04 17:37:09 2002 +0000
@@ -126,7 +126,9 @@
 {
   octave_value_list tmp = map[key];
 
-  tmp.assign (idx, rhs);
+  octave_value fill_value = Matrix ();
+
+  tmp.assign (idx, rhs, fill_value);
 
   if (! error_state)
     {
@@ -134,8 +136,6 @@
 
       int len = array_length ();
 
-      octave_value fill_value = Matrix ();
-
       if (rhs_len < len)
 	{
 	  tmp.resize (len, fill_value);
--- a/src/oct-obj.cc	Wed Dec 04 05:21:08 2002 +0000
+++ b/src/oct-obj.cc	Wed Dec 04 17:37:09 2002 +0000
@@ -156,10 +156,11 @@
 
 octave_value_list&
 octave_value_list::assign (const idx_vector& i,
-			   const octave_value_list& rhs)
+			   const octave_value_list& rhs,
+			   const octave_value& fill_val)
 {
   data.set_index (i);
-  ::assign (data, rhs.data);
+  ::assign (data, rhs.data, fill_val);
   return *this;
 }
 
--- a/src/oct-obj.h	Wed Dec 04 05:21:08 2002 +0000
+++ b/src/oct-obj.h	Wed Dec 04 17:37:09 2002 +0000
@@ -151,7 +151,8 @@
   octave_value_list index (idx_vector& i, int resize_ok = 0) const;
 
   octave_value_list& assign (const idx_vector& i,
-			     const octave_value_list& rhs);
+			     const octave_value_list& rhs,
+			     const octave_value& fill_val = octave_value ());
 
   bool all_strings_p (void) const;
 
--- a/src/utils.cc	Wed Dec 04 05:21:08 2002 +0000
+++ b/src/utils.cc	Wed Dec 04 17:37:09 2002 +0000
@@ -53,6 +53,7 @@
 #include "pathsearch.h"
 #include "str-vec.h"
 
+#include "Cell.h"
 #include <defaults.h>
 #include "defun.h"
 #include "dirfns.h"
@@ -237,15 +238,50 @@
   return octave_env::make_absolute (p.find (name), octave_env::getcwd ());
 }
 
+// Find all locations of the given file in the path.
+
+string_vector
+search_path_for_all_files (const std::string& path, const std::string& name)
+{
+  dir_path p (path);
+
+  string_vector sv = p.find_all (name);
+
+  int len = sv.length ();
+
+  for (int i = 0; i < len; i++)
+    sv[i] = octave_env::make_absolute (sv[i], octave_env::getcwd ());
+
+  return sv;
+}
+
+static string_vector
+make_absolute (const string_vector& sv)
+{
+  int len = sv.length ();
+
+  for (int i = 0; i < len; i++)
+    sv[i] = octave_env::make_absolute (sv[i], octave_env::getcwd ());
+
+  return sv;
+}
+
 DEFUN (file_in_loadpath, args, ,
   "-*- texinfo -*-\n\
-@deftypefn {Built-in Function} {} file_in_loadpath (@var{name})\n\
+@deftypefn {Built-in Function} {} file_in_loadpath (@var{file})\n\
+@deftypefnx {Built-in Function} {} file_in_loadpath (@var{file}, \"all\")\n\
 \n\
-Look up @var{name} in Octave's @code{LOADPATH}.\n\
+Return the absolute name name of @var{file} if it can be found in\n\
+the list of directories specified by @code{LOADPATH}.\n\
+If no file is found, return an empty matrix.\n\
+\n\
+If the second optional argument @code{\"all\"} is supplied, return\n\
+a cell array containing the list of all files that have the same\n\
+name in the path.  If no files are found, return an empty cell array.\n\
 @end deftypefn\n\
 @seealso{file_in_path}")
 {
-  octave_value_list retval;
+  octave_value retval;
 
   int argc = args.length () + 1;
 
@@ -255,8 +291,17 @@
     return retval;
 
   if (argc == 2)
-    retval = octave_env::make_absolute (Vload_path_dir_path.find (argv[1]),
-					octave_env::getcwd ());
+    {
+      std::string fname
+	= octave_env::make_absolute (Vload_path_dir_path.find (argv[1]),
+				     octave_env::getcwd ());
+      if (fname.empty ())
+	retval = Matrix ();
+      else
+	retval = fname;
+    }
+  else if (argc == 3 && argv[2] == "all")
+    retval = Cell (make_absolute (Vload_path_dir_path.find_all (argv[1])));
   else
     print_usage ("file_in_loadpath");
 
@@ -266,21 +311,24 @@
 DEFUN (file_in_path, args, ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} file_in_path (@var{path}, @var{file})\n\
+@deftypefnx {Built-in Function} {} file_in_path (@var{path}, @var{file}, \"all\")\n\
 Return the absolute name name of @var{file} if it can be found in\n\
 @var{path}.  The value of @var{path} should be a colon-separated list of\n\
 directories in the format described for the built-in variable\n\
-@code{LOADPATH}.\n\
-\n\
-If the file cannot be found in the path, an empty matrix is returned.\n\
+@code{LOADPATH}.  If no file is found, return an empty matrix.\n\
 For example,\n\
 \n\
 @example\n\
 file_in_path (LOADPATH, \"nargchk.m\")\n\
      @result{} \"@value{OCTAVEHOME}/share/octave/2.0/m/general/nargchk.m\"\n\
 @end example\n\
+\n\
+If the third optional argument @code{\"all\"} is supplied, return\n\
+a cell array containing the list of all files that have the same\n\
+name in the path.  If no files are found, return an empty cell array.\n\
 @end deftypefn")
 {
-  octave_value_list retval;
+  octave_value retval;
 
   int argc = args.length () + 1;
 
@@ -298,6 +346,8 @@
       else
 	retval = fname;
     }
+  else if (argc == 4 && argv[3] == "all")
+    retval = Cell (make_absolute (search_path_for_all_files (argv[1], argv[2])));
   else
     print_usage ("file_in_path");
 
--- a/src/utils.h	Wed Dec 04 05:21:08 2002 +0000
+++ b/src/utils.h	Wed Dec 04 17:37:09 2002 +0000
@@ -47,7 +47,12 @@
 
 extern int empty_arg (const char *name, int nr, int nc);
 
-extern std::string search_path_for_file (const std::string&, const std::string&);
+extern std::string
+search_path_for_file (const std::string&, const std::string&);
+
+extern string_vector
+search_path_for_all_files (const std::string&, const std::string&);
+
 extern std::string file_in_path (const std::string&, const std::string&);
 extern std::string fcn_file_in_path (const std::string&);
 extern std::string oct_file_in_path (const std::string&);