diff options
author | morriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7> | 2011-02-11 22:44:29 +0000 |
---|---|---|
committer | morriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7> | 2011-02-11 22:44:29 +0000 |
commit | df8fda2f717ffadb2ba35ab76093aa4e638473a5 (patch) | |
tree | 2609109ea6d90904d94905f6a47643b61e7a0041 /tools | |
parent | 811951e990af4a60da1f3b3f40545ccad160abc1 (diff) |
Add a function to verify that ett_ variables are registered (or at least
stored in an array which will hopefully be registered).
This is a work-in-progress, so the function is not called.
It is also EXTREMELY slow on big files. (Or maybe it's looping...
I haven't yet had the patience to let it finish processing packet-rrc.c .)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@35923 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/checkAPIs.pl | 102 |
1 files changed, 99 insertions, 3 deletions
diff --git a/tools/checkAPIs.pl b/tools/checkAPIs.pl index acba8b34ab..31cfc59db6 100755 --- a/tools/checkAPIs.pl +++ b/tools/checkAPIs.pl @@ -1016,6 +1016,100 @@ sub checkAPIsCalledWithTvbGetPtr($$$) } } +# Verify that all declared ett_ variables are registered. +# Don't bother trying to check usage (for now)... +sub check_ett_registration($$) +{ + my ($fileContentsRef, $filename) = @_; + my @ett_declarations; + my @ett_registrations; + my @unRegisteredEtts; + + # Remove macro lines + my $fileContents = ${$fileContentsRef}; + $fileContents =~ s { ^\s*\#.*$} []xogm; + + # Find all the ett_ variables declared in the file + @ett_declarations = ($fileContents =~ m{ + static + \s+ + g?int # could be int or gint + \s+ + (ett_[a-z0-9_]+) # variable name + \s*=\s* + -1\s*; + }xgios); + + if (!@ett_declarations) { + print "Found no etts in ".$filename."\n"; + return; + } + + #print "Found these etts in ".$filename.": ".join(',', @ett_declarations)."\n\n"; + + # Find the array used for registering the etts + # Save off the block of code containing just the variables + my @reg_blocks; + @reg_blocks = ($fileContents =~ m{ + static + \s+ + g?int + \s*\*\s* # it's an array of pointers + [a-z0-9_]+ # array name; usually (always?) "ett" + \s*\[\s*\]\s* # array brackets + = + \s*\{ + ((?:\s*&\s* # address of the following variable + ett_[a-z0-9_]+ # variable name + \s*,? # the comma is optional (for the last entry) + \s*)+) # match one or more variable names + \} + \s* + ; + }xgios); + #print "Found this ett registration block in ".$filename.": ".join(',', @reg_blocks)."\n"; + + if (@reg_blocks == 0) { + print "Hmm, found ".@reg_blocks." ett registration blocks in ".$filename."\n"; + # For now... + return; + } + + while (<@reg_blocks>) { + push @ett_registrations, ($_ =~ m{ + \s*&\s* # address of the following variable + (ett_[a-z0-9_]+) # variable name + \s*,? # the comma is optional (for the last entry) + }xgios); + } + #print "Found these ett registrations in ".$filename.": ".join(',', @ett_registrations)."\n"; + + # Find which declared etts are not registered + # There has to be an easier way to do this... + my $foundit = 0; + while (@ett_declarations) { + my ($ett_var) = @ett_declarations; + shift @ett_declarations; + + $foundit = 0; + foreach $_ (@ett_registrations) { + if ($_ eq $ett_var) { + $foundit = 1; + last; + } + } + + if (!$foundit) { + push @unRegisteredEtts, $ett_var; + } + } + + if (@unRegisteredEtts) { + print STDERR "Error: found these unregistered ett variables in ".$filename.": ".join(',', @unRegisteredEtts)."\n"; + } + +} + # Given the file contents and a file name, check all of the hf entries for # various problems (such as those checked for in proto.c). sub check_hf_entries($$) @@ -1045,7 +1139,7 @@ sub check_hf_entries($$) (NULL|"[A-Z0-9 '\./\(\)\?_:-]+") # blurb (NULL or a string) \s*,\s* HFILL # HFILL - }xgios); + }xgios); #print "Found @items items\n"; while (@items) { @@ -1221,12 +1315,14 @@ while ($_ = $ARGV[0]) # optionally check the hf entries if ($check_hf) { - $errorCount += check_hf_entries(\$fileContents, $filename) + $errorCount += check_hf_entries(\$fileContents, $filename); } # Remove all the C-comments and strings $fileContents =~ s {$commentAndStringRegex} []xog; + #check_ett_registration(\$fileContents, $filename); + if ($fileContents =~ m{ // }xo) { print STDERR "Error: Found C++ style comments in " .$filename."\n"; @@ -1282,7 +1378,7 @@ while ($_ = $ARGV[0]) } if (@foundAPIs && ! $machine_readable_output) { - print STDERR $pfx . ": Found " . $apiGroup . " APIs in ".$filename.": ".join(',', @foundAPIs)."\n" + print STDERR $pfx . ": Found " . $apiGroup . " APIs in ".$filename.": ".join(',', @foundAPIs)."\n"; } if (@foundAPIs && $machine_readable_output) { for my $api (@foundAPIs) { |