]> thyrsus.com Git - comparator.git/commitdiff
Better significance filtering.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 25 Aug 2003 18:24:24 +0000 (18:24 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 25 Aug 2003 18:24:24 +0000 (18:24 +0000)
filterator

index 5284efd274d67ccbb3750500f8e4be50155c89e5..81c4f6b67c1c119c22646d213bf66824c082286a 100755 (executable)
@@ -9,11 +9,21 @@ shredline = re.compile("-> ([^:]*):([0-9]+)-([0-9]+)")
 
 # Tokens to be removed when checking whether a shred is significant
 C_junk = [r'\bbreak\b', r'\bcontinue\b', r'\bdefault\b',
-          r'\belse\b', r'\breturn\b',
+          r'\belse\b', r'\bif\b', r'\bgoto\b', r'\breturn\b',
           r'\bint\b', r'\blong\b', r'\bshort\b', r'\bstatic\b', r'\bvoid\b',
-          '#endif', '#else', r'#if\b', r'\bNULL\b',
+          r'#define',r'#endif',r'#else',r'#if\b',r'#ifdef\b',r'#ifndef\b', 
           r'/\*+', r'\*+/', r'\*+',
-          r'\b0\b', r'\b1\b',]
+          r'\b0\b', r'\b1\b',
+          # Common preprocessor macros, not significant by themselves.
+          r'\bASSERT\b', r'\bFALSE\b', r'\bNULL\b', r'\bSTATIC\b', r'\bTRUE\b',
+          # Common error macros.
+          r'\bEINVAL\b', r'\bENOSYS\b', 
+          # Conventional variables frequently found in kernel code.
+          # But if they're surrounded by nothing but C syntax and no
+          # 'real' identifiers, we're looking at boilerplate
+          # function-return code.
+          r'\berr\b', r'\berror\b', r'\brc\b', r'\bretcode\b', r'\bretval\b',
+          ]
 
 # C junk to be removed from matches; inclues all single-lowercase-letter vars. 
 junk = re.compile("|".join(C_junk + map(lambda x: r'\b' + chr(x) + r'\b',
@@ -69,7 +79,7 @@ if __name__ == '__main__':
         rfp.close()
         if nofilter or nontrivial(text):
             count += 1
-            print "%s:%s-%s:" % (file, start, end)
-            #sys.stdout.write(text)
-            print `nontrivial(text)`
+            print "%%%%#%%%% %s:%s-%s:" % (file, start, end)
+            sys.stdout.write(text)
+            #print `nontrivial(text)`
     print "%d overlaps." % count