bracket-spacing: Don't modify current line

In bracket-spacing.pl, the current $line is being modified in $data.
That, however, spoils that $data for another check.  Introduce new
$tmpdata variable that can be used for temporary modifications.  The
difference between $data and $line is that $data are as much cleaned as
possible from non-code blocks and these changes must be kept.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Martin Kletzander 2014-11-13 15:04:52 +01:00
parent a9d07d33a0
commit d697de90c0

View File

@ -31,6 +31,8 @@ foreach my $file (@ARGV) {
while (defined (my $line = <FILE>)) { while (defined (my $line = <FILE>)) {
my $data = $line; my $data = $line;
# For temporary modifications
my $tmpdata;
# Kill any quoted , ; = or " # Kill any quoted , ; = or "
$data =~ s/'[";,=]'/'X'/g; $data =~ s/'[";,=]'/'X'/g;
@ -77,12 +79,15 @@ foreach my $file (@ARGV) {
# #
# foo (*bar, wizz); # foo (*bar, wizz);
# #
while ($data =~ /(\w+)\s\((?!\*)/) { # We also don't want to spoil the $data so it can be used
# later on.
$tmpdata = $data;
while ($tmpdata =~ /(\w+)\s\((?!\*)/) {
my $kw = $1; my $kw = $1;
# Allow space after keywords only # Allow space after keywords only
if ($kw =~ /^(if|for|while|switch|return)$/) { if ($kw =~ /^(if|for|while|switch|return)$/) {
$data =~ s/($kw\s\()/XXX(/; $tmpdata =~ s/($kw\s\()/XXX(/;
} else { } else {
print "$file:$.: $line"; print "$file:$.: $line";
$ret = 1; $ret = 1;
@ -147,9 +152,10 @@ foreach my $file (@ARGV) {
# Require spaces around assignment '=', compounds and '==' # Require spaces around assignment '=', compounds and '=='
# with the exception of virAssertCmpInt() # with the exception of virAssertCmpInt()
$data =~ s/(virAssertCmpInt\(.* ).?=,/$1op,/; $tmpdata = $data;
while ($data =~ /[^ ]\b[!<>&|\-+*\/%\^=]?=[^=]/ || $tmpdata =~ s/(virAssertCmpInt\(.* ).?=,/$1op,/;
$data =~ /=[^= \\\n]/) { while ($tmpdata =~ /[^ ]\b[!<>&|\-+*\/%\^=]?=[^=]/ ||
$tmpdata =~ /=[^= \\\n]/) {
print "$file:$.: $line"; print "$file:$.: $line";
$ret = 1; $ret = 1;
last; last;