summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMarkus Armbruster2019-06-04 20:16:16 +0200
committerMarkus Armbruster2019-06-12 13:20:20 +0200
commitc0a9956b32e2806a9d50ce8c651ace140f5f79f1 (patch)
treec308f7fa8b519be812f6edb61ced1fe17fd1da35 /scripts
parentNormalize position of header guard (diff)
downloadqemu-c0a9956b32e2806a9d50ce8c651ace140f5f79f1.tar.gz
qemu-c0a9956b32e2806a9d50ce8c651ace140f5f79f1.tar.xz
qemu-c0a9956b32e2806a9d50ce8c651ace140f5f79f1.zip
scripts/clean-header-guards: Fix handling of trailing comments
clean-header-guards.pl fails to recognize a header guard #endif when it's followed by a // comment, or multiple comments. Fix that. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20190604181618.19980-3-armbru@redhat.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/clean-header-guards.pl12
1 files changed, 7 insertions, 5 deletions
diff --git a/scripts/clean-header-guards.pl b/scripts/clean-header-guards.pl
index 5e67f1998c..f47d673ad5 100755
--- a/scripts/clean-header-guards.pl
+++ b/scripts/clean-header-guards.pl
@@ -103,7 +103,7 @@ sub preprocess {
for my $fname (@ARGV) {
my $text = slurp($fname);
- $text =~ m,\A(\s*\n|\s*//\N*\n|\s*/\*.*?\*/\s*\n)*|,msg;
+ $text =~ m,\A(\s*\n|\s*//\N*\n|\s*/\*.*?\*/\s*\n)*|,sg;
my $pre = $&;
unless ($text =~ /\G(.*\n)/g) {
$text =~ /\G.*/;
@@ -137,14 +137,16 @@ for my $fname (@ARGV) {
}
unless ($body =~ m,\A((.*\n)*)
- (\s*\#\s*endif\s*(/\*\s*.*\s*\*/\s*)?\n?)
- (\n|\s)*\Z,x) {
+ ([ \t]*\#[ \t]*endif([ \t]*\N*)\n)
+ ((?s)(\s*\n|\s*//\N*\n|\s*/\*.*?\*/\s*\n)*)
+ \Z,x) {
skipping($fname, "can't find end of header guard");
next;
}
$body = $1;
my $line3 = $3;
my $endif_comment = $4;
+ my $post = $5;
my $oldg = $guard;
@@ -186,14 +188,14 @@ for my $fname (@ARGV) {
my $newl1 = "#ifndef $guard\n";
my $newl2 = "#define $guard\n";
my $newl3 = "#endif\n";
- $newl3 =~ s,\Z, /* $guard */, if defined $endif_comment;
+ $newl3 =~ s,\Z, /* $guard */, if $endif_comment;
if ($line1 ne $newl1 or $line2 ne $newl2 or $line3 ne $newl3) {
$pre =~ s/\n*\Z/\n\n/ if $pre =~ /\N/;
$body =~ s/\A\n*/\n/;
if ($opt_n) {
print "$fname would be cleaned up\n" if $opt_v;
} else {
- unslurp($fname, "$pre$newl1$newl2$body$newl3");
+ unslurp($fname, "$pre$newl1$newl2$body$newl3$post");
print "$fname cleaned up\n" if $opt_v;
}
}