# HG changeset patch # User jwe # Date 1039023429 0 # Node ID e613ffa9f0e6a5064ef88bd5fef3bcbb7560a64a # Parent bc6059c5ddc7f5c782f50e1b341865cafd597baa [project @ 2002-12-04 17:37:09 by jwe] diff --git a/src/Cell.cc b/src/Cell.cc --- a/src/Cell.cc +++ b/src/Cell.cc @@ -30,6 +30,19 @@ #include "Cell.h" +Cell::Cell (const string_vector& sv) + : Array2 () +{ + int n = sv.length (); + + if (n > 0) + { + resize (n, 1); + + for (int i = 0; i < n; i++) + elem(i,0) = sv[i]; + } +} /* ;;; Local Variables: *** diff --git a/src/Cell.h b/src/Cell.h --- a/src/Cell.h +++ b/src/Cell.h @@ -55,6 +55,8 @@ Cell (const Array& c, int nr, int nc) : Array2 (c, nr, nc) { } + Cell (const string_vector& sv); + Cell (const Cell& c) : Array2 (c) { } diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2002-12-04 John W. Eaton + + * 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 * TEMPLATE-INST/Map-tc.cc, TEMPLATE-INST/Map-fnc.cc: Delete. diff --git a/src/oct-map.cc b/src/oct-map.cc --- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -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); diff --git a/src/oct-obj.cc b/src/oct-obj.cc --- a/src/oct-obj.cc +++ b/src/oct-obj.cc @@ -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; } diff --git a/src/oct-obj.h b/src/oct-obj.h --- a/src/oct-obj.h +++ b/src/oct-obj.h @@ -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; diff --git a/src/utils.cc b/src/utils.cc --- a/src/utils.cc +++ b/src/utils.cc @@ -53,6 +53,7 @@ #include "pathsearch.h" #include "str-vec.h" +#include "Cell.h" #include #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"); diff --git a/src/utils.h b/src/utils.h --- a/src/utils.h +++ b/src/utils.h @@ -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&);