annotate scripts/help/__makeinfo__.m @ 17428:577a19afdaf5

maint: Backed out changeset f81401b6b1f7. * test/parser.tst: bug #33304 should remain an error until it is fixed.
author Rik <rik@octave.org>
date Sat, 14 Sep 2013 17:07:05 -0700
parents 687872d279be
children 8c22a8d42833
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17251
f4c8c66faf34 maint: Update source file encodings to UTF-8 and fix character errors
Mike Miller <mtmiller@ieee.org>
parents: 16994
diff changeset
1 ## Copyright (C) 2009-2012 Søren Hauberg
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
2 ##
11104
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10803
diff changeset
3 ## This file is part of Octave.
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10803
diff changeset
4 ##
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10803
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
8 ## your option) any later version.
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
9 ##
11104
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10803
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
13 ## General Public License for more details.
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
14 ##
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
11104
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10803
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
18
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
19 ## -*- texinfo -*-
17347
687872d279be __makeinfo__.m: Remove @seealso code made obsolete by cset 4e9dc46d4125.
Rik <rik@octave.org>
parents: 17251
diff changeset
20 ## @deftypefn {Function File} {[@var{retval}, @var{status}] =} __makeinfo__ (@var{text})
687872d279be __makeinfo__.m: Remove @seealso code made obsolete by cset 4e9dc46d4125.
Rik <rik@octave.org>
parents: 17251
diff changeset
21 ## @deftypefnx {Function File} {[@var{retval}, @var{status}] =} __makeinfo__ (@var{text}, @var{output_type})
8768
e0fbf17a17bb __makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents: 8717
diff changeset
22 ## Undocumented internal function.
e0fbf17a17bb __makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents: 8717
diff changeset
23 ## @end deftypefn
e0fbf17a17bb __makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents: 8717
diff changeset
24
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
25 ## Run @code{makeinfo} on a given text.
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
26 ##
8768
e0fbf17a17bb __makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents: 8717
diff changeset
27 ## The string @var{text} is run through the @code{__makeinfo__} program
17347
687872d279be __makeinfo__.m: Remove @seealso code made obsolete by cset 4e9dc46d4125.
Rik <rik@octave.org>
parents: 17251
diff changeset
28 ## to generate output in various formats. This string must contain valid
8768
e0fbf17a17bb __makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents: 8717
diff changeset
29 ## Texinfo formatted text.
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
30 ##
17347
687872d279be __makeinfo__.m: Remove @seealso code made obsolete by cset 4e9dc46d4125.
Rik <rik@octave.org>
parents: 17251
diff changeset
31 ## The @var{output_type} selects the format of the output. This can be either
687872d279be __makeinfo__.m: Remove @seealso code made obsolete by cset 4e9dc46d4125.
Rik <rik@octave.org>
parents: 17251
diff changeset
32 ## @qcode{"html"}, @qcode{"texinfo"}, or @qcode{"plain text"}. By default this
687872d279be __makeinfo__.m: Remove @seealso code made obsolete by cset 4e9dc46d4125.
Rik <rik@octave.org>
parents: 17251
diff changeset
33 ## is @qcode{"plain text"}.
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
34 ##
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
35 ## The optional output argument @var{status} contains the exit status of the
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
36 ## @code{makeinfo} program as returned by @code{system}.
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
37
17347
687872d279be __makeinfo__.m: Remove @seealso code made obsolete by cset 4e9dc46d4125.
Rik <rik@octave.org>
parents: 17251
diff changeset
38 function [retval, status] = __makeinfo__ (text, output_type = "plain text")
8768
e0fbf17a17bb __makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents: 8717
diff changeset
39
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
40 ## Check input
17347
687872d279be __makeinfo__.m: Remove @seealso code made obsolete by cset 4e9dc46d4125.
Rik <rik@octave.org>
parents: 17251
diff changeset
41 if (nargin < 1 || nargin > 2)
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
42 print_usage ();
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
43 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
44
13122
f80273b38cc4 more fixes to __makeinfo__
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13121
diff changeset
45 if (! ischar (text))
8768
e0fbf17a17bb __makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents: 8717
diff changeset
46 error ("__makeinfo__: first input argument must be a string");
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
47 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
48
13122
f80273b38cc4 more fixes to __makeinfo__
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13121
diff changeset
49 if (! ischar (output_type))
17347
687872d279be __makeinfo__.m: Remove @seealso code made obsolete by cset 4e9dc46d4125.
Rik <rik@octave.org>
parents: 17251
diff changeset
50 error ("__makeinfo__: OUTPUT_TYPE must be a string");
13121
390add500107 Add back the third input parameter to __makeinfo__
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13120
diff changeset
51 endif
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13122
diff changeset
52
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
53 ## Formatting in m-files has an extra space at the beginning of every line.
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
54 ## Remove these unwanted spaces if present. First text char is "\n" delim.
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
55 if (text(2) == " ")
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
56 text = strrep (text, "\n ", "\n");
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
57 endif
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
58 ## Texinfo crashes if @end tex does not appear first on the line.
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
59 text = regexprep (text, '^ +@end tex', '@end tex', 'lineanchors');
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
60
14614
4e9dc46d4125 handle texinfo macros consistently in help system and manual
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
61 file = texi_macros_file ();
4e9dc46d4125 handle texinfo macros consistently in help system and manual
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
62 fid = fopen (file, "r");
4e9dc46d4125 handle texinfo macros consistently in help system and manual
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
63 if (fid < 0)
4e9dc46d4125 handle texinfo macros consistently in help system and manual
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
64 error ("unable to open %s for reading", file);
4e9dc46d4125 handle texinfo macros consistently in help system and manual
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
65 else
4e9dc46d4125 handle texinfo macros consistently in help system and manual
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
66 macros_text = fread (fid, Inf, "*char")';
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 15701
diff changeset
67 text = [macros_text text];
14614
4e9dc46d4125 handle texinfo macros consistently in help system and manual
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
68 endif
4e9dc46d4125 handle texinfo macros consistently in help system and manual
John W. Eaton <jwe@octave.org>
parents: 14363
diff changeset
69 fclose (fid);
10803
75780a2b0417 __makeinfo__.m: Add support to process @nopsell macro.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
70
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
71 if (strcmpi (output_type, "texinfo"))
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
72 status = 0;
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
73 retval = text;
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
74 return;
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
75 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
76
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
77 ## Create the final TeXinfo input string
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
78 text = sprintf ("\\input texinfo\n\n%s\n\n@bye\n", text);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
79
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
80 unwind_protect
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
81 ## Write Texinfo to tmp file
9983
2d347a2f4a0a __makeinfo__: style fixes
John W. Eaton <jwe@octave.org>
parents: 9982
diff changeset
82 template = "octave-help-XXXXXX";
15701
edce7d75597b Change .m files to use tempdir instead of P_tmpdir (patch #7875)
Corbin Champion <corbinlc@gmail.com>
parents: 14614
diff changeset
83 [fid, name] = mkstemp (fullfile (tempdir, template), true);
9982
7cef030b8069 let __makeinfo__ create temporary file in P_tmpdir
Jaroslav Hajek <highegg@gmail.com>
parents: 9263
diff changeset
84 if (fid < 0)
7cef030b8069 let __makeinfo__ create temporary file in P_tmpdir
Jaroslav Hajek <highegg@gmail.com>
parents: 9263
diff changeset
85 error ("__makeinfo__: could not create temporary file");
7cef030b8069 let __makeinfo__ create temporary file in P_tmpdir
Jaroslav Hajek <highegg@gmail.com>
parents: 9263
diff changeset
86 endif
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
87 fwrite (fid, text);
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
88 fclose (fid);
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
89
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
90 ## Take action depending on output type
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
91 switch (lower (output_type))
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
92 case "plain text"
17347
687872d279be __makeinfo__.m: Remove @seealso code made obsolete by cset 4e9dc46d4125.
Rik <rik@octave.org>
parents: 17251
diff changeset
93 cmd = sprintf ("%s --no-headers --no-warn --no-validate --force %s",
13121
390add500107 Add back the third input parameter to __makeinfo__
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13120
diff changeset
94 makeinfo_program (), name);
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
95 case "html"
17347
687872d279be __makeinfo__.m: Remove @seealso code made obsolete by cset 4e9dc46d4125.
Rik <rik@octave.org>
parents: 17251
diff changeset
96 cmd = sprintf ("%s --html --no-headers --no-warn --no-validate --force %s",
13121
390add500107 Add back the third input parameter to __makeinfo__
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13120
diff changeset
97 makeinfo_program (), name);
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
98 otherwise
8768
e0fbf17a17bb __makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents: 8717
diff changeset
99 error ("__makeinfo__: unsupported output type: '%s'", output_type);
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
100 endswitch
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
101
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
102 ## Call makeinfo
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
103 [status, retval] = system (cmd);
10803
75780a2b0417 __makeinfo__.m: Add support to process @nopsell macro.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
104
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
105 unwind_protect_cleanup
8768
e0fbf17a17bb __makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents: 8717
diff changeset
106 if (exist (name, "file"))
e0fbf17a17bb __makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents: 8717
diff changeset
107 delete (name);
e0fbf17a17bb __makeinfo__.m: rename from makeinfo.m
John W. Eaton <jwe@octave.org>
parents: 8717
diff changeset
108 endif
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
109 end_unwind_protect
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
110 endfunction
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
111
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
112
13044
a04e32272ecb codesprint: Turn off test warning for various internal helper functions
Rik <octave@nomad.inbox5.com>
parents: 12606
diff changeset
113 ## No test needed for internal helper function.
a04e32272ecb codesprint: Turn off test warning for various internal helper functions
Rik <octave@nomad.inbox5.com>
parents: 12606
diff changeset
114 %!assert (1)
a04e32272ecb codesprint: Turn off test warning for various internal helper functions
Rik <octave@nomad.inbox5.com>
parents: 12606
diff changeset
115