]>
gcc.gnu.org Git - gcc.git/blob - contrib/texi2pod.pl
3 # Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
5 # This file is part of GCC.
7 # GCC is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # GCC is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GCC; see the file COPYING. If not, write to
19 # the Free Software Foundation, 59 Temple Place - Suite 330,
20 # Boston MA 02111-1307, USA.
22 # This does trivial (and I mean _trivial_) conversion of Texinfo
23 # markup to Perl POD format. It's intended to be used to extract
24 # something suitable for a manpage from a Texinfo document.
48 ($flag, $value) = ($flag =~ /^([^=]+)(?:=(.+))?/);
49 die "no flag specified for -D\n"
51 die "flags may only contain letters, digits, hyphens, dashes and underscores\n"
52 unless $flag =~ /^[a-zA-Z0-9_-]+$/;
53 $defs{$flag} = $value;
57 $in = $_, next unless defined $in;
58 $out = $_, next unless defined $out;
65 open($inf, "<$in") or die "opening \"$in\": $!\n";
66 $ibase = $1 if $in =~ m|^(.+)/[^/]+$|;
72 open(STDOUT, ">$out") or die "opening
\"$out\": $!\n";
77 # Certain commands are discarded without further processing.
79 [a-z
]+index # @*index: useful only in complete manual
80 |need
# @need: useful only in printed manual
81 |(?
:end\s
+)?group
# @group .. @end group: ditto
83 |node
# @node: useful only in .info file
84 |(?
:end\s
+)?ifnottex
# @ifnottex .. @end ifnottex: use contents
89 # Look for filename and title markers.
90 /^\@setfilename\s+([^.]+)/ and $fn = $1, next;
91 /^\@settitle\s+([^.]+)/ and $tl = postprocess
($1), next;
93 # Identify a man title but keep only the one we are interested in.
94 /^\@c\s+man\s+title\s+([A-Za-z0-9-]+)\s+(.+)/ and do {
95 if (exists $defs{$1}) {
97 $tl = postprocess
($2);
102 # Look for blocks surrounded by @c man begin SECTION ... @c man end.
103 # This really oughta be @ifman ... @end ifman and the like, but such
104 # would require rev'ing all other Texinfo translators.
105 /^\@c\s+man\s+begin\s+([A-Z]+)\s+([A-Za-z0-9-]+)/ and do {
106 $output = 1 if exists $defs{$2};
110 /^\@c\s+man\s+begin\s+([A-Z]+)/ and $sect = $1, $output = 1, next;
111 /^\@c\s+man\s+end/ and do {
112 $sects{$sect} = "" unless exists $sects{$sect};
113 $sects{$sect} .= postprocess
($section);
120 /^\@set\s+([a-zA-Z0-9_-]+)\s*(.*)$/ and do {
124 /^\@clear\s+([a-zA-Z0-9_-]+)/ and do {
131 # Discard comments. (Can't do it above, because then we'd never see
135 # End-block handler goes up here because it needs to operate even
136 # if we are skipping.
137 /^\@end\s+([a-z]+)/ and do {
138 # Ignore @end foo, where foo is not an operation which may
139 # cause us to skip, if we are presently skipping.
141 next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu|iftex|copying)$/;
143 die "\@end $ended without \@$ended at line $.\n" unless defined $endw;
144 die "\@$endw ended by \@end $ended at line $.\n" unless $ended eq $endw;
146 $endw = pop @endwstack;
148 if ($ended =~ /^(?:ifset|ifclear|ignore|menu|iftex)$/) {
149 $skipping = pop @skstack;
151 } elsif ($ended =~ /^(?:example|smallexample|display)$/) {
153 $_ = ""; # need a paragraph break
154 } elsif ($ended =~ /^(?:itemize|enumerate|[fv]?table)$/) {
158 die "unknown command \@end $ended at line $.\n";
162 # We must handle commands which can cause skipping even while we
163 # are skipping, otherwise we will not process nested conditionals
165 /^\@ifset\s+([a-zA-Z0-9_-]+)/ and do {
166 push @endwstack, $endw;
167 push @skstack, $skipping;
169 $skipping = 1 unless exists $defs{$1};
173 /^\@ifclear\s+([a-zA-Z0-9_-]+)/ and do {
174 push @endwstack, $endw;
175 push @skstack, $skipping;
177 $skipping = 1 if exists $defs{$1};
181 /^\@(ignore|menu|iftex|copying)\b/ and do {
182 push @endwstack, $endw;
183 push @skstack, $skipping;
191 # Character entities. First the ones that can be replaced by raw text
192 # or discarded outright:
193 s/\@copyright\{\}/(c)/g;
195 s/\@enddots\{\}/..../g;
198 s/\@bullet(?:\{\})?/*/g;
201 s/\@minus(?:\{\})?/-/g;
204 # Now the ones that have to be replaced by special escapes
205 # (which will be turned back into text by unmunge())
211 # Inside a verbatim block, handle @var specially.
213 s/\@var\{([^\}]*)\}/<$1>/g;
216 # POD doesn't interpret E<> inside a verbatim block.
225 # Single line command handlers.
227 /^\@include\s+(.+)$/ and do {
231 # Try cwd and $ibase.
233 or open($inf, "<" . $ibase . "/" . $1)
234 or die "cannot open $1 or $ibase/$1: $!\n";
238 /^\@(?:section|unnumbered|unnumberedsec|center)\s+(.+)$/
239 and $_ = "\n=head2 $1\n";
240 /^\@subsection\s+(.+)$/
241 and $_ = "\n=head3 $1\n";
243 # Block command handlers:
244 /^\@itemize(?:\s+(\@[a-z]+|\*|-))?/ and do {
245 push @endwstack, $endw;
256 /^\@enumerate(?:\s+([a-zA-Z0-9]+))?/ and do {
257 push @endwstack, $endw;
268 /^\@([fv]?table)\s+(\@[a-z]+)/ and do {
269 push @endwstack, $endw;
273 $ic =~ s/\@(?:samp|strong|key|gcctabopt|env)/B/;
274 $ic =~ s/\@(?:code|kbd)/C/;
275 $ic =~ s/\@(?:dfn|var|emph|cite|i)/I/;
276 $ic =~ s/\@(?:file)/F/;
280 /^\@((?:small)?example|display)/ and do {
281 push @endwstack, $endw;
284 $_ = ""; # need a paragraph break
287 /^\@itemx?\s*(.+)?$/ and do {
289 # Entity escapes prevent munging by the <> processing below.
290 $_ = "\n=item $ic\<$1\>\n";
292 $_ = "\n=item $ic\n";
293 $ic =~ y/A-Ya-y/B-Zb-z/;
294 $ic =~ s/(\d+)/$1 + 1/eg;
298 $section .= $shift.$_."\n";
300 # End of current file.
305 die "No filename or title\n" unless defined $fn && defined $tl;
307 $sects{NAME
} = "$fn \- $tl\n";
308 $sects{FOOTNOTES
} .= "=back\n" if exists $sects{FOOTNOTES
};
310 for $sect (qw(NAME SYNOPSIS DESCRIPTION OPTIONS ENVIRONMENT FILES
311 BUGS NOTES FOOTNOTES SEEALSO AUTHOR COPYRIGHT)) {
312 if(exists $sects{$sect}) {
314 $head =~ s/SEEALSO/SEE ALSO/;
315 print "=head1 $head\n\n";
316 print scalar unmunge
($sects{$sect});
323 die "usage: $0 [-D toggle...] [infile [outfile]]\n";
330 # @value{foo} is replaced by whatever 'foo' is defined as.
331 while (m/(\@value\{([a-zA-Z0-9_-]+)\})/g) {
332 if (! exists $defs{$2}) {
333 print STDERR
"Option $2 not defined\n";
341 # Formatting commands.
342 # Temporary escape for @r.
343 s/\@r\{([^\}]*)\}/R<$1>/g;
344 s/\@(?:dfn|var|emph|cite|i)\{([^\}]*)\}/I<$1>/g;
345 s/\@(?:code|kbd)\{([^\}]*)\}/C<$1>/g;
346 s/\@(?:gccoptlist|samp|strong|key|option|env|command|b)\{([^\}]*)\}/B<$1>/g;
347 s/\@sc\{([^\}]*)\}/\U$1/g;
348 s/\@file\{([^\}]*)\}/F<$1>/g;
349 s/\@w\{([^\}]*)\}/S<$1>/g;
350 s/\@(?:dmn|math)\{([^\}]*)\}/$1/g;
352 # Cross references are thrown away, as are @noindent and @refill.
353 # (@noindent is impossible in .pod, and @refill is unnecessary.)
354 # @* is also impossible in .pod; we discard it and any newline that
355 # follows it. Similarly, our macro @gol must be discarded.
357 s/\(?\@xref\{(?:[^\}]*)\}(?:[^.<]|(?:<[^<>]*>))*\.\)?//g;
358 s/\s+\(\@pxref\{(?:[^\}]*)\}\)//g;
359 s/;\s+\@pxref\{(?:[^\}]*)\}//g;
365 # @uref can take one, two, or three arguments, with different
366 # semantics each time. @url and @email are just like @uref with
367 # one argument, for our purposes.
368 s/\@(?:uref|url|email)\{([^\},]*)\}/<B<$1>>/g;
369 s/\@uref\{([^\},]*),([^\},]*)\}/$2 (C<$1>)/g;
370 s/\@uref\{([^\},]*),([^\},]*),([^\},]*)\}/$3/g;
372 # Un-escape <> at this point.
376 # Now un-nest all B<>, I<>, R<>. Theoretically we could have
377 # indefinitely deep nesting; in practice, one level suffices.
378 1 while s/([BIR])<([^<>]*)([BIR])<([^<>]*)>/$1<$2>$3<$4>$1</g;
380 # Replace R<...> with bare ...; eliminate empty markup, B<>;
381 # shift white space at the ends of [BI]<...> expressions outside
385 s/([BI])<(\s+)([^>]+)>/$2$1<$3>/g;
386 s/([BI])<([^>]+?)(\s+)>/$1<$2>$3/g;
388 # Extract footnotes. This has to be done after all other
389 # processing because otherwise the regexp will choke on formatting
391 while (/\@footnote/g) {
392 s/\@footnote\{([^\}]+)\}/[$fnno]/;
393 add_footnote
($1, $fnno);
402 # Replace escaped symbols with their equivalents.
416 unless (exists $sects{FOOTNOTES
}) {
417 $sects{FOOTNOTES
} = "\n=over 4\n\n";
420 $sects{FOOTNOTES
} .= "=item $fnno.\n\n"; $fnno++;
421 $sects{FOOTNOTES
} .= $_[0];
422 $sects{FOOTNOTES
} .= "\n\n";
425 # stolen from Symbol.pm
430 my $name = "GEN" . $genseq++;
This page took 0.059364 seconds and 5 git commands to generate.