changeset 7392:17f2cdb5232e

[project @ 2008-01-17 08:14:32 by jwe]
author jwe
date Thu, 17 Jan 2008 08:14:32 +0000
parents f071480b7eac
children a2e8cfe2fd17
files scripts/ChangeLog scripts/path/__extractpath__.m scripts/path/pathdef.m scripts/path/savepath.m scripts/startup/__finish__.m scripts/startup/main-rcfile src/ChangeLog
diffstat 7 files changed, 114 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Thu Jan 17 07:50:33 2008 +0000
+++ b/scripts/ChangeLog	Thu Jan 17 08:14:32 2008 +0000
@@ -1,15 +1,27 @@
+2008-01-17  John W. Eaton  <jwe@octave.org>
+
+	* path/pathdef.m: Use fullfile instead of concatenating with filesep.
+	* path/__extractpath__.m, path/savepath.m: Use unwind_protect to
+	avoid possible file descriptor leak.
+
+2008-01-17  Ben Abbott  <bpabbott@mac.com>
+
+	* path/savepath.m: Warn if modified file is not explicitly specified.
+	* startup/main-rcfile: Call atexit ("__finish__").
+
 2008-01-16  John W. Eaton  <jwe@octave.org>
 
 	* plot/__go_draw_axes__.m (__do_enhanced_option__): New subfunction.
 	Use it to disable enhanced mode for individual labels and titles.
 
-	* startup/__finish__.m: New file.
-	* startup/Makefile.in (SOURCES): Add it to the list.
+	* startup/Makefile.in (SOURCES): Add __finish__.m to the list.
 	(install install-strip, uninstall): Handle function files.
 
 2008-01-16  Ben Abbott  <bpabbott@mac.com>
 
-	* path/__extractpath__.m, path/matlabroot.m, path/pathdef.m: New files.
+	* startup/__finish__.m: New file.
+	* path/__extractpath__.m, path/matlabroot.m,
+	path/pathdef.m: New files.
 	* path/Makefile.in (SOURCES): Add them to the list.
 
 2008-01-15  Thomas Weber  <thomas.weber.mail@gmail.com>
--- a/scripts/path/__extractpath__.m	Thu Jan 17 07:50:33 2008 +0000
+++ b/scripts/path/__extractpath__.m	Thu Jan 17 08:14:32 2008 +0000
@@ -30,7 +30,9 @@
 
 function specifiedpath = __extractpath__ (savefile)
 
-  ## The majority of this code was borrowed from savepath.m
+  ## The majority of this code was borrowed from savepath.m.
+  ## FIXME -- is there some way to share the common parts instead of
+  ## duplicating?
 
   beginstring = "## Begin savepath auto-created section, do not edit";
   endstring   = "## End savepath auto-created section";
@@ -39,8 +41,8 @@
     savefile = tilde_expand ("~/.octaverc");
   endif
 
-  ## parse the file if it exists to see if we should replace a section
-  ## or create a section
+  ## Parse the file if it exists to see if we should replace a section
+  ## or create a section.
   startline = 0;
   endline = 0;
   filelines = {};
@@ -50,30 +52,34 @@
     if (fid < 0)
       error ("__extractpath__: could not open savefile, %s: %s", savefile, msg);
     endif
-    linenum = 0;
-    while (linenum >= 0)
-      result = fgetl (fid);
-      if (isnumeric (result))
-        ## end at the end of file
-        linenum = -1;
-      else
-        linenum = linenum + 1;
-        filelines{linenum} = result;
-        ## find the first and last lines if they exist in the file
-        if (strcmp (result, beginstring))
-          startline = linenum+1;
-        elseif (strcmp (result, endstring))
-          endline = linenum-1;
-        endif
+    unwind_protect
+      linenum = 0;
+      while (linenum >= 0)
+	result = fgetl (fid);
+	if (isnumeric (result))
+	  ## End at the end of file.
+	  linenum = -1;
+	else
+	  linenum++;
+	  filelines{linenum} = result;
+	  ## Find the first and last lines if they exist in the file.
+	  if (strcmp (result, beginstring))
+	    startline = linenum + 1;
+	  elseif (strcmp (result, endstring))
+	    endline = linenum - 1;
+	  endif
+	endif
+      endwhile
+    unwind_protect_cleanup
+      closeread = fclose (fid);
+      if (closeread < 0)
+	error ("savepath: could not close savefile after reading, %s",
+	       savefile);
       endif
