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