OSDN Git Service

* texi2pod.pl: Correct handling of @itemize with no argument.
[pf3gnuchains/gcc-fork.git] / contrib / texi2pod.pl
index a22fd4f..cd0ffd9 100755 (executable)
@@ -36,6 +36,7 @@ $shift = "";
 $fnno = 1;
 $inf = "";
 $ibase = "";
+@ipath = ();
 
 while ($_ = shift) {
     if (/^-D(.*)$/) {
@@ -51,6 +52,13 @@ while ($_ = shift) {
        die "flags may only contain letters, digits, hyphens, dashes and underscores\n"
            unless $flag =~ /^[a-zA-Z0-9_-]+$/;
        $defs{$flag} = $value;
+    } elsif (/^-I(.*)$/) {
+       if ($1 ne "") {
+           $flag = $1;
+       } else {
+           $flag = shift;
+       }
+        push (@ipath, $flag);
     } elsif (/^-/) {
        usage();
     } else {
@@ -154,6 +162,8 @@ while(<$inf>) {
        } elsif ($ended =~ /^(?:itemize|enumerate|[fv]?table)$/) {
            $_ = "\n=back\n";
            $ic = pop @icstack;
+       } elsif ($ended eq "multitable") {
+           $_ = "\n=back\n";
        } else {
            die "unknown command \@end $ended at line $.\n";
        }
@@ -227,11 +237,16 @@ while(<$inf>) {
     /^\@include\s+(.+)$/ and do {
        push @instack, $inf;
        $inf = gensym();
-
-       # Try cwd and $ibase.
-       open($inf, "<" . $1) 
-           or open($inf, "<" . $ibase . "/" . $1)
-               or die "cannot open $1 or $ibase/$1: $!\n";
+       $file = postprocess($1);
+
+       # Try cwd and $ibase, then explicit -I paths.
+       $done = 0;
+       foreach $path ("", $ibase, @ipath) {
+           $mypath = $file;
+           $mypath = $path . "/" . $mypath if ($path ne "");
+           open($inf, "<" . $mypath) and ($done = 1, last);
+       }
+       die "cannot find $file" if !$done;
        next;
     };
 
@@ -239,6 +254,8 @@ while(<$inf>) {
        and $_ = "\n=head2 $1\n";
     /^\@subsection\s+(.+)$/
        and $_ = "\n=head3 $1\n";
+    /^\@subsubsection\s+(.+)$/
+       and $_ = "\n=head4 $1\n";
 
     # Block command handlers:
     /^\@itemize(?:\s+(\@[a-z]+|\*|-))?/ and do {
@@ -247,7 +264,7 @@ while(<$inf>) {
        if (defined $1) {
            $ic = $1;
        } else {
-           $ic = '@bullet';
+           $ic = '*';
        }
        $_ = "\n=over 4\n";
        $endw = "itemize";
@@ -265,6 +282,12 @@ while(<$inf>) {
        $endw = "enumerate";
     };
 
+    /^\@multitable\s.*/ and do {
+       push @endwstack, $endw;
+       $endw = "multitable";
+       $_ = "\n=over 4\n";
+    };
+
     /^\@([fv]?table)\s+(\@[a-z]+)/ and do {
        push @endwstack, $endw;
        push @icstack, $ic;
@@ -284,6 +307,16 @@ while(<$inf>) {
        $_ = "";        # need a paragraph break
     };
 
+    /^\@item\s+(.*\S)\s*$/ and $endw eq "multitable" and do {
+       @columns = ();
+       for $column (split (/\s*\@tab\s*/, $1)) {
+           # @strong{...} is used a @headitem work-alike
+           $column =~ s/^\@strong{(.*)}$/$1/;
+           push @columns, $column;
+       }
+       $_ = "\n=item ".join (" : ", @columns)."\n";
+    };
+
     /^\@itemx?\s*(.+)?$/ and do {
        if (defined $1) {
            # Entity escapes prevent munging by the <> processing below.
@@ -352,6 +385,10 @@ sub postprocess
     # keep references of the form @ref{...}, print them bold
     s/\@(?:ref)\{([^\}]*)\}/B<$1>/g;
 
+    # Change double single quotes to double quotes.
+    s/''/"/g;
+    s/``/"/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
@@ -365,6 +402,9 @@ sub postprocess
     s/\@gol//g;
     s/\@\*\s*\n?//g;
 
+    # Anchors are thrown away
+    s/\@anchor\{(?:[^\}]*)\}//g;
+
     # @uref can take one, two, or three arguments, with different
     # semantics each time.  @url and @email are just like @uref with
     # one argument, for our purposes.