Commit 3aba3d86f757e96f8ff503fa3f85c771b3a5f533

Authored by ths
1 parent 5ff9d6a4

Update texi2pod.pl.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3964 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 73 additions and 23 deletions
texi2pod.pl
1 1 #! /usr/bin/perl -w
2 2  
3   -# Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
  3 +# Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
4 4  
5   -# This file is part of GNU CC.
  5 +# This file is part of GCC.
6 6  
7   -# GNU CC is free software; you can redistribute it and/or modify
  7 +# GCC is free software; you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
9 9 # the Free Software Foundation; either version 2, or (at your option)
10 10 # any later version.
11 11  
12   -# GNU CC is distributed in the hope that it will be useful,
  12 +# GCC is distributed in the hope that it will be useful,
13 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 15 # GNU General Public License for more details.
16 16  
17 17 # You should have received a copy of the GNU General Public License
18   -# along with GNU CC; see the file COPYING. If not, write to
19   -# the Free Software Foundation, 59 Temple Place - Suite 330,
20   -# Boston MA 02111-1307, USA.
  18 +# along with GCC; see the file COPYING. If not, write to
  19 +# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
  20 +# Boston MA 02110-1301, USA.
21 21  
22 22 # This does trivial (and I mean _trivial_) conversion of Texinfo
23 23 # markup to Perl POD format. It's intended to be used to extract
... ... @@ -36,6 +36,7 @@ $shift = "";
36 36 $fnno = 1;
37 37 $inf = "";
38 38 $ibase = "";
  39 +@ipath = ();
