annotate scripts/miscellaneous/doc.m @ 6017:b124a912d28b

[project @ 2006-10-02 14:58:18 by jwe]
author jwe
date Mon, 02 Oct 2006 14:58:18 +0000
parents bd22133332bd
children 20c48710b2c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 2005 Soren Hauberg
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
2 ##
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
3 ## This program is free software; you can redistribute it and/or modify
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
4 ## it under the terms of the GNU General Public License as published by
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
5 ## the Free Software Foundation; either version 2 of the License, or
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
6 ## (at your option) any later version.
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
7 ##
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
8 ## This program is distributed in the hope that it will be useful,
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
11 ## GNU General Public License for more details.
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
12 ##
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
13 ## You should have received a copy of the GNU General Public License
5720
067948dc39bf [project @ 2006-03-28 11:25:29 by jwe]
jwe
parents: 5672
diff changeset
14 ## along with Octave; see the file COPYING. If not, write to the Free
067948dc39bf [project @ 2006-03-28 11:25:29 by jwe]
jwe
parents: 5672
diff changeset
15 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
067948dc39bf [project @ 2006-03-28 11:25:29 by jwe]
jwe
parents: 5672
diff changeset
16 ## 02110-1301, USA.
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
17
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
18 ## -*- texinfo -*-
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
19 ## @deftypefn {Command} doc @var{function_name}
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
20 ## Displays documentation for the function @var{function_name}.
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
21 ## For example, if you want to see the documentation for the Octave
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
22 ## random number generator @code{rand}, type
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
23 ## @example
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
24 ## @code{doc rand}
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
25 ## @end example
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
26 ## @seealso{help}
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
27 ## @end deftypefn
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
28
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
29 ## Author: Soren Hauberg <soren@hauberg.org>
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
30 ## Adapted-by: jwe
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
31
5720
067948dc39bf [project @ 2006-03-28 11:25:29 by jwe]
jwe
parents: 5672
diff changeset
32 ## PKG_ADD: mark_as_command doc
067948dc39bf [project @ 2006-03-28 11:25:29 by jwe]
jwe
parents: 5672
diff changeset
33
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
34 function retval = doc (fname)
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
35
5830
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
36 if (nargin == 0 || nargin == 1)
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
37
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
38 ftype = 0;
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
39
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
40 if (nargin == 1)
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
41 ## Get the directory where the function lives.
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
42 ## FIXME -- maybe we should have a better way of doing this.
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
43
5830
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
44 if (ischar (fname))
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
45 ftype = exist (fname);
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
46 else
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
47 error ("doc: expecting argument to be a character string");
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
48 endif
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
49 else
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
50 fname = "";
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
51 endif
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
52
5830
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
53 if (ftype == 2 || ftype == 3)
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
54 ffile = file_in_loadpath (strcat (fname, "."));
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
55 else
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
56 ffile = "";
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
57 endif
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
58
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
59 if (isempty (ffile))
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
60 info_dir = octave_config_info ("infodir");
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
61 else
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
62 info_dir = fileparts (ffile);
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
63 endif
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
64
5830
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
65 ## Determine if a file called doc.info exist in the same
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
66 ## directory as the function.
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
67
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
68 info_file_name = fullfile (info_dir, "doc.info");
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
69
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
70 [stat_info, err] = stat (info_file_name);
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
71
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
72 if (err < 0)
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
73 info_file_name = info_file ();
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
74 endif
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
75
6017
b124a912d28b [project @ 2006-10-02 14:58:18 by jwe]
jwe
parents: 6016
diff changeset
76 ## FIXME -- don't change the order of the arguments below because
b124a912d28b [project @ 2006-10-02 14:58:18 by jwe]
jwe
parents: 6016
diff changeset
77 ## the info-emacs-info script currently expects --directory DIR as
b124a912d28b [project @ 2006-10-02 14:58:18 by jwe]
jwe
parents: 6016
diff changeset
78 ## the third and fourth arguments. Someone should fix that.
b124a912d28b [project @ 2006-10-02 14:58:18 by jwe]
jwe
parents: 6016
diff changeset
79
b124a912d28b [project @ 2006-10-02 14:58:18 by jwe]
jwe
parents: 6016
diff changeset
80 cmd = sprintf ("\"%s\" --file \"%s\" --directory \"%s\"",
b124a912d28b [project @ 2006-10-02 14:58:18 by jwe]
jwe
parents: 6016
diff changeset
81 info_program (), info_file_name, info_dir);
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
82
5830
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
83 if (! isempty (fname))
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
84 cmd = sprintf ("%s --index-search %s", cmd, fname);
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
85 endif
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
86
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
87 status = system (cmd);
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
88
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
89 if (status == 127)
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
90 warning ("unable to find info program `%s'", info_program ());
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
91 endif
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
92
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
93 if (nargout > 0)
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
94 retval = status;
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
95 endif
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
96
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
97 else
5830
0bb816a28335 [project @ 2006-05-26 19:04:08 by jwe]
jwe
parents: 5794
diff changeset
98 print_usage ();
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
99 endif
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
100
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
101 endfunction