changeset 7272:05ee52d7fad6

[project @ 2007-12-10 07:06:00 by jwe]
author jwe
date Mon, 10 Dec 2007 07:06:01 +0000
parents c18512d0ddb6
children 7e58655dbe23
files liboctave/ChangeLog liboctave/file-ops.cc liboctave/file-ops.h src/ChangeLog src/dirfns.cc src/help.cc src/load-path.cc src/oct-hist.cc
diffstat 8 files changed, 42 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Mon Dec 10 06:52:51 2007 +0000
+++ b/liboctave/ChangeLog	Mon Dec 10 07:06:01 2007 +0000
@@ -1,3 +1,8 @@
+2007-12-10  John W. Eaton  <jwe@octave.org>
+
+	* file-ops.cc (file_ops::concat): New function.
+	* file-ops.h: Provide decl.
+
 2007-12-07  John W. Eaton  <jwe@octave.org>
 
 	* oct-time.cc (octave_base_tm::init): Only assign t->tm_zone if it
--- a/liboctave/file-ops.cc	Mon Dec 10 06:52:51 2007 +0000
+++ b/liboctave/file-ops.cc	Mon Dec 10 07:06:01 2007 +0000
@@ -857,6 +857,16 @@
   return dir_sep_chars.find (c) != NPOS;
 }
 
+std::string
+file_ops::concat (const std::string& dir, const std::string& file)
+{
+  return dir.empty ()
+    ? file
+    : (is_dir_sep (dir[dir.length()-1])
+       ? dir + file
+       : dir + file_ops::dir_sep_char + file);
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/liboctave/file-ops.h	Mon Dec 10 06:52:51 2007 +0000
+++ b/liboctave/file-ops.h	Mon Dec 10 07:06:01 2007 +0000
@@ -86,6 +86,8 @@
 
   static bool is_dir_sep (char);
 
+  static std::string concat (const std::string&, const std::string&);
+
   static char dir_sep_char;
   static std::string dir_sep_str;
   static std::string dir_sep_chars;
--- a/src/ChangeLog	Mon Dec 10 06:52:51 2007 +0000
+++ b/src/ChangeLog	Mon Dec 10 07:06:01 2007 +0000
@@ -1,5 +1,14 @@
 2007-12-10  John W. Eaton  <jwe@octave.org>
 
+	* oct-hist.cc (default_history_file): Use file_ops::concat.
+	* load-path.cc (dir_info::initialize, dir_info::get_file_list,
+	load_path::do_find_fcn, load_path::do_find_file, genpath,
+	execute_pkg_add_or_del, load_path::do_find_first_of,
+	load_path::do_find_all_first_of): Likewise.
+
+	* help.cc (Flookfor): Avoid doubling directory separator.
+	* dirfns.cc (Fmkdir): Likewise.
+
 	* pt-mat.cc (tree_matrix::rvalue): Produce sq_string if any
 	strings are sq_string objects.
 
--- a/src/dirfns.cc	Mon Dec 10 06:52:51 2007 +0000
+++ b/src/dirfns.cc	Mon Dec 10 07:06:01 2007 +0000
@@ -240,7 +240,7 @@
 	  return retval;
 	}
       else
-	dirname = parent + file_ops::dir_sep_char + dir;
+	dirname = file_ops::concat (parent, dir);
     }
   else if (nargin == 1)
     {
--- a/src/help.cc	Mon Dec 10 06:52:51 2007 +0000
+++ b/src/help.cc	Mon Dec 10 07:06:01 2007 +0000
@@ -1982,7 +1982,10 @@
 
 		      std::string file_name = load_path::find_fcn (name);
 		      
-		      std::string dir = dirs[i] + file_ops::dir_sep_str;
+		      std::string dir = dirs[i];
+
+		      if (! file_ops::is_dir_sep (dir[dir.length()-1]))
+			dir += file_ops::dir_sep_str;
 
 		      if (file_name == dir + name + ".oct"
 			  || file_name == dir + name + ".m")
--- a/src/load-path.cc	Mon Dec 10 06:52:51 2007 +0000
+++ b/src/load-path.cc	Mon Dec 10 07:06:01 2007 +0000
@@ -87,7 +87,7 @@
 	{
 	  if (has_private_subdir)
 	    {
-	      std::string pdn = dir_name + file_ops::dir_sep_str + "private";
+	      std::string pdn = file_ops::concat (dir_name, "private");
 
 	      get_private_function_map (pdn);
 	    }
@@ -123,7 +123,7 @@
 	{
 	  std::string fname = flist[i];
 
-	  std::string full_name = d + file_ops::dir_sep_str + fname;
+	  std::string full_name = file_ops::concat (d, fname);
 
 	  file_stat fs (full_name);
 
@@ -641,7 +641,7 @@
 
 	  int t = fi.types;
 
-	  retval = fi.dir_name + file_ops::dir_sep_str + fcn;
+	  retval = file_ops::concat (fi.dir_name, fcn);
 
 	  if (type == load_path::OCT_FILE)
 	    {
@@ -758,7 +758,7 @@
 	       p != dir_info_list.end ();
 	       p++)
 	    {
-	      std::string tfile = p->dir_name + file_ops::dir_sep_str + file;
+	      std::string tfile = file_ops::concat (p->dir_name, file);
 
 	      file_stat fs (tfile);
 
@@ -780,7 +780,7 @@
 	  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 file_ops::concat (p->dir_name, file);
 	    }
 	}
     }
@@ -842,7 +842,7 @@
  done:
 
   if (! dir_name.empty ())
-    retval = dir_name + file_ops::dir_sep_str + file_name;
+    retval = file_ops::concat (dir_name, file_name);
 
   return retval;
 }
@@ -889,7 +889,7 @@
 	    {
 	      if (all_files[i] == rel_flist[j])
 		retlist.push_back
-		  (p->dir_name + file_ops::dir_sep_str + rel_flist[j]);
+		  (file_ops::concat (p->dir_name, rel_flist[j]));
 	    }
 	}
     }
@@ -1197,7 +1197,7 @@
 
 	      if (! skip_p)
 		{
-		  std::string nm = dirname + file_ops::dir_sep_str + elt;
+		  std::string nm = file_ops::concat (dirname, elt);
 
 		  file_stat fs (nm);
 
@@ -1224,7 +1224,7 @@
 
   input_from_startup_file = true;
 
-  std::string file = dir + file_ops::dir_sep_str + script_file;
+  std::string file = file_ops::concat (dir, script_file);
 
   file_stat fs (file);
 
--- a/src/oct-hist.cc	Mon Dec 10 06:52:51 2007 +0000
+++ b/src/oct-hist.cc	Mon Dec 10 07:06:01 2007 +0000
@@ -87,19 +87,8 @@
     file = env_file;
 
   if (file.empty ())
-    {
-      std::string home_dir = octave_env::get_home_directory ();
-
-      if (! home_dir.empty ())
-	{
-	  file = home_dir;
-	  if (! file_ops::is_dir_sep (file[file.length()-1]))
-	    file += file_ops::dir_sep_char;
-	  file.append (".octave_hist");
-	}
-      else
-	file = ".octave_hist";
-    }
+    file = file_ops::concat (octave_env::get_home_directory (),
+			     ".octave_hist");
 
   return file;
 }