annotate scripts/path/rmpath.m @ 5903:11bb9bf343a0

[project @ 2006-07-26 03:36:33 by jwe]
author jwe
date Wed, 26 Jul 2006 03:36:33 +0000
parents 67bf9b4f2ae2
children
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 -*-
5733
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
18 ## @deftypefn {Function File} {} rmpath (@var{dir1}, @dots{})
5814
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5809
diff changeset
19 ## Remove @var{dir1}, @dots{} from the current function search path.
5733
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
20 ##
5814
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5809
diff changeset
21 ## @seealso{path, addpath, genpath, pathdef, savepath, pathsep}
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
22 ## @end deftypefn
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
23
5733
6b345b4961ca [project @ 2006-04-04 18:03:51 by jwe]
jwe
parents: 5732
diff changeset
24 ## Author: Etienne Grossmann <etienne@cs.uky.edu>
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
25
5736
e07baa8b93b9 [project @ 2006-04-04 19:41:45 by jwe]
jwe
parents: 5733
diff changeset
26 ## PKGADD: mark_as_command rmpath
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
27
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
28 function ret = rmpath (varargin)
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
29
5804
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
30 if (nargout > 0)
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
31 ret = path ();
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
32 endif
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
33
5804
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
34 psep = pathsep ();
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
35
5804
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
36 xpath = cellstr (split (path (), psep));
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
37 n_path_elts = length (xpath);
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
38
5804
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
39 for i = 1:nargin
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
40 dir_elts = cellstr (split (varargin{i}, psep));
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
41 n_dir_elts = length (dir_elts);
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
42 for j = 1:n_dir_elts
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
43 dir = regexprep (dir_elts{j}, "//+", "/");
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
44 dir = regexprep (dir, "/$", "");
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
45 elt_found = false;
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
46 for k = n_path_elts:-1:1
5814
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5809
diff changeset
47 if (strcmp (dir, "."))
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5809
diff changeset
48 warning ("rmpath: can't remove \".\" from path");
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5809
diff changeset
49 elseif (strcmp (dir, xpath{k}))
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5809
diff changeset
50 xpath(k) = [];
5804
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
51 n_path_elts--;
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
52 elt_found = true;
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
53 endif
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
54 endfor
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
55 if (! elt_found)
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
56 warning ("rmpath: %s: not found", dir);
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
57 endif
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
58 endfor
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
59 endfor
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
60
5814
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5809
diff changeset
61 ## Ensure a 1xN cell array.
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5809
diff changeset
62 xpath = xpath(:)';
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5809
diff changeset
63
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5809
diff changeset
64 xpath{2,:} = psep;
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5809
diff changeset
65 xpath{2,end} = "";
5804
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
66
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
67 tmp = strcat (xpath{:});
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
68
296cefb48d7e [project @ 2006-05-10 20:10:10 by jwe]
jwe
parents: 5789
diff changeset
69 path (tmp);
5732
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
70
17d87fbd7010 [project @ 2006-04-04 17:50:46 by jwe]
jwe
parents:
diff changeset
71 endfunction