r7859: Merge a few scripts to one script that checks for the following unused
authorJelmer Vernooij <jelmer@samba.org>
Fri, 24 Jun 2005 00:07:04 +0000 (00:07 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:18:43 +0000 (13:18 -0500)
(used in configure.in, but their output is never used) autoconf macros:
- AC_DEFINE
- AC_CHECK_FUNC
- AC_CHECK_FUNCS
- AC_CHECK_HEADER
- AC_CHECK_HEADERS

source/script/configure_check_unused.pl [new file with mode: 0755]
source/script/find_unused_defines.pl [deleted file]
source/script/find_unused_function_checks.pl [deleted file]
source/script/find_unused_header_checks.pl [deleted file]
source/script/find_unused_macros.pl
source/script/find_unused_makefilevars.pl
source/script/mkproto.pl [changed mode: 0644->0755]

diff --git a/source/script/configure_check_unused.pl b/source/script/configure_check_unused.pl
new file mode 100755 (executable)
index 0000000..1b33a9e
--- /dev/null
@@ -0,0 +1,120 @@
+#!/usr/bin/perl
+# Script that finds macros in a configure script that are not 
+# used in a set of C files.
+# Copyright Jelmer Vernooij <jelmer@samba.org>, GPL
+#
+# Usage: ./$ARGV[0] configure.in [c-files...]
+
+use strict;
+
+sub autoconf_parse($$$$)
+{
+       my $in = shift;
+       my $defines = shift;
+       my $functions = shift;
+       my $headers = shift;
+
+       open(IN, $in) or die("Can't open $in");
+
+       my $ln = 0;
+
+       foreach(<IN>) {
+               $ln++;
+
+               if(/AC_DEFINE\(([^,]+),/) { 
+                       $defines->{$1} = "$in:$ln";
+               } 
+       
+               if(/AC_CHECK_FUNCS\(\[*(.[^],)]+)/) {
+                       foreach(split / /, $1) { 
+                               $functions->{$_} = "$in:$ln";
+                       }
+               }
+
+               if(/AC_CHECK_FUNC\(([^,)]+)/) {
+                       $functions->{$1} = "$in:$ln";
+               }
+
+               if(/AC_CHECK_HEADERS\(\[*([^],)]+)/) {
+                       foreach(split / /, $1) { 
+                               $headers->{$_} = "$in:$ln";
+                       }
+               }
+
+               if(/AC_CHECK_HEADER\(([^,)]+)/) {
+                       $headers->{$1} = "$in:$ln";
+               }
+
+               if(/sinclude\(([^,]+)\)/) {
+                       autoconf_parse($1, $defines, $functions, $headers);
+               }
+       }
+
+       close IN;
+}
+
+# Return the symbols and headers used by a C file
+sub cfile_parse($$$)
+{
+       my $in = shift;
+       my $symbols = shift;
+       my $headers = shift;
+
+       open(FI, $in) or die("Can't open $in");
+       my $ln = 0;     
+       foreach(<FI>) { 
+               $ln++;
+               foreach(/\#([ \t]*)include ["<]([^">]+)/g) { 
+                       $headers->{$2} = "$in:$ln";
+               }
+
+               foreach(/([A-Za-z0-9_]+)/g) { 
+                       $symbols->{$1} = "$in:$ln";
+               }
+       }
+       close FI;
+}
+
+my %ac_defines = ();
+my %ac_func_checks = ();
+my %ac_headers = ();
+my %symbols = ();
+my %headers = ();
+
+if (scalar(@ARGV) <= 1) {
+       print("Usage: configure_find_unused.pl configure.in [CFILE...]\n");
+       exit 0;
+}
+
+autoconf_parse(shift(@ARGV), \%ac_defines, \%ac_func_checks, \%ac_headers);
+cfile_parse($_, \%symbols, \%headers) foreach(@ARGV);
+
+(keys %ac_defines) or warn("No defines found in configure.in file, parse error?");
+
+foreach (keys %ac_defines) {
+       if (not defined($symbols{$_})) {
+               print "$ac_defines{$_}: Autoconf-defined $_ is unused\n";
+       }
+}
+
+(keys %ac_func_checks) or warn("No function checks found in configure.in file, parse error?");
+
+foreach (keys %ac_func_checks) {
+       if (not defined($symbols{$_})) {
+               print "$ac_func_checks{$_}: Autoconf-checked function $_ is unused\n";
+       } elsif (not defined($symbols{"HAVE_".uc($_)})) {
+               print "$ac_func_checks{$_}: Autoconf-define for function $_ is unused\n";
+       }
+}
+
+(keys %ac_headers) or warn("No headers found in configure.in file, parse error?");
+
+foreach (keys %ac_headers) {
+       my $def = "HAVE_".uc($_);
+       $def =~ s/[\/\.]/_/g;
+       if (not defined($headers{$_})) {
+               print "$ac_headers{$_}: Autoconf-checked header $_ is unused\n";
+       } elsif (not defined($symbols{$def})) {
+               print "$ac_headers{$_}: Autoconf-define for header $_ is unused\n"; 
+       }
+}
diff --git a/source/script/find_unused_defines.pl b/source/script/find_unused_defines.pl
deleted file mode 100755 (executable)
index def1bd1..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/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:
-#  1: configure.in
-#  2: C files pattern
-
-my %symbols;
-
-# First, make a list of defines in configure
-$in = shift;
-
-while($tmp = shift) { 
-       open(FI, $tmp);
-       while(<FI>) { 
-               while(/([A-Za-z0-9_]+)/sgm) { 
-                       $symbols{$1} = 1;
-               }
-       }
-       close FI;
-}
-
-open(IN, $in) or die("Can't open $in");
-
-while(<IN>) {
-       if(/AC_DEFINE\(([^,]+),/ and $symbols{$1} != 1) { print "$1\n"; } 
-}
-
-close IN;
diff --git a/source/script/find_unused_function_checks.pl b/source/script/find_unused_function_checks.pl
deleted file mode 100755 (executable)
index 4704e90..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/perl
-# Arguments:
-#  1: configure.in
-#  2: C files
-#
-# You might want to specify configure.in again in the list of header files 
-# as well, because it also uses some includes.
-# Note that this script does not process any includes, so you might 
-# have to run "cat configure.in */config.m4 > foo.in" first.
-
-my %symbols;
-
-# First, make a list of defines in configure
-$in = shift;
-
-while($tmp = shift) { 
-       open(FI, $tmp);
-       while(<FI>) { 
-               while(/([A-Za-z0-9_]+)/sgm) { 
-                       $symbols{$1} = 1;
-               }
-       }
-       close FI;
-}
-
-open(IN, $in) or die("Can't open $in");
-
-while(<IN>) {
-       if(/AC_CHECK_FUNCS\(([\[]*)(.*)([\]]*)\)/) {
-               @hs = split / /, $2;
-               foreach(@hs) { 
-                       if($symbols{$_} != 1) { print "$_\n"; }
-               }
-       }
-}
-
-close IN;
diff --git a/source/script/find_unused_header_checks.pl b/source/script/find_unused_header_checks.pl
deleted file mode 100755 (executable)
index 8251198..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/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:
-#  1: configure.in
-#  2: header files
-#
-# You might want to specify configure.in again in the list of header files 
-# as well, because it also uses some includes.
-# Note that this script does not process any includes, so you might 
-# have to run "cat configure.in */config.m4 > foo.in" first.
-
-my %symbols;
-
-# First, make a list of defines in configure
-$in = shift;
-
-while($tmp = shift) { 
-       open(FI, $tmp);
-       while(<FI>) { 
-               while(/\#([ \t]*)include <(.*)>/sgm) { 
-                       $symbols{$2} = 1;
-               }
-       }
-       close FI;
-}
-
-open(IN, $in) or die("Can't open $in");
-
-while(<IN>) {
-       if(/AC_CHECK_HEADERS\(([\[]*)(.*)([\]]*)\)/) {
-               @hs = split / /, $2;
-               foreach(@hs) { 
-                       if($symbols{$_} != 1) { print "$_\n"; }
-               }
-       }
-}
-
-close IN;
index 49fe0973dbfc0a671152c420a537f74e4f664048..5c04b1fd88b2a0ca49529f2cb01dc68d632b4013 100755 (executable)
@@ -6,7 +6,6 @@
 
 my %defined,%used,%files;
 
-# First, make a list of defines in configure
 $in = shift;
 
 while($tmp = shift) { 
index 697ed54f5cde0b435ca9407b3994a38bc62e9aa8..1bed1228eca8da9f388fa8cde31b11220c961242 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 # Script that reads in Makefile.in and outputs the names of all 
 # used but undefined vars and all defined but unused vars 
+# Copyright Jelmer Vernooij <jelmer@samba.org>
 
 # Arguments:
 #  1: Makefile.in
old mode 100644 (file)
new mode 100755 (executable)