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 |
|
36 if (nargin != 1 || ! ischar (fname)) |
|
37 usage ("doc function_name") |
|
38 endif |
|
39 |
|
40 ## Get the directory where the function lives. |
5775
|
41 ## FIXME -- maybe we should have a better way of doing this. |
5672
|
42 |
|
43 x = exist (fname); |
|
44 |
|
45 if (x == 2) |
|
46 ffile = file_in_loadpath (strcat (fname, ".")); |
|
47 elseif (x == 3) |
|
48 ffile = file_in_loadpath (strcat (fname, ".")); |
|
49 else |
|
50 ffile = ""; |
|
51 endif |
|
52 |
|
53 if (! isempty (ffile)) |
|
54 info_dir = fileparts (ffile); |
|
55 else |
|
56 info_dir = octave_config_info ("infodir"); |
|
57 endif |
|
58 |
|
59 ## Determine if a file called doc.info exist in the same |
|
60 ## directory as the function. |
|
61 |
5794
|
62 info_file_name = fullfile (info_dir, "doc.info"); |
5672
|
63 |
5794
|
64 if (! isstruct (stat (info_file_name))) |
|
65 info_file_name = info_file (); |
5672
|
66 endif |
|
67 |
|
68 cmd = sprintf ("\"%s\" --directory \"%s\" --file \"%s\" --index-search %s", |
5794
|
69 info_program (), info_dir, info_file_name, fname); |
5672
|
70 |
|
71 status = system (cmd); |
|
72 |
|
73 if (status == 127) |
5794
|
74 warning ("unable to find info program `%s'", info_program ()); |
5672
|
75 endif |
|
76 |
|
77 if (nargout > 0) |
|
78 retval = status; |
|
79 endif |
|
80 |
|
81 endfunction |