Mercurial > hg > octave-nkf
annotate scripts/help/type.m @ 20727:4479d73eac72
Fix error when building annotation objects in gnuplot (bug #46035)
* __gnuplot_draw_figure__.m: ignore uicontextmenu objects.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Sat, 26 Sep 2015 11:26:18 +0200 |
parents | abf85f8cbd6c |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19790
diff
changeset
|
1 ## Copyright (C) 2009-2015 Søren Hauberg |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
2 ## |
11104 | 3 ## This file is part of Octave. |
4 ## | |
5 ## 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
|
6 ## under the terms of the GNU General Public License as published by |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
8 ## your option) any later version. |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
9 ## |
11104 | 10 ## 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
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
13 ## General Public License for more details. |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
14 ## |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
11104 | 16 ## along with Octave; see the file COPYING. If not, see |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
18 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9037
diff
changeset
|
20 ## @deftypefn {Command} {} type @var{name} @dots{} |
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9037
diff
changeset
|
21 ## @deftypefnx {Command} {} type -q @var{name} @dots{} |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
22 ## @deftypefnx {Function File} {text =} type ("@var{name}", @dots{}) |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
23 ## Display the contents of @var{name} which may be a file, function (m-file), |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
24 ## variable, operator, or keyword. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
25 ## |
20368
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
26 ## @code{type} normally prepends a header line describing the category of |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
27 ## @var{name} such as function or variable; The @option{-q} option suppresses |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
28 ## this behavior. |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
29 ## |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
30 ## If no output variable is used the contents are displayed on screen. |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
31 ## Otherwise, a cell array of strings is returned, where each element |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
32 ## corresponds to the contents of each requested function. |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
33 ## @end deftypefn |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
34 |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
35 function text = type (varargin) |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
36 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
37 if (nargin == 0) |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
38 print_usage (); |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
39 elseif (! iscellstr (varargin)) |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
40 error ("type: input arguments must be strings"); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
41 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
42 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
43 quiet = false; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
44 idx = strcmpi (varargin, "-q") | strcmpi (varargin, "-quiet"); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
45 if (any (idx)) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
46 quiet = true; |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
47 varargin(idx) = []; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
48 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
49 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
50 if (nargout > 0) |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
51 text = cell (size (varargin)); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
52 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
53 |
8582 | 54 for n = 1:length (varargin) |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
55 name = varargin{n}; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
56 |
8582 | 57 ## Find function and get its code |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
58 txt = ""; |
8582 | 59 cmd = sprintf ("exist ('%s')", name); |
60 e = evalin ("caller", cmd); | |
61 if (e == 1) | |
62 ## Variable | |
63 cmd = sprintf ("disp (%s);", name); | |
64 desc = evalin ("caller", cmd); | |
65 if (quiet) | |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
66 txt = desc; |
8582 | 67 else |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
68 txt = sprintf ("%s is a variable\n%s", name, desc); |
8582 | 69 endif |
70 elseif (e == 2) | |
71 ## m-file or ordinary file | |
72 file = which (name); | |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
73 if (length (file) > 2) |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
74 ext = file(end-1:end); |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
75 endif |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
76 if (isempty (file) || ! strcmpi (ext, ".m")) |
8582 | 77 ## 'name' is an ordinary file, and not a function name. |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
78 file = file_in_loadpath (name); |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
79 quiet = true; |
8582 | 80 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
81 |
8582 | 82 ## Read the file |
83 fid = fopen (file, "r"); | |
84 if (fid < 0) | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
85 error ("type: couldn't open '%s' for reading", file); |
8582 | 86 endif |
87 contents = char (fread (fid).'); | |
88 fclose (fid); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
89 |
8582 | 90 if (quiet) |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
91 txt = contents; |
8582 | 92 else |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
93 txt = sprintf ("%s is the user-defined function defined from: %s\n\n%s", |
8582 | 94 name, file, contents); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
95 endif |
8582 | 96 elseif (e == 3) |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
97 txt = sprintf ("%s is a dynamically-linked function", name); |
8582 | 98 elseif (e == 5) |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
99 txt = sprintf ("%s is a built-in function", name); |
20417
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
100 elseif (e == 103) |
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
101 contents = __get_cmdline_fcn_txt__ (name); |
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
102 if (isempty (contents)) |
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
103 txt = sprintf ("%s is a command-line function with no definition", |
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
104 name); |
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
105 else |
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
106 if (quiet) |
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
107 txt = contents; |
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
108 else |
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
109 txt = sprintf ("%s is the command-line function:\n\n%s", |
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
110 name, contents); |
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
111 endif |
abf85f8cbd6c
Expand type() to work on command-line entered functions (bug #40462).
John W. Eaton <jwe@octave.org>
parents:
20368
diff
changeset
|
112 endif |
8582 | 113 elseif (any (strcmp (__operators__ (), name))) |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
114 txt = sprintf ("%s is an operator", name); |
8582 | 115 elseif (any (strcmp (__keywords__ (), name))) |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
116 txt = sprintf ("%s is a keyword", name); |
8582 | 117 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
118 error ("type: '%s' undefined\n", name); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
119 endif |
8582 | 120 |
121 if (nargout == 0) | |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
122 disp (txt); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
123 else |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
124 text{n} = txt; |
8582 | 125 endif |
126 endfor | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
127 endfunction |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
128 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
129 |
12838
b584c07cd818
codesprint: Add tests for type()
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
130 %!test |
b584c07cd818
codesprint: Add tests for type()
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
131 %! var = 1; |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
132 %! text = type ("var"); |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
133 %! typestr = text{1}(1:17); |
12838
b584c07cd818
codesprint: Add tests for type()
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
134 %! assert (typestr, "var is a variable"); |
8582 | 135 |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
136 %!test |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
137 %! text = type ("ls"); |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
138 %! typestr = text{1}(1:31); |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
139 %! assert (typestr, "ls is the user-defined function"); |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
140 |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
141 %!test |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
142 %! text = type ("ls", "-q"); |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
143 %! typestr = text{1}(1:21); |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
144 %! assert (typestr, "## Copyright (C) 2006"); |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
145 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
146 %!assert (type ("amd"){1}, "amd is a dynamically-linked function") |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
147 %!assert (type ("cat"){1}, "cat is a built-in function") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
148 %!assert (type ("+"){1}, "+ is an operator") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
149 %!assert (type ("end"){1}, "end is a keyword") |
17399
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
150 |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
151 %!error type () |
a1fa416c7c4a
type.m: Fix function for filenames without extension (bug #39922).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
152 %!error <'__NO_NAME__' undefined> type ('__NO_NAME__') |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
153 |