changeset 7388:0e1ccfe1bf91

[project @ 2008-01-16 06:31:23 by jwe]
author jwe
date Wed, 16 Jan 2008 06:31:23 +0000
parents b429b21abdd4
children 4d0d6c357bc6
files scripts/ChangeLog scripts/path/Makefile.in scripts/path/__extractpath__.m scripts/path/matlabroot.m scripts/path/pathdef.m scripts/startup/Makefile.in scripts/startup/__finish__.m
diffstat 7 files changed, 274 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Tue Jan 15 21:43:11 2008 +0000
+++ b/scripts/ChangeLog	Wed Jan 16 06:31:23 2008 +0000
@@ -1,3 +1,14 @@
+2008-01-16  John W. Eaton  <jwe@octave.org>
+
+	* startup/__finish__.m: New file.
+	* startup/Makefile.in (SOURCES): Add it 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.
+	* path/Makefile.in (SOURCES): Add them to the list.
+
 2008-01-15  Thomas Weber  <thomas.weber.mail@gmail.com>
 
 	* special-matrix/vander.m: Vectorize.  New test.
--- a/scripts/path/Makefile.in	Tue Jan 15 21:43:11 2008 +0000
+++ b/scripts/path/Makefile.in	Wed Jan 16 06:31:23 2008 +0000
@@ -32,7 +32,7 @@
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 INSTALL_DATA = @INSTALL_DATA@
 
