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} |
6615
|
20 ## Display documentation for the function @var{function_name} |
|
21 ## directly from an on-line version of |
|
22 ## the printed manual, using the GNU Info browser. If invoked without |
|
23 ## any arguments, the manual is shown from the beginning. |
|
24 ## |
|
25 ## For example, the command @kbd{doc rand} starts the GNU Info browser |
|
26 ## at this node in the on-line version of the manual. |
|
27 ## |
|
28 ## Once the GNU Info browser is running, help for using it is available |
|
29 ## using the command @kbd{C-h}. |
5672
|
30 ## @seealso{help} |
|
31 ## @end deftypefn |
|
32 |
|
33 ## Author: Soren Hauberg <soren@hauberg.org> |
|
34 ## Adapted-by: jwe |
|
35 |
5720
|
36 ## PKG_ADD: mark_as_command doc |
|
37 |
5672
|
38 function retval = doc (fname) |
|
39 |
5830
|
40 if (nargin == 0 || nargin == 1) |
|
41 |
|
42 ftype = 0; |
|
43 |
|
44 if (nargin == 1) |
|
45 ## Get the directory where the function lives. |
|
46 ## FIXME -- maybe we should have a better way of doing this. |
5672
|
47 |
5830
|
48 if (ischar (fname)) |
|
49 ftype = exist (fname); |
|
50 else |
|
51 error ("doc: expecting argument to be a character string"); |
|
52 endif |
|
53 else |
|
54 fname = ""; |
|
55 endif |
5672
|
56 |
5830
|
57 if (ftype == 2 || ftype == 3) |
6339
|
58 ffile = which (fname); |
5830
|
59 else |
|
60 ffile = ""; |
|
61 endif |
|
62 |
|
63 if (isempty (ffile)) |
|
64 info_dir = octave_config_info ("infodir"); |
|
65 else |
|
66 info_dir = fileparts (ffile); |
|
67 endif |
5672
|
68 |
5830
|
69 ## Determine if a file called doc.info exist in the same |
|
70 ## directory as the function. |
|
71 |
|
72 info_file_name = fullfile (info_dir, "doc.info"); |
|
73 |
|
74 [stat_info, err] = stat (info_file_name); |
|
75 |
|
76 if (err < 0) |
|
77 info_file_name = info_file (); |
|
78 endif |
|
79 |
6017
|
80 ## FIXME -- don't change the order of the arguments below because |
|
81 ## the info-emacs-info script currently expects --directory DIR as |
|
82 ## the third and fourth arguments. Someone should fix that. |
|
83 |
|
84 cmd = sprintf ("\"%s\" --file \"%s\" --directory \"%s\"", |
|
85 info_program (), info_file_name, info_dir); |
5672
|
86 |
6344
|
87 have_fname = ! isempty (fname); |
|
88 |
|
89 if (have_fname) |
|
90 status = system (sprintf ("%s --index-search %s", cmd, fname)); |
5830
|
91 endif |
|
92 |
6344
|
93 if (! (have_fname && status == 0)) |
|
94 status = system (cmd); |
|
95 if (status == 127) |
|
96 warning ("unable to find info program `%s'", info_program ()); |
|
97 endif |
5830
|
98 endif |
|
99 |
|
100 if (nargout > 0) |
|
101 retval = status; |
|
102 endif |
|
103 |
5672
|
104 else |
5830
|
105 print_usage (); |
5672
|
106 endif |
|
107 |
|
108 endfunction |