We test whitespace with lots of other characters now.
---
build-aux/bracket-spacing.pl | 204 -------------------------------------------
build-aux/check-spacing.pl | 204 +++++++++++++++++++++++++++++++++++++++++++
cfg.mk | 6 +-
3 files changed, 207 insertions(+), 207 deletions(-)
delete mode 100755 build-aux/bracket-spacing.pl
create mode 100755 build-aux/check-spacing.pl
diff --git a/build-aux/bracket-spacing.pl b/build-aux/bracket-spacing.pl
deleted file mode 100755
index 5bc96d2..0000000
--- a/build-aux/bracket-spacing.pl
+++ /dev/null
@@ -1,204 +0,0 @@
-#!/usr/bin/perl
-#
-# bracket-spacing.pl: Report any usage of 'function (..args..)'
-# Also check for other syntax issues, such as correct use of ';'
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library. If not, see
-# <
http://www.gnu.org/licenses/>.
-#
-# Authors:
-# Daniel P. Berrange <berrange(a)redhat.com>
-
-use strict;
-use warnings;
-
-my $ret = 0;
-my $incomment = 0;
-
-foreach my $file (@ARGV) {
- # Per-file variables for multiline Curly Bracket (cb_) check
- my $cb_linenum = 0;
- my $cb_code = "";
- my $cb_scolon = 0;
-
- open FILE, $file;
-
- while (defined (my $line = <FILE>)) {
- my $data = $line;
- # For temporary modifications
- my $tmpdata;
-
- # Kill any quoted , ; = or "
- $data =~ s/'[";,=]'/'X'/g;
-
- # Kill any quoted strings
- $data =~ s,"([^\\\"]|\\.)*","XXX",g;
-
- # Kill any C++ style comments
- $data =~ s,//.*$,//,;
-
- next if $data =~ /^#/;
-
- # Kill contents of multi-line comments
- # and detect end of multi-line comments
- if ($incomment) {
- if ($data =~ m,\*/,) {
- $incomment = 0;
- $data =~ s,^.*\*/,*/,;
- } else {
- $data = "";
- }
- }
-
- # Kill single line comments, and detect
- # start of multi-line comments
- if ($data =~ m,/\*.*\*/,) {
- $data =~ s,/\*.*\*/,/* */,;
- } elsif ($data =~ m,/\*,) {
- $incomment = 1;
- $data =~ s,/\*.*,/*,;
- }
-
- # We need to match things like
- #
- # int foo (int bar, bool wizz);
- # foo (bar, wizz);
- #
- # but not match things like:
- #
- # typedef int (*foo)(bar wizz)
- #
- # we can't do this (efficiently) without
- # missing things like
- #
- # foo (*bar, wizz);
- #
- # 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;
-
- # Allow space after keywords only
- if ($kw =~ /^(if|for|while|switch|return)$/) {
- $tmpdata =~ s/($kw\s\()/XXX(/;
- } else {
- print "Whitespace after non-keyword:\n";
- print "$file:$.: $line";
- $ret = 1;
- last;
- }
- }
-
- # Require whitespace immediately after keywords,
- # but none after the opening bracket
- if ($data =~ /\b(if|for|while|switch|return)\(/ ||
- $data =~ /\b(if|for|while|switch|return)\s+\(\s/) {
- print "No whitespace after keyword:\n";
- print "$file:$.: $line";
- $ret = 1;
- }
-
- # Forbid whitespace between )( of a function typedef
- if ($data =~ /\(\*\w+\)\s+\(/) {
- print "Whitespace between ')' and '(':\n";
- print "$file:$.: $line";
- $ret = 1;
- }
-
- # Forbid whitespace following ( or prior to )
- if ($data =~ /\S\s+\)/ ||
- $data =~ /\(\s+\S/) {
- print "Whitespace after '(' or before ')':\n";
- print "$file:$.: $line";
- $ret = 1;
- }
-
- # Forbid whitespace before ";" or ",". Things like below are
allowed:
- #
- # 1) The expression is empty for "for" loop. E.g.
- # for (i = 0; ; i++)
- #
- # 2) An empty statement. E.g.
- # while (write(statuswrite, &status, 1) == -1 &&
- # errno == EINTR)
- # ;
- #
- if ($data =~ /[^;\s]\s+[;,]/) {
- print "Whitespace before (semi)colon:\n";
- print "$file:$.: $line";
- $ret = 1;
- }
-
- # Require EOL, macro line continuation, or whitespace after ";".
- # Allow "for (;;)" as an exception.
- if ($data =~ /;[^ \\\n;)]/) {
- print "Invalid character after semicolon:\n";
- print "$file:$.: $line";
- $ret = 1;
- }
-
- # Require EOL, space, or enum/struct end after comma.
- if ($data =~ /,[^ \\\n)}]/) {
- print "Invalid character after comma:\n";
- print "$file:$.: $line";
- $ret = 1;
- }
-
- # Require spaces around assignment '=', compounds and '=='
- # with the exception of virAssertCmpInt()
- $tmpdata = $data;
- $tmpdata =~ s/(virAssertCmpInt\(.* ).?=,/$1op,/;
- if ($tmpdata =~ /[^ ]\b[!<>&|\-+*\/%\^=]?=[^=]/ ||
- $tmpdata =~ /=[^= \\\n]/) {
- print "Spacing around '=' or '==':\n";
- print "$file:$.: $line";
- $ret = 1;
- }
-
- # One line conditional statements with one line bodies should
- # not use curly brackets.
- if ($data =~ /^\s*(if|while|for)\b.*\{$/) {
- $cb_linenum = $.;
- $cb_code = $line;
- $cb_scolon = 0;
- }
-
- # We need to check for exactly one semicolon inside the body,
- # because empty statements (e.g. with comment only) are
- # allowed
- if ($cb_linenum == $. - 1 && $data =~ /^[^;]*;[^;]*$/) {
- $cb_code .= $line;
- $cb_scolon = 1;
- }
-
- if ($data =~ /^\s*}\s*$/ &&
- $cb_linenum == $. - 2 &&
- $cb_scolon) {
-
- print "Curly brackets around single-line body:\n";
- print "$file:$cb_linenum-$.:\n$cb_code$line";
- $ret = 1;
-
- # There _should_ be no need to reset the values; but to
- # keep my inner peace...
- $cb_linenum = 0;
- $cb_scolon = 0;
- $cb_code = "";
- }
- }
- close FILE;
-}
-
-exit $ret;
diff --git a/build-aux/check-spacing.pl b/build-aux/check-spacing.pl
new file mode 100755
index 0000000..83b5898
--- /dev/null
+++ b/build-aux/check-spacing.pl
@@ -0,0 +1,204 @@
+#!/usr/bin/perl
+#
+# check-spacing.pl: Report any usage of 'function (..args..)'
+# Also check for other syntax issues, such as correct use of ';'
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see
+# <
http://www.gnu.org/licenses/>.
+#
+# Authors:
+# Daniel P. Berrange <berrange(a)redhat.com>
+
+use strict;
+use warnings;
+
+my $ret = 0;
+my $incomment = 0;
+
+foreach my $file (@ARGV) {
+ # Per-file variables for multiline Curly Bracket (cb_) check
+ my $cb_linenum = 0;
+ my $cb_code = "";
+ my $cb_scolon = 0;
+
+ open FILE, $file;
+
+ while (defined (my $line = <FILE>)) {
+ my $data = $line;
+ # For temporary modifications
+ my $tmpdata;
+
+ # Kill any quoted , ; = or "
+ $data =~ s/'[";,=]'/'X'/g;
+
+ # Kill any quoted strings
+ $data =~ s,"([^\\\"]|\\.)*","XXX",g;
+
+ # Kill any C++ style comments
+ $data =~ s,//.*$,//,;
+
+ next if $data =~ /^#/;
+
+ # Kill contents of multi-line comments
+ # and detect end of multi-line comments
+ if ($incomment) {
+ if ($data =~ m,\*/,) {
+ $incomment = 0;
+ $data =~ s,^.*\*/,*/,;
+ } else {
+ $data = "";
+ }
+ }
+
+ # Kill single line comments, and detect
+ # start of multi-line comments
+ if ($data =~ m,/\*.*\*/,) {
+ $data =~ s,/\*.*\*/,/* */,;
+ } elsif ($data =~ m,/\*,) {
+ $incomment = 1;
+ $data =~ s,/\*.*,/*,;
+ }
+
+ # We need to match things like
+ #
+ # int foo (int bar, bool wizz);
+ # foo (bar, wizz);
+ #
+ # but not match things like:
+ #
+ # typedef int (*foo)(bar wizz)
+ #
+ # we can't do this (efficiently) without
+ # missing things like
+ #
+ # foo (*bar, wizz);
+ #
+ # 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;
+
+ # Allow space after keywords only
+ if ($kw =~ /^(if|for|while|switch|return)$/) {
+ $tmpdata =~ s/($kw\s\()/XXX(/;
+ } else {
+ print "Whitespace after non-keyword:\n";
+ print "$file:$.: $line";
+ $ret = 1;
+ last;
+ }
+ }
+
+ # Require whitespace immediately after keywords,
+ # but none after the opening bracket
+ if ($data =~ /\b(if|for|while|switch|return)\(/ ||
+ $data =~ /\b(if|for|while|switch|return)\s+\(\s/) {
+ print "No whitespace after keyword:\n";
+ print "$file:$.: $line";
+ $ret = 1;
+ }
+
+ # Forbid whitespace between )( of a function typedef
+ if ($data =~ /\(\*\w+\)\s+\(/) {
+ print "Whitespace between ')' and '(':\n";
+ print "$file:$.: $line";
+ $ret = 1;
+ }
+
+ # Forbid whitespace following ( or prior to )
+ if ($data =~ /\S\s+\)/ ||
+ $data =~ /\(\s+\S/) {
+ print "Whitespace after '(' or before ')':\n";
+ print "$file:$.: $line";
+ $ret = 1;
+ }
+
+ # Forbid whitespace before ";" or ",". Things like below are
allowed:
+ #
+ # 1) The expression is empty for "for" loop. E.g.
+ # for (i = 0; ; i++)
+ #
+ # 2) An empty statement. E.g.
+ # while (write(statuswrite, &status, 1) == -1 &&
+ # errno == EINTR)
+ # ;
+ #
+ if ($data =~ /[^;\s]\s+[;,]/) {
+ print "Whitespace before (semi)colon:\n";
+ print "$file:$.: $line";
+ $ret = 1;
+ }
+
+ # Require EOL, macro line continuation, or whitespace after ";".
+ # Allow "for (;;)" as an exception.
+ if ($data =~ /;[^ \\\n;)]/) {
+ print "Invalid character after semicolon:\n";
+ print "$file:$.: $line";
+ $ret = 1;
+ }
+
+ # Require EOL, space, or enum/struct end after comma.
+ if ($data =~ /,[^ \\\n)}]/) {
+ print "Invalid character after comma:\n";
+ print "$file:$.: $line";
+ $ret = 1;
+ }
+
+ # Require spaces around assignment '=', compounds and '=='
+ # with the exception of virAssertCmpInt()
+ $tmpdata = $data;
+ $tmpdata =~ s/(virAssertCmpInt\(.* ).?=,/$1op,/;
+ if ($tmpdata =~ /[^ ]\b[!<>&|\-+*\/%\^=]?=[^=]/ ||
+ $tmpdata =~ /=[^= \\\n]/) {
+ print "Spacing around '=' or '==':\n";
+ print "$file:$.: $line";
+ $ret = 1;
+ }
+
+ # One line conditional statements with one line bodies should
+ # not use curly brackets.
+ if ($data =~ /^\s*(if|while|for)\b.*\{$/) {
+ $cb_linenum = $.;
+ $cb_code = $line;
+ $cb_scolon = 0;
+ }
+
+ # We need to check for exactly one semicolon inside the body,
+ # because empty statements (e.g. with comment only) are
+ # allowed
+ if ($cb_linenum == $. - 1 && $data =~ /^[^;]*;[^;]*$/) {
+ $cb_code .= $line;
+ $cb_scolon = 1;
+ }
+
+ if ($data =~ /^\s*}\s*$/ &&
+ $cb_linenum == $. - 2 &&
+ $cb_scolon) {
+
+ print "Curly brackets around single-line body:\n";
+ print "$file:$cb_linenum-$.:\n$cb_code$line";
+ $ret = 1;
+
+ # There _should_ be no need to reset the values; but to
+ # keep my inner peace...
+ $cb_linenum = 0;
+ $cb_scolon = 0;
+ $cb_code = "";
+ }
+ }
+ close FILE;
+}
+
+exit $ret;
diff --git a/cfg.mk b/cfg.mk
index 2939458..e7d49b6 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1104,12 +1104,12 @@ _autogen:
# regenerate HACKING as part of the syntax-check
ifneq ($(_gl-Makefile),)
-syntax-check: $(top_srcdir)/HACKING bracket-spacing-check test-wrap-argv
+syntax-check: $(top_srcdir)/HACKING spacing-check test-wrap-argv
endif
-bracket-spacing-check:
+spacing-check:
$(AM_V_GEN)files=`$(VC_LIST) | grep '\.c$$'`; \
- $(PERL) $(top_srcdir)/build-aux/bracket-spacing.pl $$files || \
+ $(PERL) $(top_srcdir)/build-aux/check-spacing.pl $$files || \
{ echo '$(ME): incorrect formatting, see HACKING for rules' 1>&2; \
exit 1; }
--
2.7.3