diff --git a/contrib/find_offenders.pl b/contrib/find_offenders.pl new file mode 100755 index 0000000000..315c3ffbd8 --- /dev/null +++ b/contrib/find_offenders.pl @@ -0,0 +1,72 @@ +#!/usr/bin/perl + +if (scalar(@ARGV) != 2) { + print "Usage: + find_offenders.pl + eg.,: running from top level source tree + #contrib/find_offenders.pl contrib/results.txt .\n"; + exit(3); +} +$source_tree = @ARGV[1]; +$header_file_list = @ARGV[0]; + +#first construct the danger list +open(FILE_LIST, "$header_file_list") || print "Could not open results.txt\n"; +open(DANGER_FILES, "> contrib/headers.txt") || print "Could not open headers.txt\n"; + +while () { +#check if this file is a file in the source tree + chomp($_); + $file_name = $_; + open(FILE, "find . -name $file_name |") || print "find failed\n"; + while() { + #file is found + print DANGER_FILES "#include <$file_name>\n"; + } + close (FILE); +} +close (DANGER_FILES); +close (FILE_LIST); + +open(DANGER_FILES, "contrib/headers.txt") || print "Could not open headers.txt\n"; +open(OFFENSIVE, "> contrib/offenders.list") || print "Could not open offenders list\n"; + +while () { + + $header = $_; + chomp($header); + print; + + open(C_FILES, "find $source_tree -name *.c |") || print "Could not complete find command\n"; + + while () { + $c_file = $_; + open(C_FILE, "$c_file") || print "Could not open $_\n"; + while () { + if (/$header/) { + print OFFENSIVE $header ." --> ". $c_file ; + } + } + close (C_FILE); + } + + close (C_FILES); + + open(H_FILES, "find . -name *.h |") || print "Could not complete find command\n"; + + while () { + $h_file = $_; + open(H_FILE, "$h_file") || print "Could not open $_\n"; + while () { + if (/$header/) { + print OFFENSIVE $header ." --> ". $h_file ; + } + } + close (H_FILE); + } + + close (H_FILES); +} + +close (DANGER_FILES); +close (OFFENSIVE);