3
# Copyright (C) 1999, 2000, 2001, 2003, 2007 Free Software
6
# This file is part of GCC.
8
# GCC 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, or (at your option)
13
# GCC 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 GCC. If not, see <http://www.gnu.org/licenses/>.
21
# This does trivial (and I mean _trivial_) conversion of Texinfo
22
# markup to Perl POD format. It's intended to be used to extract
23
# something suitable for a manpage from a Texinfo document.
49
($flag, $value) = ($flag =~ /^([^=]+)(?:=(.+))?/);
50
die "no flag specified for -D\n"
52
die "flags may only contain letters, digits, hyphens, dashes and underscores\n"
53
unless $flag =~ /^[a-zA-Z0-9_-]+$/;
54
$defs{$flag} = $value;
58
$in = $_, next unless defined $in;
59
$out = $_, next unless defined $out;
66
open($inf, "<$in") or die "opening \"$in\": $!\n";
67
$ibase = $1 if $in =~ m|^(.+)/[^/]+$|;
73
open(STDOUT, ">$out") or die "opening \"$out\": $!\n";
78
# Certain commands are discarded without further processing.
80
[a-z]+index # @*index: useful only in complete manual
81
|need # @need: useful only in printed manual
82
|(?:end\s+)?group # @group .. @end group: ditto
84
|node # @node: useful only in .info file
85
|(?:end\s+)?ifnottex # @ifnottex .. @end ifnottex: use contents
90
# Look for filename and title markers.
91
/^\@setfilename\s+([^.]+)/ and $fn = $1, next;
92
/^\@settitle\s+([^.]+)/ and $tl = postprocess($1), next;
94
# Identify a man title but keep only the one we are interested in.
95
/^\@c\s+man\s+title\s+([A-Za-z0-9-]+)\s+(.+)/ and do {
96
if (exists $defs{$1}) {
98
$tl = postprocess($2);
103
# Look for blocks surrounded by @c man begin SECTION ... @c man end.
104
# This really oughta be @ifman ... @end ifman and the like, but such
105
# would require rev'ing all other Texinfo translators.
106
/^\@c\s+man\s+begin\s+([A-Z]+)\s+([A-Za-z0-9-]+)/ and do {
107
$output = 1 if exists $defs{$2};
111
/^\@c\s+man\s+begin\s+([A-Z]+)/ and $sect = $1, $output = 1, next;
112
/^\@c\s+man\s+end/ and do {
113
$sects{$sect} = "" unless exists $sects{$sect};
114
$sects{$sect} .= postprocess($section);
121
/^\@set\s+([a-zA-Z0-9_-]+)\s*(.*)$/ and do {
125
/^\@clear\s+([a-zA-Z0-9_-]+)/ and do {
132
# Discard comments. (Can't do it above, because then we'd never see
136
# End-block handler goes up here because it needs to operate even
137
# if we are skipping.
138
/^\@end\s+([a-z]+)/ and do {
139
# Ignore @end foo, where foo is not an operation which may
140
# cause us to skip, if we are presently skipping.
142
next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu|iftex|copying)$/;
144
die "\@end $ended without \@$ended at line $.\n" unless defined $endw;
145
die "\@$endw ended by \@end $ended at line $.\n" unless $ended eq $endw;
147
$endw = pop @endwstack;
149
if ($ended =~ /^(?:ifset|ifclear|ignore|menu|iftex)$/) {
150
$skipping = pop @skstack;
152
} elsif ($ended =~ /^(?:example|smallexample|display)$/) {
154
$_ = ""; # need a paragraph break
155
} elsif ($ended =~ /^(?:itemize|enumerate|[fv]?table)$/) {
159
die "unknown command \@end $ended at line $.\n";
163
# We must handle commands which can cause skipping even while we
164
# are skipping, otherwise we will not process nested conditionals
166
/^\@ifset\s+([a-zA-Z0-9_-]+)/ and do {
167
push @endwstack, $endw;
168
push @skstack, $skipping;
170
$skipping = 1 unless exists $defs{$1};
174
/^\@ifclear\s+([a-zA-Z0-9_-]+)/ and do {
175
push @endwstack, $endw;
176
push @skstack, $skipping;
178
$skipping = 1 if exists $defs{$1};
182
/^\@(ignore|menu|iftex|copying)\b/ and do {
183
push @endwstack, $endw;
184
push @skstack, $skipping;
192
# Character entities. First the ones that can be replaced by raw text
193
# or discarded outright:
194
s/\@copyright\{\}/(c)/g;
196
s/\@enddots\{\}/..../g;
199
s/\@bullet(?:\{\})?/*/g;
202
s/\@minus(?:\{\})?/-/g;
205
# Now the ones that have to be replaced by special escapes
206
# (which will be turned back into text by unmunge())
212
# Inside a verbatim block, handle @var specially.
214
s/\@var\{([^\}]*)\}/<$1>/g;
217
# POD doesn't interpret E<> inside a verbatim block.
226
# Single line command handlers.
228
/^\@include\s+(.+)$/ and do {
231
$file = postprocess($1);
233
# Try cwd and $ibase.
234
open($inf, "<" . $file)
235
or open($inf, "<" . $ibase . "/" . $file)
236
or die "cannot open $file or $ibase/$file: $!\n";
240
/^\@(?:section|unnumbered|unnumberedsec|center)\s+(.+)$/
241
and $_ = "\n=head2 $1\n";
242
/^\@subsection\s+(.+)$/
243
and $_ = "\n=head3 $1\n";
245
# Block command handlers:
246
/^\@itemize(?:\s+(\@[a-z]+|\*|-))?/ and do {
247
push @endwstack, $endw;
258
/^\@enumerate(?:\s+([a-zA-Z0-9]+))?/ and do {
259
push @endwstack, $endw;
270
/^\@([fv]?table)\s+(\@[a-z]+)/ and do {
271
push @endwstack, $endw;
275
$ic =~ s/\@(?:samp|strong|key|gcctabopt|env)/B/;
276
$ic =~ s/\@(?:code|kbd)/C/;
277
$ic =~ s/\@(?:dfn|var|emph|cite|i)/I/;
278
$ic =~ s/\@(?:file)/F/;
282
/^\@((?:small)?example|display)/ and do {
283
push @endwstack, $endw;
286
$_ = ""; # need a paragraph break
289
/^\@itemx?\s*(.+)?$/ and do {
291
# Entity escapes prevent munging by the <> processing below.
292
$_ = "\n=item $ic\<$1\>\n";
294
$_ = "\n=item $ic\n";
295
$ic =~ y/A-Ya-y/B-Zb-z/;
296
$ic =~ s/(\d+)/$1 + 1/eg;
300
$section .= $shift.$_."\n";
302
# End of current file.
307
die "No filename or title\n" unless defined $fn && defined $tl;
309
$sects{NAME} = "$fn \- $tl\n";
310
$sects{FOOTNOTES} .= "=back\n" if exists $sects{FOOTNOTES};
312
for $sect (qw(NAME SYNOPSIS DESCRIPTION OPTIONS ENVIRONMENT FILES
313
BUGS NOTES FOOTNOTES SEEALSO AUTHOR COPYRIGHT)) {
314
if(exists $sects{$sect}) {
316
$head =~ s/SEEALSO/SEE ALSO/;
317
print "=head1 $head\n\n";
318
print scalar unmunge ($sects{$sect});
325
die "usage: $0 [-D toggle...] [infile [outfile]]\n";
332
# @value{foo} is replaced by whatever 'foo' is defined as.
333
while (m/(\@value\{([a-zA-Z0-9_-]+)\})/g) {
334
if (! exists $defs{$2}) {
335
print STDERR "Option $2 not defined\n";
343
# Formatting commands.
344
# Temporary escape for @r.
345
s/\@r\{([^\}]*)\}/R<$1>/g;
346
s/\@(?:dfn|var|emph|cite|i)\{([^\}]*)\}/I<$1>/g;
347
s/\@(?:code|kbd)\{([^\}]*)\}/C<$1>/g;
348
s/\@(?:gccoptlist|samp|strong|key|option|env|command|b)\{([^\}]*)\}/B<$1>/g;
349
s/\@sc\{([^\}]*)\}/\U$1/g;
350
s/\@file\{([^\}]*)\}/F<$1>/g;
351
s/\@w\{([^\}]*)\}/S<$1>/g;
352
s/\@(?:dmn|math)\{([^\}]*)\}/$1/g;
354
# keep references of the form @ref{...}, print them bold
355
s/\@(?:ref)\{([^\}]*)\}/B<$1>/g;
357
# Change double single quotes to double quotes.
361
# Cross references are thrown away, as are @noindent and @refill.
362
# (@noindent is impossible in .pod, and @refill is unnecessary.)
363
# @* is also impossible in .pod; we discard it and any newline that
364
# follows it. Similarly, our macro @gol must be discarded.
366
s/\(?\@xref\{(?:[^\}]*)\}(?:[^.<]|(?:<[^<>]*>))*\.\)?//g;
367
s/\s+\(\@pxref\{(?:[^\}]*)\}\)//g;
368
s/;\s+\@pxref\{(?:[^\}]*)\}//g;
374
# @uref can take one, two, or three arguments, with different
375
# semantics each time. @url and @email are just like @uref with
376
# one argument, for our purposes.
377
s/\@(?:uref|url|email)\{([^\},]*)\}/<B<$1>>/g;
378
s/\@uref\{([^\},]*),([^\},]*)\}/$2 (C<$1>)/g;
379
s/\@uref\{([^\},]*),([^\},]*),([^\},]*)\}/$3/g;
381
# Un-escape <> at this point.
385
# Now un-nest all B<>, I<>, R<>. Theoretically we could have
386
# indefinitely deep nesting; in practice, one level suffices.
387
1 while s/([BIR])<([^<>]*)([BIR])<([^<>]*)>/$1<$2>$3<$4>$1</g;
389
# Replace R<...> with bare ...; eliminate empty markup, B<>;
390
# shift white space at the ends of [BI]<...> expressions outside
394
s/([BI])<(\s+)([^>]+)>/$2$1<$3>/g;
395
s/([BI])<([^>]+?)(\s+)>/$1<$2>$3/g;
397
# Extract footnotes. This has to be done after all other
398
# processing because otherwise the regexp will choke on formatting
400
while (/\@footnote/g) {
401
s/\@footnote\{([^\}]+)\}/[$fnno]/;
402
add_footnote($1, $fnno);
411
# Replace escaped symbols with their equivalents.
425
unless (exists $sects{FOOTNOTES}) {
426
$sects{FOOTNOTES} = "\n=over 4\n\n";
429
$sects{FOOTNOTES} .= "=item $fnno.\n\n"; $fnno++;
430
$sects{FOOTNOTES} .= $_[0];
431
$sects{FOOTNOTES} .= "\n\n";
434
# stolen from Symbol.pm
439
my $name = "GEN" . $genseq++;