1 # Extract all examples from the manual source. -*- AWK -*-
3 # This file is part of GNU Bison
4 # Copyright 1992, 2000, 2001, 2005 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # This script is for use with any Awk that conforms to POSIX.
22 # It was derived from a similar script tests/generate.awk in GNU m4.
24 # Usage: extexi input-file.texi ... -- [FILES to extract]
28 for (argc = 1; argc < ARGC; ++argc)
29 if (ARGV[argc] == "--")
31 for (i = argc + 1; i < ARGC; ++i)
32 file_wanted[ARGV[i]] = 1;
41 node = substr(tmp[1], 7);
47 message("ignoring " $3);
50 message("extracting " $3);
55 /^@example$/, /^@end example$/ {
59 if ($0 ~ /^@example$/)
61 input = files_output[file] ? "\n" : "";
63 # FNR is starting at 0 instead of 1, and
64 # #line report the line number of the *next* line.
66 # Note that recent Bison support it, but not Flex.
67 if (file ~ /\.[chy]*$/)
68 input = "#line " (FNR + 1) " \"" FILENAME "\"\n";
72 if ($0 ~ /^@end example$/)
75 fatal("no contents: " file);
77 input = normalize(input);
78 # No spurious end of line: use printf.
79 if (files_output[file])
80 printf ("%s", input) >> output_dir "/" file;
82 printf ("%s", input) > output_dir "/" file;
83 close (output_dir "/" file);
84 files_output[file] = 1;
90 input = input $0 "\n";
94 # We have to handle CONTENTS line per line, since anchors in AWK are
95 # referring to the whole string, not the lines.
96 function normalize(contents, i, lines, n, line, res) {
97 # Remove the Texinfo tags.
98 n = split (contents, lines, "\n");
99 # We don't want the last field which empty: it's behind the last \n.
100 for (i = 1; i < n; ++i)
104 # Whole line commands.
105 if (line ~ /^@(c |comment|dots|end (ignore|group)|ignore|group)/)
106 # Gperf accepts empty lines as valid input!!!
107 if (file ~ /\.gperf$/)
112 gsub (/^@result\{\}/, "", line);
113 gsub (/^@error\{\}/, "", line);
114 gsub ("@[{]", "{", line);
115 gsub ("@}", "}", line);
116 gsub ("@@", "@", line);
117 gsub ("@comment.*", "", line);
125 function message(msg) {
126 if (! message_printed[msg])
128 print "extexi: " msg > "/dev/stderr";
129 message_printed[msg] = 1;
133 function fatal(msg) {