annotate scripts/path/rmpath.m @ 5732:17d87fbd7010

[project @ 2006-04-04 17:50:46 by jwe]
author jwe
date Tue, 04 Apr 2006 17:50:46 +0000
parents
children 6b345b4961ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 2000 Etienne Grossmann
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
2 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
3 ## This program is free software; you can redistribute it and/or modify
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
4 ## it under the terms of the GNU General Public License as published by
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
5 ## the Free Software Foundation; either version 2 of the License, or
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
6 ## (at your option) any later version.
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
7 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
8 ## This program is distributed in the hope that it will be useful,
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
11 ## GNU General Public License for more details.
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
12 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
13 ## You should have received a copy of the GNU General Public License
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
14 ## along with this program; if not, write to the Free Software
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
16
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
17 ## -*- texinfo -*-
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
18 ## @deftypefn {Function File} {} rmpath(dir1, ...)
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
19 ## Removes dir1,... from the current LOADPATH.
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
20 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
21 ## newpath = rmpath(path, dir1, ...)
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
22 ##
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
23 ## Removes dir1,... from path.
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
24 ## @end deftypefn
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
25
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
26 ## Author: Etienne Grossmann <etienne@cs.uky.edu>
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
27 ## Last modified: June 2005
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
28
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
29 ##PKGADD: mark_as_command rmpath
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
30
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
31 function ret = rmpath (varargin)
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
32
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
33 if (nargout == 0)
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
34 path = LOADPATH;
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
35 else
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
36 path = varargin{1};
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
37 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
38
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
39 strip_system_path = 0;
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
40 for arg = nargout + 1:length (varargin)
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
41 p = varargin{arg};
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
42 lp = length (p);
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
43
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
44 ## '' is the system path
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
45 if (lp==0)
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
46 strip_system_path = 1;
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
47 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
48
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
49 ## strip '...:p:...' -> '...:...'
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
50 lo = 0 ;
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
51 while (lo != length (path)) # Loop while I can substitute
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
52 lo = length (path);
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
53 path = strrep (path, sprintf(":%s:", p), ":");
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
54 endwhile
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
55
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
56 ## strip 'p:...' and '...:p' -> '...'
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
57 if (length (path) > lp+1 && strcmp (path(1:lp+1), sprintf ("%s:", p)))
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
58 path = path(lp+2:end);
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
59 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
60 if (length (path) > lp+1 && strcmp (path(end-lp:end), sprintf (":%s", p)))
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
61 path = path(1:end-lp-1);
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
62 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
63
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
64 ## strip 'p:' and ':p' -> ':'
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
65 if (length (path) == lp+1 && (strcmp (path, sprintf("%s:", p)) || strcmp (path, sprintf (":%s", p))))
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
66 path = ':';
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
67 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
68
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
69 ## strip 'p' -> ''
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
70 if (length (path) == lp && strcmp (path, p))
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
71 path = '';
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
72 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
73
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
74 endfor
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
75
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
76 if (strip_system_path && strcmp (path, ':'))
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
77 path = '';
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
78 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
79
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
80 if (nargout > 0)
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
81 ret = path;
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
82 elseif (! strcmp (LOADPATH, path))
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
83 LOADPATH = path;
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
84 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
85
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
86 endfunction
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
87
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
88 %!assert(rmpath(':',''),'');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
89 %!assert(rmpath('hello:',''),'hello');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
90 %!assert(rmpath('hello:world',''),'hello:world');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
91 %!assert(rmpath(':hello:world',''),'hello:world');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
92 %!assert(rmpath(':hello:world:',''),'hello:world');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
93 %!assert(rmpath(':hello::world:',''),'hello:world');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
94
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
95 %!assert(rmpath('hello','hello'),'');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
96 %!assert(rmpath(':hello','hello'),':');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
97 %!assert(rmpath('hello:','hello'),':');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
98 %!assert(rmpath('hello:hello','hello'),'');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
99 %!assert(rmpath('hello:hello:hello','hello'),'');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
100 %!assert(rmpath('hello:hello:hello:hello','hello'),'');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
101 %!assert(rmpath(':hello:hello','hello'),':');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
102 %!assert(rmpath('hello:hello:','hello'),':');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
103 %!assert(rmpath('hello','world'),'hello');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
104 %!assert(rmpath(':hello','','hello'),'');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
105 %!assert(rmpath(':hello','hello',''),'');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
106
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
107 %!assert(rmpath('hello:world','hello','world'),'');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
108 %!assert(rmpath('hello:world:','hello','world'),':');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
109 %!assert(rmpath(':hello:world:','hello','world'),':');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
110
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
111 %!assert(rmpath('hello:world','','hello','world'),'');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
112 %!assert(rmpath('hello:world:','','hello','world'),'');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
113 %!assert(rmpath(':hello:world:','','hello','world'),'');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
114
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
115 %!assert(rmpath('hello:world','hello'),'world');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
116 %!assert(rmpath('hello:world','world'),'hello');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
117 %!assert(rmpath('hello:world:','hello'),'world:');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
118 %!assert(rmpath('hello:world:','world'),'hello:');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
119 %!assert(rmpath(':hello:world:','hello'),':world:');
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
120 %!assert(rmpath(':hello:world:','world'),':hello:');