home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 March / PCWorld_2003-03_cd.bin / Software / Topware / activeperl / ActivePerl / Perl / bin / perldoc.bat < prev    next >
Encoding:
DOS Batch File  |  2002-12-01  |  22.7 KB  |  820 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!perl
  14. #line 15
  15.     eval 'exec D:\p4\Apps\Gecko\MSI\data\ActivePerl\Perl\bin\perl.exe -S $0 ${1+"$@"}'
  16.     if 0;
  17.  
  18. use warnings;
  19. use strict;
  20.  
  21. # make sure creat()s are neither too much nor too little
  22. INIT { eval { umask(0077) } }   # doubtless someone has no mask
  23.  
  24. (my $pager = <<'/../') =~ s/\s*\z//;
  25. more /e
  26. /../
  27. my @pagers = ();
  28. push @pagers, $pager if -x $pager;
  29.  
  30. (my $bindir = <<'/../') =~ s/\s*\z//;
  31. D:\p4\Apps\Gecko\MSI\data\ActivePerl\Perl\bin
  32. /../
  33.  
  34. (my $pod2man = <<'/../') =~ s/\s*\z//;
  35. pod2man
  36. /../
  37.  
  38.  
  39. use Fcntl;    # for sysopen
  40. use Getopt::Std;
  41. use Config '%Config';
  42. use File::Spec::Functions qw(catfile splitdir);
  43.  
  44. #
  45. # Perldoc revision #1 -- look up a piece of documentation in .pod format that
  46. # is embedded in the perl installation tree.
  47. #
  48. # This is not to be confused with Tom Christiansen's perlman, which is a
  49. # man replacement, written in perl. This perldoc is strictly for reading
  50. # the perl manuals, though it too is written in perl.
  51. # Massive security and correctness patches applied to this
  52. # noisome program by Tom Christiansen Sat Mar 11 15:22:33 MST 2000 
  53.  
  54. if (@ARGV<1) {
  55.     my $me = $0;        # Editing $0 is unportable
  56.     $me =~ s,.*/,,;
  57.     die <<EOF;
  58. Usage: $me [-h] [-r] [-i] [-v] [-t] [-u] [-m] [-n program] [-l] [-F] [-X] PageName|ModuleName|ProgramName
  59.        $me -f PerlFunc
  60.        $me -q FAQKeywords
  61.  
  62. The -h option prints more help.  Also try "perldoc perldoc" to get
  63. acquainted with the system.
  64. EOF
  65. }
  66.  
  67. my @global_found = ();
  68. my $global_target = "";
  69.  
  70. my $Is_VMS = $^O eq 'VMS';
  71. my $Is_MSWin32 = $^O eq 'MSWin32';
  72. my $Is_Dos = $^O eq 'dos';
  73. my $Is_OS2 = $^O eq 'os2';
  74.  
  75. sub usage{
  76.     warn "@_\n" if @_;
  77.     # Erase evidence of previous errors (if any), so exit status is simple.
  78.     $! = 0;
  79.     die <<EOF;
  80. perldoc [options] PageName|ModuleName|ProgramName...
  81. perldoc [options] -f BuiltinFunction
  82. perldoc [options] -q FAQRegex
  83.  
  84. Options:
  85.     -h   Display this help message
  86.     -r   Recursive search (slow)
  87.     -i   Ignore case
  88.     -t   Display pod using pod2text instead of pod2man and nroff
  89.              (-t is the default on win32 unless -n is specified)
  90.     -u     Display unformatted pod text
  91.     -m   Display module's file in its entirety
  92.     -n   Specify replacement for nroff
  93.     -l   Display the module's file name
  94.     -F   Arguments are file names, not modules
  95.     -v     Verbosely describe what's going on
  96.     -X     use index if present (looks for pod.idx at $Config{archlib})
  97.     -q   Search the text of questions (not answers) in perlfaq[1-9]
  98.     -U     Run in insecure mode (superuser only)
  99.  
  100. PageName|ModuleName...
  101.          is the name of a piece of documentation that you want to look at. You
  102.          may either give a descriptive name of the page (as in the case of
  103.          `perlfunc') the name of a module, either like `Term::Info' or like
  104.          `Term/Info', or the name of a program, like `perldoc'.
  105.  
  106. BuiltinFunction
  107.          is the name of a perl function.  Will extract documentation from
  108.          `perlfunc'.
  109.  
  110. FAQRegex
  111.          is a regex. Will search perlfaq[1-9] for and extract any
  112.          questions that match.
  113.  
  114. Any switches in the PERLDOC environment variable will be used before the
  115. command line arguments.  The optional pod index file contains a list of
  116. filenames, one per line.
  117.  
  118. EOF
  119. }
  120.  
  121. if (defined $ENV{"PERLDOC"}) {
  122.     require Text::ParseWords;
  123.     unshift(@ARGV, Text::ParseWords::shellwords($ENV{"PERLDOC"}));
  124. }
  125.  
  126. use vars qw( $opt_m $opt_h $opt_t $opt_l $opt_u $opt_v $opt_r $opt_i $opt_F $opt_f $opt_X $opt_q $opt_n $opt_U );
  127.  
  128. getopts("mhtluvriFf:Xq:n:U") || usage;
  129.  
  130. usage if $opt_h;
  131.  
  132. # refuse to run if we should be tainting and aren't
  133. # (but regular users deserve protection too, though!)
  134. if (!($Is_VMS || $Is_MSWin32 || $Is_Dos || $Is_OS2) && ($> == 0 || $< == 0)
  135.      && !am_taint_checking()) 
  136. {{
  137.     if ($opt_U) {
  138.         my $id = eval { getpwnam("nobody") };
  139.            $id = eval { getpwnam("nouser") } unless defined $id;
  140.            $id = -2 unless defined $id;
  141.     #
  142.     # According to Stevens' APUE and various
  143.     # (BSD, Solaris, HP-UX) man pages setting
  144.     # the real uid first and effective uid second
  145.     # is the way to go if one wants to drop privileges,
  146.     # because if one changes into an effective uid of
  147.     # non-zero, one cannot change the real uid any more.
  148.     #
  149.     # Actually, it gets even messier.  There is
  150.     # a third uid, called the saved uid, and as
  151.     # long as that is zero, one can get back to
  152.     # uid of zero.  Setting the real-effective *twice*
  153.     # helps in *most* systems (FreeBSD and Solaris)
  154.     # but apparently in HP-UX even this doesn't help:
  155.     # the saved uid stays zero (apparently the only way
  156.     # in HP-UX to change saved uid is to call setuid()
  157.     # when the effective uid is zero).
  158.     #
  159.         eval {
  160.             $< = $id; # real uid
  161.             $> = $id; # effective uid
  162.             $< = $id; # real uid
  163.             $> = $id; # effective uid
  164.         };
  165.         last if !$@ && $< && $>;
  166.     }
  167.     die "Superuser must not run $0 without security audit and taint checks.\n";
  168. }}
  169.  
  170. my $podidx;
  171. if ($opt_X) {
  172.     $podidx = "$Config{'archlib'}/pod.idx";
  173.     $podidx = "" unless -f $podidx && -r _ && -M _ <= 7;
  174. }
  175.  
  176. if ((my $opts = do{ no warnings; $opt_t + $opt_u + $opt_m + $opt_l }) > 1) {
  177.     usage("only one of -t, -u, -m or -l")
  178. }
  179. elsif ($Is_MSWin32
  180.        || $Is_Dos
  181.        || !($ENV{TERM} && $ENV{TERM} !~ /dumb|emacs|none|unknown/i))
  182. {
  183.     $opt_t = 1 unless ( $opts || $opt_n );
  184. }
  185.  
  186. if ($opt_t) { require Pod::Text; import Pod::Text; }
  187.  
  188. $opt_n = "nroff" if !$opt_n;
  189.  
  190. my @pages;
  191. if ($opt_f) {
  192.     @pages = ("perlfunc");
  193. }
  194. elsif ($opt_q) {
  195.     @pages = ("perlfaq1" .. "perlfaq9");
  196. }
  197. else {
  198.     @pages = @ARGV;
  199. }
  200.  
  201. # Does this look like a module or extension directory?
  202. if (-f "Makefile.PL") {
  203.  
  204.     # Add ., lib to @INC (if they exist)
  205.     eval q{ use lib qw(. lib); 1; } or die;
  206.  
  207.     # don't add if superuser
  208.     if ($< && $> && -f "blib") {   # don't be looking too hard now!
  209.     eval q{ use blib; 1 };
  210.     warn $@ if $@ && $opt_v;
  211.     }
  212. }
  213.  
  214. sub containspod {
  215.     my($file, $readit) = @_;
  216.     return 1 if !$readit && $file =~ /\.pod\z/i;
  217.     local($_);
  218.     open(TEST,"<", $file)     or die "Can't open $file: $!";
  219.     while (<TEST>) {
  220.     if (/^=head/) {
  221.         close(TEST)     or die "Can't close $file: $!";
  222.         return 1;
  223.     }
  224.     }
  225.     close(TEST)         or die "Can't close $file: $!";
  226.     return 0;
  227. }
  228.  
  229. sub minus_f_nocase {
  230.      my($dir,$file) = @_;
  231.      my $path = catfile($dir,$file);
  232.      return $path if -f $path and -r _;
  233.      if (!$opt_i or $Is_VMS or $Is_MSWin32 or $Is_Dos or $^O eq 'os2') {
  234.         # on a case-forgiving file system or if case is important
  235.     # that is it all we can do
  236.     warn "Ignored $path: unreadable\n" if -f _;
  237.     return '';
  238.      }
  239.      local *DIR;
  240.      # this is completely wicked.  don't mess with $", and if 
  241.      # you do, don't assume / is the dirsep!
  242.      local($")="/";
  243.      my @p = ($dir);
  244.      my($p,$cip);
  245.      foreach $p (splitdir $file){
  246.     my $try = catfile @p, $p;
  247.     stat $try;
  248.      if (-d _) {
  249.          push @p, $p;
  250.         if ( $p eq $global_target) {
  251.         my $tmp_path = catfile @p;
  252.         my $path_f = 0;
  253.         for (@global_found) {
  254.             $path_f = 1 if $_ eq $tmp_path;
  255.         }
  256.         push (@global_found, $tmp_path) unless $path_f;
  257.         print STDERR "Found as @p but directory\n" if $opt_v;
  258.         }
  259.      }
  260.     elsif (-f _ && -r _) {
  261.          return $try;
  262.      }
  263.     elsif (-f _) {
  264.         warn "Ignored $try: unreadable\n";
  265.      }
  266.     elsif (-d "@p") {
  267.          my $found=0;
  268.          my $lcp = lc $p;
  269.          opendir DIR, "@p"         or die "opendir @p: $!";
  270.          while ($cip=readdir(DIR)) {
  271.          if (lc $cip eq $lcp){
  272.              $found++;
  273.              last;
  274.          }
  275.          }
  276.          closedir DIR        or die "closedir @p: $!";
  277.          return "" unless $found;
  278.          push @p, $cip;
  279.          return "@p" if -f "@p" and -r _;
  280.         warn "Ignored @p: unreadable\n" if -f _;
  281.      }
  282.      }
  283.      return "";
  284. }
  285.  
  286.  
  287. sub check_file {
  288.     my($dir,$file) = @_;
  289.     return "" if length $dir and not -d $dir;
  290.     if ($opt_m) {
  291.     return minus_f_nocase($dir,$file);
  292.     }
  293.     else {
  294.     my $path = minus_f_nocase($dir,$file);
  295.         return $path if length $path and containspod($path);
  296.     }
  297.     return "";
  298. }
  299.  
  300.  
  301. sub searchfor {
  302.     my($recurse,$s,@dirs) = @_;
  303.     $s =~ s!::!/!g;
  304.     $s = VMS::Filespec::unixify($s) if $Is_VMS;
  305.     return $s if -f $s && containspod($s);
  306.     printf STDERR "Looking for $s in @dirs\n" if $opt_v;
  307.     my $ret;
  308.     my $i;
  309.     my $dir;
  310.     $global_target = (splitdir $s)[-1];   # XXX: why not use File::Basename?
  311.     for ($i=0; $i<@dirs; $i++) {
  312.     $dir = $dirs[$i];
  313.     ($dir = VMS::Filespec::unixpath($dir)) =~ s!/\z!! if $Is_VMS;
  314.     if (       (! $opt_m && ( $ret = check_file $dir,"$s.pod"))
  315.         or ( $ret = check_file $dir,"$s.pm")
  316.         or ( $ret = check_file $dir,$s)
  317.         or ( $Is_VMS and
  318.              $ret = check_file $dir,"$s.com")
  319.         or ( $^O eq 'os2' and
  320.              $ret = check_file $dir,"$s.cmd")
  321.         or ( ($Is_MSWin32 or $Is_Dos or $^O eq 'os2') and
  322.              $ret = check_file $dir,"$s.bat")
  323.         or ( $ret = check_file "$dir/pod","$s.pod")
  324.         or ( $ret = check_file "$dir/pod",$s)
  325.         or ( $ret = check_file "$dir/pods","$s.pod")
  326.         or ( $ret = check_file "$dir/pods",$s)
  327.     ) {
  328.         return $ret;
  329.     }
  330.  
  331.     if ($recurse) {
  332.         opendir(D,$dir)    or die "Can't opendir $dir: $!";
  333.         my @newdirs = map catfile($dir, $_), grep {
  334.         not /^\.\.?\z/s and
  335.         not /^auto\z/s  and   # save time! don't search auto dirs
  336.         -d  catfile($dir, $_)
  337.         } readdir D;
  338.         closedir(D)        or die "Can't closedir $dir: $!";
  339.         next unless @newdirs;
  340.         # what a wicked map!
  341.         @newdirs = map((s/\.dir\z//,$_)[1],@newdirs) if $Is_VMS;
  342.         print STDERR "Also looking in @newdirs\n" if $opt_v;
  343.         push(@dirs,@newdirs);
  344.     }
  345.     }
  346.     return ();
  347. }
  348.  
  349. sub filter_nroff {
  350.   my @data = split /\n{2,}/, shift;
  351.   shift @data while @data and $data[0] !~ /\S/; # Go to header
  352.   shift @data if @data and $data[0] =~ /Contributed\s+Perl/; # Skip header
  353.   pop @data if @data and $data[-1] =~ /^\w/; # Skip footer, like
  354.                 # 28/Jan/99 perl 5.005, patch 53 1
  355.   join "\n\n", @data;
  356. }
  357.  
  358. sub page {
  359.     my ($tmp, $no_tty, @pagers) = @_;
  360.     if ($no_tty) {
  361.     open(TMP,"<", $tmp)     or die "Can't open $tmp: $!";
  362.     local $_;
  363.     while (<TMP>) {
  364.         print or die "Can't print to stdout: $!";
  365.     } 
  366.     close TMP        or die "Can't close while $tmp: $!";
  367.     }
  368.     else {
  369.         # On VMS, quoting prevents logical expansion, and temp files with no
  370.         # extension get the wrong default extension (such as .LIS for TYPE)
  371.  
  372.         $tmp = VMS::Filespec::rmsexpand($tmp, '.') if ($Is_VMS);
  373.         foreach my $pager (@pagers) {
  374.           if ($Is_VMS) {
  375.             last if system("$pager $tmp") == 0;
  376.           } else {
  377.         last if system("$pager \"$tmp\"") == 0;
  378.           }
  379.     }
  380.     }
  381. }
  382.  
  383. my @found;
  384. foreach (@pages) {
  385.     if ($podidx && open(PODIDX, $podidx)) {
  386.     my $searchfor = catfile split '::';
  387.     print STDERR "Searching for '$searchfor' in $podidx\n" if $opt_v;
  388.     local $_;
  389.     while (<PODIDX>) {
  390.         chomp;
  391.         push(@found, $_) if m,/$searchfor(?:\.(?:pod|pm))?\z,i;
  392.     }
  393.     close(PODIDX)        or die "Can't close $podidx: $!";
  394.     next;
  395.     }
  396.     print STDERR "Searching for $_\n" if $opt_v;
  397.     if ($opt_F) {
  398.     next unless -r;
  399.     push @found, $_ if $opt_m or containspod($_);
  400.     next;
  401.     }
  402.     # We must look both in @INC for library modules and in $bindir
  403.     # for executables, like h2xs or perldoc itself.
  404.     my @searchdirs = ($bindir, @INC);
  405.     unless ($opt_m) {
  406.     if ($Is_VMS) {
  407.         my($i,$trn);
  408.         for ($i = 0; $trn = $ENV{'DCL$PATH;'.$i}; $i++) {
  409.         push(@searchdirs,$trn);
  410.         }
  411.         push(@searchdirs,'perl_root:[lib.pod]')  # installed pods
  412.     }
  413.     else {
  414.         push(@searchdirs, grep(-d, split($Config{path_sep},
  415.                          $ENV{'PATH'})));
  416.     }
  417.     }
  418.     my @files = searchfor(0,$_,@searchdirs);
  419.     if (@files) {
  420.     print STDERR "Found as @files\n" if $opt_v;
  421.     }
  422.     else {
  423.     # no match, try recursive search
  424.     @searchdirs = grep(!/^\.\z/s,@INC);
  425.     @files= searchfor(1,$_,@searchdirs) if $opt_r;
  426.     if (@files) {
  427.         print STDERR "Loosely found as @files\n" if $opt_v;
  428.     }
  429.     else {
  430.         print STDERR "No " .
  431.         ($opt_m ? "module" : "documentation") . " found for \"$_\".\n";
  432.         if (@global_found) {
  433.         print STDERR "However, try\n";
  434.         for my $dir (@global_found) {
  435.             opendir(DIR, $dir) or die "opendir $dir: $!";
  436.             while (my $file = readdir(DIR)) {
  437.             next if ($file =~ /^\./s);
  438.             $file =~ s/\.(pm|pod)\z//;  # XXX: badfs
  439.             print STDERR "\tperldoc $_\::$file\n";
  440.             }
  441.             closedir DIR    or die "closedir $dir: $!";
  442.         }
  443.         }
  444.     }
  445.     }
  446.     push(@found,@files);
  447. }
  448.  
  449. if (!@found) {
  450.     exit ($Is_VMS ? 98962 : 1);
  451. }
  452.  
  453. if ($opt_l) {
  454.     print join("\n", @found), "\n";
  455.     exit;
  456. }
  457.  
  458. my $lines = $ENV{LINES} || 24;
  459.  
  460. my $no_tty;
  461. if (! -t STDOUT) { $no_tty = 1 }
  462. END { close(STDOUT) || die "Can't close STDOUT: $!" }
  463.  
  464. if ($Is_MSWin32) {
  465.     push @pagers, qw( more< less notepad );
  466.     unshift @pagers, $ENV{PAGER}  if $ENV{PAGER};
  467.     for (@found) { s,/,\\,g }
  468. }
  469. elsif ($Is_VMS) {
  470.     push @pagers, qw( most more less type/page );
  471. }
  472. elsif ($Is_Dos) {
  473.     push @pagers, qw( less.exe more.com< );
  474.     unshift @pagers, $ENV{PAGER}  if $ENV{PAGER};
  475. }
  476. else {
  477.     if ($^O eq 'os2') {
  478.       unshift @pagers, 'less', 'cmd /c more <';
  479.     }
  480.     push @pagers, qw( more less pg view cat );
  481.     unshift @pagers, $ENV{PAGER}  if $ENV{PAGER};
  482. }
  483. unshift @pagers, $ENV{PERLDOC_PAGER} if $ENV{PERLDOC_PAGER};
  484.  
  485. if ($opt_m) {
  486.     foreach my $pager (@pagers) {
  487.     if (system($pager, @found) == 0) {
  488.         exit;
  489.     }
  490.     }
  491.     if ($Is_VMS) { 
  492.     eval q{
  493.         use vmsish qw(status exit); 
  494.         exit $?;
  495.         1;
  496.     } or die;
  497.     }
  498.     exit(1);
  499. }
  500.  
  501. my @pod;
  502. if ($opt_f) {
  503.     my $perlfunc = shift @found;
  504.     open(PFUNC, "<", $perlfunc)
  505.     or die("Can't open $perlfunc: $!");
  506.  
  507.     # Functions like -r, -e, etc. are listed under `-X'.
  508.     my $search_string = ($opt_f =~ /^-[rwxoRWXOeszfdlpSbctugkTBMAC]$/)
  509.             ? 'I<-X' : $opt_f ;
  510.  
  511.     # Skip introduction
  512.     local $_;
  513.     while (<PFUNC>) {
  514.     last if /^=head2 Alphabetical Listing of Perl Functions/;
  515.     }
  516.  
  517.     # Look for our function
  518.     my $found = 0;
  519.     my $inlist = 0;
  520.     while (<PFUNC>) {
  521.     if (/^=item\s+\Q$search_string\E\b/o)  {
  522.         $found = 1;
  523.     }
  524.     elsif (/^=item/) {
  525.         last if $found > 1 and not $inlist;
  526.     }
  527.     next unless $found;
  528.     if (/^=over/) {
  529.         ++$inlist;
  530.     }
  531.     elsif (/^=back/) {
  532.         --$inlist;
  533.     }
  534.     push @pod, $_;
  535.     ++$found if /^\w/;    # found descriptive text
  536.     }
  537.     if (!@pod) {
  538.     die "No documentation for perl function `$opt_f' found\n";
  539.     }
  540.     close PFUNC        or die "Can't open $perlfunc: $!";
  541. }
  542.  
  543. if ($opt_q) {
  544.     local @ARGV = @found;    # I'm lazy, sue me.
  545.     my $found = 0;
  546.     my %found_in;
  547.     my $rx = eval { qr/$opt_q/ } or die <<EOD;
  548. Invalid regular expression '$opt_q' given as -q pattern:
  549.   $@
  550. Did you mean \\Q$opt_q ?
  551.  
  552. EOD
  553.  
  554.     for (@found) { die "invalid file spec: $!" if /[<>|]/ } 
  555.     local $_;
  556.     while (<>) {
  557.     if (/^=head2\s+.*(?:$opt_q)/oi) {
  558.         $found = 1;
  559.         push @pod, "=head1 Found in $ARGV\n\n" unless $found_in{$ARGV}++;
  560.     }
  561.     elsif (/^=head[12]/) {
  562.         $found = 0;
  563.     }
  564.     next unless $found;
  565.     push @pod, $_;
  566.     }
  567.     if (!@pod) {
  568.     die("No documentation for perl FAQ keyword `$opt_q' found\n");
  569.     }
  570. }
  571.  
  572. require File::Temp;
  573.  
  574. my ($tmpfd, $tmp) = File::Temp::tempfile(UNLINK => 1);
  575.  
  576. my $filter;
  577.  
  578. if (@pod) {
  579.     my ($buffd, $buffer) = File::Temp::tempfile(UNLINK => 1);
  580.     print $buffd "=over 8\n\n";
  581.     print $buffd @pod    or die "Can't print $buffer: $!";
  582.     print $buffd "=back\n";
  583.     close $buffd    or die "Can't close $buffer: $!";
  584.     @found = $buffer;
  585.     $filter = 1;
  586. }
  587.  
  588. foreach (@found) {
  589.     my $file = $_;
  590.     my $err;
  591.  
  592.     if ($opt_t) {
  593.     Pod::Text->new()->parse_from_file($file, $tmpfd);
  594.     }
  595.     elsif (not $opt_u) {
  596.     my $cmd = catfile($bindir, $pod2man) . " --lax $file | $opt_n -man";
  597.     $cmd .= " | col -x" if $^O =~ /hpux/;
  598.     my $rslt = `$cmd`;
  599.     $rslt = filter_nroff($rslt) if $filter;
  600.     unless (($err = $?)) {
  601.         print $tmpfd $rslt
  602.         or die "Can't print $tmp: $!";
  603.     }
  604.     }
  605.     if ($opt_u or $err) {
  606.     open(IN,"<", $file)   or die("Can't open $file: $!");
  607.     my $cut = 1;
  608.     local $_;
  609.     while (<IN>) {
  610.         $cut = $1 eq 'cut' if /^=(\w+)/;
  611.         next if $cut;
  612.         print $tmpfd $_
  613.         or die "Can't print $tmp: $!";
  614.     }
  615.     close IN    or die "Can't close $file: $!";
  616.     }
  617. }
  618. close $tmpfd
  619.     or die "Can't close $tmp: $!";
  620. page($tmp, $no_tty, @pagers);
  621.  
  622. exit;
  623.  
  624. sub is_tainted {
  625.     my $arg = shift;
  626.     my $nada = substr($arg, 0, 0);  # zero-length
  627.     local $@;  # preserve caller's version
  628.     eval { eval "# $nada" };
  629.     return length($@) != 0;
  630. }
  631.  
  632. sub am_taint_checking {
  633.     my($k,$v) = each %ENV;
  634.     return is_tainted($v);  
  635. }
  636.  
  637.  
  638. __END__
  639.  
  640. =head1 NAME
  641.  
  642. perldoc - Look up Perl documentation in pod format.
  643.  
  644. =head1 SYNOPSIS
  645.  
  646. B<perldoc> [B<-h>] [B<-v>] [B<-t>] [B<-u>] [B<-m>] [B<-l>] [B<-F>]  [B<-X>] PageName|ModuleName|ProgramName
  647.  
  648. B<perldoc> B<-f> BuiltinFunction
  649.  
  650. B<perldoc> B<-q> FAQ Keyword
  651.  
  652. =head1 DESCRIPTION
  653.  
  654. I<perldoc> looks up a piece of documentation in .pod format that is embedded
  655. in the perl installation tree or in a perl script, and displays it via
  656. C<pod2man | nroff -man | $PAGER>. (In addition, if running under HP-UX,
  657. C<col -x> will be used.) This is primarily used for the documentation for
  658. the perl library modules.
  659.  
  660. Your system may also have man pages installed for those modules, in
  661. which case you can probably just use the man(1) command.
  662.  
  663. If you are looking for a table of contents to the Perl library modules
  664. documentation, see the L<perltoc> page.
  665.  
  666. =head1 OPTIONS
  667.  
  668. =over 5
  669.  
  670. =item B<-h> help
  671.  
  672. Prints out a brief help message.
  673.  
  674. =item B<-v> verbose
  675.  
  676. Describes search for the item in detail.
  677.  
  678. =item B<-t> text output
  679.  
  680. Display docs using plain text converter, instead of nroff. This may be faster,
  681. but it won't look as nice.
  682.  
  683. =item B<-u> unformatted
  684.  
  685. Find docs only; skip reformatting by pod2*
  686.  
  687. =item B<-m> module
  688.  
  689. Display the entire module: both code and unformatted pod documentation.
  690. This may be useful if the docs don't explain a function in the detail
  691. you need, and you'd like to inspect the code directly; perldoc will find
  692. the file for you and simply hand it off for display.
  693.  
  694. =item B<-l> file name only
  695.  
  696. Display the file name of the module found.
  697.  
  698. =item B<-F> file names
  699.  
  700. Consider arguments as file names, no search in directories will be performed.
  701.  
  702. =item B<-f> perlfunc
  703.  
  704. The B<-f> option followed by the name of a perl built in function will
  705. extract the documentation of this function from L<perlfunc>.
  706.  
  707. =item B<-q> perlfaq
  708.  
  709. The B<-q> option takes a regular expression as an argument.  It will search
  710. the question headings in perlfaq[1-9] and print the entries matching
  711. the regular expression.
  712.  
  713. =item B<-X> use an index if present
  714.  
  715. The B<-X> option looks for an entry whose basename matches the name given on the
  716. command line in the file C<$Config{archlib}/pod.idx>.  The pod.idx file should
  717. contain fully qualified filenames, one per line.
  718.  
  719. =item B<-U> run insecurely
  720.  
  721. Because B<perldoc> does not run properly tainted, and is known to
  722. have security issues, it will not normally execute as the superuser.
  723. If you use the B<-U> flag, it will do so, but only after setting
  724. the effective and real IDs to nobody's or nouser's account, or -2
  725. if unavailable.  If it cannot relinquish its privileges, it will not
  726. run.  
  727.  
  728. =item B<PageName|ModuleName|ProgramName>
  729.  
  730. The item you want to look up.  Nested modules (such as C<File::Basename>)
  731. are specified either as C<File::Basename> or C<File/Basename>.  You may also
  732. give a descriptive name of a page, such as C<perlfunc>.
  733.  
  734. =back
  735.  
  736. =head1 ENVIRONMENT
  737.  
  738. Any switches in the C<PERLDOC> environment variable will be used before the
  739. command line arguments.  C<perldoc> also searches directories
  740. specified by the C<PERL5LIB> (or C<PERLLIB> if C<PERL5LIB> is not
  741. defined) and C<PATH> environment variables.
  742. (The latter is so that embedded pods for executables, such as
  743. C<perldoc> itself, are available.)  C<perldoc> will use, in order of
  744. preference, the pager defined in C<PERLDOC_PAGER>, C<MANPAGER>, or
  745. C<PAGER> before trying to find a pager on its own.  (C<MANPAGER> is not
  746. used if C<perldoc> was told to display plain text or unformatted pod.)
  747.  
  748. One useful value for C<PERLDOC_PAGER> is C<less -+C -E>.
  749.  
  750. =head1 VERSION
  751.  
  752. This is perldoc v2.04.
  753.  
  754. =head1 AUTHOR
  755.  
  756. Kenneth Albanowski <kjahds@kjahds.com>
  757.  
  758. Minor updates by Andy Dougherty <doughera@lafcol.lafayette.edu>,
  759. and others.
  760.  
  761. =cut
  762.  
  763. #
  764. # Version 2.04: Sun Aug 18 13:27:12 BST 2002
  765. #   Randy W. Sims <RandyS@ThePierianSpring.org>
  766. #   allow -n to enable nroff under Win32
  767. # Version 2.03: Sun Apr 23 16:56:34 BST 2000
  768. #    Hugo van der Sanden <hv@crypt0.demon.co.uk>
  769. #    don't die when 'use blib' fails
  770. # Version 2.02: Mon Mar 13 18:03:04 MST 2000
  771. #       Tom Christiansen <tchrist@perl.com>
  772. #    Added -U insecurity option
  773. # Version 2.01: Sat Mar 11 15:22:33 MST 2000 
  774. #       Tom Christiansen <tchrist@perl.com>, querulously.
  775. #       Security and correctness patches.
  776. #       What a twisted bit of distasteful spaghetti code.
  777. # Version 2.0: ????
  778. # Version 1.15: Tue Aug 24 01:50:20 EST 1999
  779. #       Charles Wilson <cwilson@ece.gatech.edu>
  780. #    changed /pod/ directory to /pods/ for cygwin
  781. #         to support cygwin/win32
  782. # Version 1.14: Wed Jul 15 01:50:20 EST 1998
  783. #       Robin Barker <rmb1@cise.npl.co.uk>
  784. #    -strict, -w cleanups
  785. # Version 1.13: Fri Feb 27 16:20:50 EST 1997
  786. #       Gurusamy Sarathy <gsar@activestate.com>
  787. #    -doc tweaks for -F and -X options
  788. # Version 1.12: Sat Apr 12 22:41:09 EST 1997
  789. #       Gurusamy Sarathy <gsar@activestate.com>
  790. #    -various fixes for win32
  791. # Version 1.11: Tue Dec 26 09:54:33 EST 1995
  792. #       Kenneth Albanowski <kjahds@kjahds.com>
  793. #   -added Charles Bailey's further VMS patches, and -u switch
  794. #   -added -t switch, with pod2text support
  795. #
  796. # Version 1.10: Thu Nov  9 07:23:47 EST 1995
  797. #        Kenneth Albanowski <kjahds@kjahds.com>
  798. #    -added VMS support
  799. #    -added better error recognition (on no found pages, just exit. On
  800. #     missing nroff/pod2man, just display raw pod.)
  801. #    -added recursive/case-insensitive matching (thanks, Andreas). This
  802. #     slows things down a bit, unfortunately. Give a precise name, and
  803. #     it'll run faster.
  804. #
  805. # Version 1.01:    Tue May 30 14:47:34 EDT 1995
  806. #        Andy Dougherty  <doughera@lafcol.lafayette.edu>
  807. #   -added pod documentation.
  808. #   -added PATH searching.
  809. #   -added searching pod/ subdirectory (mainly to pick up perlfunc.pod
  810. #    and friends.
  811. #
  812. #
  813. # TODO:
  814. #
  815. #    Cache directories read during sloppy match
  816.  
  817. __END__
  818. :endofperl
  819.