This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[inseparable changes from patch from perl5.003_23 to perl5.003_24]
[perl5.git] / pod / pod2man.PL
index 8c054ca..c03e73d 100644 (file)
@@ -12,10 +12,9 @@ use File::Basename qw(&basename &dirname);
 
 # This forces PL files to create target in same directory as PL file.
 # This is so that make depend always knows where to find PL derivatives.
-chdir(dirname($0));
-($file = basename($0)) =~ s/\.PL$//;
-$file =~ s/\.pl$//
-       if ($^O eq 'VMS' or $^O eq 'os2');  # "case-forgiving"
+chdir dirname($0);
+$file = basename($0, '.PL');
+$file .= '.com' if $^O eq 'VMS';
 
 open OUT,">$file" or die "Can't create $file: $!";
 
@@ -25,14 +24,14 @@ print "Extracting $file (with variable substitutions)\n";
 # You can use $Config{...} to use Configure variables.
 
 print OUT <<"!GROK!THIS!";
-$Config{'startperl'}
+$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.
 
 print OUT <<'!NO!SUBS!';
-eval 'exec perl -S $0 "$@"'
-    if 0;
 
 =head1 NAME
 
@@ -198,7 +197,7 @@ Who wrote it (or AUTHORS if multiple).
 =item HISTORY
 
 Programs derived from other sources sometimes have this, or
-you might keep a modification long here.
+you might keep a modification log here.
 
 =back
 
@@ -248,7 +247,7 @@ not having a NAME is a fatal.
 =item Unknown escape: %s in %s
 
 (W) An unknown HTML entity (probably for an 8-bit character) was given via
-a C<E<lt>E<gt>> directive.  Besides amp, lt, gt, and quot, recognized
+a C<EE<lt>E<gt>> directive.  Besides amp, lt, gt, and quot, recognized
 entities are Aacute, aacute, Acirc, acirc, AElig, aelig, Agrave, agrave,
 Aring, aring, Atilde, atilde, Auml, auml, Ccedil, ccedil, Eacute, eacute,
 Ecirc, ecirc, Egrave, egrave, ETH, eth, Euml, euml, Iacute, iacute, Icirc,
@@ -273,7 +272,7 @@ C<=head1>, C<=head2>, C<=item>, C<=over>, C<=back>, or C<=cut>.
 
 If you would like to print out a lot of man page continuously, you
 probably want to set the C and D registers to set contiguous page
-numbering and even/odd paging, at least one some versions of man(7).
+numbering and even/odd paging, at least on some versions of man(7).
 Settting the F register will get you some additional experimental
 indexing:
 
@@ -388,8 +387,12 @@ $wanna_see{SYNOPSIS}++ if $section =~ /^3/;
 
 $name = @ARGV ? $ARGV[0] : "<STDIN>";
 $Filename = $name;
-$name = uc($name) if $section =~ /^1/;
-$name =~ s/\.[^.]*$//;
+if ($section =~ /^1/) {
+    require File::Basename;
+    $name = uc File::Basename::basename($name);
+}
+$name =~ s/\.(pod|p[lm])$//i;
+$name =~ s(/)(::)g; # translate Getopt/Long to Getopt::Long, etc.
 
 if ($name ne 'something') {
     FCHECK: {
@@ -402,7 +405,7 @@ if ($name ne 'something') {
                    $oops++;
                    warn "$0: Improper man page - no dash in NAME header in paragraph $. of $ARGV[0]\n"
                }
-               %namedesc = split /\s+-\s+/;
+               %namedesc = split /\s+-+\s+/;
                last FCHECK;
            }
            next if /^=cut\b/;  # DB_File and Net::Ping have =cut before NAME
@@ -604,11 +607,22 @@ END
 
 $indent = 0;
 
+$begun = "";
+
 while (<>) {
     if ($cutting) {
        next unless /^=/;
        $cutting = 0;
     }
+    if ($begun) {
+       if (/^=end\s+$begun/) {
+            $begun = "";
+       }
+       elsif ($begun =~ /^(roff|man)$/) {
+           print STDOUT $_;
+        }
+       next;
+    }
     chomp;
 
     # Translate verbatim paragraph
@@ -633,6 +647,22 @@ while (<>) {
 
     $verbatim = 0;
 
+    if (/^=for\s+(\S+)\s*/s) {
+       if ($1 eq "man" or $1 eq "roff") {
+           print STDOUT $',"\n\n";
+       } else {
+           # ignore unknown for
+       }
+       next;
+    }
+    elsif (/^=begin\s+(\S+)\s*/s) {
+       $begun = $1;
+       if ($1 eq "man" or $1 eq "roff") {
+           print STDOUT $'."\n\n";
+       }
+       next;
+    }
+
     # check for things that'll hosed our noremap scheme; affects $_
     init_noremap();
 
@@ -755,7 +785,7 @@ while (<>) {
                    ?  "the section on I<$2> in the I<$1> manpage"
                    :  "the section on I<$2>"
            }
-       }gex;
+       }gesx; # s in case it goes over multiple lines, so . matches \n
 
        s/Z<>/\\&/g;
 
@@ -1004,7 +1034,7 @@ sub internal_lrefs {
     }
 
     $retstr .= " entr" . ( @items > 1  ? "ies" : "y" )
-           .  " elsewhere in this document";
+           .  " elsewhere in this document "; # terminal space to avoid words running together (pattern used strips terminal spaces)
 
     return $retstr;