Mercurial > hg > octave-lyh
annotate scripts/miscellaneous/fullfile.m @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | 333243133364 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12931
diff
changeset
|
1 ## Copyright (C) 2003-2012 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 | |
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 | 50 else |
6046 | 51 print_usage (); |
4265 | 52 endif |
53 | |
54 endfunction | |
7288 | 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 | 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 |