]> thyrsus.com Git - comparator.git/commitdiff
Better statistics in the count fields.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 17 Sep 2003 16:44:39 +0000 (16:44 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 17 Sep 2003 16:44:39 +0000 (16:44 +0000)
main.c
report.c
scf-standard.xml
shred.h

diff --git a/main.c b/main.c
index c35d29d7d26b9c8c2963a83ec846e92cef8e7dae..83bd83ceba34b3f2ae4ce0602abb20ec7d940caf 100644 (file)
--- a/main.c
+++ b/main.c
@@ -601,15 +601,23 @@ main(int argc, char *argv[])
     puts("Merge-Program: comparator " VERSION);
     printf("Normalization: %s\n", scflist->normalization);
     printf("Shred-Size: %d\n", scflist->shred_size);
-    puts("%%");
-    for (scf = scflist; scf->next; scf = scf->next)
-       printf("%s:%d\n", scf->name, scf->totallines);
-    puts("%%");
 
     report_time("Hash merge done, %d shreds", sort_count);
     sort_hashes(sort_buffer, sort_count);
     report_time("Sort done");
-    emit_report(sort_buffer, sort_count);
+
+    emit_report1(sort_buffer, sort_count);
+
+    puts("%%");
+    for (scf = scflist; scf->next; scf = scf->next)
+       printf("%s:%d:%d:%d\n", 
+              scf->name, 
+              match_count(scf->name), 
+              line_count(scf->name), 
+              scf->totallines);
+    puts("%%");
+
+    emit_report2();
 
     exit(0);
 }
index 15d42200ce940aed7a204c8fa199c1e95658977c..763c284014cfb99189461edacdfb9af5e0bd6a66 100644 (file)
--- a/report.c
+++ b/report.c
@@ -339,11 +339,13 @@ static int sortmatch(const void *a, const void *b)
     return(0);
 }
 
-void emit_report(struct sorthash_t *obarray, int hashcount)
-/* report our results */
+static struct match_t *hitlist;
+static int mergecount;
+
+void emit_report1(struct sorthash_t *obarray, int hashcount)
+/* report our results (header portion) */
 {
-    struct match_t *hitlist, *match, *copy;
-    int mergecount;
+    struct match_t *match, *copy;
 
     hitlist = reduce_matches(obarray, &hashcount);
     if (debug)
@@ -360,6 +362,15 @@ void emit_report(struct sorthash_t *obarray, int hashcount)
        if (match->nmatches > 0 && copy < match)
            *copy++ = *match;
     mergecount = (copy - hitlist);
+
+    printf("Matches: %d\n", mergecount);
+ }
+
+void emit_report2(void)
+/* report our results (matches) */
+{
+    struct match_t *match;
+
     qsort(hitlist, mergecount, sizeof(struct match_t), sortmatch);
 
     for (match = hitlist; match < hitlist + mergecount; match++)
@@ -397,4 +408,39 @@ void emit_report(struct sorthash_t *obarray, int hashcount)
     /* free(hitlist); */
 }
 
+int match_count(const char *name)
+/* return count of matches with given tree in them */
+{
+    struct match_t *match;
+    int i, count = 0;
+
+    for (match = hitlist; match < hitlist + mergecount; match++)
+       for (i=0; i < match->nmatches; i++)
+           if (strncmp(name, match->matches[i].file->name, strlen(name)))
+           {
+               count++;
+               break;
+           }
+
+    return(count);
+}
+
+int line_count(const char *name)
+/* return number of lines from given tree in matching segments */
+{
+    struct match_t *match;
+    int i, count = 0;
+
+    for (match = hitlist; match < hitlist + mergecount; match++)
+       for (i=0; i < match->nmatches; i++)
+           if (strncmp(name, match->matches[i].file->name, strlen(name)))
+           {
+               count += match->matches[i].hash.end -  match->matches[i].hash.start + 1;
+               break;
+           }
+
+    return(count);
+}
+
+
 /* report.c ends here */
index c5f394c470cf9a54b3f9de70f5272920a8bce968..56dfad25c77c7dca199c37c6364d971a4711b643 100644 (file)
@@ -344,9 +344,20 @@ comparisons.</para>
 </variablelist>
 
 <para>The data section consists of a statistics block followed by a
-sequence of range sets.  The statistics block consists of ant number 
+sequence of range sets.  The statistics block consists of any number 
 of count lines followed by a %%\n section marker. Each linecount line
-consists of two colon-separated fields, a tree name and a line count.</para>
+consists of four colon-separated fields, 
+
+<orderedlist>
+<listitem><para>The name of a tree</para></listitem>
+<listitem><para>A count of chunks containing files from the tree</para></listitem>
+<listitem><para>A count of common lines from the tree</para></listitem>
+<listitem><para>The total line count of the tree</para></listitem>
+</orderedlist>
+
+
+
+a tree name and a line count.</para>
 
 <para>Each range set consists of two or more ranges followed by a line
 containing a %%\n section marker.  A range is represented as four
diff --git a/shred.h b/shred.h
index ecd9a33d946c9d138a2dc21d87bb18d3e3d63a85..33d6a7ab3eb8c89262954ad8e3a01d6f8dab0d65 100644 (file)
--- a/shred.h
+++ b/shred.h
@@ -67,6 +67,9 @@ extern int shredfile(struct filehdr_t *,
 extern void sort_hashes(struct sorthash_t *hashlist, int hashcount);
 
 /* shredcompare.c functions */
-extern void emit_report(struct sorthash_t *obarray, int hashcount);
+extern void emit_report1(struct sorthash_t *obarray, int hashcount);
+extern void emit_report2(void);
+extern int match_count(const char *name);
+extern int line_count(const char *name);
 
 /* shred.h ends here */