Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 199548
b: refs/heads/master
c: 3da2715
h: refs/heads/master
v: v3
  • Loading branch information
Stephen Hemminger authored and Michal Marek committed Mar 7, 2010
1 parent 6f7ae1c commit 19e958a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1f2a144f5ab5e836b5ca8f67bd76b759fa947751
refs/heads/master: 3da27157316cbcce326d56faa0a7a5cadc7ae507
24 changes: 14 additions & 10 deletions trunk/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 19e958a

Please sign in to comment.