Mercurial > forge
changeset 2396:9cbef6556ffd octave-forge
remove files ported to the octave core
author | adb014 |
---|---|
date | Tue, 22 Aug 2006 21:04:47 +0000 |
parents | 8c54c60988ec |
children | 671181dd32f5 |
files | main/path/addpath.m main/path/rmpath.m main/path/savepath.m |
diffstat | 3 files changed, 0 insertions(+), 364 deletions(-) [+] |
line wrap: on
line diff
--- a/main/path/addpath.m Tue Aug 22 20:25:25 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,124 +0,0 @@ -## Copyright (C) 2005 Bill Denney -## -## This program 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 2 of the License, or -## (at your option) any later version. -## -## This program 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 this program; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## 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). -## -## @example -## addpath(dir1,'-end',dir2,'-begin',dir3,'-END',dir4,'-BEGIN',dir5) -## @result{} Prepends dir1, dir3 and dir5 and appends 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). -## @end deftypefn - -## Author: Etienne Grossmann <etienne@cs.uky.edu> -## Modified-By: Bill Denney <bill@givebillmoney.com> -## Last modified: June 2005 - -##PKGADD: mark_as_command('addpath') - -function ret = addpath(varargin) - - if nargout > 0 - path = varargin{1}; - varargin = varargin(2:end); - else - path = LOADPATH; - end - - dir = ''; - if length(varargin) > 0 - append = 0; - switch varargin{end} - case { 0, '0', '-begin', '-BEGIN' } - varargin = varargin(1:end-1); - case { 1, '1', '-end', '-END' } - varargin = varargin(1:end-1); - append = 1; - end - - ## Avoid duplicates by stripping pre-existing entries - path = rmpath(path, varargin{:}); - - ## Check if the directories are valid - for arg = 1:length(varargin) - p = varargin{arg}; - if nargout == 0 && !isempty(p) - [s,err,m] = stat(p); - 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'))) - warning("addpath %s : not readable (mode=%s)\n", p,s.modestr); - continue; - end - end - dir = sprintf("%s:%s",dir,p); - end - - ## Add the directories to the current path - if !isempty(dir) - dir = dir(2:end); - if isempty(path) && !isempty(dir) - path = dir; - else - if strcmp(path,':'), path = ''; end - if append - path = sprintf("%s:%s", path, dir); - else - path = sprintf("%s:%s", dir, path); - end - end - end - end - - if nargout - ret = path; - else - LOADPATH = path; - end - -%!assert(addpath('','hello'),'hello'); -%!assert(addpath('','hello','world'),'hello:world') -%!assert(addpath(':','hello'),'hello:'); -%!assert(addpath(':','hello','-end'),':hello'); -%!assert(addpath('hello','hello'),'hello'); -%!assert(addpath('hello','world'),'world:hello') -%!assert(addpath('hello','world','-end'),'hello:world') -%!assert(addpath('hello:','world','-end'),'hello::world') -%!assert(addpath('hello:','hello','world','-end'),':hello:world') - -%!assert(addpath('',''),':') -%!assert(addpath(':',''),':') -%!assert(addpath('hello',''),':hello') -%!assert(addpath('hello:world',''),':hello:world') -%!assert(addpath('hello:world:',''),':hello:world') -%!assert(addpath('hello::world',''),':hello:world')
--- a/main/path/rmpath.m Tue Aug 22 20:25:25 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -## Copyright (C) 2000 Etienne Grossmann -## -## This program 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 2 of the License, or -## (at your option) any later version. -## -## This program 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 this program; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -## rmpath(dir1,...) -## -## Removes dir1,... from the current LOADPATH. -## -## newpath = rmpath(path, dir1, ...) -## -## Removes dir1,... from path. - -## Author: Etienne Grossmann <etienne@cs.uky.edu> -## Last modified: June 2005 - -##PKGADD: mark_as_command('rmpath') - -function ret = rmpath(varargin) - - if nargout == 0, - path = LOADPATH ; - else - path = varargin{1}; - endif - - ##printf('initial path=<%s>\n',path); - strip_system_path = 0; - for arg=nargout+1:length(varargin) - p = varargin{arg}; - lp = length(p); - - ## '' is the system path - if lp==0, strip_system_path = 1; end - - ## strip '...:p:...' -> '...:...' - lo = 0 ; - while lo != length(path), # Loop while I can substitute - lo = length(path) ; - path = strrep(path,sprintf(":%s:",p),":") ; - end - - ## strip 'p:...' and '...:p' -> '...' - if length(path) > lp+1 && strcmp(path(1:lp+1),sprintf("%s:",p)) - path = path(lp+2:end); - end - if length(path) > lp+1 && strcmp(path(end-lp:end),sprintf(":%s",p)) - path = path(1:end-lp-1); - end - - ## strip 'p:' and ':p' -> ':' - if length(path) == lp+1 && (strcmp(path,sprintf("%s:",p)) || strcmp(path,sprintf(":%s",p))) - path = ':'; - end - - ## strip 'p' -> '' - if length(path) == lp && strcmp(path,p) - path = ''; - end - - ##printf('strip <%s> path=<%s>\n',p,path); - end - - if strip_system_path && strcmp(path,':'), path = ''; end - - if nargout > 0 - ret = path; - elseif !strcmp(LOADPATH,path), - # printf("rmpath : loadpath is changed\n") ; - LOADPATH = path; - end - -%!assert(rmpath(':',''),''); -%!assert(rmpath('hello:',''),'hello'); -%!assert(rmpath('hello:world',''),'hello:world'); -%!assert(rmpath(':hello:world',''),'hello:world'); -%!assert(rmpath(':hello:world:',''),'hello:world'); -%!assert(rmpath(':hello::world:',''),'hello:world'); - -%!assert(rmpath('hello','hello'),''); -%!assert(rmpath(':hello','hello'),':'); -%!assert(rmpath('hello:','hello'),':'); -%!assert(rmpath('hello:hello','hello'),''); -%!assert(rmpath('hello:hello:hello','hello'),''); -%!assert(rmpath('hello:hello:hello:hello','hello'),''); -%!assert(rmpath(':hello:hello','hello'),':'); -%!assert(rmpath('hello:hello:','hello'),':'); -%!assert(rmpath('hello','world'),'hello'); -%!assert(rmpath(':hello','','hello'),''); -%!assert(rmpath(':hello','hello',''),''); - -%!assert(rmpath('hello:world','hello','world'),''); -%!assert(rmpath('hello:world:','hello','world'),':'); -%!assert(rmpath(':hello:world:','hello','world'),':'); - -%!assert(rmpath('hello:world','','hello','world'),''); -%!assert(rmpath('hello:world:','','hello','world'),''); -%!assert(rmpath(':hello:world:','','hello','world'),''); - -%!assert(rmpath('hello:world','hello'),'world'); -%!assert(rmpath('hello:world','world'),'hello'); -%!assert(rmpath('hello:world:','hello'),'world:'); -%!assert(rmpath('hello:world:','world'),'hello:'); -%!assert(rmpath(':hello:world:','hello'),':world:'); -%!assert(rmpath(':hello:world:','world'),':hello:');
--- a/main/path/savepath.m Tue Aug 22 20:25:25 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,124 +0,0 @@ -## Copyright (C) 2005 Bill Denney -## -## 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 2, 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, write to the Free -## Software Foundation, 59 Temple Place - Suite 330, Boston, MA -## 02111-1307, USA. - -## -*- texinfo -*- -## @deftypefn {Function File} {} savepath (@var{file}) -## This function saves the current @code{LOADPATH} to your personal -## default initilization file or optionally the @var{file} that you -## specify. -## -## It will return 0 if it was successful. -## -## @seealso{LOADPATH,addpath,rmpath} -## @end deftypefn - -## Author: Bill Denney <bill@givebillmoney.com> - -function varargout = savepath(savefile) - - retval = 1; - - beginstring = "## Begin savepath auto-created section, do not edit"; - endstring = "## End savepath auto-created section"; - - if nargin == 0 - savefile = [ getenv("HOME"), "/.octaverc" ]; - end - - %% 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(["savepath: could not open savefile, " savefile ": " msg]); - end - 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; - end - end - end - closeread = fclose(fid); - if (closeread < 0) - error(["savepath: could not close savefile after reading, " savefile]); - end - end - - if (startline > endline) || ((startline > 0) && (endline == 0)) - error(["savepath: unable to parse file, " savefile ". There was " ... - "probably a start line without an end line or end without start."]) - end - - %% 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 - pre = post = {}; - elseif endline == 0 - %% drop the savepath statements at the end of the file - pre = filelines; - post = {}; - elseif (startline == 1) - pre = {}; - post = filelines(endline+1:end); - elseif (endline == length(filelines)) - pre = filelines(1:startline-1); - post = {}; - else - %% insert in the middle - pre = filelines(1:startline-1); - post = filelines(endline+1:end); - end - - %% write the results - [fid, msg] = fopen(savefile, "wt"); - if (fid < 0) - error(["savepath: unable to open file for writing, " savefile ", " msg]); - end - for i = 1:length(pre), fprintf(fid, "%s\n", pre{i}); end - for i = 1:length(pathlines), fprintf(fid, "%s\n", pathlines{i}); end - for i = 1:length(post), fprintf(fid, "%s\n", post{i}); end - closeread = fclose(fid); - if (closeread < 0) - error(["savepath: could not close savefile after writing, " savefile]); - end - - retval = 0; - - if (nargout == 1) - varargout{1} = retval; - end