diff -r fc0ea95fbba0 scripts/help/__makeinfo__.m --- a/scripts/help/__makeinfo__.m Fri Sep 09 11:15:41 2011 -0700 +++ b/scripts/help/__makeinfo__.m Sat Sep 10 08:20:20 2011 -0700 @@ -19,6 +19,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} address@hidden, @var{status}] =} __makeinfo__ (@var{text}) ## @deftypefnx {Function File} address@hidden, @var{status}] =} __makeinfo__ (@var{text}, @var{output_type}) +## @deftypefnx {Function File} address@hidden, @var{status}] =} __makeinfo__ (@var{text}, @var{output_type}, @var{fsee_also}) ## Undocumented internal function. ## @end deftypefn @@ -33,6 +34,13 @@ ## @t{"plain text"}. If @var{output_type} is @t{"texinfo"}, the @t{@@seealso} ## macro is expanded, but otherwise the text is unaltered. ## +## If the optional argument @var{fsee_also} is present, it is used to expand the +## Octave specific @t{@@seealso} macro. This argument must be a function handle, +## that accepts a cell array of strings as an input argument (each element of the +## array corresponds to an argument to the @t{@@seealso} macro), and returns +## the expanded string. If this argument is not given, the @t{@@seealso} macro +## will be expanded to the text +## ## @example ## See also: arg1, arg2@, ... ## @end example @@ -50,19 +58,19 @@ ## The optional output argument @var{status} contains the exit status of the ## @code{makeinfo} program as returned by @code{system}. -function [retval, status] = __makeinfo__ (text, output_type = "plain text") +function [retval, status] = __makeinfo__ (text, output_type = "plain text", fsee_also) ## Check input - if (nargin < 1 || nargin > 2) + if (nargin < 1 || nargin > 3) print_usage (); endif - if (!ischar (text)) + if (! ischar (text)) error ("__makeinfo__: first input argument must be a string"); - endif - - if (!ischar (output_type)) + elseif (! ischar (output_type)) error ("__makeinfo__: second input argument must be a string"); + elseif (nargin == 3 && ! isa (fsee_also, "function_handle")) + error ("__makeinfo__: third input argument must be a function handle"); endif ## It seems like makeinfo sometimes gets angry if the first character @@ -70,11 +78,19 @@ text = strrep (text, "\n ", "\n"); ## Handle @seealso macro - if (strcmpi (output_type, "plain text")) + if (nargin == 3) + T = regexp (text, '@seealso *\{([^}]*)\}', "tokens"); + if (numel (T) > 1) + error ("__makeinfo__: only one @seealso reference allowed per function"); + endif + text = regexprep (text, '@seealso *\{[^}]*\}', ... + fsee_also (strtrim (strsplit (T{1}, ",", true)))); + elseif (strcmpi (output_type, "plain text")) text = regexprep (text, '@seealso *\{([^}]*)\}', "\nSee also: $1.\n\n"); else text = regexprep (text, '@seealso *\{([^}]*)\}', "\nSee also: @ref{$1}.\n\n"); endif + ## Handle @nospell macro text = regexprep (text, '@nospell *\{([^}]*)\}', "$1"); @@ -90,7 +106,7 @@ unwind_protect ## Write Texinfo to tmp file template = "octave-help-XXXXXX"; - [fid, name, msg] = mkstemp (fullfile (P_tmpdir, template), true); + [fid, name] = mkstemp (fullfile (P_tmpdir, template), true); if (fid < 0) error ("__makeinfo__: could not create temporary file"); endif @@ -100,11 +116,11 @@ ## Take action depending on output type switch (lower (output_type)) case "plain text" - cmd = sprintf ("%s --no-headers --no-warn --force --no-validate %s", - makeinfo_program (), name); + cmd = sprintf ("%s --no-headers --no-warn --force --no-validate %s", + makeinfo_program (), name); case "html" - cmd = sprintf ("%s --no-headers --html --no-warn --no-validate --force %s", - makeinfo_program (), name); + cmd = sprintf ("%s --no-headers --html --no-warn --no-validate --force %s", + makeinfo_program (), name); otherwise error ("__makeinfo__: unsupported output type: '%s'", output_type); endswitch @@ -117,6 +133,7 @@ delete (name); endif end_unwind_protect + endfunction ## No test needed for internal helper function.