Misc. doc patches missing in _20
[p5sagit/p5-mst-13.2.git] / pod / pod2latex.PL
index bd6df71..4f79c12 100644 (file)
@@ -15,8 +15,7 @@ use File::Basename qw(&basename &dirname);
 chdir(dirname($0));
 ($file = basename($0)) =~ s/\.PL$//;
 $file =~ s/\.pl$//
-       if ($Config{'osname'} eq 'VMS' or
-           $Config{'osname'} eq 'OS2');  # "case-forgiving"
+       if ($^O eq 'VMS' or $^O eq 'os2');  # "case-forgiving"
 
 open OUT,">$file" or die "Can't create $file: $!";
 
@@ -26,9 +25,9 @@ print "Extracting $file (with variable substitutions)\n";
 # You can use $Config{...} to use Configure variables.
 
 print OUT <<"!GROK!THIS!";
-$Config{'startperl'}
-    eval 'exec perl -S \$0 "\$@"'
-       if 0;
+$Config{startperl}
+    eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
+       if \$running_under_some_shell;
 !GROK!THIS!
 
 # In the following, perl variables are not expanded during extraction.
@@ -125,11 +124,21 @@ open(LATEX,">$pod.tex");
 &do_hdr();
 
 $cutting = 1;
+$begun = "";
 while (<POD>) {
     if ($cutting) {
        next unless /^=/;
        $cutting = 0;
     }
+    if ($begun) {
+       if (/^=end\s+$begun/) {
+           $begun = "";
+       }
+       elsif ($begun =~ /^(tex|latex)$/) {
+           print LATEX $_;
+       }
+       next;
+    }
     chop;
     length || (print LATEX  "\n") && next;
 
@@ -147,6 +156,22 @@ while (<POD>) {
        next;
     }
 
+    if (/^=for\s+(\S+)\s*/s) {
+       if ($1 eq "tex" or $1 eq "latex") {
+           print LATEX $',"\n";
+       } else {
+           # ignore unknown for
+       }
+       next;
+    }
+    elsif (/^=begin\s+(\S+)\s*/s) {
+       $begun = $1;
+       if ($1 eq "tex" or $1 eq "latex") {
+           print LATEX $'."\n";
+       }
+       next;
+    }
+
     # preserve '=item' line with pod quotes as they are.
     if (/^=item/) {
        ($bareitem = $_) =~ s/^=item\s*//;
@@ -501,9 +526,8 @@ sub noremap {
 }
 
 sub init_noremap {
-    if ( /[\200-\377]/ ) {
-       warn "hit bit char in input stream";
-    }
+       # escape high bit characters in input stream
+       s/([\200-\377])/"E<".ord($1).">"/ge;
 }
 
 sub clear_noremap {
@@ -514,11 +538,14 @@ sub clear_noremap {
 
 sub expand_HTML_escapes {
     local($s) = $_[0];
-    $s =~ s { E<([A-Za-z]+)> }
+    $s =~ s { E<((\d+)|([A-Za-z]+))> }
     {
        do {
-           exists $HTML_Escapes{$1}
-           ? do { $HTML_Escapes{$1} }
+               defined($2) 
+               ? do { chr($2) }
+               : 
+           exists $HTML_Escapes{$3}
+           ? do { $HTML_Escapes{$3} }
            : do {
                warn "Unknown escape: $& in $_";
                "E<$1>";