summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-06-24 00:07:04 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:18:43 -0500
commit3022bfef70f4d76d3a12cfb8ee8cbdc72644b58f (patch)
treeb3b1d9084178dd546e04114b4c67f807b34a11e6 /source4
parent3e476207765df4387bc89206316b95dfed251dd7 (diff)
downloadsamba-3022bfef70f4d76d3a12cfb8ee8cbdc72644b58f.tar.gz
samba-3022bfef70f4d76d3a12cfb8ee8cbdc72644b58f.tar.bz2
samba-3022bfef70f4d76d3a12cfb8ee8cbdc72644b58f.zip
r7859: Merge a few scripts to one script that checks for the following unused
(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 (This used to be commit 897d7b7d390815778adea1adf5e73b94f75a3048)
Diffstat (limited to 'source4')
-rwxr-xr-xsource4/script/configure_check_unused.pl120
-rwxr-xr-xsource4/script/find_unused_defines.pl30
-rwxr-xr-xsource4/script/find_unused_function_checks.pl37
-rwxr-xr-xsource4/script/find_unused_header_checks.pl40
-rwxr-xr-xsource4/script/find_unused_macros.pl1
-rwxr-xr-xsource4/script/find_unused_makefilevars.pl1
-rwxr-xr-x[-rw-r--r--]source4/script/mkproto.pl0
7 files changed, 121 insertions, 108 deletions
diff --git a/source4/script/configure_check_unused.pl b/source4/script/configure_check_unused.pl
new file mode 100755
index 0000000000..1b33a9e6b1
--- /dev/null
+++ b/source4/script/configure_check_unused.pl
@@ -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/source4/script/find_unused_defines.pl b/source4/script/find_unused_defines.pl
deleted file mode 100755
index def1bd159f..0000000000
--- a/source4/script/find_unused_defines.pl
+++ /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/source4/script/find_unused_function_checks.pl b/source4/script/find_unused_function_checks.pl
deleted file mode 100755
index 4704e907f8..0000000000
--- a/source4/script/find_unused_function_checks.pl
+++ /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/source4/script/find_unused_header_checks.pl b/source4/script/find_unused_header_checks.pl
deleted file mode 100755
index 8251198aab..0000000000
--- a/source4/script/find_unused_header_checks.pl
+++ /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;
diff --git a/source4/script/find_unused_macros.pl b/source4/script/find_unused_macros.pl
index 49fe0973db..5c04b1fd88 100755
--- a/source4/script/find_unused_macros.pl
+++ b/source4/script/find_unused_macros.pl
@@ -6,7 +6,6 @@
my %defined,%used,%files;
-# First, make a list of defines in configure
$in = shift;
while($tmp = shift) {
diff --git a/source4/script/find_unused_makefilevars.pl b/source4/script/find_unused_makefilevars.pl
index 697ed54f5c..1bed1228ec 100755
--- a/source4/script/find_unused_makefilevars.pl
+++ b/source4/script/find_unused_makefilevars.pl
@@ -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
diff --git a/source4/script/mkproto.pl b/source4/script/mkproto.pl
index 227c7c0dce..227c7c0dce 100644..100755
--- a/source4/script/mkproto.pl
+++ b/source4/script/mkproto.pl