aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Morriss <jeff.morriss.ws@gmail.com>2018-10-19 15:22:01 -0400
committerAnders Broman <a.broman58@gmail.com>2018-10-20 06:59:20 +0000
commit451b93ed99505b50174a9aa2a3032868c5fd45be (patch)
treeecce65384feb03b4b3c9530ece9443d70397bf2d
parent89d2b33b3870bf27149842f133ecf9748bdd1462 (diff)
checkAPIs: use new regex to remove comments.
The new pattern is from the Perl FAQ; it works better for me than the old code. Of note is that it works with C++/C99-style comments following a statement (as opposed to at the start of a line). The new regex is only slightly slower than the old one: `make checkAPI` goes from 3m30s of user time to 3m35s. The big functional difference can be seen by looking at the post-removal contents of packet-hl7.c. Before: struct msh { // typical/default values char field_separator; // char component_separator; // char repetition_separator; // char escape_character; // &\0\0MSH\0\0'; if (tree) { (With the old regex we lost a lot of code!) After: struct msh { char field_separator; char component_separator; char repetition_separator; char escape_character; char subcomponent_separator; char message_type[4]; char trigger_event[4]; }; Change-Id: Iac35413d480cc7b05b820cb3b292f87ed30e6801 Reviewed-on: https://code.wireshark.org/review/30265 Petri-Dish: Jeff Morriss <jeff.morriss.ws@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl> Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rwxr-xr-xtools/checkAPIs.pl20
1 files changed, 4 insertions, 16 deletions
diff --git a/tools/checkAPIs.pl b/tools/checkAPIs.pl
index 6caec1df53..7667898a10 100755
--- a/tools/checkAPIs.pl
+++ b/tools/checkAPIs.pl
@@ -1052,13 +1052,6 @@ my $debug = 0;
# http://aspn.activestate.com/ASPN/Cookbook/Rx/Recipe/59811
# They are in the public domain.
-# 1. A complicated regex which matches "classic C"-style comments.
-my $CComment = qr{ / [*] [^*]* [*]+ (?: [^/*] [^*]* [*]+ )* / }x;
-
-# 1.a A regex that matches C++/C99-and-later-style comments.
-# XXX handle comments after a statement and not just at the beginning of a line.
-my $CppComment = qr{ ^ \s* // (.*?) \n }xm;
-
# 2. A regex which matches double-quoted strings.
# ?s added so that strings containing a 'line continuation'
# ( \ followed by a new-line) will match.
@@ -1067,13 +1060,6 @@ my $DoubleQuotedStr = qr{ (?: ["] (?s: \\. | [^\"\\])* ["]) }x;
# 3. A regex which matches single-quoted strings.
my $SingleQuotedStr = qr{ (?: \' (?: \\. | [^\'\\])* [']) }x;
-# 4. Now combine 1 through 3 to produce a regex which
-# matches _either_ double or single quoted strings
-# OR comments. We surround the comment-matching
-# regex in capturing parenthesis to store the contents
-# of the comment in $1.
-# my $commentAndStringRegex = qr{(?:$DoubleQuotedStr|$SingleQuotedStr)|($CComment)|($CppComment)};
-
#
# MAIN
#
@@ -1207,8 +1193,10 @@ while ($_ = pop @filelist)
$errorCount++;
}
- # Remove all the C/C++ comments
- $fileContents =~ s{ $CComment | $CppComment } []xog;
+ # Remove C/C++ comments
+ # The below pattern is modified (to keep newlines at the end of C++-style comments) from that at:
+ # https://perldoc.perl.org/perlfaq6.html#How-do-I-use-a-regular-expression-to-strip-C-style-comments-from-a-file?
+ $fileContents =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $3 ? $3 : "\n"#gse;
# optionally check the hf entries (including those under #if 0)
if ($check_hf) {