OSDN Git Service

* texi2pod.pl:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 19 Nov 2000 19:02:50 +0000 (19:02 +0000)
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 19 Nov 2000 19:02:50 +0000 (19:02 +0000)
  - Add real command line parsing.
  - Support @ifset, @ifclear, @set, @value, -D switch.
  - Support @sc.  Improve handling of @ref and friends.
  - Discard @subsection, @need, @node lines.
  - Un-nest font changes to match texinfo semantics.
  - Handle @{ and @}.  Oops.
  - Don't emit E<> directives inside verbatim blocks.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@37569 138bc75d-0d04-0410-961f-82ee72b054a4

contrib/ChangeLog
contrib/texi2pod.pl

index 73dd29f..8f5dfe5 100644 (file)
@@ -1,3 +1,14 @@
+2000-11-19  Zack Weinberg  <zackw@stanford.edu>
+
+       * texi2pod.pl:
+         - Add real command line parsing.
+         - Support @ifset, @ifclear, @set, @value, -D switch.
+         - Support @sc.  Improve handling of @ref and friends.
+         - Discard @subsection, @need, @node lines.
+         - Un-nest font changes to match texinfo semantics.
+         - Handle @{ and @}.  Oops.
+         - Don't emit E<> directives inside verbatim blocks.
+
 2000-11-12  Bruce Korb  <bkorb@gnu.org>
 
        * release: generalize the release script a bit.
 2000-11-12  Bruce Korb  <bkorb@gnu.org>
 
        * release: generalize the release script a bit.
index bb26fb2..420625b 100755 (executable)
 # markup to Perl POD format.  It's intended to be used to extract
 # something suitable for a manpage from a Texinfo document.
 
 # markup to Perl POD format.  It's intended to be used to extract
 # something suitable for a manpage from a Texinfo document.
 
-$in = $ARGV[0];
-$out = "x";
-die "usage: $0 infile outfile\n" unless defined $in && defined $out;
-
-close STDIN;
-open(IN,$in);
-
 $output = 0;
 $ignore = 0;
 $output = 0;
 $ignore = 0;
+$skipping = 0;
 %sects = ();
 $section = "";
 @icstack = ();
 @endwstack = ();
 %sects = ();
 $section = "";
 @icstack = ();
 @endwstack = ();
+@skstack = ();
 $shift = "";
 $shift = "";
+%defs = ();
 
 
-while(<IN>)
+while($_ = shift)
+{
+    if (/^-D(.*)$/) {
+       if ($1 ne "") {
+           $flag = $1;
+       } else {
+           $flag = shift;
+       }
+       die "no flag specified for -D\n"
+           unless $flag ne "";
+       die "flags may only contain letters, digits, hyphens, and underscores\n"
+           unless $flag =~ /^[a-zA-Z0-9_-]+$/;
+       $defs{$flag} = "";
+    } elsif (/^-/) {
+       usage();
+    } else {
+       $in = $_, next unless defined $in;
+       $out = $_, next unless defined $out;
+       usage();
+    }
+}
+
+if (defined $in) {
+    open(STDIN, $in) or die "opening \"$in\": $!\n";
+}
+if (defined $out) {
+    open(STDOUT, ">$out") or die "opening \"$out\": $!\n";
+}
+
+while(<STDIN>)
 {
     chomp;
 {
     chomp;
-    /^\@end ignore/ and $ignore = 0, next;
-    next if $ignore;
     /^\@c man begin ([A-Z]+)/ and $sect = $1, $output = 1, next;
     /^\@c man end/ and do {
        $_ = $section;
     /^\@c man begin ([A-Z]+)/ and $sect = $1, $output = 1, next;
     /^\@c man end/ and do {
        $_ = $section;
-       s/</&lt;/g;
-       s/>/&gt;/g;
 
        s/\@(?:dfn|var|emph|cite)\{([^\}]*)\}/I<$1>/g;
        s/\@(?:code|kbd)\{([^\}]*)\}/C<$1>/g;
        s/\@(?:samp|strong|key)\{([^\}]*)\}/B<$1>/g;
 
        s/\@(?:dfn|var|emph|cite)\{([^\}]*)\}/I<$1>/g;
        s/\@(?:code|kbd)\{([^\}]*)\}/C<$1>/g;
        s/\@(?:samp|strong|key)\{([^\}]*)\}/B<$1>/g;
+       s/\@value\{([a-zA-Z0-9_-]+)\}/$defs{$1}/g;
+       s/\@sc\{([^\}]*)\}/\U$1/g;
        s/\@file\{([^\}]*)\}/F<$1>/g;
        s/\@(?:url|email)\{([^\}]*)\}/E<lt>C<$1>E<rt>/g;
        s/\@file\{([^\}]*)\}/F<$1>/g;
        s/\@(?:url|email)\{([^\}]*)\}/E<lt>C<$1>E<rt>/g;
-       s/\@[a-z]?ref\{(?:[^\}]*)\}.?//g;
-       s/\(\@p[a-z]?ref\{(?:[^\}]*)\}\).?//g;
+       s/\@xref\{(?:[^\}]*)\}[^.]*.//g;
+       s/\s+\(\@p[a-z]?ref\{(?:[^\}]*)\}\)//g;
        s/\@copyright\{\}//g;
        s/\@noindent\s*//g;
        s/\@refill//g;
        s/\@\././g;
 
        s/\@copyright\{\}//g;
        s/\@noindent\s*//g;
        s/\@refill//g;
        s/\@\././g;
 
