]> thyrsus.com Git - comparator.git/commitdiff
Improve filtering.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 18 Sep 2003 05:13:23 +0000 (05:13 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 18 Sep 2003 05:13:23 +0000 (05:13 +0000)
linebyline.c
main.c
report.c
shred.h
shredtree.c

index 0547953f05931e72065962cebc261c333d9b64dd..7fc9ad899db7636df834d07b5e114fd03d4f6a12 100644 (file)
@@ -7,23 +7,23 @@
 
 static char *c_patterns[] = {
     /* Idioms that don't convey any meaning in isolation */
-    "return [a-z]+", "return -?[01]+",
-    "goto +[a-z]+", "exit *\\([01]\\)",
+    "return [a-z]+", "return [01]+",
+    "goto +[a-z]+", "exit *[01]",
     /* Pragmas */
-    "/\\* *ARGSUSED *\\*/",
-    "/\\* *NOTREACHED *\\*/", 
-    "/\\* *FALL *THRO?UG?H? *\\*/",
+    " ARGSUSED ",
+    " NOTREACHED ", 
+    " FALL *THRO?UG?H? ",
     /* Bare C keywords */
     " auto ", " break ",  " case "," continue ", " default ", " do ", " else ",
     " enum ", " if ", " goto "," return ", " switch ", " while ", " int ",
     " long ", " short ", " static ", " struct ", " typedef ", " union ", 
     " void ",
-    /* Preprocessor constructs (# has already been stripped)*/
-    "^ *define","^ *endif","^ *else", "^ *ifdef ","^ *ifndef ",
+    /* Preprocessor constructs (# has already been stripped) */
+    "^ define"," endif"," else", " ifdef "," ifndef ",
     /* Common preprocessor macros, not significant by themselves. */
     " ASSERT ", " EXTERN ", " FALSE ", " NULL "," STATIC ", " TRUE ",
     /* Macro include lines are noise, too. */
-    "^ *include.*","^ *line.*",
+    " include .*"," line .*",
     /* Common error macros. */
     " EFAULT ",
     " EINVAL ",
diff --git a/main.c b/main.c
index 1893626974671d40d3a1ad4271a21132efb47d8d..3ca3b8b6216bc8ed14ad95b42be0e59908cc0964 100644 (file)
--- a/main.c
+++ b/main.c
@@ -374,19 +374,20 @@ void dump_array(const char *legend,
 
     fputs(legend, stdout);
     for (np = obarray; np < obarray + hashcount; np++)
-    {
-       fprintf(stdout, "%2d: %s %s:%d:%d",
-               np-obarray, 
-               hash_dump(np->hash.hash),
-               np->file->name, np->hash.start, np->hash.end);
-       if (np->hash.flags)
+       if (!(np->hash.flags & INTERNAL_FLAG))
        {
-           fputc('\t', stdout);
-           dump_flags(np->hash.flags, stdout);
-           fprintf(stdout, " (0x%02x)", np->hash.flags);
+           fprintf(stdout, "%2d: %s %s:%d:%d",
+                   np-obarray, 
+                   hash_dump(np->hash.hash),
+                   np->file->name, np->hash.start, np->hash.end);
+           if (np->hash.flags)
+           {
+               fputc('\t', stdout);
+               dump_flags(np->hash.flags, stdout);
+               fprintf(stdout, " (0x%02x)", np->hash.flags);
+           }
+           fputc('\n', stdout);
        }
-       fputc('\n', stdout);
-    }
 }
 
 void report_time(char *legend, ...)
index 5f6005d8c533457c368f9fbce6dd187c144f9bc7..5f720d104c93fa9d0a6d6f03ab65c2ea1391c01e 100644 (file)
--- a/report.c
+++ b/report.c
@@ -66,6 +66,7 @@ static int merge_ranges(struct sorthash_t *p,
        p[i].hash.start = min(p[i].hash.start, q[i].hash.start);
        p[i].hash.end   = max(p[i].hash.end, q[i].hash.end);
        p[i].hash.flags |= q[i].hash.flags;
+       q[i].hash.flags = INTERNAL_FLAG;        /* used only in debug code */
     }
     return(1);
 }
@@ -226,15 +227,15 @@ static int compact_matches(struct sorthash_t *obarray, const int hashcount)
       * The technique: first mark...
       */
      if (SORTHASHCMP(obarray, obarray+1))
-        obarray[0].hash.flags = UNIQUE_FLAG;
+        obarray[0].hash.flags = INTERNAL_FLAG;
      for (np = obarray+1; np < obarray + hashcount-1; np++)
         if (SORTHASHCMP(np, np-1) && SORTHASHCMP(np, np+1))
-            np->hash.flags = UNIQUE_FLAG;
+            np->hash.flags = INTERNAL_FLAG;
      if (SORTHASHCMP(obarray+hashcount-2, obarray+hashcount-1))
-        obarray[hashcount-1].hash.flags = UNIQUE_FLAG;
+        obarray[hashcount-1].hash.flags = INTERNAL_FLAG;
      /* ...then sweep. */
      for (mp = np = obarray; np < obarray + hashcount; np++)
-        if (np->hash.flags != UNIQUE_FLAG)
+        if (np->hash.flags != INTERNAL_FLAG)
             *mp++ = *np;
      /* now we get to reduce the memory footprint */
      report_time("Compaction reduced %d shreds to %d", 
@@ -282,7 +283,10 @@ struct match_t *reduce_matches(struct sorthash_t *obarray, int *hashcountp)
             if (!sametree(np[i].file->name, np[(i+1) % nmatches].file->name))
                 heterogenous++;
         if (!heterogenous)
+        {
+            np[i].hash.flags = INTERNAL_FLAG;  /* used only in debug code */
             continue;
+        }
 
         if (debug)
         {
@@ -362,6 +366,8 @@ void emit_report1(struct sorthash_t *obarray, int hashcount)
        dump_array("After removing uniques.\n", obarray, hashcount);
     report_time("%d range groups after removing unique hashes", matchcount);
     mergecount = collapse_ranges(hitlist, matchcount);
+    if (debug)
+       dump_array("After merging ranges.\n", obarray, hashcount);
     report_time("%d range groups after merging", mergecount);
 
     /*
diff --git a/shred.h b/shred.h
index 3270382432979a7a593e2253ef375528ced869b6..c67d98f7186fe415fd21b9cc324a8c0906c84e8b 100644 (file)
--- a/shred.h
+++ b/shred.h
@@ -35,7 +35,7 @@ struct hash_t
 #define C_CODE         0x01    /* identified as C code */
 #define SHELL_CODE     0x02    /* identified as shell code */
 #define CATEGORIZED    0x03    /* we can significance-test this */
-#define UNIQUE_FLAG    0x80    /* internal use only */
+#define INTERNAL_FLAG  0x80    /* internal use only */
 };
 #define SORTHASHCMP(s, t) hash_compare((s)->hash.hash, (t)->hash.hash)
 
index a04537baf751bc9ba0cf6fd246a9afd758f5ebaf..d7ddb3a4dba6e576949d3f0a480723bbf02616ce 100644 (file)
@@ -40,7 +40,7 @@ static int eligible(const char *file)
 #define endswith(suff) !strcmp(suff, file + strlen(file) - strlen(suff))
     if (endswith(".c") || endswith(".h") || endswith(".html"))
        return(1);
-    else if (endswith(".o") || endswith("~"))
+    else if (endswith(".o") || endswith("~") || endswith(".bdf"))
        return(0);
     else if (strstr(file, "CVS") || strstr(file,"RCS") || strstr(file,"SCCS"))
        return(0);