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