]>
git.saurik.com Git - bison.git/blob - examples/extexi
2 # Extract all examples from the manual source.
4 # This file is part of GNU Bison
6 # Copyright (C) 1992, 2000-2001, 2005-2006, 2009-2015 Free Software
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # Usage: extexi [OPTION...] input-file.texi ... -- [FILES to extract]
24 # Look for @example environments preceded with lines such as:
26 # @comment file calc.y
28 # @comment file calc.y: 3
30 # and output their content in that file (calc.y). When numbers are
31 # provided, use them to decide the output order (block numbered 1 is
32 # output before block 2, even if the latter appears before). The same
33 # number may be used several time, in which case the order of
38 # Whether we generate synclines.
43 # Remove Texinfo mark up.
48 s/^\@(c |comment|dots|end (ignore|group)|ignore|group).*//mg;
49 s/\@value\{VERSION\}/$ENV{VERSION}/g;
50 s/^\@(error|result)\{\}//mg;
56 # Print messages only once.
63 print STDERR
"extexi: $msg\n";
68 # basename => full file name for files we should extract.
75 my $f = new IO
::File
($in)
76 or die "$in: cannot open: $?";
77 # FILE-NAME => { BLOCK-NUM => CODE }
80 # The latest "@comment file: FILE [BLOCK-NUM]" arguments.
83 # The @example block currently read.
88 if (/^\@comment file: ([^:\n]+)(?::\s*(\d+))?$/)
94 $file = $file_wanted{$f};
95 message
(" GEN $file");
102 elsif ($file && /^\@(small)?example$/ .. /^\@end (small)?example$/)
104 if (/^\@(small)?example$/)
106 # Bison supports synclines, but not Flex.
107 $input .= sprintf ("#line %s \"$in\"\n", $. + 1)
108 if $synclines && $file =~ /\.[chy]*$/;
111 elsif (/^\@end (small)?example$/)
113 die "no contents: $file"
116 $file{$file}{$block} .= normalize
($input);
117 $file = $input = undef;
128 for my $file (keys %file)
130 # No spurious end of line: use printf.
131 my $o = new IO
::File
(">$file")
132 or die "$file: cannot create: $?";
133 print $o $file{$file}{$_}
134 for sort keys %{$file{$file}};
145 $file_wanted{basename
($arg)} = $arg;
151 elsif ($arg eq '--synclines')
164 ### Setup "GNU" style for perl-mode and cperl-mode.
166 ## perl-indent-level: 2
167 ## perl-continued-statement-offset: 2
168 ## perl-continued-brace-offset: 0
169 ## perl-brace-offset: 0
170 ## perl-brace-imaginary-offset: 0
171 ## perl-label-offset: -2
172 ## cperl-indent-level: 2
173 ## cperl-brace-offset: 0
174 ## cperl-continued-brace-offset: 0
175 ## cperl-label-offset: -2
176 ## cperl-extra-newline-before-brace: t
177 ## cperl-merge-trailing-else: nil
178 ## cperl-continued-statement-offset: 2