diff options
author | teor <teor@torproject.org> | 2019-03-25 14:01:20 +1000 |
---|---|---|
committer | teor <teor@torproject.org> | 2019-03-25 14:01:20 +1000 |
commit | d4d541c53c209370ae33f5f6caad2ec13743a4ba (patch) | |
tree | a1430960358386b53007e22f5b12eeaf7ad32f45 /scripts | |
parent | 9d0ce0afcce9bbf969d11ba081f829aef5071e9c (diff) | |
parent | 065b74fa36344295a12f53e7399e7b20c6d887e0 (diff) | |
download | tor-d4d541c53c209370ae33f5f6caad2ec13743a4ba.tar.gz tor-d4d541c53c209370ae33f5f6caad2ec13743a4ba.zip |
Merge remote-tracking branch 'tor-github/pr/785'
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/maint/checkSpace.pl | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/maint/checkSpace.pl b/scripts/maint/checkSpace.pl index 633b47e314..433ae62807 100755 --- a/scripts/maint/checkSpace.pl +++ b/scripts/maint/checkSpace.pl @@ -18,6 +18,8 @@ if ($ARGV[0] =~ /^-/) { our %basenames = (); +our %guardnames = (); + for my $fn (@ARGV) { open(F, "$fn"); my $lastnil = 0; @@ -31,6 +33,10 @@ for my $fn (@ARGV) { } else { $basenames{$basename} = $fn; } + my $isheader = ($fn =~ /\.h/); + my $seenguard = 0; + my $guardname = "<none>"; + while (<F>) { ## Warn about windows-style newlines. # (We insist on lines that end with a single LF character, not @@ -112,6 +118,23 @@ for my $fn (@ARGV) { next; } } + + if ($isheader) { + if ($seenguard == 0) { + if (/ifndef\s+(\S+)/) { + ++$seenguard; + $guardname = $1; + } + } elsif ($seenguard == 1) { + if (/^\#define (\S+)/) { + ++$seenguard; + if ($1 ne $guardname) { + msg "GUARD:$fn:$.: Header guard macro mismatch.\n"; + } + } + } + } + if (m!/\*.*?\*/!) { s!\s*/\*.*?\*/!!; } elsif (m!/\*!) { @@ -201,6 +224,15 @@ for my $fn (@ARGV) { } } } + if ($isheader && $C) { + if ($seenguard < 2) { + msg "$fn:No #ifndef/#define header guard pair found.\n"; + } elsif ($guardnames{$guardname}) { + msg "$fn:Guard macro $guardname also used in $guardnames{$guardname}\n"; + } else { + $guardnames{$guardname} = $fn; + } + } close(F); } |