annotate scripts/miscellaneous/fullfile.m @ 17744:d63878346099

maint: Update copyright notices for release.
author John W. Eaton <jwe@octave.org>
date Wed, 23 Oct 2013 22:09:27 -0400
parents 333243133364
children 8ca827e18349
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 16994
diff changeset
1 ## Copyright (C) 2003-2013 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)
7514
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
28 ## Discard all empty arguments
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
29 varargin(cellfun ("isempty", varargin)) = [];
7514
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
30 nargs = numel (varargin);
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
31 if (nargs > 1)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
32 filename = varargin{1};
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
33 if (strcmp (filename(end), filesep))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
34 filename(end) = "";
7288
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
35 endif
7514
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
36 for i = 2:nargs
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
37 tmp = varargin{i};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
38 if (i < nargs && strcmp (tmp(end), filesep))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
39 tmp(end) = "";
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
40 elseif (i == nargs && strcmp (tmp, filesep))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
41 tmp = "";
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
42 endif
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14363
diff changeset
43 filename = [filename filesep tmp];
7514
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
44 endfor
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
45 elseif (nargs == 1)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
46 filename = varargin{1};
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
47 else
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
48 filename = "";
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
49 endif
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
50 else
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5835
diff changeset
51 print_usage ();
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
52 endif
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
53
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
54 endfunction
7288
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
55
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
56
7514
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
57 %!shared fs, fsx, xfs, fsxfs, xfsy
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
58 %! fs = filesep ();
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14363
diff changeset
59 %! fsx = [fs "x"];
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14363
diff changeset
60 %! xfs = ["x" fs];
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14363
diff changeset
61 %! fsxfs = [fs "x" fs];
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14363
diff changeset
62 %! xfsy = ["x" fs "y"];
7288
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
63 %!assert (fullfile (""), "")
7514
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
64 %!assert (fullfile (fs), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
65 %!assert (fullfile ("", fs), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
66 %!assert (fullfile (fs, ""), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
67 %!assert (fullfile ("", fs), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
68 %!assert (fullfile ("x"), "x")
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
69 %!assert (fullfile ("", "x"), "x")
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
70 %!assert (fullfile ("x", ""), "x")
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
71 %!assert (fullfile ("", "x", ""), "x")
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
72 %!assert (fullfile ("x", "y"), xfsy)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
73 %!assert (fullfile ("x", "", "y"), xfsy)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
74 %!assert (fullfile ("x", "", "y", ""), xfsy)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
75 %!assert (fullfile ("", "x", "", "y", ""), xfsy)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
76 %!assert (fullfile (fs), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
77 %!assert (fullfile (fs, fs), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
78 %!assert (fullfile (fs, "x"), fsx)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
79 %!assert (fullfile (fs, xfs), fsxfs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
80 %!assert (fullfile (fsx, fs), fsxfs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
81 %!assert (fullfile (fs, "x", fs), fsxfs)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
82