annotate scripts/miscellaneous/doc.m @ 5794:1138ced03f14

[project @ 2006-05-08 20:23:04 by jwe]
author jwe
date Mon, 08 May 2006 20:23:07 +0000
parents ace8d8d26933
children 0bb816a28335
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
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
36 if (nargin != 1 || ! ischar (fname))
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
37 usage ("doc function_name")
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
38 endif
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
39
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
40 ## Get the directory where the function lives.
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5720
diff changeset
41 ## 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
42
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
43 x = exist (fname);
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
44
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
45 if (x == 2)
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
46 ffile = file_in_loadpath (strcat (fname, "."));
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
47 elseif (x == 3)
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
48 ffile = file_in_loadpath (strcat (fname, "."));
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
49 else
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
50 ffile = "";
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
51 endif
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
52
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
53 if (! isempty (ffile))
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
54 info_dir = fileparts (ffile);
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
55 else
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
56 info_dir = octave_config_info ("infodir");
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
57 endif
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
58
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
59 ## Determine if a file called doc.info exist in the same
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
60 ## directory as the function.
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
61
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
62 info_file_name = fullfile (info_dir, "doc.info");
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
63
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
64 if (! isstruct (stat (info_file_name)))
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
65 info_file_name = info_file ();
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
66 endif
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
67
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
68 cmd = sprintf ("\"%s\" --directory \"%s\" --file \"%s\" --index-search %s",
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
69 info_program (), info_dir, info_file_name, fname);
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
70
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
71 status = system (cmd);
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
72
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
73 if (status == 127)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
74 warning ("unable to find info program `%s'", info_program ());
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
75 endif
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
76
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
77 if (nargout > 0)
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
78 retval = status;
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
79 endif
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
80
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents:
diff changeset
81 endfunction