Mercurial > hg > octave-nkf
changeset 5672:62734ddaf17b
[project @ 2006-03-15 21:27:34 by jwe]
author | jwe |
---|---|
date | Wed, 15 Mar 2006 21:27:35 +0000 |
parents | 387dd5b34757 |
children | 0dc67016832b |
files | scripts/ChangeLog scripts/miscellaneous/doc.m src/ChangeLog src/help.cc src/toplev.cc |
diffstat | 5 files changed, 108 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2006-03-15 John W. Eaton <jwe@octave.org> + + * miscellaneous/doc.m: New file. + From Soren Hauberg <soren@hauberg.org>. + 2006-03-15 Keith Goodman <kwgoodman@gmail.com> * miscellaneous/mkoctfile.m: New file.
new file mode 100644 --- /dev/null +++ b/scripts/miscellaneous/doc.m @@ -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 <soren@hauberg.org> +## 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
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2006-03-15 John W. Eaton <jwe@octave.org> + + * 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 <soren@hauberg.org>. + + * toplev.cc (Fsystem): Return output if nargout > 1, not 0. + 2006-03-14 Keith Goodman <kwgoodman@gmail.com> * help.cc (Fhelp, Fwhich, Flookfor): Doc string fix.
--- a/src/help.cc +++ b/src/help.cc @@ -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 <topic>' to search the manual index.\n\ +`doc <topic>' 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;