comparison scripts/help/help.m @ 8575:f134925a1cfa

m-file implementation of help system
author Soren Hauberg <soren@hauberg.org>
date Thu, 22 Jan 2009 18:22:52 -0500
parents
children 540165304f00
comparison
equal deleted inserted replaced
8574:83b8c739d626 8575:f134925a1cfa
1 ## Copyright (C) 2009 Søren Hauberg
2 ##
3 ## This program is free software; you can redistribute it and/or modify it
4 ## under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 3 of the License, or (at
6 ## your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ## General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; see the file COPYING. If not, see
15 ## <http://www.gnu.org/licenses/>.
16
17 ## -*- texinfo -*-
18 ## @deftypefn {Command} help @var{name}
19 ## Display the help text for @var{name}.
20 ## If invoked without any arguments, @code{help} prints a list
21 ## of all the available operators and functions.
22 ##
23 ## For example, the command @kbd{help help} prints a short message
24 ## describing the @code{help} command.
25 ##
26 ## The help command can give you information about operators, but not the
27 ## comma and semicolons that are used as command separators. To get help
28 ## for those, you must type @kbd{help comma} or @kbd{help semicolon}.
29 ## @seealso{doc, which, lookfor}
30 ## @end deftypefn
31
32 ## PKG_ADD: mark_as_command help
33
34 function help (name)
35 if (nargin == 0)
36 disp ("Help is available for the topics listed below.");
37 disp ("");
38
39 disp ("*** operators:");
40 operators = __operators__ ();
41 disp (list_in_columns (operators (:, 1)));
42
43 disp ("*** reserved words:");
44 keywords = __keywords__ ();
45 disp (list_in_columns (keywords (:, 1)));
46
47 disp ("*** available functions:");
48 functions = __list_functions__ ();
49 disp (list_in_columns (functions));
50
51 elseif (nargin == 1 && ischar (name))
52 ## Get help text
53 [text, format] = get_help_text (name);
54
55 ## Take action depending on help text format
56 switch (lower (format))
57 case "plain text"
58 status = 0;
59 case "texinfo"
60 [text, status] = makeinfo (text, "plain text");
61 case "html"
62 [text, status] = strip_html_tags (text);
63 case "not found"
64 error ("help: `%s' not found\n", name);
65 otherwise
66 error ("help: internal error: unsupported help text format: '%s'\n", format);
67 endswitch
68
69 ## Print text
70 if (status != 0)
71 warning ("makeinfo: Texinfo formatting filter exited abnormally");
72 warning ("makeinfo: raw Texinfo source of help text follows...\n");
73 endif
74
75 which (name);
76 printf ("\n%s\n%s", text, __additional_help_message__ ());
77
78 else
79 error ("help: invalid input\n");
80 endif
81 endfunction
82