# HG changeset patch # User jwe # Date 1142458055 0 # Node ID 62734ddaf17b58679eda3e3bbefcf75b7c93cd20 # Parent 387dd5b347576b20f36e432267bf13629b3a3c4a [project @ 2006-03-15 21:27:34 by jwe] diff -r 387dd5b34757 -r 62734ddaf17b scripts/ChangeLog --- a/scripts/ChangeLog Wed Mar 15 20:11:46 2006 +0000 +++ b/scripts/ChangeLog Wed Mar 15 21:27:35 2006 +0000 @@ -1,3 +1,8 @@ +2006-03-15 John W. Eaton + + * miscellaneous/doc.m: New file. + From Soren Hauberg . + 2006-03-15 Keith Goodman * miscellaneous/mkoctfile.m: New file. diff -r 387dd5b34757 -r 62734ddaf17b scripts/miscellaneous/doc.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/miscellaneous/doc.m Wed Mar 15 21:27:35 2006 +0000 @@ -0,0 +1,78 @@ +## Copyright (C) 2005 Soren Hauberg +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +## -*- texinfo -*- +## @deftypefn {Command} doc @var{function_name} +## Displays documentation for the function @var{function_name}. +## For example, if you want to see the documentation for the Octave +## random number generator @code{rand}, type +## @example +## @code{doc rand} +## @end example +## @seealso{help} +## @end deftypefn + +## Author: Soren Hauberg +## Adapted-by: jwe + +function retval = doc (fname) + + if (nargin != 1 || ! ischar (fname)) + usage ("doc function_name") + endif + + ## Get the directory where the function lives. + ## XXX FIXME XXX -- maybe we should have a better way of doing this. + + x = exist (fname); + + if (x == 2) + ffile = file_in_loadpath (strcat (fname, ".")); + elseif (x == 3) + ffile = file_in_loadpath (strcat (fname, ".")); + else + ffile = ""; + endif + + if (! isempty (ffile)) + info_dir = fileparts (ffile); + else + info_dir = octave_config_info ("infodir"); + endif + + ## Determine if a file called doc.info exist in the same + ## directory as the function. + + info_file = fullfile (info_dir, "doc.info"); + + if (! isstruct (stat (info_file))) + info_file = INFO_FILE; + endif + + cmd = sprintf ("\"%s\" --directory \"%s\" --file \"%s\" --index-search %s", + INFO_PROGRAM, info_dir, info_file, fname); + + status = system (cmd); + + if (status == 127) + warning ("unable to find info program `%s'", INFO_PROGRAM); + endif + + if (nargout > 0) + retval = status; + endif + +endfunction diff -r 387dd5b34757 -r 62734ddaf17b src/ChangeLog --- a/src/ChangeLog Wed Mar 15 20:11:46 2006 +0000 +++ b/src/ChangeLog Wed Mar 15 21:27:35 2006 +0000 @@ -1,3 +1,12 @@ +2006-03-15 John W. Eaton + + * help.cc (help_from_info): Simplify. + (try_info): Use feval to call doc instead of executing info program. + (additional_help_message): Point users to doc instead of help -i. + From Soren Hauberg . + + * toplev.cc (Fsystem): Return output if nargout > 1, not 0. + 2006-03-14 Keith Goodman * help.cc (Fhelp, Fwhich, Flookfor): Doc string fix. diff -r 387dd5b34757 -r 62734ddaf17b src/help.cc --- a/src/help.cc Wed Mar 15 20:11:46 2006 +0000 +++ b/src/help.cc Wed Mar 15 21:27:35 2006 +0000 @@ -453,7 +453,7 @@ os << "\ Additional help for built-in functions, operators, and variables\n\ is available in the on-line version of the manual. Use the command\n\ -`help -i ' to search the manual index.\n\ +`doc ' to search the manual index.\n\ \n\ Help and information about Octave is also available on the WWW\n\ at http://www.octave.org and via the help@octave.org\n\ @@ -568,45 +568,18 @@ static int try_info (const std::string& nm) { - int status = 0; - - OSSTREAM cmd_buf; + int retval = -1; -#if __MINGW32__ - cmd_buf << Vinfo_prog << " --file \"" << Vinfo_file << "\""; -#else - cmd_buf << "\"" << Vinfo_prog << "\" --file \"" << Vinfo_file << "\""; -#endif - - std::string directory_name = Vinfo_file; - size_t pos = directory_name.rfind ('/'); - - if (pos != NPOS) - { - directory_name.resize (pos + 1); - cmd_buf << " --directory \"" << directory_name << "\""; - } + warning ("please use `doc' instead of `help -i'"); - if (nm.length () > 0) - cmd_buf << " --index-search " << nm; - - cmd_buf << OSSTREAM_ENDS; - - volatile octave_interrupt_handler old_interrupt_handler - = octave_ignore_interrupts (); - - status = system (OSSTREAM_C_STR (cmd_buf)); + octave_value_list args; + args(0) = nm; + octave_value_list result = feval ("doc", args, 1); - OSSTREAM_FREEZE (cmd_buf); - - octave_set_interrupt_handler (old_interrupt_handler); + if (result.length () > 0) + retval = result(0).int_value (); - if (WIFEXITED (status)) - status = WEXITSTATUS (status); - else - status = 127; - - return status; + return retval; } static void @@ -620,20 +593,11 @@ { int status = try_info (argv[i]); - if (status) - { - if (status == 127) - { - error ("help: unable to find info"); - error ("help: you need info 2.18 or later (texinfo 3.12)"); - break; - } - else - { - message ("help", "`%s' is not indexed in the manual", - argv[i].c_str ()); - } - } + if (status == 127) + break; + else if (status != 0) + message ("help", "`%s' is not indexed in the manual", + argv[i].c_str ()); } } } @@ -929,7 +893,7 @@ \n\ Once the GNU Info browser is running, help for using it is available\n\ using the command @kbd{C-h}.\n\ -@seealso{which, lookfor}\n\ +@seealso{doc, which, lookfor}\n\ @end deffn") { octave_value_list retval; diff -r 387dd5b34757 -r 62734ddaf17b src/toplev.cc --- a/src/toplev.cc Wed Mar 15 20:11:46 2006 +0000 +++ b/src/toplev.cc Wed Mar 15 21:27:35 2006 +0000 @@ -438,7 +438,7 @@ if (nargin > 0 && nargin < 4) { - bool return_output = (nargout > 0 || nargin > 1); + bool return_output = (nargout > 1 || nargin > 1); std::string cmd_str = args(0).string_value ();