Mercurial > hg > octave-nkf
annotate scripts/help/help.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | 8b2a47a99701 |
children | 3c6e8aaa9555 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2009-2011 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 -*- |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} help @var{name} |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
21 ## Display the help text for @var{name}. |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
22 ## If invoked without any arguments, @code{help} displays instructions |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
23 ## on how to access help from the command line. |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
24 ## |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
25 ## For example, the command @kbd{help help} prints a short message |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
26 ## describing the @code{help} command. |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
27 ## |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
28 ## @deftypefnx {Function File} {@var{text} =} help (@var{name}) |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
29 ## Return the help text for the function, @var{name}. |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
30 ## |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
31 ## The help command can give you information about operators, but not the |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
32 ## comma and semicolons that are used as command separators. To get help |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
33 ## for those, you must type @kbd{help comma} or @kbd{help semicolon}. |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
8768
diff
changeset
|
34 ## @seealso{doc, lookfor, which} |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
35 ## @end deftypefn |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
36 |
10632
69a715c81eab
help.m: avoid unnecessary use of varargout
John W. Eaton <jwe@octave.org>
parents:
10625
diff
changeset
|
37 function retval = help (name) |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
38 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
39 if (nargin == 0) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
40 |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
41 puts ("\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
42 For help with individual commands and functions type\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
43 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
44 help NAME\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
45 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
46 (replace NAME with the name of the command or function you would\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
47 like to learn more about).\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
48 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
49 For a more detailed introduction to GNU Octave, please consult the\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
50 manual. To read the manual from the prompt type\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
51 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
52 doc\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
53 \n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
54 GNU Octave is supported and developed by its user community.\n\ |
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
55 For more information visit http://www.octave.org.\n\n"); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
56 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
57 elseif (nargin == 1 && ischar (name)) |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
58 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
59 ## Get help text |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
60 [text, format] = get_help_text (name); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
61 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
62 ## Take action depending on help text format |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
63 switch (lower (format)) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
64 case "plain text" |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
65 status = 0; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
66 case "texinfo" |
8768
e0fbf17a17bb
__makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents:
8748
diff
changeset
|
67 [text, status] = __makeinfo__ (text, "plain text"); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
68 case "html" |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
69 [text, status] = strip_html_tags (text); |
8631
52956d669506
Display sensible error message when the help text of an undocumented function is requested
Soren Hauberg <hauberg@gmail.com>
parents:
8630
diff
changeset
|
70 case "not documented" |
52956d669506
Display sensible error message when the help text of an undocumented function is requested
Soren Hauberg <hauberg@gmail.com>
parents:
8630
diff
changeset
|
71 error ("help: `%s' is not documented\n", name); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
72 case "not found" |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
73 do_contents (name); |
10549 | 74 return; |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
75 otherwise |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
76 error ("help: internal error: unsupported help text format: '%s'\n", format); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
77 endswitch |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
78 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
79 ## Print text |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
80 if (status != 0) |
8768
e0fbf17a17bb
__makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents:
8748
diff
changeset
|
81 warning ("help: Texinfo formatting filter exited abnormally; raw Texinfo source of help text follows...\n"); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
82 endif |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
83 |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
84 if (nargout == 0) |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
85 which (name); |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
86 printf ("\n%s\n%s", text, __additional_help_message__ ()); |
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
87 else |
10632
69a715c81eab
help.m: avoid unnecessary use of varargout
John W. Eaton <jwe@octave.org>
parents:
10625
diff
changeset
|
88 retval = text; |
10625
07933067e4ab
help.m: Allow docstring to be returned as output, and correct docstring.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
89 endif |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
90 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
91 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
92 error ("help: invalid input\n"); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
93 endif |
8748
d1eed318100f
help.m: shorten default help text
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
94 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
95 endfunction |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff
changeset
|
96 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
97 function do_contents (name) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
98 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
99 found = false; |
8630
540165304f00
Allow displaying 'Contents.m' files.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
100 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
101 dlist = find_dir_in_path (name, "all"); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
102 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
103 for i = 1:numel (dlist) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
104 fname = make_absolute_filename (fullfile (dlist{i}, "Contents.m")); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
105 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
106 [text, format] = get_help_text_from_file (fname); |
8630
540165304f00
Allow displaying 'Contents.m' files.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
107 |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
108 ## Take action depending on help text format |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
109 switch (lower (format)) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
110 case "plain text" |
10549 | 111 status = 0; |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
112 case "texinfo" |
10549 | 113 [text, status] = __makeinfo__ (text, "plain text"); |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
114 case "html" |
10549 | 115 [text, status] = strip_html_tags (text); |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
116 endswitch |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
117 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
118 if (! isempty (text)) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
119 found = true; |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
120 ## Print text. |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
121 if (status != 0) |
10549 | 122 warning ("help: Texinfo formatting filter exited abnormally; raw Texinfo source of help text follows...\n"); |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
123 endif |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
124 printf ("%s:\n\n%s\n", fname, text); |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
125 endif |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
126 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
127 endfor |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
128 |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
129 if (found) |
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
130 puts (__additional_help_message__ ()); |
10445
62f8ae5ab2cc
warn about missing matlab funcs in help
Jaroslav Hajek <highegg@gmail.com>
parents:
9806
diff
changeset
|
131 else |
11215
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
132 msg = feval (missing_function_hook, name); |
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
133 |
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
134 if (isempty (msg)) |
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
135 msg = sprintf ("`%s' not found", name); |
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
136 endif |
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
137 |
8b2a47a99701
help: print message if function not found
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
138 error ("help: %s\n", msg); |
8630
540165304f00
Allow displaying 'Contents.m' files.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
139 endif |
9806
8e345f2fe4d6
improved support for Contents.m files
John W. Eaton <jwe@octave.org>
parents:
9724
diff
changeset
|
140 |
8630
540165304f00
Allow displaying 'Contents.m' files.
Soren Hauberg <hauberg@gmail.com>
parents:
8575
diff
changeset
|
141 endfunction |