# HG changeset patch # User Carlo de Falco # Date 1315609615 -7200 # Node ID 086144a76b29d87ece15bb88d3c0251ab45c3720 # Parent fc0ea95fbba0fb0e68481d191592f5febd18ff5e Add back the third input parameter to __makeinfo__ * __makeinfo__.m: Add back the third input prameter. diff -r fc0ea95fbba0 -r 086144a76b29 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 01:06:55 2011 +0200 @@ -17,8 +17,8 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} address@hidden, @var{status}] =} __makeinfo__ (@var{text}) -## @deftypefnx {Function File} address@hidden, @var{status}] =} __makeinfo__ (@var{text}, @var{output_type}) +## @deftypefn {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{see_also}) ## Undocumented internal function. ## @end deftypefn @@ -33,6 +33,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{see_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 input argument (each elements of the +## array corresponds to the arguments to the @t{@@seealso} macro), and return +## 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,10 +57,10 @@ ## 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", see_also = []) ## Check input - if (nargin < 1 || nargin > 2) + if (nargin < 1 || nargin > 3) print_usage (); endif @@ -65,16 +72,34 @@ error ("__makeinfo__: second input argument must be a string"); endif + if (isempty (see_also)) + if (strcmpi (output_type, "plain text")) + see_also = @simple_see_also; + else + see_also = @simple_see_also_with_refs; + endif + endif + + if (!isa (see_also, "function_handle")) + error (["__makeinfo__: third input argument must ", ... + "be the empty matrix, or a function handle"]); + endif + + ## It seems like makeinfo sometimes gets angry if the first character ## on a line is a space, so we remove these. - text = strrep (text, "\n ", "\n"); + text = strrep (text, "\n ", "\n"); ## Handle @seealso macro - if (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 + see_also_pat = '@seealso *\{([^}]*)\}'; + args = regexp (text, see_also_pat, 'tokens'); + for ii = 1:numel (args) + if (! isempty (args{ii})) + expanded = feval (see_also, strtrim (strsplit (args{ii}{:}, ',', true))); + text = regexprep (text, see_also_pat, expanded); + endif + endfor + ## Handle @nospell macro text = regexprep (text, '@nospell *\{([^}]*)\}', "$1"); @@ -100,11 +125,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 @@ -122,3 +147,12 @@ ## No test needed for internal helper function. %!assert (1) +function expanded = simple_see_also_with_refs (args) + expanded = strcat ("\nSee also:", sprintf (" @ref{%s},", args {:})); + expanded = strcat (expanded (1:end-1), "\n\n"); +endfunction + +function expanded = simple_see_also (args) + expanded = strcat ("\nSee also:", sprintf (" %s,", args {:})); + expanded = strcat (expanded (1:end-1), "\n\n"); +endfunction