changeset 6838:5e3350bdd91d

[project @ 2007-08-28 02:59:58 by jwe]
author jwe
date Tue, 28 Aug 2007 02:59:59 +0000
parents 7eefeed173ea
children 40ad39648884
files doc/interpreter/Makefile.in liboctave/ChangeLog liboctave/oct-env.cc liboctave/oct-env.h src/ChangeLog src/file-io.cc src/load-path.cc src/load-save.cc
diffstat 8 files changed, 93 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/Makefile.in	Mon Aug 27 20:20:55 2007 +0000
+++ b/doc/interpreter/Makefile.in	Tue Aug 28 02:59:59 2007 +0000
@@ -79,8 +79,8 @@
 	intro.txi io.txi linalg.txi matrix.txi nonlin.txi numbers.txi \
 	op-idx.txi optim.txi package.txi plot.txi poly.txi preface.txi \
 	quad.txi quaternion.txi set.txi signal.txi sparse.txi stats.txi \
-	stmt.txi strings.txi struct.txi system.txi \
-	testfun.txi tips.txi var.txi vr-idx.txi
+	stmt.txi strings.txi system.txi testfun.txi tips.txi var.txi \
+	vr-idx.txi
 
 SOURCES := $(SUB_SOURCE) $(SCRIPT_SOURCES)
 
