annotate scripts/miscellaneous/fullfile.m @ 7288:1885f4c7e4b3

[project @ 2007-12-11 17:19:44 by jwe]
author jwe
date Tue, 11 Dec 2007 17:19:44 +0000
parents a1dbe9d80eee
children 4f6a73fd8df9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
1 ## Copyright (C) 2003, 2005, 2006, 2007 John W. Eaton
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
2 ##
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
4 ##
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
9 ##
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
14 ##
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
18
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
4350
b4661459eff7 [project @ 2003-02-21 19:29:43 by jwe]
jwe
parents: 4266
diff changeset
20 ## @deftypefn {Function File} {@var{filename} =} fullfile (@var{dir1}, @var{dir2}, @dots{}, @var{file})
b4661459eff7 [project @ 2003-02-21 19:29:43 by jwe]
jwe
parents: 4266
diff changeset
21 ## Return a complete filename constructed from the given components.
5835
07dd13bfc0ba [project @ 2006-05-31 18:21:49 by jwe]
jwe
parents: 5595
diff changeset
22 ## @seealso{fileparts}
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
23 ## @end deftypefn
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
24
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
25 function filename = fullfile (varargin)
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
26
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
27 if (nargin > 0)
7288
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
28 filename = "";
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
29 for first = 1:nargin
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
30 tmp = varargin{first};
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
31 if (! isempty (tmp))
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
32 filename = tmp;
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
33 break;
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
34 endif
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
35 endfor
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
36 for i = first+1:nargin
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
37 tmp = varargin{i};
7288
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
38 if (! isempty (tmp))
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
39 if (strcmp (tmp(1), filesep))
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
40 tmp(1) = "";
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
41 endif
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
42 if (i < nargin && strcmp (tmp(end), filesep))
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
43 tmp(end) = "";
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
44 endif
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
45 filename = strcat (filename, filesep, tmp);
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
46 endif
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
47 endfor
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
48 else
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5835
diff changeset
49 print_usage ();
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
50 endif
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
51
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
52 endfunction
7288
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
53
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
54 %!assert (fullfile (""), "")
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
55 %!assert (fullfile (filesep ()), filesep ())
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
56 %!assert (fullfile ("", filesep ()), filesep ())
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
57 %!assert (fullfile (filesep (), ""), filesep ())
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
58 %!assert (fullfile ("", filesep ()), filesep ())
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
59 %!assert (fullfile ("foo"), "foo")
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
60 %!assert (fullfile ("", "foo"), "foo")
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
61 %!assert (fullfile ("foo", ""), "foo")
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
62 %!assert (fullfile ("", "foo", ""), "foo")
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
63 %!assert (fullfile ("foo", "bar"), strcat ("foo", filesep (), "bar"))
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
64 %!assert (fullfile ("foo", "", "bar"), strcat ("foo", filesep (), "bar"))
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
65 %!assert (fullfile ("foo", "", "bar", ""), strcat ("foo", filesep (), "bar"))
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
66 %!assert (fullfile ("", "foo", "", "bar", ""), strcat ("foo", filesep (), "bar"))