dupincludes.pl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env perl
  2. # Locate duplicate includes
  3. # Copyright (c) 2005, Pavel Roskin
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. use strict;
  17. my %sys_includes;
  18. my %loc_includes;
  19. if ($#ARGV != 0) {
  20. print "Usage: dupincludes.pl file\n";
  21. exit 1;
  22. }
  23. my $filename = $ARGV[0];
  24. if (!open (FILE, "$filename")) {
  25. print "Cannot open file \"$filename\"\n";
  26. exit 1;
  27. }
  28. foreach (<FILE>) {
  29. if (/^\s*#\s*include\s*<(.*)>/) {
  30. if (defined $sys_includes{$1}) {
  31. print "$filename: duplicate <$1>\n";
  32. } else {
  33. $sys_includes{$1} = 1;
  34. }
  35. } elsif (/^\s*#\s*include\s*"(.*)"/) {
  36. if (defined $loc_includes{$1}) {
  37. print "$filename: duplicate \"$1\"\n";
  38. } else {
  39. $loc_includes{$1} = 1;
  40. }
  41. }
  42. }