1 ## Copyright (C) 2005-2012 Søren Hauberg
3 ## This file is part of Octave.
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.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Command} {} doc @var{function_name}
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.
26 ## For example, the command @kbd{doc rand} starts the GNU Info browser
27 ## at the @code{rand} node in the on-line version of the manual.
29 ## Once the GNU Info browser is running, help for using it is available
30 ## using the command @kbd{C-h}.
34 ## Author: Soren Hauberg <soren@hauberg.org>
37 function retval = doc (fname)
39 if (nargin == 0 || nargin == 1)
44 ## Get the directory where the function lives.
45 ## FIXME -- maybe we should have a better way of doing this.
48 ftype = exist (fname);
50 error ("doc: expecting argument to be a character string");
56 if (ftype == 2 || ftype == 3)
57 ffile = which (fname);
63 info_dir = octave_config_info ("infodir");
65 info_dir = fileparts (ffile);
68 ## Determine if a file called doc.info exist in the same
69 ## directory as the function.
71 info_file_name = fullfile (info_dir, "doc.info");
73 [stat_info, err] = stat (info_file_name);
76 info_file_name = info_file ();
79 ## FIXME -- don't change the order of the arguments below because
80 ## the info-emacs-info script currently expects --directory DIR as
81 ## the third and fourth arguments. Someone should fix that.
83 cmd = sprintf ("\"%s\" --file \"%s\" --directory \"%s\"",
84 info_program (), info_file_name, info_dir);
86 have_fname = ! isempty (fname);
89 status = system (sprintf ("%s --index-search %s", cmd, fname));
92 if (! (have_fname && status == 0))
93 status = system (cmd);
95 warning ("unable to find info program `%s'", info_program ());
109 %!test if exist( info_file ()) != 2 && exist (sprintf ("%s.gz", info_file ())) != 2
110 %! error ("Info file %s or %s.gz does not exist!", info_file (), info_file ());