# HG changeset patch # User dbateman # Date 1146749930 0 # Node ID 7d77b6839ca71d8f01d33bfdaba9285cc621de3f # Parent c3e8552402ab1356d7a6bb831bd274b97b3d01c9 [project @ 2006-05-04 13:38:49 by dbateman] diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2006-05-03 David Bateman + + * path/rmpath.m, path/addpath.m, miscellaneous/path.m: Replace all + explicit uses of a path seperation character with pathsep(). + 2006-05-03 Bob Weigel * scripts/set/setdiff.m: New arg, byrows. New tests. diff --git a/scripts/miscellaneous/path.m b/scripts/miscellaneous/path.m --- a/scripts/miscellaneous/path.m +++ b/scripts/miscellaneous/path.m @@ -28,32 +28,35 @@ ## current value of @code{LOADPATH}. ## ## If @var{nargin} is greater than zero, concatenate the arguments, -## separating them with @code{":"}. Set @code{LOADPATH} to the result +## separating them with @code{pathsep()}. Set @code{LOADPATH} to the result ## and also return it. ## ## No checks are made for duplicate elements. +## @seealso{pathsep} ## @end deftypefn ## Author: jwe function retval = path (varargin) + psep = pathsep (); + if (nargin > 0) p = varargin{1}; for i = 2:nargin - p = sprintf ("%s:%s", p, varargin{i}); + p = sprintf ("%s%s%s", p, psep, varargin{i}); endfor LOADPATH = p; endif - if (LOADPATH(1) == ":") + if (LOADPATH(1) == psep) p = strcat (DEFAULT_LOADPATH, LOADPATH); else - t = findstr (LOADPATH, "::"); + t = findstr (LOADPATH, [psep,psep]); if (any (t)) loc = t(1); p = strcat (LOADPATH(1:loc), DEFAULT_LOADPATH, LOADPATH(loc+1:end)); - elseif (LOADPATH(end) == ":") + elseif (LOADPATH(end) == psep) p = strcat (LOADPATH, DEFAULT_LOADPATH); else p = LOADPATH; @@ -62,7 +65,7 @@ if (nargin == 0 && nargout == 0) puts ("\nOctave's search path contains the following directories:\n\n "); - puts (strrep (p, ":", "\n ")); + puts (strrep (p, psep, "\n ")); puts ("\n\n"); else retval = p; diff --git a/scripts/path/addpath.m b/scripts/path/addpath.m --- a/scripts/path/addpath.m +++ b/scripts/path/addpath.m @@ -61,6 +61,8 @@ append = 1; endswitch + psep = pathsep(); + ## Avoid duplicates by stripping pre-existing entries path = rmpath (path, varargin{:}); @@ -82,7 +84,7 @@ continue; endif endif - dir = sprintf ("%s:%s", dir, p); + dir = sprintf ("%s%s%s", dir, psep, p); endfor ## Add the directories to the current path @@ -91,11 +93,11 @@ if (isempty (path) && ! isempty (dir)) path = dir; else - if strcmp (path, ":"), path = ""; end + if strcmp (path, psep), path = ""; end if append - path = sprintf ("%s:%s", path, dir); + path = sprintf ("%s%s%s", path, psep, dir); else - path = sprintf ("%s:%s", dir, path); + path = sprintf ("%s%s%s", dir, psep, path); endif endif endif @@ -110,18 +112,18 @@ endfunction %!assert(addpath('','hello'),'hello'); -%!assert(addpath('','hello','world'),'hello:world') -%!assert(addpath(':','hello'),'hello:'); -%!assert(addpath(':','hello','-end'),':hello'); +%!assert(addpath('','hello','world'),['hello',pathsep(),'world']) +%!assert(addpath(pathsep(),'hello'),['hello',pathsep()]); +%!assert(addpath(pathsep(),'hello','-end'),[pathsep(),'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('hello','world'),['world',pathsep(),'hello']) +%!assert(addpath('hello','world','-end'),['hello',pathsep(),'world']) +%!assert(addpath(['hello',pathsep()],'world','-end'),['hello',pathsep(),pathsep(),'world']) +%!assert(addpath(['hello',pathsep()],'hello','world','-end'),[pathsep(),'hello',pathsep(),'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') +%!assert(addpath('',''),pathsep()) +%!assert(addpath(pathsep(),''),pathsep()) +%!assert(addpath('hello',''),[pathsep(),'hello']) +%!assert(addpath(['hello',pathsep(),'world'],''),[pathsep(),'hello',pathsep(),'world']) +%!assert(addpath(['hello',pathsep(),'world',pathsep()],''),[pathsep(),'hello',pathsep(),'world']) +%!assert(addpath(['hello',pathsep(),pathsep(),'world'],''),[pathsep(),'hello',pathsep(),'world']) diff --git a/scripts/path/rmpath.m b/scripts/path/rmpath.m --- a/scripts/path/rmpath.m +++ b/scripts/path/rmpath.m @@ -33,6 +33,8 @@ path = varargin{1}; endif + psep = pathsep(); + strip_system_path = 0; for arg = nargout + 1:length (varargin) p = varargin{arg}; @@ -47,22 +49,24 @@ lo = 0 ; while (lo != length (path)) # Loop while I can substitute lo = length (path); - path = strrep (path, sprintf(":%s:", p), ":"); + path = strrep (path, sprintf("%s%s%s", psep, p, psep), psep); endwhile ## strip "p:..." and "...:p" -> "..." - if (length (path) > lp+1 && strcmp (path(1:lp+1), sprintf ("%s:", p))) + if (length (path) > lp+1 && + strcmp (path(1:lp+1), sprintf ("%s%s", p, psep))) path = path(lp+2:end); endif - if (length (path) > lp+1 && strcmp (path(end-lp:end), sprintf (":%s", p))) + if (length (path) > lp+1 && + strcmp (path(end-lp:end), sprintf ("%s%s", psep, p))) 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 = ":"; + && (strcmp (path, sprintf ("%s%s", p, psep)) + || strcmp (path, sprintf ("%s%s", psep, p)))) + path = psep; endif ## strip "p" -> "" @@ -72,7 +76,7 @@ endfor - if (strip_system_path && strcmp (path, ":")) + if (strip_system_path && strcmp (path, psep)) path = ""; endif @@ -84,36 +88,36 @@ endfunction -%!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(pathsep(),''),''); +%!assert(rmpath(['hello',pathsep()],''),'hello'); +%!assert(rmpath(['hello',pathsep(),'world'],''),['hello',pathsep(),'world']); +%!assert(rmpath([pathsep(),'hello',pathsep(),'world'],''),['hello',pathsep(),'world']); +%!assert(rmpath([pathsep(),'hello',pathsep(),'world',pathsep()],''),['hello',pathsep(),'world']); +%!assert(rmpath([pathsep(),'hello',pathsep(),pathsep(),'world',pathsep()],''),['hello',pathsep(),'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([pathsep,'hello'],'hello'),pathsep()); +%!assert(rmpath(['hello',pathsep()],'hello'),pathsep()); +%!assert(rmpath(['hello',pathsep(),'hello'],'hello'),''); +%!assert(rmpath(['hello',pathsep(),'hello',pathsep(),'hello'],'hello'),''); +%!assert(rmpath(['hello',pathsep(),'hello',pathsep(),'hello',pathsep(),'hello'],'hello'),''); +%!assert(rmpath([pathsep(),'hello',pathsep(),'hello'],'hello'),pathsep()); +%!assert(rmpath(['hello',pathsep(),'hello',pathsep()],'hello'),pathsep()); %!assert(rmpath('hello','world'),'hello'); -%!assert(rmpath(':hello','','hello'),''); -%!assert(rmpath(':hello','hello',''),''); +%!assert(rmpath([pathsep(),'hello'],'','hello'),''); +%!assert(rmpath([pathsep(),'hello'],'hello',''),''); -%!assert(rmpath('hello:world','hello','world'),''); -%!assert(rmpath('hello:world:','hello','world'),':'); -%!assert(rmpath(':hello:world:','hello','world'),':'); +%!assert(rmpath(['hello',pathsep(),'world'],'hello','world'),''); +%!assert(rmpath(['hello',pathsep(),'world',pathsep()],'hello','world'),pathsep()); +%!assert(rmpath([pathsep(),'hello',pathsep(),'world',pathsep()],'hello','world'),pathsep()); -%!assert(rmpath('hello:world','','hello','world'),''); -%!assert(rmpath('hello:world:','','hello','world'),''); -%!assert(rmpath(':hello:world:','','hello','world'),''); +%!assert(rmpath(['hello',pathsep(),'world'],'','hello','world'),''); +%!assert(rmpath(['hello',pathsep(),'world',pathsep()],'','hello','world'),''); +%!assert(rmpath([pathsep(),'hello',pathsep(),'world',pathsep()],'','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:'); +%!assert(rmpath(['hello',pathsep(),'world'],'hello'),'world'); +%!assert(rmpath(['hello',pathsep(),'world'],'world'),'hello'); +%!assert(rmpath(['hello',pathsep(),'world',pathsep()],'hello'),['world',pathsep()]); +%!assert(rmpath(['hello',pathsep(),'world',pathsep()],'world'),['hello',pathsep()]); +%!assert(rmpath([pathsep(),'hello',pathsep(),'world',pathsep()],'hello'),[pathsep(),'world',pathsep()]); +%!assert(rmpath([pathsep(),'hello',pathsep(),'world',pathsep()],'world'),[pathsep(),'hello',pathsep()]);