Mercurial > hg > octave-nkf
changeset 5830:0bb816a28335
[project @ 2006-05-26 19:04:08 by jwe]
author | jwe |
---|---|
date | Fri, 26 May 2006 19:04:08 +0000 |
parents | 93785a1b0f97 |
children | b0d4ff99a0c5 |
files | scripts/ChangeLog scripts/miscellaneous/doc.m |
diffstat | 2 files changed, 58 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2006-05-26 John W. Eaton <jwe@octave.org> + + * miscellaneous/doc.m: Also handle nargin == 0. + 2006-05-23 John W. Eaton <jwe@octave.org> * plot/mesh.m: Use __gnupot_raw__ except where __gnuplot_set__ is
--- a/scripts/miscellaneous/doc.m +++ b/scripts/miscellaneous/doc.m @@ -33,49 +33,65 @@ function retval = doc (fname) - if (nargin != 1 || ! ischar (fname)) - usage ("doc function_name") - endif + if (nargin == 0 || nargin == 1) + + ftype = 0; + + if (nargin == 1) + ## Get the directory where the function lives. + ## FIXME -- maybe we should have a better way of doing this. - ## Get the directory where the function lives. - ## FIXME -- maybe we should have a better way of doing this. + if (ischar (fname)) + ftype = exist (fname); + else + error ("doc: expecting argument to be a character string"); + endif + else + fname = ""; + endif - x = exist (fname); + if (ftype == 2 || ftype == 3) + ffile = file_in_loadpath (strcat (fname, ".")); + else + ffile = ""; + endif + + if (isempty (ffile)) + info_dir = octave_config_info ("infodir"); + else + info_dir = fileparts (ffile); + endif - if (x == 2) - ffile = file_in_loadpath (strcat (fname, ".")); - elseif (x == 3) - ffile = file_in_loadpath (strcat (fname, ".")); - else - ffile = ""; - endif + ## Determine if a file called doc.info exist in the same + ## directory as the function. + + info_file_name = fullfile (info_dir, "doc.info"); + + [stat_info, err] = stat (info_file_name); + + if (err < 0) + info_file_name = info_file (); + endif + + cmd = sprintf ("\"%s\" --directory \"%s\" --file \"%s\"", + info_program (), info_dir, info_file_name); - if (! isempty (ffile)) - info_dir = fileparts (ffile); + if (! isempty (fname)) + cmd = sprintf ("%s --index-search %s", cmd, fname); + endif + + status = system (cmd); + + if (status == 127) + warning ("unable to find info program `%s'", info_program ()); + endif + + if (nargout > 0) + retval = status; + endif + 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_name = fullfile (info_dir, "doc.info"); - - if (! isstruct (stat (info_file_name))) - info_file_name = info_file (); - endif - - cmd = sprintf ("\"%s\" --directory \"%s\" --file \"%s\" --index-search %s", - info_program (), info_dir, info_file_name, fname); - - status = system (cmd); - - if (status == 127) - warning ("unable to find info program `%s'", info_program ()); - endif - - if (nargout > 0) - retval = status; + print_usage (); endif endfunction