-SOURCES = savepath.m
+SOURCES = __extractpath__.m matlabroot.m pathdef.m savepath.m
 
 DISTFILES = $(addprefix $(srcdir)/, Makefile.in $(SOURCES))
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/path/__extractpath__.m	Wed Jan 16 06:31:23 2008 +0000
@@ -0,0 +1,85 @@
+## Copyright (C) 2005, 2006, 2007 Bill Denney
+## Copyright (C) 2007 Ben Abbott
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{val} =} __extractpath__ (@var{file})
+## Extact the path information from the script/function @var{file},
+## created by @file{savepath.m}. If @var{file} is omitted, 
+## @file{~/.octaverc} is used.  If successful, @code{__extractpath__}
+## returns the path specified in @var{file}.
+## @seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}
+## @end deftypefn
+
+## Author: Ben Abbott <bpabbott@mac.com>
+
+function specifiedpath = __extractpath__ (savefile)
+
+  ## The majority of this code was borrowed from savepath.m
+
+  beginstring = "## Begin savepath auto-created section, do not edit";
+  endstring   = "## End savepath auto-created section";
+
+  if (nargin == 0)
+    savefile = tilde_expand ("~/.octaverc");
+  endif
+
+  ## parse the file if it exists to see if we should replace a section
+  ## or create a section
+  startline = 0;
+  endline = 0;
+  filelines = {};
+  if (exist (savefile) == 2)
+    ## read in all lines of the file
+    [fid, msg] = fopen (savefile, "rt");
+    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;
+        elseif (strcmp (result, endstring))
+          endline = linenum;
+        endif
+      endif
+    endwhile
+    closeread = fclose (fid);
+    if (closeread < 0)
+      error ("savepath: could not close savefile after reading, %s", savefile);
+    endif
+  endif
+
+  ## extract the path specifiation
+  if (startline > endline || (startline > 0 && endline == 0))
+    error ("savepath: unable to parse file, %s", savefile);
+  elseif startline > 0
+    specifiedpath = filelines(startline:endline);
+  else
+    specifiedpath = {};
+  endif
+
+endfunction  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/path/matlabroot.m	Wed Jan 16 06:31:23 2008 +0000
@@ -0,0 +1,32 @@
+## Copyright (C) 2008 Ben Abbott
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{val} =} matlabroot ()
+## Return the location of Octave's home.
+## @seealso{OCTAVE_HOME}
+## @end deftypefn
+
+function val = matlabroot ()
+
+  val = OCTAVE_HOME;
+
+endfunction
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/path/pathdef.m	Wed Jan 16 06:31:23 2008 +0000
@@ -0,0 +1,96 @@
+## Copyright (C) 2008 Ben Abbott
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{val} =} pathdef ()
+## Return the default path for Octave.
+## The path information is extracted from one of three sources.
+## In order of preference, those are;
+##
+## @enumerate
+## @item @file{~/.octaverc}
+## @item @file{<octave-home>/.../<version>/m/startup/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 ()
+
+  ## Save the path present when called. This will be used to restore
+  ## path when done.
+  presentpath = path;
+
+  ## Use Octave's orignal path as the default default.
+  val = __pathorig__;
+
+  ## Locate the site octaverc file (is there a better way?).
+  prestr = [OCTAVE_HOME, filesep];
+  poststr = [filesep, version, filesep, 'm', filesep', 'startup'];
+  ncolon = [0, strfind(presentpath,':'), numel(presentpath)+1];
+  site_octaverc = '';
+  for nc = 1:(numel(ncolon)-1)
+    pathdir = presentpath((ncolon(nc)+1):(ncolon(nc+1)-1));
+    npre = strfind (pathdir, prestr);
+    npost = strfind (pathdir, poststr);
+    if (npre == 1 &&
+        npost > numel (prestr) &&
+        npost == numel (pathdir) - numel (poststr)+1)
+      site_octaverc = [pathdir, filesep, 'octaverc'];
+      break;
+    endif
+  endfor
+  if isempty (site_octaverc) || ~exist (site_octaverc, 'file')
+    regexp_octaverc = [prestr, '*', poststr, filesep, 'octaverc'];
+    warning (['pathdef: could not locate `',regexp_octaverc,'''.'])
+  endif
+
+  ## locate the user ~\.octaverc file.
+  user_octaverc = tilde_expand ("~/.octaverc");
+
+  ## Extract the specified paths from the site and user octaverc's.
+  site_pathscript = __extractpath__ (site_octaverc);
+  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)
+    try
+      eval (user_pathscript);
+      val = path;
+    catch
+      warning (['Path defined in ',user_octaverc,' produced an error'])
+    end_try_catch
+  elseif numel (site_pathscript)
+    try
+      eval (site_pathscript);
+      val = path;
+    catch
+      warning (['Path defined in ',site_octaverc,' produced an error'])
+    end_try_catch
+  endif
+
+  ## Restore the path
+  path (presentpath);
+
+endfunction
+
+
--- a/scripts/startup/Makefile.in	Tue Jan 15 21:43:11 2008 +0000
+++ b/scripts/startup/Makefile.in	Wed Jan 16 06:31:23 2008 +0000
@@ -33,12 +33,12 @@
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 INSTALL_DATA = @INSTALL_DATA@
 
-SOURCES = main-rcfile local-rcfile inputrc
+SOURCES = __finish__.m main-rcfile local-rcfile inputrc
 
 DISTFILES = $(addprefix $(srcdir)/, Makefile.in $(SOURCES))
 
-FCN_FILES =
-FCN_FILES_NO_DIR =
+FCN_FILES = $(addprefix $(srcdir)/, $(SOURCES))
+FCN_FILES_NO_DIR = $(notdir $(FCN_FILES))
 
 all: PKG_ADD
 .PHONY: all
@@ -62,16 +62,16 @@
 	  $(INSTALL_DATA) $(srcdir)/local-rcfile \
 	    $(DESTDIR)$(localfcnfiledir)/$(script_sub_dir)/octaverc; \
 	fi
-#	for f in $(FCN_FILES_NO_DIR); do \
-#	  rm -f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/$$f; \
-#	  $(INSTALL_DATA) $(srcdir)/$$f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/$$f; \
-#	done
+	for f in $(FCN_FILES_NO_DIR); do \
+	  rm -f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/$$f; \
+	  $(INSTALL_DATA) $(srcdir)/$$f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/$$f; \
+	done
 .PHONY: install install-strip
 
 uninstall:
-#	for f in $(FCN_FILES_NO_DIR); \
-#	  do rm -f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/$$f; \
-#	done
+	for f in $(FCN_FILES_NO_DIR); \
+	  do rm -f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/$$f; \
+	done
 .PHONY: uninstall
 
 clean:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/startup/__finish__.m	Wed Jan 16 06:31:23 2008 +0000
@@ -0,0 +1,39 @@
+## Copyright (C) 2008 Ben Abbott
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} __finish__ ()
+## Checks for the existence of the function/script, @file{finish}, in the 
+## path or current working directory and executes it. This function is
+## intended to be excecuted upon a clean exit form Octave.
+##
+## This functin is intended to be called upon a clean exit from Octave.
+## This is accomplished in the system script @file{startup/octaverc} by 
+## use of the built in function @code{onexit}.
+## @seealso{octaverc, onexit}
+## @end deftypefn
+
+function __finish__ ()
+
+  if exist ('finish','file')
+    ## No arg list here since finish might be a script.
+    finish;
+  endif
+
+endfunction
+