]> thyrsus.com Git - comparator.git/commitdiff
Refactored.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 18 Sep 2003 06:44:49 +0000 (06:44 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 18 Sep 2003 06:44:49 +0000 (06:44 +0000)
main.c
report.c
shred.h

diff --git a/main.c b/main.c
index 607e57b767a8064deb5882f24595c95c478611d5..ef1d899db89233245f34d831c40e762927841c71 100644 (file)
--- a/main.c
+++ b/main.c
@@ -452,7 +452,7 @@ main(int argc, char *argv[])
     extern char        *optarg;        /* set by getopt */
     extern int optind;         /* set by getopt */
 
-    int status, file_only, compile_only, argcount;
+    int status, file_only, compile_only, argcount, mergecount;
     struct scf_t       *scf;
     char *dir, *outfile;
 
@@ -645,7 +645,8 @@ main(int argc, char *argv[])
     sort_hashes(sort_buffer, sort_count);
     report_time("Sort done");
 
-    emit_report1(sort_buffer, sort_count);
+    mergecount = merge_compare(sort_buffer, sort_count);
+    printf("Matches: %d\n", mergecount);
 
     puts("%%");
     for (scf = scflist; scf->next; scf = scf->next)
@@ -656,7 +657,7 @@ main(int argc, char *argv[])
               scf->totallines);
     puts("%%");
 
-    emit_report2();
+    emit_report();
 
     exit(0);
 }
index 7d2e7e1b81df47dc91f64ad9b7edf80cad066577..9570825a0d8a709d81d2a39b9e902e70b057ba2c 100644 (file)
--- a/report.c
+++ b/report.c
@@ -356,7 +356,7 @@ static int sortmatch(const void *a, const void *b)
 static struct match_t *hitlist;
 static int mergecount;
 
-void emit_report1(struct sorthash_t *obarray, int hashcount)
+int merge_compare(struct sorthash_t *obarray, int hashcount)
 /* report our results (header portion) */
 {
     struct match_t *match, *copy;
@@ -370,60 +370,65 @@ void emit_report1(struct sorthash_t *obarray, int hashcount)
     if (debug)
        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);
 
+    mergecount = collapse_ranges(hitlist, matchcount);
     /*
-     * A little extra effort so we can generate a sorted report.
-     * Compact the match list in order to cut the n log n qsort time
+     * Here's where we do significance filtering.  As a side effect,
+     * compact the match list in order to cut the n log n qsort time
      */
     for (copy = match = hitlist; match < hitlist + matchcount; match++)
        if (match->nmatches > 0 && copy < match)
-           *copy++ = *match;
+       {
+           int i, flags = 0, maxsize = 0;
+
+           for (i=0; i < match->nmatches; i++)
+           {
+               struct sorthash_t       *rp = match->matches+i;
+               int matchsize = rp->hash.end - rp->hash.start + 1;
+
+               if (matchsize >= maxsize)
+                   maxsize = matchsize;
+
+               /*
+                * This odd-looking bit of logic, deals with an
+                * annoying edge case.  Sometimes we'll get boilerplate C
+                * stuff in both a C and a text file. To cope, propagate
+                * insignificance -- if we know from one context that a
+                * particular span of text is not interesting, declare it
+                * uninteresting everywhere.
+                */
+               flags |= rp->hash.flags;
+           }
+
+           /*
+            * Filter for sigificance right at the last minute.  The
+            * point of doing it this way is to allow significance bits to 
+            * propagate through range merges.
+            */
+           if (maxsize >= minsize && (nofilter || !(flags & INSIGNIFICANT)))
+               *copy++ = *match;
+       }
+
     mergecount = (copy - hitlist);
 
-    printf("Matches: %d\n", mergecount);
+    /* sort everything so the report looks neat */
+    qsort(hitlist, mergecount, sizeof(struct match_t), sortmatch);
+
+    if (debug)
+       dump_array("After merging ranges.\n", obarray, hashcount);
+    report_time("%d range groups after merging", mergecount);
+
+    return(mergecount);
  }
 
-void emit_report2(void)
+void emit_report(void)
 /* report our results (matches) */
 {
     struct match_t *match;
 
-    qsort(hitlist, mergecount, sizeof(struct match_t), sortmatch);
-
     for (match = hitlist; match < hitlist + mergecount; match++)
     {
-       int     i, flags = 0, maxsize = 0;
-
-       for (i=0; i < match->nmatches; i++)
-       {
-           struct sorthash_t   *rp = match->matches+i;
-           int matchsize = rp->hash.end - rp->hash.start + 1;
-
-           if (matchsize >= maxsize)
-               maxsize = matchsize;
-
-           /*
-            * This odd-looking bit of logic, deals with an
-            * annoying edge case.  Sometimes we'll get boilerplate C
-            * stuff in both a C and a text file. To cope, propagate
-            * insignificance -- if we know from one context that a
-            * particular span of text is not interesting, declare it
-            * uninteresting everywhere.
-            */
-           flags |= rp->hash.flags;
-       }
-
-       /*
-        * Filter for sigificance right at the last minute.  The
-        * point of doing it this way is to allow significance bits to 
-        * propagate through range merges.
-        */
-       if (maxsize < minsize || (!nofilter && (flags & INSIGNIFICANT)))
-           continue;
+       int     i;
 
        for (i=0; i < match->nmatches; i++)
        {
diff --git a/shred.h b/shred.h
index be175e419c05cf39d22a7b19c7f946c5fa534439..a825bfa0621b6a9506125309e525e417afb09261 100644 (file)
--- a/shred.h
+++ b/shred.h
@@ -80,8 +80,8 @@ extern void filter_set(int);
 extern int filter_pass(const char *line);
 
 /* shredcompare.c functions */
-extern void emit_report1(struct sorthash_t *obarray, int hashcount);
-extern void emit_report2(void);
+extern int merge_compare(struct sorthash_t *obarray, int hashcount);
+extern void emit_report(void);
 extern int match_count(const char *name);
 extern int line_count(const char *name);