Documents for Merijn and lots of XXXs for NI-S :-)
[p5sagit/p5-mst-13.2.git] / utils / perldoc.PL
index 22fdd1c..7929a27 100644 (file)
@@ -25,6 +25,8 @@ print "Extracting $file (with variable substitutions)\n";
 # In this section, perl variables will be expanded during extraction.
 # You can use $Config{...} to use Configure variables.
 
+my $versiononly = $Config{versiononly} ? $Config{version} : '';
+
 print OUT <<"!GROK!THIS!";
 $Config{startperl}
     eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
@@ -43,7 +45,11 @@ my \@pagers = ();
 push \@pagers, \$pager if -x \$pager;
 
 (my \$bindir = <<'/../') =~ s/\\s*\\z//;
-$Config{scriptdir}
+$Config{scriptdirexp}
+/../
+
+(my \$pod2man = <<'/../') =~ s/\\s*\\z//;
+pod2man$versiononly
 /../
 
 !GROK!THIS!
@@ -163,9 +169,29 @@ if (!($Is_VMS || $Is_MSWin32 || $Is_Dos || $Is_OS2) && ($> == 0 || $< == 0)
         my $id = eval { getpwnam("nobody") };
            $id = eval { getpwnam("nouser") } unless defined $id;
            $id = -2 unless defined $id;
+       #
+       # According to Stevens' APUE and various
+       # (BSD, Solaris, HP-UX) man pages setting
+       # the real uid first and effective uid second
+       # is the way to go if one wants to drop privileges,
+       # because if one changes into an effective uid of
+       # non-zero, one cannot change the real uid any more.
+       #
+       # Actually, it gets even messier.  There is
+       # a third uid, called the saved uid, and as
+       # long as that is zero, one can get back to
+       # uid of zero.  Setting the real-effective *twice*
+       # helps in *most* systems (FreeBSD and Solaris)
+       # but apparently in HP-UX even this doesn't help:
+       # the saved uid stays zero (apparently the only way
+       # in HP-UX to change saved uid is to call setuid()
+       # when the effective uid is zero).
+       #
         eval {
-            $> = $id;  # must do this one first!
-            $< = $id;
+            $< = $id; # real uid
+            $> = $id; # effective uid
+            $< = $id; # real uid
+            $> = $id; # effective uid
         };
         last if !$@ && $< && $>;
     }
@@ -316,7 +342,7 @@ sub searchfor {
     for ($i=0; $i<@dirs; $i++) {
        $dir = $dirs[$i];
        ($dir = VMS::Filespec::unixpath($dir)) =~ s!/\z!! if $Is_VMS;
-       if (       ( $ret = check_file $dir,"$s.pod")
+       if (       (! $opt_m && ( $ret = check_file $dir,"$s.pod"))
                or ( $ret = check_file $dir,"$s.pm")
                or ( $ret = check_file $dir,$s)
                or ( $Is_VMS and
@@ -371,9 +397,13 @@ sub page {
        close TMP               or die "Can't close while $tmp: $!";
     }
     else {
-       foreach my $pager (@pagers) {
+        # On VMS, quoting prevents logical expansion, and temp files with no
+        # extension get the wrong default extension (such as .LIS for TYPE)
+
+        $tmp = VMS::Filespec::rmsexpand($tmp, '.') if ($Is_VMS);
+        foreach my $pager (@pagers) {
           if ($Is_VMS) {
-           last if system("$pager $tmp") == 0; # quoting prevents logical expansion
+            last if system("$pager $tmp") == 0;
           } else {
            last if system("$pager \"$tmp\"") == 0;
           }
@@ -381,18 +411,6 @@ sub page {
     }
 }
 
-sub cleanup {
-    my @files = @_;
-    for (@files) {
-       next unless defined;
-       if ($Is_VMS) { 
-           1 while unlink($_);    # XXX: expect failure
-       } else {
-           unlink($_);            # or die "Can't unlink $_: $!";
-       } 
-    }
-}
-
 my @found;
 foreach (@pages) {
     if ($podidx && open(PODIDX, $podidx)) {
@@ -440,7 +458,8 @@ foreach (@pages) {
            print STDERR "Loosely found as @files\n" if $opt_v;
        }
        else {
-           print STDERR "No documentation found for \"$_\".\n";
+           print STDERR "No " .
+               ($opt_m ? "module" : "documentation") . " found for \"$_\".\n";
            if (@global_found) {
                print STDERR "However, try\n";
                for my $dir (@global_found) {
@@ -570,7 +589,7 @@ EOD
            $found = 1;
            push @pod, "=head1 Found in $ARGV\n\n" unless $found_in{$ARGV}++;
        }
-       elsif (/^=head2/) {
+       elsif (/^=head[12]/) {
            $found = 0;
        }
        next unless $found;
@@ -581,34 +600,14 @@ EOD
     }
 }
 
-# until here we could simply exit or die
-# now we create temporary files that we have to clean up
-# namely $tmp, $buffer
-# that's because you did it wrong, should be descriptor based --tchrist
-
-my $tmp;
-my $tmpfd;
-my $buffer;
-
 require File::Temp;
 
-($tmpfd, $tmp) = File::Temp::tempfile();
-
-# make sure cleanup called
-eval q{
-    sub END { cleanup($tmp, $buffer) } 
-    1;
-} || die;
-
-# exit/die in a windows sighandler is dangerous, so let it do the
-# default thing, which is to exit
-eval q{ use sigtrap qw(die INT TERM HUP QUIT) } unless $^O eq 'MSWin32';
+my ($tmpfd, $tmp) = File::Temp::tempfile(UNLINK => 1);
 
 my $filter;
 
 if (@pod) {
-    my $buffd;
-    ($buffd, $buffer) = File::Temp::tempfile();
+    my ($buffd, $buffer) = File::Temp::tempfile(UNLINK => 1);
     print $buffd "=over 8\n\n";
     print $buffd @pod  or die "Can't print $buffer: $!";
     print $buffd "=back\n";
@@ -625,7 +624,7 @@ foreach (@found) {
        Pod::Text->new()->parse_from_file($file, $tmpfd);
     }
     elsif (not $opt_u) {
-       my $cmd = catfile($bindir, 'pod2man') . " --lax $file | $opt_n -man";
+       my $cmd = catfile($bindir, $pod2man) . " --lax $file | $opt_n -man";
        $cmd .= " | col -x" if $^O =~ /hpux/;
        my $rslt = `$cmd`;
        $rslt = filter_nroff($rslt) if $filter;
@@ -741,7 +740,7 @@ the regular expression.
 
 =item B<-X> use an index if present
 
-The B<-X> option looks for a entry whose basename matches the name given on the
+The B<-X> option looks for an entry whose basename matches the name given on the
 command line in the file C<$Config{archlib}/pod.idx>.  The pod.idx file should
 contain fully qualified filenames, one per line.
 
@@ -751,7 +750,7 @@ Because B<perldoc> does not run properly tainted, and is known to
 have security issues, it will not normally execute as the superuser.
 If you use the B<-U> flag, it will do so, but only after setting
 the effective and real IDs to nobody's or nouser's account, or -2
-if unavailable.  If it cannot relinguish its privileges, it will not
+if unavailable.  If it cannot relinquish its privileges, it will not
 run.  
 
 =item B<PageName|ModuleName|ProgramName>