annotate scripts/miscellaneous/fullfile.m @ 10549:95c3e38098bf

Untabify .m scripts
author Rik <code@nomad.inbox5.com>
date Fri, 23 Apr 2010 11:28:50 -0700
parents eb63fbe60fab
children fd0a3ac60b0e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 7540
diff changeset
1 ## Copyright (C) 2003, 2005, 2006, 2007, 2008 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
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
29 varargin(cellfun (@isempty, varargin)) = [];
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
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
43 filename = cstrcat (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
7514
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
56 %!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
57 %! fs = filesep ();
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7514
diff changeset
58 %! fsx = cstrcat (fs, "x");
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7514
diff changeset
59 %! xfs = cstrcat ("x", fs);
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7514
diff changeset
60 %! fsxfs = cstrcat (fs, "x", fs);
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7514
diff changeset
61 %! xfsy = cstrcat ("x", fs, "y");
7288
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
62 %!assert (fullfile (""), "")
7514
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
63 %!assert (fullfile (fs), fs)
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 ("x"), "x")
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", "y"), xfsy)
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 (fs), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
76 %!assert (fullfile (fs, 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, "x"), fsx)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
78 %!assert (fullfile (fs, xfs), fsxfs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
79 %!assert (fullfile (fsx, fs), fsxfs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
80 %!assert (fullfile (fs, "x", fs), fsxfs)