checkdeclares.pl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env perl
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # checkdeclares: find struct declared more than once
  5. #
  6. # Copyright 2021 Wan Jiabing<wanjiabing@vivo.com>
  7. # Inspired by checkincludes.pl
  8. #
  9. # This script checks for duplicate struct declares.
  10. # Note that this will not take into consideration macros so
  11. # you should run this only if you know you do have real dups
  12. # and do not have them under #ifdef's.
  13. # You could also just review the results.
  14. use strict;
  15. sub usage {
  16. print "Usage: checkdeclares.pl file1.h ...\n";
  17. print "Warns of struct declaration duplicates\n";
  18. exit 1;
  19. }
  20. if ($#ARGV < 0) {
  21. usage();
  22. }
  23. my $dup_counter = 0;
  24. foreach my $file (@ARGV) {
  25. open(my $f, '<', $file)
  26. or die "Cannot open $file: $!.\n";
  27. my %declaredstructs = ();
  28. while (<$f>) {
  29. if (m/^\s*struct\s*(\w*);$/o) {
  30. ++$declaredstructs{$1};
  31. }
  32. }
  33. close($f);
  34. foreach my $structname (keys %declaredstructs) {
  35. if ($declaredstructs{$structname} > 1) {
  36. print "$file: struct $structname is declared more than once.\n";
  37. ++$dup_counter;
  38. }
  39. }
  40. }
  41. if ($dup_counter == 0) {
  42. print "No duplicate struct declares found.\n";
  43. }