Mercurial > hg > octave-max
changeset 5733:6b345b4961ca
[project @ 2006-04-04 18:03:51 by jwe]
author | jwe |
---|---|
date | Tue, 04 Apr 2006 18:03:51 +0000 |
parents | 17d87fbd7010 |
children | a7d2c47371d2 |
files | scripts/path/addpath.m scripts/path/rmpath.m scripts/path/savepath.m |
diffstat | 3 files changed, 55 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/path/addpath.m +++ b/scripts/path/addpath.m @@ -17,26 +17,27 @@ ## Based on code Copyright (C) 2000 Etienne Grossmann ## -*- texinfo -*- -## @deftypefn {Function File} {} addpath(dir1, ...) -## Prepends @code{dir1}, @code{...} to the current @code{LOADPATH}. -## If the directory is already in the path, it will place it where you -## specify in the path (defaulting to prepending it). +## @deftypefn {Function File} {} addpath(@var{dir1}, @dots{}) +## Prepend @var{dir1}, @dots{} to the current @code{LOADPATH}. +## If the directory is already in the path, it is moved to the specified +## location, prepending by default. ## ## @example -## addpath(dir1,'-end',dir2,'-begin',dir3,'-END',dir4,'-BEGIN',dir5) -## @result{} Prepends dir1, dir3 and dir5 and appends dir2 and dir4. +## addpath (dir1, "-end", dir2, "-begin", dir3, "-END", dir4, "-BEGIN", dir5) +## @result{} Prepend dir1, dir3 and dir5 and append dir2 and dir4. ## @end example ## ## An error will be returned if the string is not a directory, the ## directory doesn't exist or you don't have read access to it. ## -## BUG: This function can't add directories called @code{-end} or -## @code{-begin} (case insensitively). +## BUG: This function can't add directories called @samp{-end} or +## @samp{-begin} (case insensitively). +## +## @seealso{LOADPATH, rmpath, savepath} ## @end deftypefn -## Author: Etienne Grossmann <etienne@cs.uky.edu> -## Modified-By: Bill Denney <bill@givebillmoney.com> -## Last modified: June 2005 +## Author: Etienne Grossmann <etienne@cs.uky.edu> +## Modified-By: Bill Denney <bill@givebillmoney.com> ##PKGADD: mark_as_command addpath @@ -49,13 +50,13 @@ path = LOADPATH; endif - dir = ''; + dir = ""; if (length (varargin) > 0) append = 0; switch varargin{end} - case { 0, '0', '-begin', '-BEGIN' } + case { 0, "0", "-begin", "-BEGIN" } varargin = varargin(1:end-1); - case { 1, '1', '-end', '-END' } + case { 1, "1", "-end", "-END" } varargin = varargin(1:end-1); append = 1; endswitch @@ -68,15 +69,15 @@ p = varargin{arg}; if (nargout == 0 && ! isempty (p)) [s, err, m] = stat (p); - if (err ~= 0) + if (err != 0) warning ("addpath %s : %s\n", p, m); continue; elseif (index (s.modestr, "d") != 1) warning ("addpath %s : not a directory (mode=%s)\n", p, s.modestr); continue; - elseif ! ((s.modestr(8) == 'r') || ... - ((getgid == s.gid) && (s.modestr(5) == 'r')) || ... - ((getuid == s.uid) && (s.modestr(2) == 'r'))) + elseif (! (s.modestr(8) == "r" + || (getgid == s.gid && s.modestr(5) == "r") + || (getuid == s.uid && s.modestr(2) == "r"))) warning ("addpath %s : not readable (mode=%s)\n", p, s.modestr); continue; endif @@ -90,7 +91,7 @@ if (isempty (path) && ! isempty (dir)) path = dir; else - if strcmp (path, ':'), path = ''; end + if strcmp (path, ":"), path = ""; end if append path = sprintf ("%s:%s", path, dir); else
--- a/scripts/path/rmpath.m +++ b/scripts/path/rmpath.m @@ -15,16 +15,13 @@ ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## -*- texinfo -*- -## @deftypefn {Function File} {} rmpath(dir1, ...) -## Removes dir1,... from the current LOADPATH. -## -## newpath = rmpath(path, dir1, ...) -## -## Removes dir1,... from path. +## @deftypefn {Function File} {} rmpath (@var{dir1}, @dots{}) +## Remove @var{dir1}, @dots{} from the current @code{LOADPATH}. +## +## @seealso{LOADPATH, addpath, savepath} ## @end deftypefn -## Author: Etienne Grossmann <etienne@cs.uky.edu> -## Last modified: June 2005 +## Author: Etienne Grossmann <etienne@cs.uky.edu> ##PKGADD: mark_as_command rmpath @@ -41,19 +38,19 @@ p = varargin{arg}; lp = length (p); - ## '' is the system path - if (lp==0) + ## "" is the system path + if (lp == 0) strip_system_path = 1; endif - ## strip '...:p:...' -> '...:...' + ## strip "...:p:..." -> "...:..." lo = 0 ; while (lo != length (path)) # Loop while I can substitute lo = length (path); path = strrep (path, sprintf(":%s:", p), ":"); endwhile - ## strip 'p:...' and '...:p' -> '...' + ## strip "p:..." and "...:p" -> "..." if (length (path) > lp+1 && strcmp (path(1:lp+1), sprintf ("%s:", p))) path = path(lp+2:end); endif @@ -61,20 +58,22 @@ path = path(1:end-lp-1); endif - ## strip 'p:' and ':p' -> ':' - if (length (path) == lp+1 && (strcmp (path, sprintf("%s:", p)) || strcmp (path, sprintf (":%s", p)))) - path = ':'; + ## strip "p:" and ":p" -> ":" + if (length (path) == lp+1 + && (strcmp (path, sprintf ("%s:", p)) + || strcmp (path, sprintf (":%s", p)))) + path = ":"; endif - ## strip 'p' -> '' + ## strip "p" -> "" if (length (path) == lp && strcmp (path, p)) - path = ''; + path = ""; endif endfor - if (strip_system_path && strcmp (path, ':')) - path = ''; + if (strip_system_path && strcmp (path, ":")) + path = ""; endif if (nargout > 0)
--- a/scripts/path/savepath.m +++ b/scripts/path/savepath.m @@ -25,7 +25,7 @@ ## ## It will return 0 if it was successful. ## -## @seealso{LOADPATH,addpath,rmpath} +## @seealso{LOADPATH, addpath, rmpath} ## @end deftypefn ## Author: Bill Denney <bill@givebillmoney.com> @@ -37,17 +37,17 @@ beginstring = "## Begin savepath auto-created section, do not edit"; endstring = "## End savepath auto-created section"; - if nargin == 0 - savefile = fullfile (getenv ("HOME"), strcat (filesep, ".octaverc")); + if (nargin == 0) + savefile = "~/.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 = {}; if (exist (savefile) == 2) - %% read in all lines of the file + ## read in all lines of the file [fid, msg] = fopen (savefile, "rt"); if (fid < 0) error ("savepath: could not open savefile, %s: %s", savefile, msg); @@ -56,12 +56,12 @@ while (linenum >= 0) result = fgetl (fid); if (isnumeric (result)) - %% end at the end of file + ## 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 + ## find the first and last lines if they exist in the file if (strcmp (result, beginstring)) startline = linenum; elseif (strcmp (result, endstring)) @@ -75,20 +75,20 @@ endif endif - if (startline > endline) || ((startline > 0) && (endline == 0)) + if (startline > endline || (startline > 0 && endline == 0)) error ("savepath: unable to parse file, %s. There was probably a start line without an end line or end without start.", savefile); endif - %% put the path into a cell array + ## put the path into a cell array pathlines = { beginstring, [" LOADPATH=\"", LOADPATH, "\";"], endstring }; - %% put the current savepath lines into the file - if (isempty(filelines)) || ... - ((startline == 1) && (endline == length(filelines))) - %% savepath is the entire file + ## put the current savepath lines into the file + if (isempty (filelines) + || (startline == 1 && endline == length (filelines))) + ## savepath is the entire file pre = post = {}; elseif (endline == 0) - %% drop the savepath statements at the end of the file + ## drop the savepath statements at the end of the file pre = filelines; post = {}; elseif (startline == 1) @@ -98,12 +98,12 @@ pre = filelines(1:startline-1); post = {}; else - %% insert in the middle + ## insert in the middle pre = filelines(1:startline-1); post = filelines(endline+1:end); endif - %% write the results + ## write the results [fid, msg] = fopen (savefile, "wt"); if (fid < 0) error ("savepath: unable to open file for writing, %s, %s", savefile, msg);