-    endwhile
-    closeread = fclose (fid);
-    if (closeread < 0)
-      error ("savepath: could not close savefile after reading, %s", savefile);
-    endif
+    end_unwind_protect
   endif
 
-  ## extract the path specifiation
+  ## Extract the path specifiation.
   if (startline > endline || (startline > 0 && endline == 0))
     error ("savepath: unable to parse file, %s", savefile);
   elseif startline > 0
--- a/scripts/path/pathdef.m	Thu Jan 17 07:50:33 2008 +0000
+++ b/scripts/path/pathdef.m	Thu Jan 17 08:14:32 2008 +0000
@@ -25,39 +25,42 @@
 ## @enumerate
 ## @item @file{~/.octaverc}
 ## @item @file{<octave-home>/.../<version>/m/startup/octaverc}
-## @item Octave"s path prior to changes by any octaverc.
+## @item Octave's path prior to changes by any octaverc.
 ## @end enumerate
 ## @seealso{path, addpath, rmpath, genpath, savepath, pathsep}
 ## @end deftypefn
 
 function val = pathdef ()
 
-  ## Use Octave"s orignal path as the default default.
+  ## Use Octave's orignal path as the default default.
   val = __pathorig__ ();
 
-  ## Locate the site octaverc file (is there a better way?).
+  ## Locate the site octaverc file.
   pathdir = octave_config_info ("localstartupfiledir");
-  site_octaverc = [pathdir, filesep, "octaverc"];
+  site_octaverc = fullfile (pathdir, "octaverc");
 
   ## locate the user ~\.octaverc file.
-  user_octaverc = ["~", filesep, ".octaverc"];
-  user_octaverc = sprintf ("~%s.octaverc", filesep);
+  user_octaverc = fullfile ("~", ".octaverc");
 
   ## Extract the specified paths from the site and user octaverc"s.
   site_pathscript = __extractpath__ (site_octaverc);
-  if exist (user_octaverc, "file")
+  if (exist (user_octaverc, "file"))
     user_pathscript = __extractpath__ (user_octaverc);
   else
     user_pathscript = "";
   endif
 
-  ## A path definition in the user octaverc has precedence over the site
-  if numel (user_pathscript)
+  ## A path definition in the user octaverc has precedence over the
+  ## site.
+
+  ## FIXME -- use a subfunction here to avoid code duplication?
+
+  if (numel (user_pathscript))
     try
       if (numel (user_pathscript) == 1)
-        n = strfind (user_pathscript{1},"'");
+        n = strfind (user_pathscript{1}, "'");
         if (numel(n) == 1)
