French translation update - fixes
[ardour.git] / tools / cstyle.py
index 415c47795dd2cfc909c3cde27b64624070aebdaa..7b7806bbb408d0216ab46f37a3d3054ceae46180 100755 (executable)
@@ -112,34 +112,38 @@ class CStyleChecker:
                self.indent_re = re.compile ("^\s*")
                self.last_line_indent = ""
                self.last_line_indent_curly = False
-               self.re_checks = \
+               self.error_checks = \
                         [ ( re.compile ("^ "),          "leading space as indentation instead of tab - use tabs to indent, spaces to align" )
-                          , ( re.compile ("{[^\s]"),      "missing space after open brace" )
+                        ]                                                                                                                                       
+               self.warning_checks = \
+                        [   ( re.compile ("{[^\s]"),      "missing space after open brace" )
                           , ( re.compile ("[^\s]}"),      "missing space before close brace" )
-                          , ( re.compile ("[ \t]+$"),     "contains trailing whitespace" )
-                          
+                          , ( re.compile ("^[ \t]+$"),     "empty line contains whitespace" )
+                          , ( re.compile ("[^\s][ \t]+$"),     "contains trailing whitespace" )
+
                           , ( re.compile (",[^\s\n]"),            "missing space after comma" )
                           , ( re.compile (";[a-zA-Z0-9]"),        "missing space after semi-colon" )
                           , ( re.compile ("=[^\s\"'=]"),          "missing space after assignment" )
                           
-                          # Open and close parenthesis.                                                                                                           
-                          , ( re.compile ("[^\s\(\[\*&']\("),             "missing space before open parenthesis" )
-                          , ( re.compile ("\)(-[^>]|[^,'\s\n\)\]-])"),    "missing space after close parenthesis" )
+                          # Open and close parenthesis.
+                          , ( re.compile ("[^_\s\(\[\*&']\("),             "missing space before open parenthesis" )
+                          , ( re.compile ("\)(-[^>]|[^;,'\s\n\)\]-])"),    "missing space after close parenthesis" )
                           , ( re.compile ("\( [^;]"),                     "space after open parenthesis" )
                           , ( re.compile ("[^;] \)"),                     "space before close parenthesis" )
-                          
+
                           # Open and close square brace.
                           , ( re.compile ("\[ "),                                 "space after open square brace" )
                           , ( re.compile (" \]"),                                 "space before close square brace" )
-                          
+
                           # Space around operators.
                           , ( re.compile ("[^\s][\*/%+-][=][^\s]"),               "missing space around opassign" )
                           , ( re.compile ("[^\s][<>!=^/][=]{1,2}[^\s]"),  "missing space around comparison" )
-                          
+
                           # Parens around single argument to return.
                           , ( re.compile ("\s+return\s+\([a-zA-Z0-9_]+\)\s+;"),   "parens around return value" )
                         ]                                                                                                                                       
 
+                
 
        def get_error_count (self):
                """
@@ -203,13 +207,20 @@ class CStyleChecker:
                else:
                        self.last_line_indent_curly = False
 
-               # Now all the regex checks.
-               for (check_re, msg) in self.re_checks:
+               # Now all the stylistic warnings regex checks.
+               for (check_re, msg) in self.warning_checks:
+                       if check_re.search (line):
+                               self.warning (msg)
+
+                # Now all the stylistic error regex checks.
+               for (check_re, msg) in self.error_checks:
                        if check_re.search (line):
                                self.error (msg)
 
-               if re.search ("[a-zA-Z0-9][<>!=^/&\|]{1,2}[a-zA-Z0-9]", line):
-                       if not re.search (".*#include.*[a-zA-Z0-9]/[a-zA-Z]", line):
+                                
+               if re.search ("[a-zA-Z0-9_][<>!=^/&\|]{1,2}[a-zA-Z0-9_]", line):
+                        # ignore #include <foo.h> and C++ templates with indirection/pointer/reference operators
+                       if not re.search (".*#include.*[a-zA-Z0-9]/[a-zA-Z]", line) and not re.search ("[a-zA-Z0-9_]>[&\*]*\s", line):
                                self.error ("missing space around operator")
 
                self.last_line_indent = indent
@@ -219,11 +230,19 @@ class CStyleChecker:
                """
                Print an error message and increment the error count.
                """
-               print ("%s (%d) : %s" % (self.filename, self.line_num, msg))
+               print ("%s (%d) : STYLE ERROR %s" % (self.filename, self.line_num, msg))
                if self.debug:
                        print ("'" + self.orig_line + "'")
                self.error_count += 1
 
+       def warning (self, msg):
+               """
+               Print a warning message and increment the error count.
+               """
+               print ("%s (%d) : STYLE WARNING %s" % (self.filename, self.line_num, msg))
+               if self.debug:
+                       print ("'" + self.orig_line + "'")
+                
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
 if len (sys.argv) < 1: