Mercurial > hg > octave-terminal
changeset 7391:f071480b7eac
[project @ 2008-01-17 07:50:33 by jwe]
author | jwe |
---|---|
date | Thu, 17 Jan 2008 07:50:33 +0000 |
parents | 3a21ee84a432 |
children | 17f2cdb5232e |
files | scripts/path/__extractpath__.m scripts/path/pathdef.m scripts/path/savepath.m scripts/startup/main-rcfile src/load-path.cc |
diffstat | 5 files changed, 64 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/path/__extractpath__.m +++ b/scripts/path/__extractpath__.m @@ -61,9 +61,9 @@ filelines{linenum} = result; ## find the first and last lines if they exist in the file if (strcmp (result, beginstring)) - startline = linenum; + startline = linenum+1; elseif (strcmp (result, endstring)) - endline = linenum; + endline = linenum-1; endif endif endwhile
--- a/scripts/path/pathdef.m +++ b/scripts/path/pathdef.m @@ -25,72 +25,69 @@ ## @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 () - ## 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__; + ## 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 + pathdir = octave_config_info ("localstartupfiledir"); + site_octaverc = [pathdir, filesep, "octaverc"]; ## locate the user ~\.octaverc file. - user_octaverc = tilde_expand ("~/.octaverc"); + user_octaverc = ["~", filesep, ".octaverc"]; + user_octaverc = sprintf ("~%s.octaverc", filesep); - ## Extract the specified paths from the site and user octaverc's. + ## 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 = ''; + 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; + if (numel (user_pathscript) == 1) + n = strfind (user_pathscript{1},"'"); + if (numel(n) == 1) + n = strfind (user_pathscript{1},""""); + endif + val = user_pathscript{1}(n(1):n(end)); + else + presentpath = path; + eval (user_pathscript); + val = path; + path (presentpath); + endif catch - warning (['Path defined in ',user_octaverc,' produced an error']) + warning ("pathdef: Path defined in `%s' produced an error.",user_octaverc) end_try_catch elseif numel (site_pathscript) try - eval (site_pathscript); - val = path; + if (numel (site_pathscript) == 1) + n = strfind (site_pathscript{1},"'"); + if (numel(n) == 1) + n = strfind (site_pathscript{1},""""); + endif + val = site_pathscript{1}(n(1):n(end)); + else + presentpath = path; + eval (site_pathscript); + val = path; + path (presentpath); + endif catch - warning (['Path defined in ',site_octaverc,' produced an error']) + warning ("pathdef: Path defined in `%s' produced an error.",site_octaverc) end_try_catch endif - ## Restore the path - path (presentpath); - endfunction
--- a/scripts/path/savepath.m +++ b/scripts/path/savepath.m @@ -36,7 +36,7 @@ endstring = "## End savepath auto-created section"; if (nargin == 0) - savefile = tilde_expand ("~/.octaverc"); + savefile = ["~", filesep, ".octaverc"]; endif ## parse the file if it exists to see if we should replace a section @@ -118,6 +118,8 @@ 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 retval = 0;
--- a/scripts/startup/main-rcfile +++ b/scripts/startup/main-rcfile @@ -18,3 +18,6 @@ ## will also skip automatic loading of packages. pkg ("load", "auto"); + +atexit ('__finish__'); +
--- a/src/load-path.cc +++ b/src/load-path.cc @@ -1679,12 +1679,27 @@ return retval; } -DEFUN (pathdef, , , +DEFUN (restoredefaultpath, , , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} restoredefaultpath (@dots{})\n\ +Restore Octave's path to it's initial state at startup.\n\ +\n\ +@seealso{path, addpath, rmpath, genpath, pathdef, savepath, pathsep}\n\ +@end deftypefn") +{ + load_path::initialize (true); + + return octave_value (load_path::system_path ()); +} + +DEFUN (__pathorig__, , , "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {@var{val} =} pathdef ()\n\ -Return the default list of directories in which to search for function\n\ -files.\n\ -@seealso{path, addpath, rmpath, genpath, savepath, pathsep}\n\ +@deftypefn {Built-in Function} {@var{val} =} __pathorig__ ()\n\ +Return Octave's original default list of directories in which to search\n\ +for function files. This corresponds to the path that exists prior to\n\ +running the system's @file{octaverc}, or the users' @file{~/.octaverc}\n\ +@seealso{path, addpath, rmpath, genpath, savepath, pathsep, \n\ +restoredefaultpath}\n\ @end deftypefn") { return octave_value (load_path::system_path ());