Add script that reports unused macros/defines
[sfrench/samba-autobuild/.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 # First, make a list of defines in configure
10 $in = shift;
11
12 while($tmp = shift) { 
13         $files{$tmp} = $tmp;
14         open(FI, $tmp);
15         while(<FI>) { 
16                 $line = $_;
17                 $cur = "";
18                 if(/^#define ([A-Za-z0-9_]+)/) {
19                         $defined{$1} = $tmp;
20                         $cur = $1;
21                 }
22
23                 $_ = $line;
24                 while(/([A-Za-z0-9_]+)/sgm) { 
25                         if($cur cmp $1) { $used{$1} = $tmp; }
26                 }
27         }
28         close FI;
29 }
30
31 foreach(keys %defined) {
32         if(!$used{$_}) { print "$_\n"; }
33 }