r7859: Merge a few scripts to one script that checks for the following unused
[samba.git] / source4 / script / find_unused_macros.pl
1 #!/usr/bin/perl
2 # Script that reads in configure and outputs the names of all the defines 
3 # it defines that are used nowhere in the code
4
5 # Arguments: C and H files
6
7 my %defined,%used,%files;
8
9 $in = shift;
10
11 while($tmp = shift) { 
12         $files{$tmp} = $tmp;
13         open(FI, $tmp);
14         while(<FI>) { 
15                 $line = $_;
16                 $cur = "";
17                 if(/^#define ([A-Za-z0-9_]+)/) {
18                         $defined{$1} = $tmp;
19                         $cur = $1;
20                 }
21
22                 $_ = $line;
23                 while(/([A-Za-z0-9_]+)/sgm) { 
24                         if($cur cmp $1) { $used{$1} = $tmp; }
25                 }
26         }
27         close FI;
28 }
29
30 foreach(keys %defined) {
31         if(!$used{$_}) { print "$_\n"; }
32 }