dupincludes.pl 792 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env perl
  2. # Copyright (c) 2005, Pavel Roskin
  3. # This script is Free Software, and it can be copied, distributed and
  4. # modified under the terms of GNU General Public License, version 2.
  5. # Locate duplicate includes
  6. use strict;
  7. my %sys_includes;
  8. my %loc_includes;
  9. if ($#ARGV != 0) {
  10. print "Usage: dupincludes.pl file\n";
  11. exit 1;
  12. }
  13. my $filename = $ARGV[0];
  14. if (!open (FILE, "$filename")) {
  15. print "Cannot open file \"$filename\"\n";
  16. exit 1;
  17. }
  18. foreach (<FILE>) {
  19. if (/^\s*#\s*include\s*<(.*)>/) {
  20. if (defined $sys_includes{$1}) {
  21. print "$filename: duplicate <$1>\n";
  22. } else {
  23. $sys_includes{$1} = 1;
  24. }
  25. } elsif (/^\s*#\s*include\s*"(.*)"/) {
  26. if (defined $loc_includes{$1}) {
  27. print "$filename: duplicate \"$1\"\n";
  28. } else {
  29. $loc_includes{$1} = 1;
  30. }
  31. }
  32. }