--- a/liboctave/ChangeLog	Mon Aug 27 20:20:55 2007 +0000
+++ b/liboctave/ChangeLog	Tue Aug 28 02:59:59 2007 +0000
@@ -1,3 +1,9 @@
+2007-08-27  John W. Eaton  <jwe@octave.org>
+
+	* oct-env.cc (octave_env::rooted_relative_pathname,
+	octave_env::do_rooted_relative_pathname): New functions.
+	* oct-env.h: Provide decls.
+
 2007-08-24  David Bateman  <dbateman@free.fr>
 
         * MSparse.h (MSparse<T>& insert (const Sparse<T>&, 
--- a/liboctave/oct-env.cc	Mon Aug 27 20:20:55 2007 +0000
+++ b/liboctave/oct-env.cc	Tue Aug 28 02:59:59 2007 +0000
@@ -110,6 +110,13 @@
     ? instance->do_absolute_pathname (s) : false;
 }
 
+bool
+octave_env::rooted_relative_pathname (const std::string& s)
+{
+  return (instance_ok ())
+    ? instance->do_rooted_relative_pathname (s) : false;
+}
+
 std::string
 octave_env::base_pathname (const std::string& s)
 {
@@ -261,6 +268,29 @@
   return false;
 }
 
+bool
+octave_env::do_rooted_relative_pathname (const std::string& s) const
+{
+  size_t len = s.length ();
+
+  if (len == 0)
+    return false;
+
+  if (len == 1 && s[0] == '.')
+    return true;
+
+  if (len > 1 && s[0] == '.' && file_ops::is_dir_sep (s[1]))
+    return true;
+
+  if (len == 2 && s[0] == '.' && s[1] == '.')
+    return true;
+
+  if (len > 2 && s[0] == '.' && s[1] == '.' && file_ops::is_dir_sep (s[2]))
+    return true;
+
+  return false;
+}
+
 // Return the `basename' of the pathname in STRING (the stuff after
 // the last directory separator).  If STRING is not a full pathname,
 // simply return it.
--- a/liboctave/oct-env.h	Mon Aug 27 20:20:55 2007 +0000
+++ b/liboctave/oct-env.h	Tue Aug 28 02:59:59 2007 +0000
@@ -40,6 +40,8 @@
 
   static bool absolute_pathname (const std::string& s);
 
+  static bool rooted_relative_pathname (const std::string& s);
+
   static std::string base_pathname (const std::string& s);
 
   static std::string make_absolute (const std::string& s,
@@ -75,6 +77,8 @@
 
   bool do_absolute_pathname (const std::string& s) const;
 
+  bool do_rooted_relative_pathname (const std::string& s) const;
+
   std::string do_base_pathname (const std::string& s) const;
 
   std::string do_make_absolute (const std::string& s,
--- a/src/ChangeLog	Mon Aug 27 20:20:55 2007 +0000
+++ b/src/ChangeLog	Tue Aug 28 02:59:59 2007 +0000
@@ -1,5 +1,10 @@
 2007-08-27  John W. Eaton  <jwe@octave.org>
 
+	* load-path.cc (load_path::do_find_file): Also files with non
+	rooted relative names.
+	* load-save.cc (find_file_to_load): Likewise.  Also handle
+	appending .mat to files with relative names.
+
 	* graphics.cc (base_properties::mark_modified,
 	base_properties::override_defaults,
 	base_properties::delete_children, figure::get_default,
--- a/src/file-io.cc	Mon Aug 27 20:20:55 2007 +0000
+++ b/src/file-io.cc	Tue Aug 28 02:59:59 2007 +0000
@@ -394,7 +394,9 @@
 	{
 	  std::string fname = file_ops::tilde_expand (name);
 
-	  if (! (md & std::ios::out || octave_env::absolute_pathname (fname)))
+	  if (! (md & std::ios::out
+		 || octave_env::absolute_pathname (fname)
+		 || octave_env::rooted_relative_pathname (fname)))
 	    {
 	      file_stat fs (fname);
 
--- a/src/load-path.cc	Mon Aug 27 20:20:55 2007 +0000
+++ b/src/load-path.cc	Tue Aug 28 02:59:59 2007 +0000
@@ -743,39 +743,48 @@
 {
   std::string retval;
 
-  if (octave_env::absolute_pathname (file))
+  if (file.find ('/') != NPOS)
     {
-      file_stat fs (file);
-
-      if (fs.exists ())
-	return file;
-    }
-
-  std::string dir_name;
+      if (octave_env::absolute_pathname (file)
+	  || octave_env::rooted_relative_pathname (file))
+	{
+	  file_stat fs (file);
 
-  for (const_dir_info_list_iterator p = dir_info_list.begin ();
-       p != dir_info_list.end ();
-       p++)
-    {
-      string_vector all_files = p->all_files;
-
-      octave_idx_type len = all_files.length ();
+	  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 = p->dir_name + file_ops::dir_sep_str + file;
 
-      for (octave_idx_type i = 0; i < len; i++)
-	{
-	  if (all_files[i] == file)
-	    {
-	      dir_name = p->dir_name;
+	      file_stat fs (tfile);
 
-	      goto done;
+	      if (fs.exists ())
+		return tfile;
 	    }
 	}
     }
-
- done:
+  else
+    {
+      for (const_dir_info_list_iterator p = dir_info_list.begin ();
+	   p != dir_info_list.end ();
+	   p++)
+	{
+	  string_vector all_files = p->all_files;
 
-  if (! dir_name.empty ())
-    retval = dir_name + file_ops::dir_sep_str + file;
+	  octave_idx_type len = all_files.length ();
+
+	  for (octave_idx_type i = 0; i < len; i++)
+	    {
+	      if (all_files[i] == file)
+		return p->dir_name + file_ops::dir_sep_str + file;
+	    }
+	}
+    }
 
   return retval;
 }
--- a/src/load-save.cc	Mon Aug 27 20:20:55 2007 +0000
+++ b/src/load-save.cc	Tue Aug 28 02:59:59 2007 +0000
@@ -594,7 +594,8 @@
 {
   std::string fname = name;
 
-  if (! octave_env::absolute_pathname (fname))
+  if (! (octave_env::absolute_pathname (fname)
+	 || octave_env::rooted_relative_pathname (fname)))
     {
       file_stat fs (fname);
 
@@ -612,8 +613,14 @@
 	}
     }
 
-  if (fname.rfind (".") == NPOS)
+  size_t dot_pos = fname.rfind (".");
+  size_t sep_pos = fname.find_last_of (file_ops::dir_sep_chars);
+    
+  if (dot_pos == NPOS || (sep_pos != NPOS && dot_pos < sep_pos))
     {
+      // Either no '.' in name or no '.' appears after last directory
+      // separator.
+
       file_stat fs (fname);
 
       if (! (fs.exists () && fs.is_reg ()))