| # checkincludes: find/remove files included more than once |
| # Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>. |
| # Copyright 2009 Luis R. Rodriguez <mcgrof@gmail.com> |
| # This script checks for duplicate includes. It also has support |
| # to remove them in place. Note that this will not take into |
| # consideration macros so you should run this only if you know |
| # you do have real dups and do not have them under #ifdef's. You |
| # could also just review the results. |
| print "Usage: checkincludes.pl [-r]\n"; |
| print "By default we just warn of duplicates\n"; |
| print "To remove duplicated includes in place use -r\n"; |
| foreach my $file (@ARGV) { |
| or die "Cannot open $file: $!.\n"; |
| if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { |
| foreach my $filename (keys %includedfiles) { |
| if ($includedfiles{$filename} > 1) { |
| print "$file: $filename is included more than once.\n"; |
| or die("Cannot write to $file: $!"); |
| if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { |
| foreach my $filename (keys %includedfiles) { |
| if ($includedfiles{$filename} > 1) { |
| $includedfiles{$filename}--; |
| print "$file: removed $dups duplicate includes\n"; |