diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-12-03 03:02:54 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-12-03 03:02:54 +0000 |
commit | ba0a2090f574df90404f8a0bbe689389ce0ebcab (patch) | |
tree | 53f8d0ad53e5fc0f05d68a0073273080ef5bd392 /gnu/usr.bin/perl/utils | |
parent | 0121b80e4f69c2ad9631e8d20b5c91f3b2a40434 (diff) |
Resolve conflicts for perl 5.8.2, remove old files, and add OpenBSD-specific scaffolding
Diffstat (limited to 'gnu/usr.bin/perl/utils')
-rw-r--r-- | gnu/usr.bin/perl/utils/Makefile | 8 | ||||
-rw-r--r-- | gnu/usr.bin/perl/utils/c2ph.PL | 30 | ||||
-rw-r--r-- | gnu/usr.bin/perl/utils/dprofpp.PL | 104 | ||||
-rw-r--r-- | gnu/usr.bin/perl/utils/h2ph.PL | 96 | ||||
-rw-r--r-- | gnu/usr.bin/perl/utils/h2xs.PL | 245 | ||||
-rw-r--r-- | gnu/usr.bin/perl/utils/libnetcfg.PL | 6 | ||||
-rw-r--r-- | gnu/usr.bin/perl/utils/perlbug.PL | 6 | ||||
-rw-r--r-- | gnu/usr.bin/perl/utils/perldoc.PL | 830 |
8 files changed, 334 insertions, 991 deletions
diff --git a/gnu/usr.bin/perl/utils/Makefile b/gnu/usr.bin/perl/utils/Makefile index 3b1294ec47e..8b98950a1de 100644 --- a/gnu/usr.bin/perl/utils/Makefile +++ b/gnu/usr.bin/perl/utils/Makefile @@ -5,9 +5,9 @@ REALPERL = ../perl # Files to be built with variable substitution after miniperl is # available. Dependencies handled manually below (for now). -pl = c2ph.PL h2ph.PL h2xs.PL perlbug.PL perldoc.PL perlivp.PL pl2pm.PL splain.PL perlcc.PL dprofpp.PL libnetcfg.PL piconv.PL enc2xs.PL -plextract = c2ph h2ph h2xs perlbug perldoc perlivp pl2pm splain perlcc dprofpp libnetcfg piconv enc2xs -plextractexe = ./c2ph ./h2ph ./h2xs ./perlbug ./perldoc ./perlivp ./pl2pm ./splain ./perlcc ./dprofpp ./libnetcfg ./piconv ./enc2xs +pl = c2ph.PL cpan.PL h2ph.PL h2xs.PL perlbug.PL perldoc.PL perlivp.PL pl2pm.PL splain.PL perlcc.PL dprofpp.PL libnetcfg.PL piconv.PL enc2xs.PL +plextract = c2ph cpan h2ph h2xs perlbug perldoc perlivp pl2pm splain perlcc dprofpp libnetcfg piconv enc2xs +plextractexe = ./c2ph ./cpan ./h2ph ./h2xs ./perlbug ./perldoc ./perlivp ./pl2pm ./splain ./perlcc ./dprofpp ./libnetcfg ./piconv ./enc2xs all: $(plextract) @@ -29,6 +29,8 @@ $(plextract): c2ph: c2ph.PL ../config.sh +cpan: cpan.PL ../config.sh + h2ph: h2ph.PL ../config.sh h2xs: h2xs.PL ../config.sh diff --git a/gnu/usr.bin/perl/utils/c2ph.PL b/gnu/usr.bin/perl/utils/c2ph.PL index d676218ce39..91ecc04552b 100644 --- a/gnu/usr.bin/perl/utils/c2ph.PL +++ b/gnu/usr.bin/perl/utils/c2ph.PL @@ -184,9 +184,9 @@ declarations at least, but that's quite a bit. Prior to this point, anyone programming in perl who wanted to interact with C programs, like the kernel, was forced to guess the layouts of -the C strutures, and then hardwire these into his program. Of course, +the C structures, and then hardwire these into his program. Of course, when you took your wonderfully crafted program to a system where the -sgtty structure was laid out differently, you program broke. Which is +sgtty structure was laid out differently, your program broke. Which is a shame. We've had Larry's h2ph translator, which helped, but that only works on @@ -353,13 +353,25 @@ delete $intrinsics{'null'}; $indent = 2; $CC = 'cc'; -$CFLAGS = '-g -S'; +!NO!SUBS! + +if (($Config{gccversion} || '') =~ /^(\d+)\.(\d+)/ + and ($1 > 3 or ($1 == 3 and $2 >= 2))) { + print OUT q/$CFLAGS = '-gstabs -S';/; +} else { + print OUT q/$CFLAGS = '-g -S';/; +} + +print OUT <<'!NO!SUBS!'; + $DEFINES = ''; $perl++ if $0 =~ m#/?c2ph$#; require 'getopts.pl'; +use File::Temp 'tempdir'; + eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift; &Getopts('aixdpvtnws:') || &usage(0); @@ -488,9 +500,10 @@ if (@ARGV) { $ARGV[0] =~ s/\.c$/.s/; } else { - $TMP = "/tmp/c2ph.$$.c"; + $TMPDIR = tempdir(CLEANUP => 1); + $TMP = "$TMPDIR/c2ph.$$.c"; &system("cat @ARGV > $TMP") && exit 1; - &system("cd /tmp; $CC $CFLAGS $DEFINES $TMP") && exit 1; + &system("cd $TMPDIR; $CC $CFLAGS $DEFINES $TMP") && exit 1; unlink $TMP; $TMP =~ s/\.c$/.s/; @ARGV = ($TMP); @@ -1261,7 +1274,8 @@ sub fetch_template { } sub compute_intrinsics { - local($TMP) = "/tmp/c2ph-i.$$.c"; + $TMPDIR ||= tempdir(CLEANUP => 1); + local($TMP) = "$TMPDIR/c2ph-i.$$.c"; open (TMP, ">$TMP") || die "can't open $TMP: $!"; select(TMP); @@ -1289,7 +1303,7 @@ EOF close TMP; select(STDOUT); - open(PIPE, "cd /tmp && $CC $TMP && /tmp/a.out|"); + open(PIPE, "cd $TMPDIR && $CC $TMP && $TMPDIR/a.out|"); while (<PIPE>) { chop; split(' ',$_,2);; @@ -1298,7 +1312,7 @@ EOF $intrinsics{$_[1]} = $template{$_[0]}; } close(PIPE) || die "couldn't read intrinsics!"; - unlink($TMP, '/tmp/a.out'); + unlink($TMP, '$TMPDIR/a.out'); print STDERR "done\n" if $trace; } diff --git a/gnu/usr.bin/perl/utils/dprofpp.PL b/gnu/usr.bin/perl/utils/dprofpp.PL index aff0f9b1e38..eabc7b1cd66 100644 --- a/gnu/usr.bin/perl/utils/dprofpp.PL +++ b/gnu/usr.bin/perl/utils/dprofpp.PL @@ -14,9 +14,8 @@ use File::Spec; # 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 ($Config{'osname'} eq 'OS2'); # "case-forgiving" -$file =~ s/\.pl$/.com/ if ($Config{'osname'} eq 'VMS'); # "case-forgiving" +($file = basename($0)) =~ s/\.PL$//i; +$file .= '.COM' if ($^O eq 'VMS'); my $dprof_pm = File::Spec->catfile(File::Spec->updir, 'ext', 'Devel', 'DProf', 'DProf.pm'); my $VERSION = 0; @@ -31,6 +30,13 @@ close PM; if( $VERSION == 0 ){ die "Did not find VERSION in $dprof_pm"; } +my $stty = 'undef'; +foreach my $s (qw(/bin/stty /usr/bin/stty)) { + if (-x $s) { + $stty = qq["$s"]; + last; + } +} open OUT,">$file" or die "Can't create $file: $!"; print "Extracting $file (with variable substitutions)\n"; @@ -46,6 +52,7 @@ $Config{'startperl'} require 5.003; my \$VERSION = '$VERSION'; +my \$stty = $stty; !GROK!THIS! @@ -535,16 +542,16 @@ sub settime { $hz ||= 1; if( $opt_r ){ - $$runtime = ($rrun_rtime - $overhead - $over_rtime * $total_marks/$over_tests/2)/$hz; + $$runtime = ($rrun_rtime - $overhead)/$hz; } elsif( $opt_s ){ - $$runtime = ($rrun_stime - $overhead - $over_stime * $total_marks/$over_tests/2)/$hz; + $$runtime = ($rrun_stime - $overhead)/$hz; } elsif( $opt_u ){ - $$runtime = ($rrun_utime - $overhead - $over_utime * $total_marks/$over_tests/2)/$hz; + $$runtime = ($rrun_utime - $overhead)/$hz; } else{ - $$runtime = ($rrun_ustime - $overhead - ($over_utime + $over_stime) * $total_marks/$over_tests/2)/$hz; + $$runtime = ($rrun_ustime - $overhead)/$hz; } $$runtime = 0 unless $$runtime > 0; } @@ -575,10 +582,9 @@ sub display_tree { exclusives_in_tree($deep_times); my $kid; - local *kids = $deep_times->{kids}; # %kids my $time; - if (%kids) { + if (%{$deep_times->{kids}}) { $time = sprintf '%.*fs = (%.*f + %.*f)', $time_precision, $deep_times->{incl_time}/$hz, $time_precision, $deep_times->{excl_time}/$hz, @@ -589,7 +595,7 @@ sub display_tree { print ' ' x (2*$level), "$name x $deep_times->{count} \t${time}s\n" if $deep_times->{count}; - for $kid (sort kids_by_incl keys %kids) { + for $kid (sort kids_by_incl %{$deep_times->{kids}}) { display_tree( $deep_times->{kids}{$kid}, $kid, $level + 1 ); } } @@ -626,15 +632,16 @@ sub display { sub move_keys { my ($source, $dest) = @_; - my $kid; - - for $kid (keys %$source) { - if (exists $dest->{$kid}) { - $dest->{count} += $source->{count}; - $dest->{incl_time} += $source->{incl_time}; - move_keys($source->{kids},$dest->{kids}); + + for my $kid_name (keys %$source) { + my $source_kid = delete $source->{$kid_name}; + + if (my $dest_kid = $dest->{$kid_name}) { + $dest_kid->{count} += $source_kid->{count}; + $dest_kid->{incl_time} += $source_kid->{incl_time}; + move_keys($source_kid->{kids},$dest_kid->{kids}); } else { - $dest->{$kid} = delete $source->{$kid}; + $dest->{$kid_name} = $source_kid; } } } @@ -645,11 +652,11 @@ sub add_to_tree { $name = $curdeep_times->[-1]{name}; } die "Shorted?!" unless @$curdeep_times >= 2; - $curdeep_times->[-2]{kids}{$name} = { count => 0 , kids => {}, - incl_time => 0, - } - unless exists $curdeep_times->[-2]{kids}{$name}; - my $entry = $curdeep_times->[-2]{kids}{$name}; + my $entry = $curdeep_times->[-2]{kids}{$name} ||= { + count => 0, + kids => {}, + incl_time => 0, + }; # Now transfer to the new node (could not do earlier, since name can change) $entry->{count}++; $entry->{incl_time} += $t - $curdeep_times->[-1]{enter_stamp}; @@ -666,6 +673,7 @@ sub parsestack { my( $x, $z, $c, $id, $pack ); my @stack = (); my @tstack = (); + my %outer; my $tab = 3; my $in = 0; @@ -674,7 +682,6 @@ sub parsestack { my $l_name = ''; my $repcnt = 0; my $repstr = ''; - my $dprof_t = 0; my $dprof_stamp; my %cv_hash; my $in_level = not defined $opt_g; # Level deep in report grouping @@ -720,22 +727,22 @@ sub parsestack { $name = defined $syst ? $syst : $cv_hash{$usert}; } - next unless $in_level or $name eq $opt_g or $dir eq '*'; + next unless $in_level or $name eq $opt_g; if ( $dir eq '-' or $dir eq '*' ) { my $ename = $dir eq '*' ? $stack[-1][0] : $name; $overhead += $over_per_call; if ($name eq "Devel::DProf::write") { - $dprof_t += $t - $dprof_stamp; + $overhead += $t - $dprof_stamp; next; } elsif (defined $opt_g and $ename eq $opt_g) { $in_level--; } add_to_tree($curdeep_times, $ename, - $t - $dprof_t - $overhead) if $opt_S; + $t - $overhead) if $opt_S; exitstamp( \@stack, \@tstack, - $t - $dprof_t - $overhead, + $t - $overhead, $times, $ctimes, $ename, \$in, $tab, - $curdeep_times ); + $curdeep_times, \%outer ); } next unless $in_level or $name eq $opt_g; if( $dir eq '+' or $dir eq '*' ){ @@ -774,11 +781,12 @@ sub parsestack { push( @$idkeys, $name ); } $calls->{$name}++; + $outer{$name}++; push @$curdeep_times, { kids => {}, name => $name, - enter_stamp => $t - $dprof_t - $overhead, + enter_stamp => $t - $overhead, } if $opt_S; - $x = [ $name, $t - $dprof_t - $overhead ]; + $x = [ $name, $t - $overhead ]; push( @stack, $x ); # my children will put their time here @@ -792,6 +800,11 @@ sub parsestack { print ' ' x $l_in, "$l_name$repstr\n"; } + while (my ($key, $count) = each %outer) { + next unless $count; + warn "$key has $count unstacked calls in outer\n"; + } + if( @stack ){ if( ! $opt_F ){ warn "Garbled profile is missing some exit time stamps:\n"; @@ -807,11 +820,11 @@ sub parsestack { foreach $x ( reverse @stack ){ $name = $x->[0]; exitstamp( \@stack, \@tstack, - $t - $dprof_t - $overhead, $times, + $t - $overhead, $times, $ctimes, $name, \$in, $tab, - $curdeep_times ); + $curdeep_times, \%outer ); add_to_tree($curdeep_times, $name, - $t - $dprof_t - $overhead) + $t - $overhead) if $opt_S; } } @@ -823,7 +836,7 @@ sub parsestack { } sub exitstamp { - my($stack, $tstack, $t, $times, $ctimes, $name, $in, $tab, $deep) = @_; + my($stack, $tstack, $t, $times, $ctimes, $name, $in, $tab, $deep, $outer) = @_; my( $x, $c, $z ); $x = pop( @$stack ); @@ -852,8 +865,9 @@ sub exitstamp { $c = pop( @$tstack ); # total time this func has been active $z = $t - $x->[1]; - $ctimes->{$name} += $z; - $times->{$name} += ($z > $c)? $z - $c: 0; + $ctimes->{$name} += $z + unless --$outer->{$name}; + $times->{$name} += $z - $c; # pass my time to my parent if( @$tstack ){ $c = pop( @$tstack ); @@ -922,7 +936,7 @@ sub rby_avgcpu { $persecs->{$a} <=> $persecs->{$b} } format CSTAT_top = Total Elapsed Time = @>>>>>>> Seconds -(($rrun_rtime - $overhead - $over_rtime * $total_marks/$over_tests/2) / $hz) +(($rrun_rtime - $overhead) / $hz) @>>>>>>>>>> Time = @>>>>>>> Seconds $whichtime, $runtime @<<<<<<<< Times @@ -930,11 +944,17 @@ $incl_excl %Time ExclSec CumulS #Calls sec/call Csec/c Name . -format STAT = - ^>>> ^>>>> ^>>>>> ^>>>>> ^>>>>> ^>>>>> ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -$pcnt, $secs, $csecs, $ncalls, $percall, $cpercall, $name -. +BEGIN { + my $fmt = ' ^>>> ^>>>> ^>>>>> ^>>>>> ^>>>>> ^>>>>> ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'; + if (-t STDOUT and defined $stty and my ($cols) = `$stty -a` =~ /\bcolumns\s+(\d+)/) + { + $fmt .= '<' x ($cols - length $fmt) if $cols > 80; + } + eval "format STAT = \n$fmt" . ' +$pcnt, $secs, $csecs, $ncalls, $percall, $cpercall, $name +.'; +} !NO!SUBS! close OUT or die "Can't close $file: $!"; diff --git a/gnu/usr.bin/perl/utils/h2ph.PL b/gnu/usr.bin/perl/utils/h2ph.PL index d1772c6fe9f..d28dc731f08 100644 --- a/gnu/usr.bin/perl/utils/h2ph.PL +++ b/gnu/usr.bin/perl/utils/h2ph.PL @@ -42,8 +42,13 @@ use Config; use File::Path qw(mkpath); use Getopt::Std; -getopts('Dd:rlhaQ'); -use vars qw($opt_D $opt_d $opt_r $opt_l $opt_h $opt_a $opt_Q); +# Make sure read permissions for all are set: +if (defined umask && (umask() & 0444)) { + umask (umask() & ~0444); +} + +getopts('Dd:rlhaQe'); +use vars qw($opt_D $opt_d $opt_r $opt_l $opt_h $opt_a $opt_Q $opt_e); die "-r and -a options are mutually exclusive\n" if ($opt_r and $opt_a); my @inc_dirs = inc_dirs() if $opt_a; @@ -65,13 +70,21 @@ my %isatype; @isatype{@isatype} = (1) x @isatype; my $inif = 0; my %Is_converted; +my %bad_file = (); @ARGV = ('-') unless @ARGV; build_preamble_if_necessary(); +sub reindent($) { + my($text) = shift; + $text =~ s/\n/\n /g; + $text =~ s/ /\t/g; + $text; +} + my ($t, $tab, %curargs, $new, $eval_index, $dir, $name, $args, $outfile); -my ($incl, $next); +my ($incl, $incl_type, $next); while (defined (my $file = next_file())) { if (-l $file and -d $file) { link_if_possible($file) if ($opt_l); @@ -107,7 +120,9 @@ while (defined (my $file = next_file())) { open(OUT,">$Dest_dir/$outfile") || die "Can't create $outfile: $!\n"; } - print OUT "require '_h2ph_pre.ph';\n\n"; + print OUT + "require '_h2ph_pre.ph';\n\n", + "no warnings 'redefine';\n\n"; while (defined (local $_ = next_line($file))) { if (s/^\s*\#\s*//) { @@ -169,22 +184,31 @@ while (defined (my $file = next_file())) { print OUT $t,"unless(defined(\&$name)) {\n sub $name () {\t",$new,";}\n}\n"; } } - } elsif (/^(include|import)\s*[<"](.*)[>"]/) { - ($incl = $2) =~ s/\.h$/.ph/; - print OUT $t,"require '$incl';\n"; - } elsif(/^include_next\s*[<"](.*)[>"]/) { - ($incl = $1) =~ s/\.h$/.ph/; + } elsif (/^(include|import|include_next)\s*[<\"](.*)[>\"]/) { + $incl_type = $1; + $incl = $2; + if (($incl_type eq 'include_next') || + ($opt_e && exists($bad_file{$incl}))) { + $incl =~ s/\.h$/.ph/; print OUT ($t, "eval {\n"); $tab += 4; $t = "\t" x ($tab / 8) . ' ' x ($tab % 8); + print OUT ($t, "my(\@REM);\n"); + if ($incl_type eq 'include_next') { print OUT ($t, "my(\%INCD) = map { \$INC{\$_} => 1 } ", - "(grep { \$_ eq \"$incl\" } keys(\%INC));\n"); + "(grep { \$_ eq \"$incl\" } ", + "keys(\%INC));\n"); print OUT ($t, - "my(\@REM) = map { \"\$_/$incl\" } ", + "\@REM = map { \"\$_/$incl\" } ", "(grep { not exists(\$INCD{\"\$_/$incl\"})", - "and -f \"\$_/$incl\" } \@INC);\n"); + " and -f \"\$_/$incl\" } \@INC);\n"); + } else { + print OUT ($t, + "\@REM = map { \"\$_/$incl\" } ", + "(grep {-r \"\$_/$incl\" } \@INC);\n"); + } print OUT ($t, "require \"\$REM[0]\" if \@REM;\n"); $tab -= 4; @@ -193,6 +217,10 @@ while (defined (my $file = next_file())) { "};\n"); print OUT ($t, "warn(\$\@) if \$\@;\n"); + } else { + $incl =~ s/\.h$/.ph/; + print OUT $t,"require '$incl';\n"; + } } elsif (/^ifdef\s+(\w+)/) { print OUT $t,"if(defined(&$1)) {\n"; $tab += 4; @@ -274,22 +302,22 @@ while (defined (my $file = next_file())) { } } } - print OUT "1;\n"; - $Is_converted{$file} = 1; + if ($opt_e && exists($bad_file{$file})) { + unlink($Dest_dir . '/' . $outfile); + $next = ''; + } else { + print OUT "1;\n"; queue_includes_from($file) if ($opt_a); + } } -exit $Exit; - - -sub reindent($) { - my($text) = shift; - $text =~ s/\n/\n /g; - $text =~ s/ /\t/g; - $text; +if ($opt_e && (scalar(keys %bad_file) > 0)) { + warn "Was unable to convert the following files:\n"; + warn "\t" . join("\n\t",sort(keys %bad_file)) . "\n"; } +exit $Exit; sub expr { my $joined_args; @@ -463,10 +491,18 @@ sub next_line $out .= $1; } elsif ($in =~ s/^(\\.)//) { # \... $out .= $1; - } elsif ($in =~ s/^('(\\.|[^'\\])*')//) { # '... - $out .= $1; - } elsif ($in =~ s/^("(\\.|[^"\\])*")//) { # "... - $out .= $1; + } elsif ($in =~ /^'/) { # '... + if ($in =~ s/^('(\\.|[^'\\])*')//) { + $out .= $1; + } else { + next READ; + } + } elsif ($in =~ /^"/) { # "... + if ($in =~ s/^("(\\.|[^"\\])*")//) { + $out .= $1; + } else { + next READ; + } } elsif ($in =~ s/^\/\/.*//) { # //... # fall through } elsif ($in =~ m/^\/\*/) { # /*... @@ -485,7 +521,15 @@ sub next_line $in =~ s!\'T KNOW!!) { $out =~ s!I DON$!I_DO_NOT_KNOW!; } else { + if ($opt_e) { + warn "Cannot parse $file:\n$in\n"; + $bad_file{$file} = 1; + $in = ''; + $out = undef; + last READ; + } else { die "Cannot parse:\n$in\n"; + } } } diff --git a/gnu/usr.bin/perl/utils/h2xs.PL b/gnu/usr.bin/perl/utils/h2xs.PL index df89626b91f..8b43191aa47 100644 --- a/gnu/usr.bin/perl/utils/h2xs.PL +++ b/gnu/usr.bin/perl/utils/h2xs.PL @@ -144,6 +144,24 @@ C<AUTOLOAD> from the .pm file. Turn on debugging messages. +=item B<-e>, B<--omit-enums>=[I<regular expression>] + +If I<regular expression> is not given, skip all constants that are defined in +a C enumeration. Otherwise skip only those constants that are defined in an +enum whose name matches I<regular expression>. + +Since I<regular expression> is optional, make sure that this switch is followed +by at least one other switch if you omit I<regular expression> and have some +pending arguments such as header-file names. This is ok: + + h2xs -e -n Module::Foo foo.h + +This is not ok: + + h2xs -n Module::Foo -e foo.h + +In the latter, foo.h is taken as I<regular expression>. + =item B<-f>, B<--force> Allows an extension to be created for a header even if that header is @@ -267,57 +285,68 @@ also the section on L<LIMITATIONS of B<-x>>. =head1 EXAMPLES - # Default behavior, extension is Rusers - h2xs rpcsvc/rusers + # Default behavior, extension is Rusers + h2xs rpcsvc/rusers - # Same, but extension is RUSERS - h2xs -n RUSERS rpcsvc/rusers + # Same, but extension is RUSERS + h2xs -n RUSERS rpcsvc/rusers - # Extension is rpcsvc::rusers. Still finds <rpcsvc/rusers.h> - h2xs rpcsvc::rusers + # Extension is rpcsvc::rusers. Still finds <rpcsvc/rusers.h> + h2xs rpcsvc::rusers - # Extension is ONC::RPC. Still finds <rpcsvc/rusers.h> - h2xs -n ONC::RPC rpcsvc/rusers + # Extension is ONC::RPC. Still finds <rpcsvc/rusers.h> + h2xs -n ONC::RPC rpcsvc/rusers - # Without constant() or AUTOLOAD - h2xs -c rpcsvc/rusers + # Without constant() or AUTOLOAD + h2xs -c rpcsvc/rusers - # Creates templates for an extension named RPC - h2xs -cfn RPC + # Creates templates for an extension named RPC + h2xs -cfn RPC - # Extension is ONC::RPC. - h2xs -cfn ONC::RPC + # Extension is ONC::RPC. + h2xs -cfn ONC::RPC + + # Extension is Lib::Foo which works at least with Perl5.005_03. + # Constants are created for all #defines and enums h2xs can find + # in foo.h. + h2xs -b 5.5.3 -n Lib::Foo foo.h - # Makefile.PL will look for library -lrpc in - # additional directory /opt/net/lib - h2xs rpcsvc/rusers -L/opt/net/lib -lrpc + # Extension is Lib::Foo which works at least with Perl5.005_03. + # Constants are created for all #defines but only for enums + # whose names do not start with 'bar_'. + h2xs -b 5.5.3 -e '^bar_' -n Lib::Foo foo.h - # Extension is DCE::rgynbase - # prefix "sec_rgy_" is dropped from perl function names - h2xs -n DCE::rgynbase -p sec_rgy_ dce/rgynbase + # Makefile.PL will look for library -lrpc in + # additional directory /opt/net/lib + h2xs rpcsvc/rusers -L/opt/net/lib -lrpc - # Extension is DCE::rgynbase - # prefix "sec_rgy_" is dropped from perl function names - # subroutines are created for sec_rgy_wildcard_name and sec_rgy_wildcard_sid - h2xs -n DCE::rgynbase -p sec_rgy_ \ - -s sec_rgy_wildcard_name,sec_rgy_wildcard_sid dce/rgynbase + # Extension is DCE::rgynbase + # prefix "sec_rgy_" is dropped from perl function names + h2xs -n DCE::rgynbase -p sec_rgy_ dce/rgynbase - # Make XS without defines in perl.h, but with function declarations - # visible from perl.h. Name of the extension is perl1. - # When scanning perl.h, define -DEXT=extern -DdEXT= -DINIT(x)= - # Extra backslashes below because the string is passed to shell. - # Note that a directory with perl header files would - # be added automatically to include path. - h2xs -xAn perl1 -F "-DEXT=extern -DdEXT= -DINIT\(x\)=" perl.h + # Extension is DCE::rgynbase + # prefix "sec_rgy_" is dropped from perl function names + # subroutines are created for sec_rgy_wildcard_name and + # sec_rgy_wildcard_sid + h2xs -n DCE::rgynbase -p sec_rgy_ \ + -s sec_rgy_wildcard_name,sec_rgy_wildcard_sid dce/rgynbase - # Same with function declaration in proto.h as visible from perl.h. - h2xs -xAn perl2 perl.h,proto.h + # Make XS without defines in perl.h, but with function declarations + # visible from perl.h. Name of the extension is perl1. + # When scanning perl.h, define -DEXT=extern -DdEXT= -DINIT(x)= + # Extra backslashes below because the string is passed to shell. + # Note that a directory with perl header files would + # be added automatically to include path. + h2xs -xAn perl1 -F "-DEXT=extern -DdEXT= -DINIT\(x\)=" perl.h - # Same but select only functions which match /^av_/ - h2xs -M '^av_' -xAn perl2 perl.h,proto.h + # Same with function declaration in proto.h as visible from perl.h. + h2xs -xAn perl2 perl.h,proto.h - # Same but treat SV* etc as "opaque" types - h2xs -o '^[S]V \*$' -M '^av_' -xAn perl2 perl.h,proto.h + # Same but select only functions which match /^av_/ + h2xs -M '^av_' -xAn perl2 perl.h,proto.h + + # Same but treat SV* etc as "opaque" types + h2xs -o '^[S]V \*$' -M '^av_' -xAn perl2 perl.h,proto.h =head2 Extension based on F<.h> and F<.c> files @@ -463,7 +492,7 @@ See L<perlxs> and L<perlxstut> for additional details. use strict; -my( $H2XS_VERSION ) = ' $Revision: 1.22 $ ' =~ /\$Revision:\s+([^\s]+)/; +my( $H2XS_VERSION ) = ' $Revision: 1.23 $ ' =~ /\$Revision:\s+([^\s]+)/; my $TEMPLATE_VERSION = '0.01'; my @ARGS = @ARGV; my $compat_version = $]; @@ -475,6 +504,7 @@ $Text::Wrap::huge = 'overflow'; $Text::Wrap::columns = 80; use ExtUtils::Constant qw (WriteConstants WriteMakefileSnippet autoload); use File::Compare; +use File::Path; sub usage { warn "@_\n" if @_; @@ -497,6 +527,9 @@ OPTIONS: -c, --omit-constant Omit the constant() function and specialised AUTOLOAD from the XS file. -d, --debugging Turn on debugging messages. + -e, --omit-enums Omit constants from enums in the constant() function. + If a pattern is given, only the matching enums are + ignored. -f, --force Force creation of the extension even if the C header does not exist. -g, --global Include code for safely storing static data in the .xs file. @@ -538,6 +571,7 @@ my ($opt_A, $opt_a, $opt_c, $opt_d, + $opt_e, $opt_f, $opt_g, $opt_h, @@ -561,6 +595,7 @@ my ($opt_A, ); Getopt::Long::Configure('bundling'); +Getopt::Long::Configure('pass_through'); my %options = ( 'omit-autoload|A' => \$opt_A, @@ -575,6 +610,7 @@ my %options = ( 'compat-version|b=s' => \$opt_b, 'omit-constant|c' => \$opt_c, 'debugging|d' => \$opt_d, + 'omit-enums|e:s' => \$opt_e, 'force|f' => \$opt_f, 'global|g' => \$opt_g, 'help|h|?' => \$opt_h, @@ -673,9 +709,10 @@ my @path_h; while (my $arg = shift) { if ($arg =~ /^-l/i) { - $extralibs = "$arg @ARGV"; - last; + $extralibs .= "$arg "; + next; } + last if $extralibs; push(@path_h, $arg); } @@ -841,7 +878,34 @@ if( @path_h ){ } } } - close(CH); + if (defined $opt_e and !$opt_e) { + close(CH); + } + else { + # Work from miniperl too - on "normal" systems + my $SEEK_SET = eval 'use Fcntl qw/SEEK_SET/; SEEK_SET' or 0; + seek CH, 0, $SEEK_SET; + my $src = do { local $/; <CH> }; + close CH; + no warnings 'uninitialized'; + + # Remove C and C++ comments + $src =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs; + + while ($src =~ /(\benum\s*([\w_]*)\s*\{\s([\s\w=,]+)\})/gsc) { + my ($enum_name, $enum_body) = + $1 =~ /enum\s*([\w_]*)\s*\{\s([\s\w=,]+)\}/gs; + # skip enums matching $opt_e + next if $opt_e && $enum_name =~ /$opt_e/; + my $val = 0; + for my $item (split /,/, $enum_body) { + my ($key, $declared_val) = $item =~ /(\w*)\s*=\s*(.*)/; + $val = length($declared_val) ? $declared_val : 1 + $val; + $seen_define{$key} = $declared_val; + $const_names{$key}++; + } + } # while (...) + } # if (!defined $opt_e or $opt_e) } } } @@ -849,7 +913,6 @@ if( @path_h ){ # Save current directory so that C::Scan can use it my $cwd = File::Spec->rel2abs( File::Spec->curdir ); -my ($ext, $nested, @modparts, $modfname, $modpname); # As Ilya suggested, use a name that contains - and then it can't clash with # the names of any packages. A directory 'fallback' will clash with any # new pragmata down the fallback:: tree, but that seems unlikely. @@ -857,35 +920,21 @@ my $constscfname = 'const-c.inc'; my $constsxsfname = 'const-xs.inc'; my $fallbackdirname = 'fallback'; -$ext = chdir 'ext' ? 'ext/' : ''; - -if( $module =~ /::/ ){ - $nested = 1; - @modparts = split(/::/,$module); - $modfname = $modparts[-1]; - $modpname = join('/',@modparts); -} -else { - $nested = 0; - @modparts = (); - $modfname = $modpname = $module; -} - - +my $ext = chdir 'ext' ? 'ext/' : ''; + +my @modparts = split(/::/,$module); +my $modpname = join('-', @modparts); +my $modfname = pop @modparts; +my $modpmdir = join '/', 'lib', @modparts; +my $modpmname = join '/', $modpmdir, $modfname.'.pm'; + if ($opt_O) { warn "Overwriting existing $ext$modpname!!!\n" if -e $modpname; } else { die "Won't overwrite existing $ext$modpname\n" if -e $modpname; } -if( $nested ){ - my $modpath = ""; - foreach (@modparts){ - -d "$modpath$_" || mkdir("$modpath$_", 0777); - $modpath .= "$_/"; - } -} --d "$modpname" || mkdir($modpname, 0777); +-d "$modpname" || mkpath([$modpname], 0, 0775); chdir($modpname) || die "Can't chdir $ext$modpname: $!\n"; my %types_seen; @@ -1017,10 +1066,11 @@ if( ! $opt_X ){ # use XS, unless it was disabled } my @const_names = sort keys %const_names; -open(PM, ">$modfname.pm") || die "Can't create $ext$modpname/$modfname.pm: $!\n"; +-d $modpmdir || mkpath([$modpmdir], 0, 0775); +open(PM, ">$modpmname") || die "Can't create $ext$modpname/$modpmname: $!\n"; $" = "\n\t"; -warn "Writing $ext$modpname/$modfname.pm\n"; +warn "Writing $ext$modpname/$modpmname\n"; print PM <<"END"; package $module; @@ -1169,7 +1219,7 @@ print PM <<"END"; __END__ END -my ($email,$author); +my ($email,$author,$licence); eval { my $username; @@ -1185,6 +1235,14 @@ eval { $author ||= "A. U. Thor"; $email ||= 'a.u.thor@a.galaxy.far.far.away'; +$licence = sprintf << "DEFAULT", $^V; +Copyright (C) ${\(1900 + (localtime) [5])} by $author + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version %vd or, +at your option, any later version of Perl 5 you may have available. +DEFAULT + my $revhist = ''; $revhist = <<EOT if $opt_C; # @@ -1243,6 +1301,12 @@ if ($opt_x && $opt_a) { while ($name, $struct) = each %structs; } +# Prefix the default licence with hash symbols. +# Is this just cargo cult - it seems that the first thing that happens to this +# block is that all the hashes are then s///g out. +my $licence_hash = $licence; +$licence_hash =~ s/^/#/gm; + my $pod = <<"END" unless $opt_P; ## Below is stub documentation for your module. You'd better edit it! # @@ -1255,13 +1319,6 @@ my $pod = <<"END" unless $opt_P; # use $module; # blah blah blah # -#=head1 ABSTRACT -# -# This should be the abstract for $module. -# The abstract is used when making PPD (Perl Package Description) files. -# If you don't want an ABSTRACT you should also edit Makefile.PL to -# remove the ABSTRACT_FROM option. -# #=head1 DESCRIPTION # #Stub documentation for $module, created by h2xs. It looks like the @@ -1288,10 +1345,7 @@ $exp_doc$meth_doc$revhist # #=head1 COPYRIGHT AND LICENSE # -#Copyright ${\(1900 + (localtime) [5])} by $author -# -#This library is free software; you can redistribute it and/or modify -#it under the same terms as Perl itself. +$licence_hash # #=cut END @@ -1842,12 +1896,12 @@ use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( - 'NAME' => '$module', - 'VERSION_FROM' => '$modfname.pm', # finds \$VERSION - 'PREREQ_PM' => {$prereq_pm}, # e.g., Module::Name => 1.1 - (\$] >= 5.005 ? ## Add these new keywords supported since 5.005 - (ABSTRACT_FROM => '$modfname.pm', # retrieve abstract from module - AUTHOR => '$author <$email>') : ()), + NAME => '$module', + VERSION_FROM => '$modpmname', # finds \$VERSION + PREREQ_PM => {$prereq_pm}, # e.g., Module::Name => 1.1 + (\$] >= 5.005 ? ## Add these new keywords supported since 5.005 + (ABSTRACT_FROM => '$modpmname', # retrieve abstract from module + AUTHOR => '$author <$email>') : ()), END if (!$opt_X) { # print C stuff, unless XS is disabled $opt_F = '' unless defined $opt_F; @@ -1858,9 +1912,9 @@ if (!$opt_X) { # print C stuff, unless XS is disabled EOC print PL <<END; - 'LIBS' => ['$extralibs'], # e.g., '-lm' - 'DEFINE' => '$opt_F', # e.g., '-DHAVE_SOMETHING' -$Icomment 'INC' => '$I', # e.g., '${Ihelp}-I/usr/include/other' + LIBS => ['$extralibs'], # e.g., '-lm' + DEFINE => '$opt_F', # e.g., '-DHAVE_SOMETHING' +$Icomment INC => '$I', # e.g., '${Ihelp}-I/usr/include/other' END my $C = grep {$_ ne "$modfname.c"} @@ -1871,7 +1925,7 @@ END EOC print PL <<END; -$Ccomment $Cpre\'OBJECT' => '\$(O_FILES)', # link all the C files too +$Ccomment ${Cpre}OBJECT => '\$(O_FILES)', # link all the C files too END } # ' # Grr print PL ");\n"; @@ -1992,16 +2046,13 @@ COPYRIGHT AND LICENCE Put the correct copyright and licence information here. -Copyright (C) $thisyear $author - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. +$licence _RMEND_ close(RM) || die "Can't close $ext$modpname/README: $!\n"; my $testdir = "t"; -my $testfile = "$testdir/1.t"; +my $testfile = "$testdir/$modpname.t"; unless (-d "$testdir") { mkdir "$testdir" or die "Cannot mkdir $testdir: $!\n"; } @@ -2012,7 +2063,7 @@ open EX, ">$testfile" or die "Can't create $ext$modpname/$testfile: $!\n"; print EX <<_END_; # Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl 1.t' +# `make test'. After `make install' it should work as `perl $modpname.t' ######################### @@ -2126,7 +2177,7 @@ EOP warn "Writing $ext$modpname/MANIFEST\n"; open(MANI,'>MANIFEST') or die "Can't create MANIFEST: $!"; -my @files = grep { -f } (<*>, <t/*>, <$fallbackdirname/*>); +my @files = grep { -f } (<*>, <t/*>, <$fallbackdirname/*>, <$modpmdir/*>); if (!@files) { eval {opendir(D,'.');}; unless ($@) { @files = readdir(D); closedir(D); } diff --git a/gnu/usr.bin/perl/utils/libnetcfg.PL b/gnu/usr.bin/perl/utils/libnetcfg.PL index 5d0e6fbbd98..1f47c24a177 100644 --- a/gnu/usr.bin/perl/utils/libnetcfg.PL +++ b/gnu/usr.bin/perl/utils/libnetcfg.PL @@ -91,7 +91,7 @@ L<Net::Config>, L<Net::libnetFAQ> Graham Barr, the original Configure script of libnet. -Jarkko Hietaniemi, conversion into libnet cfg for inclusion into Perl 5.8. +Jarkko Hietaniemi, conversion into libnetcfg for inclusion into Perl 5.8. =cut @@ -368,9 +368,9 @@ Without options, the old configuration is shown. The default name of the old configuration file is by default "libnet.cfg", unless otherwise specified using the -i option, C<-i oldfile>, and it is searched first from the current directory, -and the from your module path. +and then from your module path. -The default name of new configuration file is "libnet.cfg", and by +The default name of the new configuration file is "libnet.cfg", and by default it is written to the current directory, unless otherwise specified using the -o option. diff --git a/gnu/usr.bin/perl/utils/perlbug.PL b/gnu/usr.bin/perl/utils/perlbug.PL index 4a1d3357a71..b9906f8acfe 100644 --- a/gnu/usr.bin/perl/utils/perlbug.PL +++ b/gnu/usr.bin/perl/utils/perlbug.PL @@ -138,7 +138,8 @@ my $Version = "1.34"; my( $file, $usefile, $cc, $address, $perlbug, $testaddress, $filename, $messageid, $domain, $subject, $from, $verbose, $ed, $outfile, $Is_MacOS, $category, $severity, - $fh, $me, $Is_MSWin32, $Is_Linux, $Is_VMS, $msg, $body, $andcc, %REP, $ok); + $fh, $me, $Is_MSWin32, $Is_Linux, $Is_VMS, $msg, $body, $andcc, %REP, $ok, + $Is_OpenBSD); my $perl_version = $^V ? sprintf("v%vd", $^V) : $]; @@ -211,6 +212,7 @@ sub Init { $Is_MSWin32 = $^O eq 'MSWin32'; $Is_VMS = $^O eq 'VMS'; $Is_Linux = lc($^O) eq 'linux'; + $Is_OpenBSD = lc($^O) eq 'openbsd'; $Is_MacOS = $^O eq 'MacOS'; @ARGV = split m/\s+/, @@ -833,7 +835,7 @@ sub Send { # on linux certain mail implementations won't accept the subject # as "~s subject" and thus the Subject header will be corrupted # so don't use Mail::Send to be safe - if ($::HaveSend && !$Is_Linux) { + if ($::HaveSend && !$Is_Linux && !$Is_OpenBSD) { $msg = new Mail::Send Subject => $subject, To => $address; $msg->cc($cc) if $cc; $msg->add("Reply-To",$from) if $from; diff --git a/gnu/usr.bin/perl/utils/perldoc.PL b/gnu/usr.bin/perl/utils/perldoc.PL index 76caaabda03..e201de9d910 100644 --- a/gnu/usr.bin/perl/utils/perldoc.PL +++ b/gnu/usr.bin/perl/utils/perldoc.PL @@ -1,5 +1,11 @@ #!/usr/local/bin/perl +# This is for generating the perldoc executable. +# It may eventually be expanded to generate many executables, as +# explained in the preface of /Programming Perl/ 3e. + +require 5; +use strict; use Config; use File::Basename qw(&basename &dirname); use Cwd; @@ -13,836 +19,40 @@ use Cwd; # 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. -$origdir = cwd; + +my $origdir = cwd; chdir dirname($0); -$file = basename($0, '.PL'); +my $file = basename($0, '.PL'); +my $file_shortname = $file; # should be like "perldoc", maybe "perlsyn", etc. +warn "How odd, I'm going to generate $file_shortname?!" + unless $file_shortname =~ m/^\w+$/; + $file .= '.com' if $^O eq 'VMS'; open OUT,">$file" or die "Can't create $file: $!"; -print "Extracting $file (with variable substitutions)\n"; +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+"\$@"}' if 0; -use warnings; -use strict; - -# make sure creat()s are neither too much nor too little -INIT { eval { umask(0077) } } # doubtless someone has no mask - -(my \$pager = <<'/../') =~ s/\\s*\\z//; -$Config{pager} -/../ -my \@pagers = (); -push \@pagers, \$pager if -x \$pager; +# This "$file" file was generated by "$0" -(my \$bindir = <<'/../') =~ s/\\s*\\z//; -$Config{scriptdirexp} -/../ - -(my \$pod2man = <<'/../') =~ s/\\s*\\z//; -pod2man$versiononly -/../ +require 5; +BEGIN { \$^W = 1 if \$ENV{'PERLDOCDEBUG'} } +use Pod::Perldoc; +exit( Pod::Perldoc->run() ); !GROK!THIS! -# In the following, perl variables are not expanded during extraction. - -print OUT <<'!NO!SUBS!'; - -use Fcntl; # for sysopen -use Getopt::Std; -use Config '%Config'; -use File::Spec::Functions qw(catfile splitdir); - -# -# Perldoc revision #1 -- look up a piece of documentation in .pod format that -# is embedded in the perl installation tree. -# -# This is not to be confused with Tom Christiansen's perlman, which is a -# man replacement, written in perl. This perldoc is strictly for reading -# the perl manuals, though it too is written in perl. -# -# Massive security and correctness patches applied to this -# noisome program by Tom Christiansen Sat Mar 11 15:22:33 MST 2000 - -if (@ARGV<1) { - my $me = $0; # Editing $0 is unportable - $me =~ s,.*/,,; - die <<EOF; -Usage: $me [-h] [-r] [-i] [-v] [-t] [-u] [-m] [-n program] [-l] [-F] [-X] PageName|ModuleName|ProgramName - $me -f PerlFunc - $me -q FAQKeywords - -The -h option prints more help. Also try "perldoc perldoc" to get -acquainted with the system. -EOF -} - -my @global_found = (); -my $global_target = ""; - -my $Is_VMS = $^O eq 'VMS'; -my $Is_MSWin32 = $^O eq 'MSWin32'; -my $Is_Dos = $^O eq 'dos'; -my $Is_OS2 = $^O eq 'os2'; - -sub usage{ - warn "@_\n" if @_; - # Erase evidence of previous errors (if any), so exit status is simple. - $! = 0; - die <<EOF; -perldoc [options] PageName|ModuleName|ProgramName... -perldoc [options] -f BuiltinFunction -perldoc [options] -q FAQRegex - -Options: - -h Display this help message - -r Recursive search (slow) - -i Ignore case - -t Display pod using pod2text instead of pod2man and nroff - (-t is the default on win32) - -u Display unformatted pod text - -m Display module's file in its entirety - -n Specify replacement for nroff - -l Display the module's file name - -F Arguments are file names, not modules - -v Verbosely describe what's going on - -X use index if present (looks for pod.idx at $Config{archlib}) - -q Search the text of questions (not answers) in perlfaq[1-9] - -U Run in insecure mode (superuser only) - -PageName|ModuleName... - is the name of a piece of documentation that you want to look at. You - may either give a descriptive name of the page (as in the case of - `perlfunc') the name of a module, either like `Term::Info' or like - `Term/Info', or the name of a program, like `perldoc'. - -BuiltinFunction - is the name of a perl function. Will extract documentation from - `perlfunc'. - -FAQRegex - is a regex. Will search perlfaq[1-9] for and extract any - questions that match. - -Any switches in the PERLDOC environment variable will be used before the -command line arguments. The optional pod index file contains a list of -filenames, one per line. - -EOF -} - -if (defined $ENV{"PERLDOC"}) { - require Text::ParseWords; - unshift(@ARGV, Text::ParseWords::shellwords($ENV{"PERLDOC"})); -} -!NO!SUBS! - -my $getopts = "mhtluvriFf:Xq:n:U"; -print OUT <<"!GET!OPTS!"; - -use vars qw( @{[map "\$opt_$_", ($getopts =~ /\w/g)]} ); - -getopts("$getopts") || usage; -!GET!OPTS! - -print OUT <<'!NO!SUBS!'; - -usage if $opt_h; - -# refuse to run if we should be tainting and aren't -# (but regular users deserve protection too, though!) -if (!($Is_VMS || $Is_MSWin32 || $Is_Dos || $Is_OS2) && ($> == 0 || $< == 0) - && !am_taint_checking()) -{{ - if ($opt_U) { - 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; # real uid - $> = $id; # effective uid - $< = $id; # real uid - $> = $id; # effective uid - }; - last if !$@ && $< && $>; - } - die "Superuser must not run $0 without security audit and taint checks.\n"; -}} - -$opt_n = "nroff" if !$opt_n; - -my $podidx; -if ($opt_X) { - $podidx = "$Config{'archlib'}/pod.idx"; - $podidx = "" unless -f $podidx && -r _ && -M _ <= 7; -} - -if ((my $opts = do{ no warnings; $opt_t + $opt_u + $opt_m + $opt_l }) > 1) { - usage("only one of -t, -u, -m or -l") -} -elsif ($Is_MSWin32 - || $Is_Dos - || !($ENV{TERM} && $ENV{TERM} !~ /dumb|emacs|none|unknown/i)) -{ - $opt_t = 1 unless $opts; -} - -if ($opt_t) { require Pod::Text; import Pod::Text; } - -my @pages; -if ($opt_f) { - @pages = ("perlfunc"); -} -elsif ($opt_q) { - @pages = ("perlfaq1" .. "perlfaq9"); -} -else { - @pages = @ARGV; -} - -# Does this look like a module or extension directory? -if (-f "Makefile.PL") { - - # Add ., lib to @INC (if they exist) - eval q{ use lib qw(. lib); 1; } or die; - - # don't add if superuser - if ($< && $> && -f "blib") { # don't be looking too hard now! - eval q{ use blib; 1 }; - warn $@ if $@ && $opt_v; - } -} - -sub containspod { - my($file, $readit) = @_; - return 1 if !$readit && $file =~ /\.pod\z/i; - local($_); - open(TEST,"<", $file) or die "Can't open $file: $!"; - while (<TEST>) { - if (/^=head/) { - close(TEST) or die "Can't close $file: $!"; - return 1; - } - } - close(TEST) or die "Can't close $file: $!"; - return 0; -} - -sub minus_f_nocase { - my($dir,$file) = @_; - my $path = catfile($dir,$file); - return $path if -f $path and -r _; - if (!$opt_i or $Is_VMS or $Is_MSWin32 or $Is_Dos or $^O eq 'os2') { - # on a case-forgiving file system or if case is important - # that is it all we can do - warn "Ignored $path: unreadable\n" if -f _; - return ''; - } - local *DIR; - # this is completely wicked. don't mess with $", and if - # you do, don't assume / is the dirsep! - local($")="/"; - my @p = ($dir); - my($p,$cip); - foreach $p (splitdir $file){ - my $try = catfile @p, $p; - stat $try; - if (-d _) { - push @p, $p; - if ( $p eq $global_target) { - my $tmp_path = catfile @p; - my $path_f = 0; - for (@global_found) { - $path_f = 1 if $_ eq $tmp_path; - } - push (@global_found, $tmp_path) unless $path_f; - print STDERR "Found as @p but directory\n" if $opt_v; - } - } - elsif (-f _ && -r _) { - return $try; - } - elsif (-f _) { - warn "Ignored $try: unreadable\n"; - } - elsif (-d "@p") { - my $found=0; - my $lcp = lc $p; - opendir DIR, "@p" or die "opendir @p: $!"; - while ($cip=readdir(DIR)) { - if (lc $cip eq $lcp){ - $found++; - last; - } - } - closedir DIR or die "closedir @p: $!"; - return "" unless $found; - push @p, $cip; - return "@p" if -f "@p" and -r _; - warn "Ignored @p: unreadable\n" if -f _; - } - } - return ""; -} - - -sub check_file { - my($dir,$file) = @_; - return "" if length $dir and not -d $dir; - if ($opt_m) { - return minus_f_nocase($dir,$file); - } - else { - my $path = minus_f_nocase($dir,$file); - return $path if length $path and containspod($path); - } - return ""; -} - - -sub searchfor { - my($recurse,$s,@dirs) = @_; - $s =~ s!::!/!g; - $s = VMS::Filespec::unixify($s) if $Is_VMS; - return $s if -f $s && containspod($s); - printf STDERR "Looking for $s in @dirs\n" if $opt_v; - my $ret; - my $i; - my $dir; - $global_target = (splitdir $s)[-1]; # XXX: why not use File::Basename? - for ($i=0; $i<@dirs; $i++) { - $dir = $dirs[$i]; - ($dir = VMS::Filespec::unixpath($dir)) =~ s!/\z!! if $Is_VMS; - 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 - $ret = check_file $dir,"$s.com") - or ( $^O eq 'os2' and - $ret = check_file $dir,"$s.cmd") - or ( ($Is_MSWin32 or $Is_Dos or $^O eq 'os2') and - $ret = check_file $dir,"$s.bat") - or ( $ret = check_file "$dir/pod","$s.pod") - or ( $ret = check_file "$dir/pod",$s) - or ( $ret = check_file "$dir/pods","$s.pod") - or ( $ret = check_file "$dir/pods",$s) - ) { - return $ret; - } - - if ($recurse) { - opendir(D,$dir) or die "Can't opendir $dir: $!"; - my @newdirs = map catfile($dir, $_), grep { - not /^\.\.?\z/s and - not /^auto\z/s and # save time! don't search auto dirs - -d catfile($dir, $_) - } readdir D; - closedir(D) or die "Can't closedir $dir: $!"; - next unless @newdirs; - # what a wicked map! - @newdirs = map((s/\.dir\z//,$_)[1],@newdirs) if $Is_VMS; - print STDERR "Also looking in @newdirs\n" if $opt_v; - push(@dirs,@newdirs); - } - } - return (); -} - -sub filter_nroff { - my @data = split /\n{2,}/, shift; - shift @data while @data and $data[0] !~ /\S/; # Go to header - shift @data if @data and $data[0] =~ /Contributed\s+Perl/; # Skip header - pop @data if @data and $data[-1] =~ /^\w/; # Skip footer, like - # 28/Jan/99 perl 5.005, patch 53 1 - join "\n\n", @data; -} - -sub page { - my ($tmp, $no_tty, @pagers) = @_; - if ($no_tty) { - open(TMP,"<", $tmp) or die "Can't open $tmp: $!"; - local $_; - while (<TMP>) { - print or die "Can't print to stdout: $!"; - } - close TMP or die "Can't close while $tmp: $!"; - } - else { - # 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; - } else { - last if system("$pager \"$tmp\"") == 0; - } - } - } -} - -my @found; -foreach (@pages) { - if ($podidx && open(PODIDX, $podidx)) { - my $searchfor = catfile split '::'; - print STDERR "Searching for '$searchfor' in $podidx\n" if $opt_v; - local $_; - while (<PODIDX>) { - chomp; - push(@found, $_) if m,/$searchfor(?:\.(?:pod|pm))?\z,i; - } - close(PODIDX) or die "Can't close $podidx: $!"; - next; - } - print STDERR "Searching for $_\n" if $opt_v; - if ($opt_F) { - next unless -r; - push @found, $_ if $opt_m or containspod($_); - next; - } - # We must look both in @INC for library modules and in $bindir - # for executables, like h2xs or perldoc itself. - my @searchdirs = ($bindir, @INC); - unless ($opt_m) { - if ($Is_VMS) { - my($i,$trn); - for ($i = 0; $trn = $ENV{'DCL$PATH;'.$i}; $i++) { - push(@searchdirs,$trn); - } - push(@searchdirs,'perl_root:[lib.pod]') # installed pods - } - else { - push(@searchdirs, grep(-d, split($Config{path_sep}, - $ENV{'PATH'}))); - } - } - my @files = searchfor(0,$_,@searchdirs); - if (@files) { - print STDERR "Found as @files\n" if $opt_v; - } - else { - # no match, try recursive search - @searchdirs = grep(!/^\.\z/s,@INC); - @files= searchfor(1,$_,@searchdirs) if $opt_r; - if (@files) { - print STDERR "Loosely found as @files\n" if $opt_v; - } - else { - print STDERR "No " . - ($opt_m ? "module" : "documentation") . " found for \"$_\".\n"; - if (@global_found) { - print STDERR "However, try\n"; - for my $dir (@global_found) { - opendir(DIR, $dir) or die "opendir $dir: $!"; - while (my $file = readdir(DIR)) { - next if ($file =~ /^\./s); - $file =~ s/\.(pm|pod)\z//; # XXX: badfs - print STDERR "\tperldoc $_\::$file\n"; - } - closedir DIR or die "closedir $dir: $!"; - } - } - } - } - push(@found,@files); -} - -if (!@found) { - exit ($Is_VMS ? 98962 : 1); -} - -if ($opt_l) { - print join("\n", @found), "\n"; - exit; -} - -my $lines = $ENV{LINES} || 24; - -my $no_tty; -if (! -t STDOUT) { $no_tty = 1 } -END { close(STDOUT) || die "Can't close STDOUT: $!" } - -if ($Is_MSWin32) { - push @pagers, qw( more< less notepad ); - unshift @pagers, $ENV{PAGER} if $ENV{PAGER}; - for (@found) { s,/,\\,g } -} -elsif ($Is_VMS) { - push @pagers, qw( most more less type/page ); -} -elsif ($Is_Dos) { - push @pagers, qw( less.exe more.com< ); - unshift @pagers, $ENV{PAGER} if $ENV{PAGER}; -} -else { - if ($^O eq 'os2') { - unshift @pagers, 'less', 'cmd /c more <'; - } - push @pagers, qw( more less pg view cat ); - unshift @pagers, $ENV{PAGER} if $ENV{PAGER}; -} -unshift @pagers, $ENV{PERLDOC_PAGER} if $ENV{PERLDOC_PAGER}; - -if ($opt_m) { - foreach my $pager (@pagers) { - if (system($pager, @found) == 0) { - exit; - } - } - if ($Is_VMS) { - eval q{ - use vmsish qw(status exit); - exit $?; - 1; - } or die; - } - exit(1); -} - -my @pod; -if ($opt_f) { - my $perlfunc = shift @found; - open(PFUNC, "<", $perlfunc) - or die("Can't open $perlfunc: $!"); - - # Functions like -r, -e, etc. are listed under `-X'. - my $search_string = ($opt_f =~ /^-[rwxoRWXOeszfdlpSbctugkTBMAC]$/) - ? 'I<-X' : $opt_f ; - - # Skip introduction - local $_; - while (<PFUNC>) { - last if /^=head2 Alphabetical Listing of Perl Functions/; - } - - # Look for our function - my $found = 0; - my $inlist = 0; - while (<PFUNC>) { - if (/^=item\s+\Q$search_string\E\b/o) { - $found = 1; - } - elsif (/^=item/) { - last if $found > 1 and not $inlist; - } - next unless $found; - if (/^=over/) { - ++$inlist; - } - elsif (/^=back/) { - --$inlist; - } - push @pod, $_; - ++$found if /^\w/; # found descriptive text - } - if (!@pod) { - die "No documentation for perl function `$opt_f' found\n"; - } - close PFUNC or die "Can't open $perlfunc: $!"; -} - -if ($opt_q) { - local @ARGV = @found; # I'm lazy, sue me. - my $found = 0; - my %found_in; - my $rx = eval { qr/$opt_q/ } or die <<EOD; -Invalid regular expression '$opt_q' given as -q pattern: - $@ -Did you mean \\Q$opt_q ? - -EOD - - for (@found) { die "invalid file spec: $!" if /[<>|]/ } - local $_; - while (<>) { - if (/^=head2\s+.*(?:$opt_q)/oi) { - $found = 1; - push @pod, "=head1 Found in $ARGV\n\n" unless $found_in{$ARGV}++; - } - elsif (/^=head[12]/) { - $found = 0; - } - next unless $found; - push @pod, $_; - } - if (!@pod) { - die("No documentation for perl FAQ keyword `$opt_q' found\n"); - } -} - -require File::Temp; - -my ($tmpfd, $tmp) = File::Temp::tempfile(UNLINK => 1); - -my $filter; - -if (@pod) { - 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"; - close $buffd or die "Can't close $buffer: $!"; - @found = $buffer; - $filter = 1; -} - -foreach (@found) { - my $file = $_; - my $err; - - if ($opt_t) { - Pod::Text->new()->parse_from_file($file, $tmpfd); - } - elsif (not $opt_u) { - 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; - unless (($err = $?)) { - print $tmpfd $rslt - or die "Can't print $tmp: $!"; - } - } - if ($opt_u or $err) { - open(IN,"<", $file) or die("Can't open $file: $!"); - my $cut = 1; - local $_; - while (<IN>) { - $cut = $1 eq 'cut' if /^=(\w+)/; - next if $cut; - print $tmpfd $_ - or die "Can't print $tmp: $!"; - } - close IN or die "Can't close $file: $!"; - } -} -close $tmpfd - or die "Can't close $tmp: $!"; -page($tmp, $no_tty, @pagers); - -exit; - -sub is_tainted { - my $arg = shift; - my $nada = substr($arg, 0, 0); # zero-length - local $@; # preserve caller's version - eval { eval "# $nada" }; - return length($@) != 0; -} - -sub am_taint_checking { - my($k,$v) = each %ENV; - return is_tainted($v); -} - - -__END__ - -=head1 NAME - -perldoc - Look up Perl documentation in pod format. - -=head1 SYNOPSIS - -B<perldoc> [B<-h>] [B<-v>] [B<-t>] [B<-u>] [B<-m>] [B<-l>] [B<-F>] [B<-X>] PageName|ModuleName|ProgramName - -B<perldoc> B<-f> BuiltinFunction - -B<perldoc> B<-q> FAQ Keyword - -=head1 DESCRIPTION - -I<perldoc> looks up a piece of documentation in .pod format that is embedded -in the perl installation tree or in a perl script, and displays it via -C<pod2man | nroff -man | $PAGER>. (In addition, if running under HP-UX, -C<col -x> will be used.) This is primarily used for the documentation for -the perl library modules. - -Your system may also have man pages installed for those modules, in -which case you can probably just use the man(1) command. - -If you are looking for a table of contents to the Perl library modules -documentation, see the L<perltoc> page. - -=head1 OPTIONS - -=over 5 - -=item B<-h> help - -Prints out a brief help message. - -=item B<-v> verbose - -Describes search for the item in detail. - -=item B<-t> text output - -Display docs using plain text converter, instead of nroff. This may be faster, -but it won't look as nice. - -=item B<-u> unformatted - -Find docs only; skip reformatting by pod2* - -=item B<-m> module - -Display the entire module: both code and unformatted pod documentation. -This may be useful if the docs don't explain a function in the detail -you need, and you'd like to inspect the code directly; perldoc will find -the file for you and simply hand it off for display. - -=item B<-l> file name only - -Display the file name of the module found. - -=item B<-F> file names - -Consider arguments as file names, no search in directories will be performed. - -=item B<-f> perlfunc - -The B<-f> option followed by the name of a perl built in function will -extract the documentation of this function from L<perlfunc>. - -=item B<-q> perlfaq - -The B<-q> option takes a regular expression as an argument. It will search -the question headings in perlfaq[1-9] and print the entries matching -the regular expression. - -=item B<-X> use an index if present - -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. - -=item B<-U> run insecurely - -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 relinquish its privileges, it will not -run. - -=item B<PageName|ModuleName|ProgramName> - -The item you want to look up. Nested modules (such as C<File::Basename>) -are specified either as C<File::Basename> or C<File/Basename>. You may also -give a descriptive name of a page, such as C<perlfunc>. - -=back - -=head1 ENVIRONMENT - -Any switches in the C<PERLDOC> environment variable will be used before the -command line arguments. C<perldoc> also searches directories -specified by the C<PERL5LIB> (or C<PERLLIB> if C<PERL5LIB> is not -defined) and C<PATH> environment variables. -(The latter is so that embedded pods for executables, such as -C<perldoc> itself, are available.) C<perldoc> will use, in order of -preference, the pager defined in C<PERLDOC_PAGER>, C<MANPAGER>, or -C<PAGER> before trying to find a pager on its own. (C<MANPAGER> is not -used if C<perldoc> was told to display plain text or unformatted pod.) - -One useful value for C<PERLDOC_PAGER> is C<less -+C -E>. - -=head1 VERSION - -This is perldoc v2.03. - -=head1 AUTHOR - -Kenneth Albanowski <kjahds@kjahds.com> - -Minor updates by Andy Dougherty <doughera@lafcol.lafayette.edu>, -and others. - -=cut - -# -# Version 2.03: Sun Apr 23 16:56:34 BST 2000 -# Hugo van der Sanden <hv@crypt0.demon.co.uk> -# don't die when 'use blib' fails -# Version 2.02: Mon Mar 13 18:03:04 MST 2000 -# Tom Christiansen <tchrist@perl.com> -# Added -U insecurity option -# Version 2.01: Sat Mar 11 15:22:33 MST 2000 -# Tom Christiansen <tchrist@perl.com>, querulously. -# Security and correctness patches. -# What a twisted bit of distasteful spaghetti code. -# Version 2.0: ???? -# Version 1.15: Tue Aug 24 01:50:20 EST 1999 -# Charles Wilson <cwilson@ece.gatech.edu> -# changed /pod/ directory to /pods/ for cygwin -# to support cygwin/win32 -# Version 1.14: Wed Jul 15 01:50:20 EST 1998 -# Robin Barker <rmb1@cise.npl.co.uk> -# -strict, -w cleanups -# Version 1.13: Fri Feb 27 16:20:50 EST 1997 -# Gurusamy Sarathy <gsar@activestate.com> -# -doc tweaks for -F and -X options -# Version 1.12: Sat Apr 12 22:41:09 EST 1997 -# Gurusamy Sarathy <gsar@activestate.com> -# -various fixes for win32 -# Version 1.11: Tue Dec 26 09:54:33 EST 1995 -# Kenneth Albanowski <kjahds@kjahds.com> -# -added Charles Bailey's further VMS patches, and -u switch -# -added -t switch, with pod2text support -# -# Version 1.10: Thu Nov 9 07:23:47 EST 1995 -# Kenneth Albanowski <kjahds@kjahds.com> -# -added VMS support -# -added better error recognition (on no found pages, just exit. On -# missing nroff/pod2man, just display raw pod.) -# -added recursive/case-insensitive matching (thanks, Andreas). This -# slows things down a bit, unfortunately. Give a precise name, and -# it'll run faster. -# -# Version 1.01: Tue May 30 14:47:34 EDT 1995 -# Andy Dougherty <doughera@lafcol.lafayette.edu> -# -added pod documentation. -# -added PATH searching. -# -added searching pod/ subdirectory (mainly to pick up perlfunc.pod -# and friends. -# -# -# TODO: -# -# Cache directories read during sloppy match -!NO!SUBS! close OUT or die "Can't close $file: $!"; chmod 0755, $file or die "Can't reset permissions for $file: $!\n"; exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':'; chdir $origdir; + |