Mercurial > hg > octave-nkf
annotate scripts/miscellaneous/fullfile.m @ 13832:2e4252228f73
waitbar.m: Eliminate docstring reference to waitbar(frac,msg)
* waitbar.m: Eliminate docstring reference to waitbar(frac,msg)
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 05 Nov 2011 13:46:15 -0700 |
parents | cefd568ea073 |
children | 72c96de7a403 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2003-2011 John W. Eaton |
4265 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
4265 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
4265 | 18 |
19 ## -*- texinfo -*- | |
4350 | 20 ## @deftypefn {Function File} {@var{filename} =} fullfile (@var{dir1}, @var{dir2}, @dots{}, @var{file}) |
21 ## Return a complete filename constructed from the given components. | |
5835 | 22 ## @seealso{fileparts} |
4265 | 23 ## @end deftypefn |
24 | |
25 function filename = fullfile (varargin) | |
26 | |
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 | 34 filename(end) = ""; |
7288 | 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 | 37 tmp = varargin{i}; |
38 if (i < nargs && strcmp (tmp(end), filesep)) | |
39 tmp(end) = ""; | |
40 elseif (i == nargs && strcmp (tmp, filesep)) | |
41 tmp = ""; | |
42 endif | |
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 | 50 else |
6046 | 51 print_usage (); |
4265 | 52 endif |
53 | |
54 endfunction | |
7288 | 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 | 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) |