Mercurial > octave
annotate scripts/help/which.m @ 28024:c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
Octave is always linked with SuiteSparse libraries to support
functions in liboctave so there is no advantage to dynamically load
the interpreter DEFUN functions that depend on SuiteSparse.
* __eigs__.cc, amd.cc, ccolamd.cc, chol.cc, colamd.cc, dmperm.cc,
qr.cc, symbfact.cc, symrcm.cc: Move from dldfcn to corefcn directory.
Define functions with DEFUN or DEFMETHOD instead of DEFUN_DLD or
DEFMETHOD_DLD.
* libinterp/dldfcn/module-files, libinterp/corefcn/module.mk: Update.
* amd.cc (Famd): Don't mlock function.
* symbfact.cc (Fsymbfact): Don't mlock function.
* variables.cc, type.m, which.m: Update tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 29 Jan 2020 06:30:40 -0500 |
parents | bd51beb6205e |
children | 90fea9cc9caa 0a5b15007766 |
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 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 2009-2020 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 |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
41 m = __which__ (varargin{:}); |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
42 |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
43 ## 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
|
44 ## functions in name resolution. |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
45 for i = 1:nargin |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
46 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
|
47 ['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
|
48 if (m(i).is_variable) |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
49 m(i).file = "variable"; |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
50 endif |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
51 endfor |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
52 |
20922
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
53 if (nargout == 0) |
18451
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
54 for i = 1:nargin |
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
55 if (m(i).is_variable) |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
56 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
|
57 elseif (isempty (m(i).file)) |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
58 if (! isempty (m(i).type)) |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
59 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
|
60 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
|
61 endif |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
62 else |
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 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
|
67 else |
168a18a57fc2
which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
68 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
|
69 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
|
70 endif |
20922
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
71 else |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
72 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
|
73 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
|
74 endif |
18451
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
75 endif |
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
76 endfor |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
77 else |
20922
49081851fddc
Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
78 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
|
79 ## 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
|
80 ## 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
|
81 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
|
82 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
|
83 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
|
84 endif |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
85 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
86 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
87 endfunction |
12843
3035c2e130de
codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
88 |
3035c2e130de
codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
89 |
3035c2e130de
codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
90 %!test |
3035c2e130de
codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
91 %! 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
|
92 %! 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
|
93 %!test |
28024
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
94 %! str = which ("fftw"); |
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
95 %! 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
|
96 %!test |
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
|
97 %! str = which ("inputParser"); |
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
|
98 %! assert (str, "built-in function"); |
18451
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
99 %!test |
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
100 %! x = 3; |
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
101 %! str = which ("x"); |
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
102 %! assert (str, "variable"); |
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
103 |
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
|
104 %!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
|
105 |
18451
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
106 %!test |
28024
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
107 %! str = which ("fftw"); |
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
108 %! 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
|
109 %! fftw = 12; |
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
110 %! str = which ("fftw"); |
18451
2bd78ab75b23
which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
111 %! 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
|
112 %! clear fftw; |
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
113 %! str = which ("fftw"); |
c28b8ba841fb
move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
114 %! 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
|
115 |
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
|
116 %!error which () |
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
|
117 %!error which (1) |
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
|
118 |