From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 06/12] scripts/clean-header-guards: Fix handling of trailing comments
Date: Fri, 7 Jun 2019 17:26:40 +0200 [thread overview]
Message-ID: <20190607152646.4822-7-armbru@redhat.com> (raw)
In-Reply-To: <20190607152646.4822-1-armbru@redhat.com>
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>
---
| 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
--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;
}
}
--
2.21.0
next prev parent reply other threads:[~2019-06-07 18:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-07 15:26 [Qemu-devel] [PULL 00/12] Miscellaneous patches for 2019-06-07 Markus Armbruster
2019-06-07 15:26 ` [Qemu-devel] [PULL 01/12] qemu-common: Move tcg_enabled() etc. to sysemu/tcg.h Markus Armbruster
2019-06-07 15:26 ` [Qemu-devel] [PULL 02/12] qemu-common: Move qemu_isalnum() etc. to qemu/ctype.h Markus Armbruster
2019-06-07 15:26 ` [Qemu-devel] [PULL 03/12] Include qemu/module.h where needed, drop it from qemu-common.h Markus Armbruster
2019-06-07 15:26 ` [Qemu-devel] [PULL 04/12] Include qemu-common.h exactly where needed Markus Armbruster
2019-06-07 15:26 ` [Qemu-devel] [PULL 05/12] Normalize position of header guard Markus Armbruster
2019-06-07 15:26 ` Markus Armbruster [this message]
2019-06-07 15:26 ` [Qemu-devel] [PULL 07/12] Clean up a few header guard symbols Markus Armbruster
2019-06-07 15:26 ` [Qemu-devel] [PULL 08/12] Supply missing header guards Markus Armbruster
2019-06-07 15:26 ` [Qemu-devel] [PULL 09/12] Clean up a header guard symbols (again) Markus Armbruster
2019-06-07 15:26 ` [Qemu-devel] [PULL 10/12] MAINTAINERS: Remove duplicate entries of qemu-devel@nongnu.org Markus Armbruster
2019-06-07 15:26 ` [Qemu-devel] [PULL 11/12] MAINTAINERS: Improve section headlines Markus Armbruster
2019-06-07 15:26 ` [Qemu-devel] [PULL 12/12] MAINTAINERS: Polish headline decorations Markus Armbruster
2019-06-10 10:02 ` [Qemu-devel] [PULL 00/12] Miscellaneous patches for 2019-06-07 Peter Maydell
2019-06-11 15:26 ` Markus Armbruster
-- strict thread matches above, loose matches on Subject: below --
2019-06-11 15:24 [Qemu-devel] [PULL 00/12] Miscellaneous patches for 2019-06-11 Markus Armbruster
2019-06-11 15:24 ` [Qemu-devel] [PULL 06/12] scripts/clean-header-guards: Fix handling of trailing comments Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190607152646.4822-7-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).