diff options
Diffstat (limited to 'scripts/checkincludes.pl')
| -rwxr-xr-x | scripts/checkincludes.pl | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl index 676ddc07d6fa..97b2c6143fe4 100755 --- a/scripts/checkincludes.pl +++ b/scripts/checkincludes.pl | |||
| @@ -11,6 +11,8 @@ | |||
| 11 | # you do have real dups and do not have them under #ifdef's. You | 11 | # you do have real dups and do not have them under #ifdef's. You |
| 12 | # could also just review the results. | 12 | # could also just review the results. |
| 13 | 13 | ||
| 14 | use strict; | ||
| 15 | |||
| 14 | sub usage { | 16 | sub usage { |
| 15 | print "Usage: checkincludes.pl [-r]\n"; | 17 | print "Usage: checkincludes.pl [-r]\n"; |
| 16 | print "By default we just warn of duplicates\n"; | 18 | print "By default we just warn of duplicates\n"; |
| @@ -35,23 +37,24 @@ if ($#ARGV >= 1) { | |||
| 35 | } | 37 | } |
| 36 | } | 38 | } |
| 37 | 39 | ||
| 38 | foreach $file (@ARGV) { | 40 | foreach my $file (@ARGV) { |
| 39 | open(FILE, $file) or die "Cannot open $file: $!.\n"; | 41 | open(my $f, '<', $file) |
| 42 | or die "Cannot open $file: $!.\n"; | ||
| 40 | 43 | ||
| 41 | my %includedfiles = (); | 44 | my %includedfiles = (); |
| 42 | my @file_lines = (); | 45 | my @file_lines = (); |
| 43 | 46 | ||
| 44 | while (<FILE>) { | 47 | while (<$f>) { |
| 45 | if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { | 48 | if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { |
| 46 | ++$includedfiles{$1}; | 49 | ++$includedfiles{$1}; |
| 47 | } | 50 | } |
| 48 | push(@file_lines, $_); | 51 | push(@file_lines, $_); |
| 49 | } | 52 | } |
| 50 | 53 | ||
| 51 | close(FILE); | 54 | close($f); |
| 52 | 55 | ||
| 53 | if (!$remove) { | 56 | if (!$remove) { |
| 54 | foreach $filename (keys %includedfiles) { | 57 | foreach my $filename (keys %includedfiles) { |
| 55 | if ($includedfiles{$filename} > 1) { | 58 | if ($includedfiles{$filename} > 1) { |
| 56 | print "$file: $filename is included more than once.\n"; | 59 | print "$file: $filename is included more than once.\n"; |
| 57 | } | 60 | } |
| @@ -59,27 +62,28 @@ foreach $file (@ARGV) { | |||
| 59 | next; | 62 | next; |
| 60 | } | 63 | } |
| 61 | 64 | ||
| 62 | open(FILE,">$file") || die("Cannot write to $file: $!"); | 65 | open($f, '>', $file) |
| 66 | or die("Cannot write to $file: $!"); | ||
| 63 | 67 | ||
| 64 | my $dups = 0; | 68 | my $dups = 0; |
| 65 | foreach (@file_lines) { | 69 | foreach (@file_lines) { |
| 66 | if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { | 70 | if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { |
| 67 | foreach $filename (keys %includedfiles) { | 71 | foreach my $filename (keys %includedfiles) { |
| 68 | if ($1 eq $filename) { | 72 | if ($1 eq $filename) { |
| 69 | if ($includedfiles{$filename} > 1) { | 73 | if ($includedfiles{$filename} > 1) { |
| 70 | $includedfiles{$filename}--; | 74 | $includedfiles{$filename}--; |
| 71 | $dups++; | 75 | $dups++; |
| 72 | } else { | 76 | } else { |
| 73 | print FILE $_; | 77 | print {$f} $_; |
| 74 | } | 78 | } |
| 75 | } | 79 | } |
| 76 | } | 80 | } |
| 77 | } else { | 81 | } else { |
| 78 | print FILE $_; | 82 | print {$f} $_; |
| 79 | } | 83 | } |
| 80 | } | 84 | } |
| 81 | if ($dups > 0) { | 85 | if ($dups > 0) { |
| 82 | print "$file: removed $dups duplicate includes\n"; | 86 | print "$file: removed $dups duplicate includes\n"; |
| 83 | } | 87 | } |
| 84 | close(FILE); | 88 | close($f); |
| 85 | } | 89 | } |
