]> xenbits.xensource.com Git - libvirt.git/commitdiff
syntax-check: mandate space after mid-line semicolon
authorEric Blake <eblake@redhat.com>
Fri, 24 May 2013 16:43:45 +0000 (10:43 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 28 May 2013 14:26:05 +0000 (08:26 -0600)
Enforce the style cleanup in the previous patch.

* build-aux/bracket-spacing.pl: Enforce trailing spacing.
* cfg.mk (bracket-spacing-check): Tweak error wording.
* docs/hacking.html.in: Document the rule.
* HACKING: Regenerate.

Signed-off-by: Eric Blake <eblake@redhat.com>
HACKING
build-aux/bracket-spacing.pl
cfg.mk
docs/hacking.html.in

diff --git a/HACKING b/HACKING
index 2bd6d692f9e2d6c5b4f68464351757f2f09d7cd5..a310faa067d51670d0859df0edbc3f724f3b4125 100644 (file)
--- a/HACKING
+++ b/HACKING
@@ -318,6 +318,29 @@ immediately prior to any closing bracket. E.g.
       int foo(int wizz);    // Good
 
 
+Semicolons
+==========
+Semicolons should never have a space beforehand. Inside the condition of a
+"for" loop, there should always be a space or line break after each semicolon,
+except for the special case of an infinite loop (although more infinite loops
+use "while"). While not enforced, loop counters generally use post-increment.
+
+      for (i = 0 ;i < limit ; ++i) { // Bad
+      for (i = 0; i < limit; i++) { // Good
+      for (;;) { // ok
+      while (1) { // Better
+
+Empty loop bodies are better represented with curly braces and a comment,
+although use of a semicolon is not currently rejected.
+
+      while ((rc = waitpid(pid, &st, 0) == -1) &&
+             errno == EINTR); // ok
+      while ((rc = waitpid(pid, &st, 0) == -1) &&
+             errno == EINTR) { // Better
+          /* nothing */
+      }
+
+
 Curly braces
 ============
 Omit the curly braces around an "if", "while", "for" etc. body only when that
index 2eeeeb463af8d5342dad8b566463df21fdd7ade8..fbb323e51045a47c0068b8818c9708b133fd246c 100755 (executable)
@@ -1,6 +1,7 @@
 #!/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
@@ -31,6 +32,9 @@ foreach my $file (@ARGV) {
     while (defined (my $line = <FILE>)) {
         my $data = $line;
 
+        # Kill any quoted ; or "
+        $data =~ s,'[";]','X',g;
+
         # Kill any quoted strings
         $data =~ s,"([^\\\"]|\\.)*","XXX",g;
 
@@ -125,6 +129,14 @@ foreach my $file (@ARGV) {
             $ret = 1;
             last;
         }
+
+        # Require EOL, macro line continuation, or whitespace after ";".
+        # Allow "for (;;)" as an exception.
+        while ($data =~ /;[^    \\\n;)]/) {
+            print "$file:$.: $line";
+            $ret = 1;
+            last;
+        }
     }
     close FILE;
 }
diff --git a/cfg.mk b/cfg.mk
index 55359e886c8d0029d3f0d720f560981ddbf43a0a..a01df56a59b43cc4b8a3b621c2fe07360cd0a028 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -845,7 +845,8 @@ syntax-check: $(top_srcdir)/HACKING bracket-spacing-check
 bracket-spacing-check:
        $(AM_V_GEN)files=`$(VC_LIST) | grep '\.c$$'`; \
        $(PERL) $(top_srcdir)/build-aux/bracket-spacing.pl $$files || \
-          (echo $(ME): incorrect whitespace around brackets, see HACKING for rules && exit 1)
+         { echo "$(ME): incorrect whitespace, see HACKING for rules" 2>&; \
+           exit 1; }
 
 # sc_po_check can fail if generated files are not built first
 sc_po_check: \
index 78959f3ad3dea833ec94b0db48ae2e5b667c00cd..904b846e0168f3eda125cac6ed5b36ac447956b4 100644 (file)
       int foo(int wizz);    // Good
 </pre>
 
+    <h2><a name="semicolon">Semicolons</a></h2>
+
+    <p>
+      Semicolons should never have a space beforehand.  Inside the
+      condition of a <code>for</code> loop, there should always be a
+      space or line break after each semicolon, except for the special
+      case of an infinite loop (although more infinite loops
+      use <code>while</code>).  While not enforced, loop counters
+      generally use post-increment.
+    </p>
+    <pre>
+      for (i = 0 ;i &lt; limit ; ++i) { // Bad
+      for (i = 0; i &lt; limit; i++) { // Good
+      for (;;) { // ok
+      while (1) { // Better
+</pre>
+    <p>
+      Empty loop bodies are better represented with curly braces and a
+      comment, although use of a semicolon is not currently rejected.
+    </p>
+    <pre>
+      while ((rc = waitpid(pid, &amp;st, 0) == -1) &amp;&amp;
+             errno == EINTR); // ok
+      while ((rc = waitpid(pid, &amp;st, 0) == -1) &amp;&amp;
+             errno == EINTR) { // Better
+          /* nothing */
+      }
+</pre>
+
     <h2><a name="curly_braces">Curly braces</a></h2>
 
     <p>