From 3022bfef70f4d76d3a12cfb8ee8cbdc72644b58f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 24 Jun 2005 00:07:04 +0000 Subject: 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) --- source4/script/configure_check_unused.pl | 120 ++++++++++++++++++++++++++ source4/script/find_unused_defines.pl | 30 ------- source4/script/find_unused_function_checks.pl | 37 -------- source4/script/find_unused_header_checks.pl | 40 --------- source4/script/find_unused_macros.pl | 1 - source4/script/find_unused_makefilevars.pl | 1 + source4/script/mkproto.pl | 0 7 files changed, 121 insertions(+), 108 deletions(-) create mode 100755 source4/script/configure_check_unused.pl delete mode 100755 source4/script/find_unused_defines.pl delete mode 100755 source4/script/find_unused_function_checks.pl delete mode 100755 source4/script/find_unused_header_checks.pl mode change 100644 => 100755 source4/script/mkproto.pl (limited to 'source4/script') 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 , 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() { + $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() { + $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() { - while(/([A-Za-z0-9_]+)/sgm) { - $symbols{$1} = 1; - } - } - close FI; -} - -open(IN, $in) or die("Can't open $in"); - -while() { - 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() { - while(/([A-Za-z0-9_]+)/sgm) { - $symbols{$1} = 1; - } - } - close FI; -} - -open(IN, $in) or die("Can't open $in"); - -while() { - 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() { - while(/\#([ \t]*)include <(.*)>/sgm) { - $symbols{$2} = 1; - } - } - close FI; -} - -open(IN, $in) or die("Can't open $in"); - -while() { - 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 # Arguments: # 1: Makefile.in diff --git a/source4/script/mkproto.pl b/source4/script/mkproto.pl old mode 100644 new mode 100755 -- cgit