Mercurial > octave
annotate scripts/miscellaneous/fileparts.m @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | 7854d5752dd2 |
children | 597f3ee61a48 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
3 ## Copyright (C) 2003-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
4264 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
4264 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
4264 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
4264 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
4264 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
27 ## @deftypefn {} {[@var{dir}, @var{name}, @var{ext}] =} fileparts (@var{filename}) |
19205 | 28 ## Return the directory, name, and extension components of @var{filename}. |
29 ## | |
30 ## The input @var{filename} is a string which is parsed. There is no attempt | |
31 ## to check whether the filename or directory specified actually exists. | |
19214
8cc4a9bb253b
fullfile.m: Match documentation name to function variable name.
Rik <rik@octave.org>
parents:
19205
diff
changeset
|
32 ## @seealso{fullfile, filesep} |
4264 | 33 ## @end deftypefn |
34 | |
19205 | 35 function [dir, name, ext] = fileparts (filename) |
4264 | 36 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
37 if (nargin < 1) |
6046 | 38 print_usage (); |
4264 | 39 endif |
40 | |
17438
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
41 if (! ischar (filename) || rows (filename) > 1) |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
42 error ("fileparts: FILENAME must be a single string"); |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
43 endif |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
44 |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
45 ds = strchr (filename, filesep ("all"), 1, "last"); |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
46 if (isempty (ds)) |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
47 ds = 0; |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
48 endif |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
49 es = rindex (filename, "."); |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
50 ## These can be the same if they are both 0 (no dir or ext). |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
51 if (es <= ds) |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
52 es = length (filename)+1; |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
53 endif |
19205 | 54 |
17438
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
55 if (ds == 0) |
19205 | 56 dir = ""; |
17438
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
57 elseif (ds == 1) |
19205 | 58 dir = filename(1); |
17438
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
59 else |
19205 | 60 dir = filename(1:ds-1); |
17438
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
61 endif |
19205 | 62 |
17438
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
63 name = filename(ds+1:es-1); |
19205 | 64 if (isempty (name)) |
65 name = ""; | |
66 endif | |
67 | |
17438
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
68 if (es > 0 && es <= length (filename)) |
19205 | 69 ext = filename(es:end); |
17438
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
70 else |
19205 | 71 ext = ""; |
17438
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
72 endif |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
73 |
4264 | 74 endfunction |
8201
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
75 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
76 |
8201
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
77 %!test |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
78 %! [d, n, e] = fileparts ("file"); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
79 %! assert (strcmp (d, "") && strcmp (n, "file") && strcmp (e, "")); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
80 |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
81 %!test |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
82 %! [d, n, e] = fileparts ("file.ext"); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
83 %! assert (strcmp (d, "") && strcmp (n, "file") && strcmp (e, ".ext")); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
84 |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
85 %!test |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
86 %! [d, n, e] = fileparts ("/file.ext"); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
87 %! assert (strcmp (d, "/") && strcmp (n, "file") && strcmp (e, ".ext")); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
88 |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
89 %!test |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
90 %! [d, n, e] = fileparts ("dir/file.ext"); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
91 %! assert (strcmp (d, "dir") && strcmp (n, "file") && strcmp (e, ".ext")); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
92 |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
93 %!test |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
94 %! [d, n, e] = fileparts ("./file.ext"); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
95 %! assert (strcmp (d, ".") && strcmp (n, "file") && strcmp (e, ".ext")); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
96 |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
97 %!test |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
98 %! [d, n, e] = fileparts ("d1/d2/file.ext"); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
99 %! assert (strcmp (d, "d1/d2") && strcmp (n, "file") && strcmp (e, ".ext")); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
100 |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
101 %!test |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
102 %! [d, n, e] = fileparts ("/d1/d2/file.ext"); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
103 %! assert (strcmp (d, "/d1/d2") && strcmp (n, "file") && strcmp (e, ".ext")); |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
104 |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
105 %!test |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
106 %! [d, n, e] = fileparts ("/.ext"); |
19205 | 107 %! assert (strcmp (d, "/") && strcmp (n, "") && strcmp (e, ".ext")); |
8201
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
108 |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
109 %!test |
0ab4eed59455
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
110 %! [d, n, e] = fileparts (".ext"); |
19205 | 111 %! assert (strcmp (d, "") && strcmp (n, "") && strcmp (e, ".ext")); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
112 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
113 ## Test input validation |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28891
diff
changeset
|
114 %!error <Invalid call> fileparts () |
17438
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
115 %!error <FILENAME must be a single string> fileparts (1) |
791c117eb2cf
fileparts.m: Check for multi-line char inputs (bug #40062)
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
116 %!error <FILENAME must be a single string> fileparts (["a"; "b"]) |