-          n = strfind (user_pathscript{1},"""");
+          n = strfind (user_pathscript{1}, "\"");
         endif
         val = user_pathscript{1}(n(1):n(end));
       else
@@ -67,14 +70,14 @@
         path (presentpath);
       endif
     catch
-      warning ("pathdef: Path defined in `%s' produced an error.",user_octaverc)
+      warning ("pathdef: invalid path found in `%s'", user_octaverc);
     end_try_catch
-  elseif numel (site_pathscript)
+  elseif (numel (site_pathscript))
     try
       if (numel (site_pathscript) == 1)
-        n = strfind (site_pathscript{1},"'");
+        n = strfind (site_pathscript{1}, "'");
         if (numel(n) == 1)
-          n = strfind (site_pathscript{1},"""");
+          n = strfind (site_pathscript{1}, "\"");
         endif
         val = site_pathscript{1}(n(1):n(end));
       else
@@ -84,10 +87,8 @@
         path (presentpath);
       endif
     catch
-      warning ("pathdef: Path defined in `%s' produced an error.",site_octaverc)
+      warning ("pathdef: invalid path found in `%s'", site_octaverc);
     end_try_catch
   endif
 
 endfunction
-
-
--- a/scripts/path/savepath.m	Thu Jan 17 07:50:33 2008 +0000
+++ b/scripts/path/savepath.m	Thu Jan 17 08:14:32 2008 +0000
@@ -50,27 +50,31 @@
     if (fid < 0)
       error ("savepath: could not open savefile, %s: %s", savefile, msg);
     endif
-    linenum = 0;
-    while (linenum >= 0)
-      result = fgetl (fid);
-      if (isnumeric (result))
-        ## end at the end of file
-        linenum = -1;
-      else
-        linenum = linenum + 1;
-        filelines{linenum} = result;
-        ## find the first and last lines if they exist in the file
-        if (strcmp (result, beginstring))
-          startline = linenum;
-        elseif (strcmp (result, endstring))
-          endline = linenum;
-        endif
+    unwind_protect
+      linenum = 0;
+      while (linenum >= 0)
+	result = fgetl (fid);
+	if (isnumeric (result))
+	  ## end at the end of file
+	  linenum = -1;
+	else
+	  linenum = linenum + 1;
+	  filelines{linenum} = result;
+	  ## find the first and last lines if they exist in the file
+	  if (strcmp (result, beginstring))
+	    startline = linenum;
+	  elseif (strcmp (result, endstring))
+	    endline = linenum;
+	  endif
+	endif
+      endwhile
+    unwind_protect_cleanup
+      closeread = fclose (fid);
+      if (closeread < 0)
+	error ("savepath: could not close savefile after reading, %s",
+	       savefile);
       endif
-    endwhile
-    closeread = fclose (fid);
-    if (closeread < 0)
-      error ("savepath: could not close savefile after reading, %s", savefile);
-    endif
+    end_unwind_protect
   endif
 
   if (startline > endline || (startline > 0 && endline == 0))
@@ -103,24 +107,27 @@
   if (fid < 0)
     error ("savepath: unable to open file for writing, %s, %s", savefile, msg);
   endif
-  for i = 1:length (pre)
-    fprintf (fid, "%s\n", pre{i})
-  endfor
+  unwind_protect
+    for i = 1:length (pre)
+      fprintf (fid, "%s\n", pre{i})
+    endfor
 
-  ## Use single quotes for PATH argument to avoid string escape
-  ## processing.
-  fprintf (fid, "%s\n  path ('%s');\n%s\n",
-	   beginstring, path (), endstring);
+    ## Use single quotes for PATH argument to avoid string escape
+    ## processing.
+    fprintf (fid, "%s\n  path ('%s');\n%s\n",
+	     beginstring, path (), endstring);
 
-  for i = 1:length (post)
-    fprintf (fid, "%s\n", post{i});
-  endfor
-  closeread = fclose (fid);
-  if (closeread < 0)
-    error ("savepath: could not close savefile after writing, %s", savefile);
-  elseif (nargin == 0)
-    warning ("savepath: current path saved to %s",savefile)
-  endif
+    for i = 1:length (post)
+      fprintf (fid, "%s\n", post{i});
+    endfor
+  unwind_protect_cleanup
+    closeread = fclose (fid);
+    if (closeread < 0)
+      error ("savepath: could not close savefile after writing, %s", savefile);
+    elseif (nargin == 0)
+      warning ("savepath: current path saved to %s", savefile);
+    endif
+  end_unwind_protect
 
   retval = 0;
 
--- a/scripts/startup/__finish__.m	Thu Jan 17 07:50:33 2008 +0000
+++ b/scripts/startup/__finish__.m	Thu Jan 17 08:14:32 2008 +0000
@@ -30,7 +30,7 @@
 
 function __finish__ ()
 
-  if exist ('finish','file')
+  if (exist ("finish", "file"))
     ## No arg list here since finish might be a script.
     finish;
   endif
--- a/scripts/startup/main-rcfile	Thu Jan 17 07:50:33 2008 +0000
+++ b/scripts/startup/main-rcfile	Thu Jan 17 08:14:32 2008 +0000
@@ -19,5 +19,4 @@
 
 pkg ("load", "auto");
 
-atexit ('__finish__');
-
+atexit ("__finish__");
--- a/src/ChangeLog	Thu Jan 17 07:50:33 2008 +0000
+++ b/src/ChangeLog	Thu Jan 17 08:14:32 2008 +0000
@@ -1,3 +1,8 @@
+2008-01-17  Ben Abbott <bpabbott@mac.com>
+
+	* load-path.cc (F__pathorig__): Rename from Fpathdef.
+	(Frestoredefaultpath): New function.
+
 2008-01-16  John W. Eaton  <jwe@octave.org>
 
 	* pt-assign.cc (tree_simple_assignment::rvalue,