| 1 |
#!/usr/local/bin/perl |
| 2 |
|
| 3 |
sub count |
| 4 |
{ |
| 5 |
local($file) = @_; |
| 6 |
if (open(C,"gcc -E -DHAVE_UNISTD_H $file|")) |
| 7 |
{ |
| 8 |
my $match = 0; |
| 9 |
local(%vars); |
| 10 |
while (<C>) |
| 11 |
{ |
| 12 |
next if (/^\s*$/); |
| 13 |
$match = m/$file/ if (/^#/); |
| 14 |
if ($match) |
| 15 |
{ |
| 16 |
study; |
| 17 |
&match; |
| 18 |
} |
| 19 |
} |
| 20 |
close(C); |
| 21 |
$match = 0; |
| 22 |
foreach (keys %vars) |
| 23 |
{ |
| 24 |
$file{$_} .= "$file($vars{$_}),"; |
| 25 |
$match += $vars{$_}; |
| 26 |
} |
| 27 |
printf(STDERR "%5d $file\n",$match); |
| 28 |
} |
| 29 |
else |
| 30 |
{ |
| 31 |
warn "Cannot open pipe to $file"; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
open(NEED,"<need") || die; |
| 36 |
while (<NEED>) |
| 37 |
{ |
| 38 |
next if (/^ld:/); |
| 39 |
next if (/^\s+\./); |
| 40 |
if (/^([A-Za-z][A-Za-z0-9_]*).*\.o\s*$/) |
| 41 |
{ |
| 42 |
$need{$1}++; |
| 43 |
} |
| 44 |
elsif (/^\s+_([_A-Za-z][A-Za-z0-9_]*)\s*$/) |
| 45 |
{ |
| 46 |
my $sym = $1; |
| 47 |
$need{$sym}++ unless($sym =~ /^_/); |
| 48 |
} |
| 49 |
else |
| 50 |
{ |
| 51 |
warn "No match:$_"; |
| 52 |
} |
| 53 |
} |
| 54 |
close(NEED); |
| 55 |
|
| 56 |
print STDERR "Building proc\n"; |
| 57 |
$proc = "sub match {\n"; |
| 58 |
foreach (keys %need) |
| 59 |
{ |
| 60 |
$proc .= " \$count{\"$_\"}++,\$vars{\"$_\"}++ if (/\\b$_\\b/);\n" |
| 61 |
} |
| 62 |
$proc .= "}\n"; |
| 63 |
print STDERR "eval...\n"; |
| 64 |
eval ($proc); |
| 65 |
|
| 66 |
foreach (@ARGV) |
| 67 |
{ |
| 68 |
&count($_); |
| 69 |
} |
| 70 |
|
| 71 |
foreach (sort keys %need) |
| 72 |
{ |
| 73 |
my $file = $file{$_}; |
| 74 |
chop($file); |
| 75 |
printf("%6d %-20s %s\n",$count{$_},$_,$file); |
| 76 |
} |