Mercurial > octave
annotate scripts/help/which.m @ 31551:fd29c7a50a78 stable
maint: use commas, semicolons consistently with Octave conventions.
* makeValidName.m: Remove %!test and move BIST %!asserts to column 1.
* base64decode.m, base64encode.m, which.m, logm.m, uniquetol.m, perms.m:
Delete semicolon (';') at end of %!assert BIST.
* lin2mu.m, interp2.m, interpn.m, lsqnonneg.m, pqpnonneg.m, uniquetol.m,
betainc.m, normalize.m: Add semicolon (';') to end of assert statement within
%!test BIST.
* __memoize__.m, tar_is_bsd.m, publish.m: Add semicolon (';') to line with
keyword "persistent".
* stft.m: Use comma (',') after "case" keyword when code immediately follows.
* gallery.m: Align commas used in case statements in massive switch block.
Remove unnecessary parentheses around a numeric case argument.
* ranks.m: Remove semicolon (';') from case statemnt argument.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 26 Nov 2022 06:32:08 -0800 |
parents | 2569c40924e7 |
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:
30324
diff
changeset
|
3 ## Copyright (C) 2009-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27018
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/>. |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
7 ## |
11104 | 8 ## This file is part of Octave. |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23295
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
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:
23295
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:
22430
diff
changeset
|
13 ## (at your option) any later version. |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
14 ## |
11104 | 15 ## Octave is distributed in the hope that it will be useful, but |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22430
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22430
diff
changeset
|
18 ## GNU General Public License for more details. |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
19 ## |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
11104 | 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:
23295
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 ######################################################################## |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
25 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
27 ## @deftypefn {} {} which name @dots{} |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
28 ## Display the type of each @var{name}. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
29 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
30 ## If @var{name} is defined from a function file, the full name of the file is |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
31 ## also displayed. |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
32 ## @seealso{help, lookfor} |
11547 | 33 ## @end deftypefn |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
34 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
35 function varargout = which (varargin) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
36 |
20922
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
37 if (nargin == 0 || ! iscellstr (varargin)) |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
38 print_usage (); |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
39 endif |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
40 |
31444
2569c40924e7
which.m: Add warning for unimplemented '-all' option (bug #32088)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
41 ## FIXME: "-all" option not implemented. Warn user that only the first |
2569c40924e7
which.m: Add warning for unimplemented '-all' option (bug #32088)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
42 ## result found will be returned. See bug #32088. |
2569c40924e7
which.m: Add warning for unimplemented '-all' option (bug #32088)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
43 if (any (isall = strcmpi (varargin, "-all"))) |
2569c40924e7
which.m: Add warning for unimplemented '-all' option (bug #32088)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
44 warning (["which: '-all' not yet implemented - only the first result ", ... |
2569c40924e7
which.m: Add warning for unimplemented '-all' option (bug #32088)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
45 "will be returned\n"]); |
2569c40924e7
which.m: Add warning for unimplemented '-all' option (bug #32088)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
46 varargin = varargin(! isall); |
2569c40924e7
which.m: Add warning for unimplemented '-all' option (bug #32088)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
47 nargin = nargin - sum (isall); |
2569c40924e7
which.m: Add warning for unimplemented '-all' option (bug #32088)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
48 endif |
2569c40924e7
which.m: Add warning for unimplemented '-all' option (bug #32088)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
49 |
20922
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
50 m = __which__ (varargin{:}); |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
51 |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
52 ## Check whether each name is a variable, variables take precedence over |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
53 ## functions in name resolution. |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
54 for i = 1:nargin |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
55 m(i).is_variable = evalin ("caller", |
27018
a20ead51515d
move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
56 ['exist ("' undo_string_escapes(m(i).name) '", "var")'], ""); |
20922
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
57 if (m(i).is_variable) |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
58 m(i).file = "variable"; |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
59 endif |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
60 endfor |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
61 |
20922
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
62 if (nargout == 0) |
18451
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
63 for i = 1:nargin |
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
64 if (m(i).is_variable) |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
65 printf ("'%s' is a variable\n", m(i).name); |
20922
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
66 elseif (isempty (m(i).file)) |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
67 if (! isempty (m(i).type)) |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
68 printf ("'%s' is a %s\n", |
20922
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
69 m(i).name, m(i).type); |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
70 endif |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
71 else |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
72 if (isempty (m(i).type)) |
25781
e04c56bbbace
isdir.m: Make m-file a legacy function (bug #54489)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
73 if (isfolder (m(i).file)) |
23046
168a18a57fc2
which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
74 printf ("'%s' is the directory %s\n", |
168a18a57fc2
which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
75 m(i).name, m(i).file); |
168a18a57fc2
which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
76 else |
168a18a57fc2
which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
77 printf ("'%s' is the file %s\n", |
168a18a57fc2
which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
78 m(i).name, m(i).file); |
168a18a57fc2
which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
79 endif |
20922
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
80 else |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
81 printf ("'%s' is a %s from the file %s\n", |
20922
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
82 m(i).name, m(i).type, m(i).file); |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
83 endif |
18451
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
84 endif |
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
85 endfor |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
86 else |
20922
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
87 varargout = {m.file}; |
23295
c1362a71fb0e
which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
88 ## Return type, instead of "", for built-in classes (bug #50541). |
c1362a71fb0e
which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
89 ## FIXME: remove code if __which__ is updated to return path for classes |
c1362a71fb0e
which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
90 idx = find (cellfun ("isempty", varargout)); |
c1362a71fb0e
which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
91 if (idx) |
c1362a71fb0e
which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
92 varargout(idx) = m(idx).type; |
c1362a71fb0e
which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
93 endif |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
94 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
95 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
96 endfunction |
12843
3035c2e130de
codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
97 |
3035c2e130de
codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
98 |
3035c2e130de
codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
99 %!test |
3035c2e130de
codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
100 %! str = which ("ls"); |
23295
c1362a71fb0e
which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
101 %! assert (str(end-17:end), fullfile ("miscellaneous", "ls.m")); |
12843
3035c2e130de
codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
102 %!test |
28024
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
103 %! str = which ("fftw"); |
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
104 %! assert (str(end-7:end), "fftw.oct"); |
31551
fd29c7a50a78
maint: use commas, semicolons consistently with Octave conventions.
Rik <rik@octave.org>
parents:
31444
diff
changeset
|
105 %!assert <*49434> (which ("inputParser"), file_in_loadpath ("inputParser.m")) |
18451
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
106 %!test |
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
107 %! x = 3; |
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
108 %! str = which ("x"); |
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
109 %! assert (str, "variable"); |
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
110 |
23295
c1362a71fb0e
which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
111 %!assert (which ("__NO_SUCH_NAME__"), "") |
c1362a71fb0e
which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
112 |
18451
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
113 %!test |
28024
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
114 %! str = which ("fftw"); |
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
115 %! assert (str(end-7:end), "fftw.oct"); |
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
116 %! fftw = 12; |
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
117 %! str = which ("fftw"); |
18451
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
118 %! assert (str, "variable"); |
28024
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
119 %! clear fftw; |
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
120 %! str = which ("fftw"); |
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
121 %! assert (str(end-7:end), "fftw.oct"); |
23295
c1362a71fb0e
which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
122 |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28024
diff
changeset
|
123 %!error <Invalid call> which () |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28024
diff
changeset
|
124 %!error <Invalid call> which (1) |
31444
2569c40924e7
which.m: Add warning for unimplemented '-all' option (bug #32088)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
125 %!warning <'-all' not yet implemented> which ("1", "-all") |
23295
c1362a71fb0e
which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
126 |