File: counts

package info (click to toggle)
perl-tk 1%3A804.033-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 34,724 kB
  • ctags: 37,174
  • sloc: ansic: 349,541; perl: 52,192; sh: 17,904; makefile: 5,732; asm: 3,565; ada: 1,681; pascal: 1,089; cpp: 1,006; yacc: 883; cs: 879
file content (76 lines) | stat: -rwxr-xr-x 1,173 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/local/bin/perl

sub count
{
 local($file) = @_;
 if (open(C,"gcc -E -DHAVE_UNISTD_H $file|"))
  {
   my $match = 0;
   local(%vars);
   while (<C>)
   {
    next if (/^\s*$/);
    $match = /$file/ if (/^#/);
    if ($match)
     {
      study;
      &match;
     }
   }
   close(C);
   $match = 0;
   foreach (keys %vars)
    {
     $file{$_} .= "$file($vars{$_}),";
     $match += $vars{$_};
    }
   printf(STDERR "%5d $file\n",$match);
  }
 else
  {
   warn "Cannot open pipe to $file";
  }
}

open(NEED,"<need") || die;
while (<NEED>)
{
 next if (/^ld:/);
 next if (/^\s+\./);
 if (/^([A-Za-z][A-Za-z0-9_]*).*\.o\s*$/)
  {
   $need{$1}++;
  }
 elsif (/^\s+_([_A-Za-z][A-Za-z0-9_]*)\s*$/)
  {
   my $sym = $1;
   $need{$sym}++ unless($sym =~ /^_/);
  }
 else
  {
   warn "No match:$_";
  }
}
close(NEED);

print STDERR "Building proc\n";
$proc = "sub match {\n";
foreach (keys %need)
{
 $proc .= " \$count{\"$_\"}++,\$vars{\"$_\"}++ if (/\\b$_\\b/);\n"
}
$proc .= "}\n";
print STDERR "eval...\n";
eval ($proc);

foreach (@ARGV)
 {
  &count($_);
 }

foreach (sort keys %need)
{
 my $file = $file{$_};
 chop($file);
 printf("%6d %-20s %s\n",$count{$_},$_,$file);
}