1 # Extract all examples from the manual source. -*- AWK -*-
3 # Copyright (C) 1992, 2000-2001, 2006-2010, 2013-2014, 2017 Free
4 # Software Foundation, Inc.
6 # This file is part of GNU M4.
8 # GNU M4 is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # GNU M4 is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # This script is for use with any New AWK.
25 status = xfail = examples =
0;
27 print "# This file is part of the GNU m4 test suite. -*- Autotest -*-";
28 # I don't know how to get this file's name, so it's hard coded :(
29 print "# Do not edit by hand, it was generated by generate.awk.";
31 print "# Copyright (C) 1992, 2000, 2001, 2006, 2007, 2008, 2009 Free";
32 print "# Software Foundation, Inc.";
34 print "AT_BANNER([Documentation examples.])";
39 /^@node
/ { # Start a new test group.
44 node =
substr(tmp
[1], 7);
48 /^@comment file
: / { # Produce a data file instead of a test.
52 /^@comment options
: / { # Pass additional options to m4.
54 gsub ("@comment options:", "", options
);
57 /^@comment xfail$
/ { # Expect the test to fail.
61 /^@comment examples$
/ { # The test uses files from the examples dir.
65 /^@comment ignore$
/ { # This is just formatted doc text, not an actual test.
67 status = xfail = examples =
0;
72 /^@comment status
: / { # Expected exit status of a test.
76 /^@example$
/, /^@
end example$
/ { # The body of the test.
80 if ($
0 ~
/^@example$
/)
85 printf ("echo \"$at_srcdir/%s:%d:\"\n", FILENAME, NR)
89 if ($
0 ~
/^@
end example$
/)
95 fatal
("while getting file " file \
96 " found output = " output
"," \
97 " found error = " error
);
99 input = normalize
(input
);
100 printf ("AT_DATA([[%s]],\n[[%s]])\n\n", file
, input
);
104 new_test
(input
, status
, output
, error
, options
, xfail
, examples
);
106 status = xfail = examples =
0;
107 file = input = output = error = options =
"";
116 if ($
0 ~
/^@result\
{\
}/)
117 output = output $
0 "\n";
118 else if ($
0 ~
/^@error\
{\
}/)
119 error = error $
0 "\n";
121 input = input $
0 "\n";
129 # We have to handle CONTENTS line per line, since anchors in AWK are
130 # referring to the whole string, not the lines.
131 function normalize
(contents
, i
, lines
, n
, line
, res
) {
132 # Remove the Texinfo tags.
133 n =
split (contents
, lines
, "\n");
134 # We don't want the last field which empty: it's behind the last \n.
135 for (i =
1; i
< n
; ++i
)
138 gsub ("^@result[{]}", "", line
);
139 gsub ("^@error[{]}", "", line
);
140 gsub ("@[{]", "{", line
);
141 gsub ("@}", "}", line
);
142 gsub ("@@", "@", line
);
143 gsub ("@tabchar[{]}", "\t", line
);
144 gsub ("@w[{] }", " @\\&t@", line
);
145 gsub ("m4_", "m@\\&t@4_", line
);
147 # Some of the examples have improperly balanced square brackets.
148 gsub ("[[]", "@<:@", line
);
149 gsub ("[]]", "@:>@", line
);
156 function new_group
(node
) {
158 gsub (".", "-", banner
);
160 printf ("## %s ##\n", banner
);
161 printf ("## %s. ##\n", node
);
162 printf ("## %s ##\n", banner
);
164 printf ("AT_SETUP([%s])\n", node
);
165 printf ("AT_KEYWORDS([[documentation]])\n\n");
168 function new_test
(input
, status
, output
, error
, options
, xfail
, examples
) {
169 input = normalize
(input
);
170 output = normalize
(output
);
171 error = normalize
(error
);
173 if (error ==
"ignore\n")
176 if (options ~
/ mpeval
/)
177 printf ("AT_CHECK_GMP\n");
179 printf ("AT_XFAIL_IF([:])\n");
183 printf ("AT_DATA([expout1],\n[[%s]])\n", output
);
184 printf ("$SED -e \"s|doc/examples|$abs_top_srcdir/doc/examples|g\" \\\n");
185 printf (" < expout1 > expout\n\n");
188 printf ("AT_DATA([experr1],\n[[%s]])\n", error
);
189 printf ("$SED \"s|doc/examples|$abs_top_srcdir/doc/examples|g\" \\\n");
190 printf (" < experr1 > experr\n\n");
192 options = options
" -I\"$abs_top_srcdir/doc/examples\"";
195 printf ("AT_DATA([[input.m4]],\n[[%s]])\n\n", input
);
196 # Some of these tests `include' files from tests/.
197 printf ("AT_CHECK_M4([[%s]], %s,", options
, status
);
199 printf ("\n[expout]");
201 printf ("\n[[%s]]", output
);
204 if (examples ==
1 && error
)
205 printf (",\n[experr]");
207 printf (",\n[[%s]]", error
);
210 printf (", [[input.m4]])\n\n");
213 function fatal
(msg
) {
214 print "generate.awk: " FILENAME ":" NR ": " msg
> "/dev/stderr"