changeset 11105:a6ab46b5926f

load_path::do_find{all,}first_of: search path for relative file names
author John W. Eaton <jwe@octave.org>
date Mon, 18 Oct 2010 01:19:28 -0400
parents 2c356a35d7f5
children 36c18286a61b
files src/ChangeLog src/load-path.cc
diffstat 2 files changed, 58 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2010-10-18  John W. Eaton  <jwe@octave.org>
+
+	* load-path.cc (load_path::do_find_first_of,
+	load_path::do_find_all_first_of): Also search path for relative
+	filenames.
+
 2010-10-17  John W. Eaton  <jwe@octave.org>
 
 	* DLD-FUNCTIONS/tril.cc: Use Octave copyright notice instead of
--- a/src/load-path.cc
+++ b/src/load-path.cc
@@ -1257,15 +1257,35 @@
 
   for (octave_idx_type i = 0; i < flen; i++)
     {
-      if (octave_env::absolute_pathname (flist[i]))
+      std::string file = flist[i];
+
+      if (file.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos)
         {
-          file_stat fs (flist[i]);
-
-          if (fs.exists ())
-            return flist[i];
+          if (octave_env::absolute_pathname (file)
+              || octave_env::rooted_relative_pathname (file))
+            {
+              file_stat fs (file);
+
+              if (fs.exists ())
+                return file;
+            }
+          else
+            {
+              for (const_dir_info_list_iterator p = dir_info_list.begin ();
+                   p != dir_info_list.end ();
+                   p++)
+                {
+                  std::string tfile = file_ops::concat (p->dir_name, file);
+
+                  file_stat fs (tfile);
+
+                  if (fs.exists ())
+                    return tfile;
+                }
+            }
         }
       else
-        rel_flist[rel_flen++] = flist[i];
+        rel_flist[rel_flen++] = file;
     }
 
   rel_flist.resize (rel_flen);
@@ -1316,15 +1336,35 @@
 
   for (octave_idx_type i = 0; i < flen; i++)
     {
-      if (octave_env::absolute_pathname (flist[i]))
+      std::string file = flist[i];
+
+      if (file.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos)
         {
-          file_stat fs (flist[i]);
-
-          if (fs.exists ())
-            retlist.push_back (flist[i]);
+          if (octave_env::absolute_pathname (file)
+              || octave_env::rooted_relative_pathname (file))
+            {
+              file_stat fs (file);
+
+              if (fs.exists ())
+                retlist.push_back (file);
+            }
+          else
+            {
+              for (const_dir_info_list_iterator p = dir_info_list.begin ();
+                   p != dir_info_list.end ();
+                   p++)
+                {
+                  std::string tfile = file_ops::concat (p->dir_name, file);
+
+                  file_stat fs (tfile);
+
+                  if (fs.exists ())
+                    retlist.push_back (tfile);
+                }
+            }
         }
       else
-        rel_flist[rel_flen++] = flist[i];
+        rel_flist[rel_flen++] = file;
     }
 
   rel_flist.resize (rel_flen);