changeset 5789:7d77b6839ca7

[project @ 2006-05-04 13:38:49 by dbateman]
author dbateman
date Thu, 04 May 2006 13:38:50 +0000
parents c3e8552402ab
children 60659f01c75b
files scripts/ChangeLog scripts/miscellaneous/path.m scripts/path/addpath.m scripts/path/rmpath.m
diffstat 4 files changed, 71 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Thu May 04 12:20:52 2006 +0000
+++ b/scripts/ChangeLog	Thu May 04 13:38:50 2006 +0000
@@ -1,3 +1,8 @@
+2006-05-03  David Bateman  <dbateman@free.fr>
+
+	* 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 <rweigel@gmu.edu>
 
         * scripts/set/setdiff.m: New arg, byrows.  New tests.
--- a/scripts/miscellaneous/path.m	Thu May 04 12:20:52 2006 +0000
+++ b/scripts/miscellaneous/path.m	Thu May 04 13:38:50 2006 +0000
@@ -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;
--- a/scripts/path/addpath.m	Thu May 04 12:20:52 2006 +0000
+++ b/scripts/path/addpath.m	Thu May 04 13:38:50 2006 +0000
@@ -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'])
--- a/scripts/path/rmpath.m	Thu May 04 12:20:52 2006 +0000
+++ b/scripts/path/rmpath.m	Thu May 04 13:38:50 2006 +0000
@@ -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()]);