|
@@ -11,6 +11,8 @@
|
|
# you do have real dups and do not have them under #ifdef's. You
|
|
# you do have real dups and do not have them under #ifdef's. You
|
|
# could also just review the results.
|
|
# could also just review the results.
|
|
|
|
|
|
|
|
+use strict;
|
|
|
|
+
|
|
sub usage {
|
|
sub usage {
|
|
print "Usage: checkincludes.pl [-r]\n";
|
|
print "Usage: checkincludes.pl [-r]\n";
|
|
print "By default we just warn of duplicates\n";
|
|
print "By default we just warn of duplicates\n";
|
|
@@ -35,23 +37,24 @@ if ($#ARGV >= 1) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-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 %includedfiles = ();
|
|
my @file_lines = ();
|
|
my @file_lines = ();
|
|
|
|
|
|
- while (<FILE>) {
|
|
|
|
|
|
+ while (<$f>) {
|
|
if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
|
|
if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
|
|
++$includedfiles{$1};
|
|
++$includedfiles{$1};
|
|
}
|
|
}
|
|
push(@file_lines, $_);
|
|
push(@file_lines, $_);
|
|
}
|
|
}
|
|
|
|
|
|
- close(FILE);
|
|
|
|
|
|
+ close($f);
|
|
|
|
|
|
if (!$remove) {
|
|
if (!$remove) {
|
|
- foreach $filename (keys %includedfiles) {
|
|
|
|
|
|
+ foreach my $filename (keys %includedfiles) {
|
|
if ($includedfiles{$filename} > 1) {
|
|
if ($includedfiles{$filename} > 1) {
|
|
print "$file: $filename is included more than once.\n";
|
|
print "$file: $filename is included more than once.\n";
|
|
}
|
|
}
|
|
@@ -59,27 +62,28 @@ foreach $file (@ARGV) {
|
|
next;
|
|
next;
|
|
}
|
|
}
|
|
|
|
|
|
- open(FILE,">$file") || die("Cannot write to $file: $!");
|
|
|
|
|
|
+ open($f, '>', $file)
|
|
|
|
+ or die("Cannot write to $file: $!");
|
|
|
|
|
|
my $dups = 0;
|
|
my $dups = 0;
|
|
foreach (@file_lines) {
|
|
foreach (@file_lines) {
|
|
if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
|
|
if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
|
|
- foreach $filename (keys %includedfiles) {
|
|
|
|
|
|
+ foreach my $filename (keys %includedfiles) {
|
|
if ($1 eq $filename) {
|
|
if ($1 eq $filename) {
|
|
if ($includedfiles{$filename} > 1) {
|
|
if ($includedfiles{$filename} > 1) {
|
|
$includedfiles{$filename}--;
|
|
$includedfiles{$filename}--;
|
|
$dups++;
|
|
$dups++;
|
|
} else {
|
|
} else {
|
|
- print FILE $_;
|
|
|
|
|
|
+ print {$f} $_;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- print FILE $_;
|
|
|
|
|
|
+ print {$f} $_;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($dups > 0) {
|
|
if ($dups > 0) {
|
|
print "$file: removed $dups duplicate includes\n";
|
|
print "$file: removed $dups duplicate includes\n";
|
|
}
|
|
}
|
|
- close(FILE);
|
|
|
|
|
|
+ close($f);
|
|
}
|
|
}
|