-       s/&lt;/E<lt>/g;
-       s/&gt;/E<gt>/g;
+       # Turn B<blah I<blah> blah> into B<blah> I<blah> B<blah> to
+       # match Texinfo semantics of @emph inside @samp.
+
        s/&LT;/</g;
        s/&GT;/>/g;
        s/&LT;/</g;
        s/&GT;/>/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;
+       s/([BI])<(\s+)([^>]+)>/$2$1<$3>/g;
+       s/([BI])<([^>]+?)(\s+)>/$1<$2>$3/g;
+
+       s/&lt;/E<lt>/g;
+       s/&gt;/E<gt>/g;
+       s/&lbrace;/\{/g;
+       s/&rbrace;/\}/g;
 
        $sects{$sect} = $_;
        $section = "";
        $output = 0;
        next;
     };
 
        $sects{$sect} = $_;
        $section = "";
        $output = 0;
        next;
     };
-    
+
     /^\@(c|[a-z]+index)\b/ and next;
     /^\@(c|[a-z]+index)\b/ and next;
+    /^\@subsection/ and next;
+    /^\@need/ and next;
+    /^\@node/ and next;
 
     /^\@setfilename\s+([^.]+)/ and $fn = $1, next;
     /^\@settitle\s+([^.]+)/ and $tl = $1, next;
 
     next unless $output;
 
 
     /^\@setfilename\s+([^.]+)/ and $fn = $1, next;
     /^\@settitle\s+([^.]+)/ and $tl = $1, next;
 
     next unless $output;
 
+    /^\@end\s+([a-z]+)/ and do {
+       if(defined $endw)
+       {
+           die "\@$endw ended by \@end $1 at line $.\n"
+               unless $1 eq $endw;
+
+           if($endw =~ /example$/)
+           {
+               $shift = "";
+               $_ = "";
+           }
+           elsif($endw =~ /^if/)
+           {
+               $skipping = pop @skstack;
+               $_ = "";
+           }
+           else
+           {
+               $_ = "\n=back\n";
+               $ic = pop @icstack;
+           }
+           $endw = pop @endwstack;
+       }
+    };
+
+    /^\@end ignore/ and $ignore = 0, next;
+    next if $ignore;
+    next if $skipping;
+
     /^\@ignore/ and $ignore = 1, next;
 
     /^\@ignore/ and $ignore = 1, next;
 
+    /^\@set\s+([a-zA-Z0-9_-]+)\s*(.*)$/ and $defs{$1} = $2, next;
+    /^\@clear\s+([a-zA-Z0-9_-]+)/ and delete $defs{$1}, next;
+
+    /^\@ifset\s+([a-zA-Z0-9_-]+)/ and do {
+       push @endwstack, $endw;
+       push @skstack, $skipping;
+       $endw = "ifset";
+       $skipping = 1 unless exists $defs{$1};
+    };
+
+    /^\@ifclear\s+([a-zA-Z0-9_-]+)/ and do {
+       push @endwstack, $endw;
+       push @skstack, $skipping;
+       $endw = "ifset";
+       $skipping = 1 if exists $defs{$1};
+    };
+
     /^\@itemize (\@[a-z]+)/ and do {
        push @endwstack, $endw;
        push @icstack, $ic;
     /^\@itemize (\@[a-z]+)/ and do {
        push @endwstack, $endw;
        push @icstack, $ic;
@@ -99,27 +182,6 @@ while(<IN>)
        next;
     };
 
        next;
     };
 
-    /^\@end\s+([a-z]+)/ and do {
-       if(defined $endw)
-       {
-           die "\@$endw ended by \@end $1 at line $.\n"
-               unless $1 eq $endw;
-
-           if($endw =~ /example$/)
-           {
-               $shift = "";
-               $_ = "";
-           }
-           else
-           {
-               $_ = "\n=back\n";
-               undef $endw;
-               $ic = pop @icstack;
-           }
-           $endw = pop @endwstack;
-       }
-    };
-
     /^\@itemx?\s*(.+)?$/ and do {
        if(defined $1)
        {
     /^\@itemx?\s*(.+)?$/ and do {
        if(defined $1)
        {
@@ -131,7 +193,21 @@ while(<IN>)
            $ic =~ y/A-Ya-y1-8/B-Zb-z2-9/;
        }
     };
            $ic =~ y/A-Ya-y1-8/B-Zb-z2-9/;
        }
     };
-       
+
+    /^\@section\s+(.+)$/ and do {
+       $_ = "\n=head2 $1\n";
+    };
+
+    # POD doesn't interpret E<> inside a verbatim block.
+    if ($shift eq "") {
+       s/</&lt;/g;
+       s/>/&gt;/g;
+    } else {
+       s/</&LT;/g;
+       s/>/&GT;/g;
+    }
+    s/\@\{/&lbrace;/g;
+    s/\@\}/&rbrace;/g;
     $section .= $shift.$_."\n";
 }
 
     $section .= $shift.$_."\n";
 }
 
@@ -149,3 +225,8 @@ for $sect (qw(NAME SYNOPSIS DESCRIPTION OPTIONS ENVIRONMENT FILES
        print "\n";
     }
 }
        print "\n";
     }
 }
+
+sub usage
+{
+    die "usage: $0 [-D toggle...] [infile [outfile]]\n";
+}