OSDN Git Service

contrib:
[pf3gnuchains/gcc-fork.git] / contrib / texi2pod.pl
index 6a2e6cd..8c8b4f9 100755 (executable)
@@ -1,5 +1,24 @@
 #! /usr/bin/perl -w
 
+#   Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+
+# This file is part of GNU CC.
+
+# GNU CC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# GNU CC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with GNU CC; see the file COPYING.  If not, write to
+# the Free Software Foundation, 59 Temple Place - Suite 330,
+# Boston MA 02111-1307, USA.
+
 # This does trivial (and I mean _trivial_) conversion of Texinfo
 # markup to Perl POD format.  It's intended to be used to extract
 # something suitable for a manpage from a Texinfo document.
@@ -52,6 +71,7 @@ while(<STDIN>)
         |(?:end\s+)?group      # @group .. @end group: ditto
         |page                  # @page: ditto
         |node                  # @node: useful only in .info file
+        |(?:end\s+)?ifnottex   # @ifnottex .. @end ifnottex: use contents
        )\b/x and next;
     
     chomp;
@@ -83,17 +103,17 @@ while(<STDIN>)
        # Ignore @end foo, where foo is not an operation which may
        # cause us to skip, if we are presently skipping.
        my $ended = $1;
-       next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu)$/;
+       next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu|iftex)$/;
 
        die "\@end $ended without \@$ended at line $.\n" unless defined $endw;
        die "\@$endw ended by \@end $ended at line $.\n" unless $ended eq $endw;
 
        $endw = pop @endwstack;
 
-       if ($ended =~ /^(?:ifset|ifclear|ignore|menu)$/) {
+       if ($ended =~ /^(?:ifset|ifclear|ignore|menu|iftex)$/) {
            $skipping = pop @skstack;
            next;
-       } elsif ($ended =~ /^(?:example|smallexample)$/) {
+       } elsif ($ended =~ /^(?:example|smallexample|display)$/) {
            $shift = "";
            $_ = "";    # need a paragraph break
        } elsif ($ended =~ /^(?:itemize|enumerate|table)$/) {
@@ -123,7 +143,7 @@ while(<STDIN>)
        next;
     };
 
-    /^\@(ignore|menu)\b/ and do {
+    /^\@(ignore|menu|iftex)\b/ and do {
        push @endwstack, $endw;
        push @skstack, $skipping;
        $endw = $1;
@@ -144,6 +164,7 @@ while(<STDIN>)
     s/\@TeX\{\}/TeX/g;
     s/\@pounds\{\}/\#/g;
     s/\@minus(?:\{\})?/-/g;
+    s/\\,/,/g;
 
     # Now the ones that have to be replaced by special escapes
     # (which will be turned back into text by unmunge())
@@ -151,6 +172,12 @@ while(<STDIN>)
     s/\@\{/&lbrace;/g;
     s/\@\}/&rbrace;/g;
     s/\@\@/&at;/g;
+
+    # Inside a verbatim block, handle @var specially.
+    if ($shift ne "") {
+       s/\@var\{([^\}]*)\}/<$1>/g;
+    }
+
     # POD doesn't interpret E<> inside a verbatim block.
     if ($shift eq "") {
        s/</&lt;/g;
@@ -164,7 +191,7 @@ while(<STDIN>)
     /^\@set\s+([a-zA-Z0-9_-]+)\s*(.*)$/ and $defs{$1} = $2, next;
     /^\@clear\s+([a-zA-Z0-9_-]+)/ and delete $defs{$1}, next;
 
-    /^\@section\s+(.+)$/ and $_ = "\n=head2 $1\n";
+    /^\@(?:section|unnumbered|unnumberedsec|center)\s+(.+)$/ and $_ = "\n=head2 $1\n";
     /^\@subsection\s+(.+)$/ and $_ = "\n=head3 $1\n";
 
     # Block command handlers:
@@ -176,7 +203,7 @@ while(<STDIN>)
        $endw = "itemize";
     };
 
-    /^\@enumerate(?:\s+([A-Z0-9]+))?/ and do {
+    /^\@enumerate(?:\s+([a-zA-Z0-9]+))?/ and do {
        push @endwstack, $endw;
        push @icstack, $ic;
        if (defined $1) {
@@ -200,7 +227,7 @@ while(<STDIN>)
        $endw = "table";
     };
 
-    /^\@((?:small)?example)/ and do {
+    /^\@((?:small)?example|display)/ and do {
        push @endwstack, $endw;
        $endw = $1;
        $shift = "\t";
@@ -213,7 +240,8 @@ while(<STDIN>)
            $_ = "\n=item $ic\&LT;$1\&GT;\n";
        } else {
            $_ = "\n=item $ic\n";
-           $ic =~ y/A-Ya-y1-8/B-Zb-z2-9/;
+           $ic =~ y/A-Ya-y/B-Zb-z/;
+           $ic =~ s/(\d+)/$1 + 1/eg;
        }
     };
 
@@ -259,9 +287,6 @@ sub postprocess
     s/\@w\{([^\}]*)\}/S<$1>/g;
     s/\@(?:dmn|math)\{([^\}]*)\}/$1/g;
 
-    # Handle @r inside bold.
-    1 while s/B<((?:[^<>]*|I<[^<>*]*>)*)R<([^>]*)>/B<$1>${2}B</g;
-
     # Cross references are thrown away, as are @noindent and @refill.
     # (@noindent is impossible in .pod, and @refill is unnecessary.)
     # @* is also impossible in .pod; we discard it and any newline that
@@ -283,9 +308,11 @@ sub postprocess
     s/\@uref\{([^\},]*),([^\},]*),([^\},]*)\}/$3/g;
 
     # Turn B<blah I<blah> blah> into B<blah> I<blah> B<blah> to
-    # match Texinfo semantics of @emph inside @samp.
+    # match Texinfo semantics of @emph inside @samp.  Also handle @r
+    # inside bold.
     s/&LT;/</g;
     s/&GT;/>/g;
+    1 while s/B<((?:[^<>]|I<[^<>]*>)*)R<([^>]*)>/B<$1>${2}B</g;
     1 while (s/B<([^<>]*)I<([^>]+)>/B<$1>I<$2>B</g);
     1 while (s/I<([^<>]*)B<([^>]+)>/I<$1>B<$2>I</g);
     s/[BI]<>//g;