39 40  
40 41 while ($_ = shift) {
41 42 if (/^-D(.*)$/) {
... ... @@ -51,6 +52,13 @@ while ($_ = shift) {
51 52 die "flags may only contain letters, digits, hyphens, dashes and underscores\n"
52 53 unless $flag =~ /^[a-zA-Z0-9_-]+$/;
53 54 $defs{$flag} = $value;
  55 + } elsif (/^-I(.*)$/) {
  56 + if ($1 ne "") {
  57 + $flag = $1;
  58 + } else {
  59 + $flag = shift;
  60 + }
  61 + push (@ipath, $flag);
54 62 } elsif (/^-/) {
55 63 usage();
56 64 } else {
... ... @@ -138,7 +146,7 @@ while(<$inf>) {
138 146 # Ignore @end foo, where foo is not an operation which may
139 147 # cause us to skip, if we are presently skipping.
140 148 my $ended = $1;
141   - next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu|iftex)$/;
  149 + next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu|iftex|copying)$/;
142 150  
143 151 die "\@end $ended without \@$ended at line $.\n" unless defined $endw;
144 152 die "\@$endw ended by \@end $ended at line $.\n" unless $ended eq $endw;
... ... @@ -154,6 +162,8 @@ while(<$inf>) {
154 162 } elsif ($ended =~ /^(?:itemize|enumerate|[fv]?table)$/) {
155 163 $_ = "\n=back\n";
156 164 $ic = pop @icstack;
  165 + } elsif ($ended eq "multitable") {
  166 + $_ = "\n=back\n";
157 167 } else {
158 168 die "unknown command \@end $ended at line $.\n";
159 169 }
... ... @@ -178,7 +188,7 @@ while(<$inf>) {
178 188 next;
179 189 };
180 190  
181   - /^\@(ignore|menu|iftex)\b/ and do {
  191 + /^\@(ignore|menu|iftex|copying)\b/ and do {
182 192 push @endwstack, $endw;
183 193 push @skstack, $skipping;
184 194 $endw = $1;
... ... @@ -227,11 +237,16 @@ while(<$inf>) {
227 237 /^\@include\s+(.+)$/ and do {
228 238 push @instack, $inf;
229 239 $inf = gensym();
230   -
231   - # Try cwd and $ibase.
232   - open($inf, "<" . $1)
233   - or open($inf, "<" . $ibase . "/" . $1)
234   - or die "cannot open $1 or $ibase/$1: $!\n";
  240 + $file = postprocess($1);
  241 +
  242 + # Try cwd and $ibase, then explicit -I paths.
  243 + $done = 0;
  244 + foreach $path ("", $ibase, @ipath) {
  245 + $mypath = $file;
  246 + $mypath = $path . "/" . $mypath if ($path ne "");
  247 + open($inf, "<" . $mypath) and ($done = 1, last);
  248 + }
  249 + die "cannot find $file" if !$done;
235 250 next;
236 251 };
237 252  
... ... @@ -239,12 +254,18 @@ while(&lt;$inf&gt;) {
239 254 and $_ = "\n=head2 $1\n";
240 255 /^\@subsection\s+(.+)$/
241 256 and $_ = "\n=head3 $1\n";
  257 + /^\@subsubsection\s+(.+)$/
  258 + and $_ = "\n=head4 $1\n";
242 259  
243 260 # Block command handlers:
244   - /^\@itemize\s+(\@[a-z]+|\*|-)/ and do {
  261 + /^\@itemize(?:\s+(\@[a-z]+|\*|-))?/ and do {
245 262 push @endwstack, $endw;
246 263 push @icstack, $ic;
247   - $ic = $1;
  264 + if (defined $1) {
  265 + $ic = $1;
  266 + } else {
  267 + $ic = '*';
  268 + }
248 269 $_ = "\n=over 4\n";
249 270 $endw = "itemize";
250 271 };
... ... @@ -261,6 +282,12 @@ while(&lt;$inf&gt;) {
261 282 $endw = "enumerate";
262 283 };
263 284  
  285 + /^\@multitable\s.*/ and do {
  286 + push @endwstack, $endw;
  287 + $endw = "multitable";
  288 + $_ = "\n=over 4\n";
  289 + };
  290 +
264 291 /^\@([fv]?table)\s+(\@[a-z]+)/ and do {
265 292 push @endwstack, $endw;
266 293 push @icstack, $ic;
... ... @@ -280,10 +307,19 @@ while(&lt;$inf&gt;) {
280 307 $_ = ""; # need a paragraph break
281 308 };
282 309  
  310 + /^\@item\s+(.*\S)\s*$/ and $endw eq "multitable" and do {
  311 + @columns = ();
  312 + for $column (split (/\s*\@tab\s*/, $1)) {
  313 + # @strong{...} is used a @headitem work-alike
  314 + $column =~ s/^\@strong{(.*)}$/$1/;
  315 + push @columns, $column;
  316 + }
  317 + $_ = "\n=item ".join (" : ", @columns)."\n";
  318 + };
  319 +
283 320 /^\@itemx?\s*(.+)?$/ and do {
284 321 if (defined $1) {
285 322 # Entity escapes prevent munging by the <> processing below.
286   -# print "$ic\n";
287 323 $_ = "\n=item $ic\&LT;$1\&GT;\n";
288 324 } else {
289 325 $_ = "\n=item $ic\n";
... ... @@ -346,6 +382,13 @@ sub postprocess
346 382 s/\@w\{([^\}]*)\}/S<$1>/g;
347 383 s/\@(?:dmn|math)\{([^\}]*)\}/$1/g;
348 384  
  385 + # keep references of the form @ref{...}, print them bold
  386 + s/\@(?:ref)\{([^\}]*)\}/B<$1>/g;
  387 +
  388 + # Change double single quotes to double quotes.
  389 + s/''/"/g;
  390 + s/``/"/g;
  391 +
349 392 # Cross references are thrown away, as are @noindent and @refill.
350 393 # (@noindent is impossible in .pod, and @refill is unnecessary.)
351 394 # @* is also impossible in .pod; we discard it and any newline that
... ... @@ -359,6 +402,9 @@ sub postprocess
359 402 s/\@gol//g;
360 403 s/\@\*\s*\n?//g;
361 404  
  405 + # Anchors are thrown away
  406 + s/\@anchor\{(?:[^\}]*)\}//g;
  407 +
362 408 # @uref can take one, two, or three arguments, with different
363 409 # semantics each time. @url and @email are just like @uref with
364 410 # one argument, for our purposes.
... ... @@ -366,14 +412,18 @@ sub postprocess
366 412 s/\@uref\{([^\},]*),([^\},]*)\}/$2 (C<$1>)/g;
367 413 s/\@uref\{([^\},]*),([^\},]*),([^\},]*)\}/$3/g;
368 414  
369   - # Turn B<blah I<blah> blah> into B<blah> I<blah> B<blah> to
370   - # match Texinfo semantics of @emph inside @samp. Also handle @r
371   - # inside bold.
  415 + # Un-escape <> at this point.
372 416 s/&LT;/</g;
373 417 s/&GT;/>/g;
374   - 1 while s/B<((?:[^<>]|I<[^<>]*>)*)R<([^>]*)>/B<$1>${2}B</g;
375   - 1 while (s/B<([^<>]*)I<([^>]+)>/B<$1>I<$2>B</g);
376   - 1 while (s/I<([^<>]*)B<([^>]+)>/I<$1>B<$2>I</g);
  418 +
  419 + # Now un-nest all B<>, I<>, R<>. Theoretically we could have
  420 + # indefinitely deep nesting; in practice, one level suffices.
  421 + 1 while s/([BIR])<([^<>]*)([BIR])<([^<>]*)>/$1<$2>$3<$4>$1</g;
  422 +
  423 + # Replace R<...> with bare ...; eliminate empty markup, B<>;
  424 + # shift white space at the ends of [BI]<...> expressions outside
  425 + # the expression.
  426 + s/R<([^<>]*)>/$1/g;
377 427 s/[BI]<>//g;
378 428 s/([BI])<(\s+)([^>]+)>/$2$1<$3>/g;
379 429 s/([BI])<([^>]+?)(\s+)>/$1<$2>$3/g;
... ...