Skip to content

Commit

Permalink
checkincludes: fix perlcritic warnings
Browse files Browse the repository at this point in the history
Turn on strict checking.
Use local file handles.
Use three argument open.

Signed-off-by: Stephen Hemminger <[email protected]>
Cc: Cong Wang <[email protected]>
Cc: Michal Marek <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Michal Marek <[email protected]>
  • Loading branch information
Stephen Hemminger authored and michal42 committed Mar 7, 2010
1 parent 1f2a144 commit 3da2715
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions scripts/checkincludes.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# you do have real dups and do not have them under #ifdef's. You
# could also just review the results.

use strict;

sub usage {
print "Usage: checkincludes.pl [-r]\n";
print "By default we just warn of duplicates\n";
Expand All @@ -35,51 +37,53 @@ sub usage {
}
}

foreach $file (@ARGV) {
open(FILE, $file) or die "Cannot open $file: $!.\n";
foreach my $file (@ARGV) {
open(my $f, '<', $file)
or die "Cannot open $file: $!.\n";

my %includedfiles = ();
my @file_lines = ();

while (<FILE>) {
while (<$f>) {
if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
++$includedfiles{$1};
}
push(@file_lines, $_);
}

close(FILE);
close($f);

if (!$remove) {
foreach $filename (keys %includedfiles) {
foreach my $filename (keys %includedfiles) {
if ($includedfiles{$filename} > 1) {
print "$file: $filename is included more than once.\n";
}
}
next;
}

open(FILE,">$file") || die("Cannot write to $file: $!");
open($f, '>', $file)
or die("Cannot write to $file: $!");

my $dups = 0;
foreach (@file_lines) {
if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
foreach $filename (keys %includedfiles) {
foreach my $filename (keys %includedfiles) {
if ($1 eq $filename) {
if ($includedfiles{$filename} > 1) {
$includedfiles{$filename}--;
$dups++;
} else {
print FILE $_;
print {$f} $_;
}
}
}
} else {
print FILE $_;
print {$f} $_;
}
}
if ($dups > 0) {
print "$file: removed $dups duplicate includes\n";
}
close(FILE);
close($f);
}

0 comments on commit 3da2715

Please sign in to comment.