Back to home page

OSCL-LXR

 
 

    


0001 #!/usr/bin/env perl
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # checkdeclares: find struct declared more than once
0005 #
0006 # Copyright 2021 Wan Jiabing<wanjiabing@vivo.com>
0007 # Inspired by checkincludes.pl
0008 #
0009 # This script checks for duplicate struct declares.
0010 # Note that this will not take into consideration macros so
0011 # you should run this only if you know you do have real dups
0012 # and do not have them under #ifdef's.
0013 # You could also just review the results.
0014 
0015 use strict;
0016 
0017 sub usage {
0018     print "Usage: checkdeclares.pl file1.h ...\n";
0019     print "Warns of struct declaration duplicates\n";
0020     exit 1;
0021 }
0022 
0023 if ($#ARGV < 0) {
0024     usage();
0025 }
0026 
0027 my $dup_counter = 0;
0028 
0029 foreach my $file (@ARGV) {
0030     open(my $f, '<', $file)
0031         or die "Cannot open $file: $!.\n";
0032 
0033     my %declaredstructs = ();
0034 
0035     while (<$f>) {
0036         if (m/^\s*struct\s*(\w*);$/o) {
0037             ++$declaredstructs{$1};
0038         }
0039     }
0040 
0041     close($f);
0042 
0043     foreach my $structname (keys %declaredstructs) {
0044         if ($declaredstructs{$structname} > 1) {
0045             print "$file: struct $structname is declared more than once.\n";
0046             ++$dup_counter;
0047         }
0048     }
0049 }
0050 
0051 if ($dup_counter == 0) {
0052     print "No duplicate struct declares found.\n";
0053 }