## Copyright (C) 2008 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 3 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; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} address@hidden =} makeinfo (@var{text}, @var{output_type}, ...) ## Run @code{makeinfo} on a given text. ## ## The string @var{text} is run through the @code{makeinfo} program to generate ## output in various formats. The @var{output_type} selects the format of the ## output. This can be either @t{"html"}, @t{"plaintext"}, or @t{"custom"}. ## See the source code of this function for details on how to use the ## @t{"custom"} output type. ## @end deftypefn function [retval, status] = makeinfo (text, output_type, varargin) ## Define the @seealso macro idx = find (strcmpi ("seealso", varargin)); if (length (idx) > 0 && idx < length (varargin)) see_also = varargin {idx+1}; varargin = {varargin{1:idx-1}, varargin{idx+2:end}}; else see_also = "@macro seealso {list}\n\ @sp 1\n\ @noindent\n\ See also: \\list\\.\n\ @end macro\n"; endif ## Create the final TeXinfo input string orig_text = text; text = sprintf ("\\input address@hidden", see_also, text); ## Replace \ with \\, and " with \" because that's what 'echo' wants ## XXX: remove this if we use a temp. file. #text = strrep (text, "\\", "\\\\"); #text = strrep (text, "\"", "\\\""); #text = strrep (text, "$", "\\$"); #text = strrep (text, "!", "\\!"); #text = strrep (text, "|", "\\|"); unwind_protect ## Write Texinfo to tmp file [fid, name, msg] = mkstemp ("octave_help_XXXXXX", true); fwrite (fid, text); fclose (fid); ## Take action depending on output type switch (lower (output_type)) case "plaintext" cmd = sprintf ("cat %s | %s --no-headers --no-warn --force --no-validate", name, makeinfo_program ()); %cmd = sprintf ("echo \"%s\" | %s --no-headers --no-warn --force --no-validate", % text, makeinfo_program ()); case "html" cmd = sprintf ("cat %s | %s --no-headers --html --no-warn --no-validate", name, makeinfo_program ()); %cmd = sprintf ("echo \"%s\" | %s --no-headers --html --no-warn --no-validate", % text, makeinfo_program ()); case "custom" cmd = sprintf ("cat %s | %s %s", name, makeinfo_program (), varargin{1}); otherwise error ("makeinfo: unsupported output type: '%s'", output_type); endswitch ## Call makeinfo [status, retval] = system (cmd); unwind_protect_cleanup if (exist(name, "file")) delete (name); endif end_unwind_protect endfunction