FreeBSD Bugzilla – Attachment 17051 Details for
Bug 31088
Make whereis.pl use strict, and a couple of minor cleanups
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 5.56 KB, created by
jos
on 2001-10-06 22:00:07 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
jos
Created:
2001-10-06 22:00:07 UTC
Size:
5.56 KB
patch
obsolete
>--- whereis.pl.orig Sat Oct 6 13:47:54 2001 >+++ whereis.pl Sat Oct 6 13:48:11 2001 >@@ -31,31 +31,42 @@ > # $FreeBSD: src/usr.bin/whereis/whereis.pl,v 1.8 1999/08/28 01:07:37 peter Exp $ > # > >+use strict; >+ > sub usage > { >- print STDERR "usage: $0 [-bms] [-u] [-BMS dir... -f] name ...\n"; >+ warn "usage: $0 [-bms] [-u] [-BMS dir... -f] name ...\n"; > exit 1; > } > >+my $opt_b = 0; >+my $opt_m = 0; >+my $opt_s = 0; >+my $opt_u = 0; >+my $manpath; >+my(@binaries, @manuals, @sources, @names); >+ >+ > sub scanopts > { >- local($i, $j); >+ my($i, $j); >+ $i = 0; > arg: > while ($ARGV[$i] =~ /^-/) { > opt: >- for ($j = 1; $j < length($ARGV[$i]); $j++) { >+ for ($j = 1; $j < length($ARGV[$i]); ++$j) { > local($_) = substr($ARGV[$i], $j, 1); >- local($what, @list); >- $opt_b++, next opt if /b/; >- $opt_m++, next opt if /m/; >- $opt_s++, next opt if /s/; >- $opt_u++, next opt if /u/; >+ my($what, @list); >+ ++$opt_b, next opt if /b/; >+ ++$opt_m, next opt if /m/; >+ ++$opt_s, next opt if /s/; >+ ++$opt_u, next opt if /u/; > &usage unless /[BMS]/; > > # directory list processing > $what = $_; @list = (); > push(@list, substr($ARGV[$i], $j+1)) if $j+1 < length($ARGV[$i]); >- $i++; >+ ++$i; > while ($i <= $#ARGV && $ARGV[$i] !~ /^-/) { > push(@list, $ARGV[$i++]); > } >@@ -66,7 +77,7 @@ > $i++, last arg if $ARGV[$i] =~ /^-f$/; > next arg; > } >- $i++; >+ ++$i; > } > &usage if $i > $#ARGV; > >@@ -78,12 +89,7 @@ > > sub decolonify > { >- local($list) = @_; >- local($_, @rv); >- foreach(split(/:/, $list)) { >- push(@rv, $_); >- } >- return @rv; >+ return split(/:/, shift); > } > > >@@ -92,14 +98,12 @@ > # default to all if no type requested > if ($opt_b + $opt_m + $opt_s == 0) {$opt_b = $opt_m = $opt_s = 1;} > >-if (!defined(@binaries)) { >+unless (@binaries) { > # > # first, use default path, then append /usr/libexec and the user's path > # >- local($cs_path) = `/sbin/sysctl -n user.cs_path`; >- local(@list, %path); >- >- chop($cs_path); >+ chop(my($cs_path) = `/sbin/sysctl -n user.cs_path`); >+ my(@list, %path); > > @list = &decolonify($cs_path); > push(@list, "/usr/libexec"); >@@ -108,33 +112,31 @@ > # resolve ~, remove duplicates > foreach (@list) { > s/^~/$ENV{'HOME'}/ if /^~/; >- push(@binaries, $_) if !$path{$_}; >- $path{$_}++; >+ push(@binaries, $_) unless $path{$_}; >+ ++$path{$_}; > } > } > >-if (!defined(@manuals)) { >+unless (@manuals) { > # > # first, use default manpath, then append user's $MANPATH > # >- local($usermanpath) = $ENV{'MANPATH'}; >+ my($usermanpath) = $ENV{'MANPATH'} || ''; > delete $ENV{'MANPATH'}; >- local($manpath) = `/usr/bin/manpath`; >- local(@list, %path, $i); >- >- chop($manpath); >+ chop($manpath = `/usr/bin/manpath`); >+ my(@list, %path); > > @list = &decolonify($manpath); > push(@list, &decolonify($usermanpath)); > > # remove duplicates > foreach (@list) { >- push(@manuals, $_) if !$path{$_}; >- $path{$_}++; >+ push(@manuals, $_) unless $path{$_}; >+ ++$path{$_}; > } > } > >-if (!defined(@sources)) { >+unless (@sources) { > # > # default command sources > # >@@ -149,6 +151,7 @@ > # > # if /usr/ports exists, look in all its subdirs, too > # >+ local *PORTS; > if (-d "/usr/ports" && opendir(PORTS, "/usr/ports")) { > while ($_ = readdir(PORTS)) { > next if /^\.\.?$/; >@@ -163,31 +166,30 @@ > if ($opt_m) { > # construct a new MANPATH > foreach (@manuals) { >- next if ! -d $_; >- if ($manpath) { $manpath .= ":$_"; } >- else { $manpath = $_; } >+ next unless -d; >+ $manpath .= $manpath ? ":$_" : $_; > } > } > > # > # main loop > # >-foreach $name (@names) { >+foreach my $name (@names) { > $name =~ s|^.*/||; # strip leading path name component > $name =~ s/,v$//; $name =~ s/^s\.//; # RCS or SCCS suffix/prefix >- $name =~ s/\.(Z|z|gz)$//; # compression suffix >+ $name =~ s/\.(Z|z|gz|bz2)$//; # compression suffix > >- $line = ""; >- $unusual = 0; >+ my $line = ""; >+ my $unusual = 0; > > if ($opt_b) { > # > # Binaries have to match exactly, and must be regular executable > # files. > # >- $unusual++; >+ ++$unusual; > foreach (@binaries) { >- $line .= " $_/$name", $unusual--, last if -f "$_/$name" && -x _; >+ $line .= " $_/$name", --$unusual, last if -f "$_/$name" && -x _; > } > } > >@@ -195,13 +197,12 @@ > # > # Ask the man command to do the search for us. > # >- $unusual++; >- chop($result = `man -S 1:8 -M $manpath -w $name 2> /dev/null`); >+ ++$unusual; >+ chop(my $result = `man -S 1:8 -M $manpath -w $name 2> /dev/null`); > if ($result ne '') { >- $unusual--; >- ($cat, $junk, $src) = split(/[() \t\n]+/, $result); >- if ($src ne '') { $line .= " $src"; } >- else { $line .= " $cat"; } >+ --$unusual; >+ my($cat, $junk, $src) = split(/[()\s]+/, $result); >+ $line .= $src ? " $src" : " $cat"; > } > } > >@@ -209,10 +210,10 @@ > # > # Sources match if a subdir with the exact name is found. > # >- $found = 0; >- $unusual++; >+ my $found = 0; >+ ++$unusual; > foreach (@sources) { >- $line .= " $_/$name", $unusual--, $found++ if -d "$_/$name"; >+ $line .= " $_/$name", --$unusual, ++$found if -d "$_/$name"; > } > # > # If not yet found, ask locate(1) to do the search for us. >@@ -223,9 +224,9 @@ > # > if (!$found && open(LOCATE, "locate */$name 2>/dev/null |")) { > locate_item: >- while (chop($loc = <LOCATE>)) { >+ while (chop(my $loc = <LOCATE>)) { > foreach (@sources) { >- $line .= " $loc", $unusual--, last locate_item >+ $line .= " $loc", --$unusual, last locate_item > if $loc =~ m|^$_/[^/]+/|; > } > } >@@ -239,4 +240,3 @@ > print "$name:$line\n"; > } > } >-
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 31088
: 17051