Add script that reports unused macros/defines
authorJelmer Vernooij <jelmer@samba.org>
Sat, 16 Aug 2003 05:20:22 +0000 (05:20 +0000)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 16 Aug 2003 05:20:22 +0000 (05:20 +0000)
(This used to be commit dd850b5bd8abc123f455b715fb62dd4d54297178)

source4/script/find_unused_macros.pl [new file with mode: 0755]

diff --git a/source4/script/find_unused_macros.pl b/source4/script/find_unused_macros.pl
new file mode 100755 (executable)
index 0000000..49fe097
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+# Script that reads in configure and outputs the names of all the defines 
+# it defines that are used nowhere in the code
+
+# Arguments: C and H files
+
+my %defined,%used,%files;
+
+# First, make a list of defines in configure
+$in = shift;
+
+while($tmp = shift) { 
+       $files{$tmp} = $tmp;
+       open(FI, $tmp);
+       while(<FI>) { 
+               $line = $_;
+               $cur = "";
+               if(/^#define ([A-Za-z0-9_]+)/) {
+                       $defined{$1} = $tmp;
+                       $cur = $1;
+               }
+
+               $_ = $line;
+               while(/([A-Za-z0-9_]+)/sgm) { 
+                       if($cur cmp $1) { $used{$1} = $tmp; }
+               }
+       }
+       close FI;
+}
+
+foreach(keys %defined) {
+       if(!$used{$_}) { print "$_\n"; }
+}