From 044392aed99af6868a1e94251feb03ae89c55f8c Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 17 Sep 2003 16:44:39 +0000 Subject: [PATCH] Better statistics in the count fields. --- main.c | 18 +++++++++++----- report.c | 54 ++++++++++++++++++++++++++++++++++++++++++++---- scf-standard.xml | 15 ++++++++++++-- shred.h | 5 ++++- 4 files changed, 80 insertions(+), 12 deletions(-) diff --git a/main.c b/main.c index c35d29d..83bd83c 100644 --- 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); } diff --git a/report.c b/report.c index 15d4220..763c284 100644 --- 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 */ diff --git a/scf-standard.xml b/scf-standard.xml index c5f394c..56dfad2 100644 --- a/scf-standard.xml +++ b/scf-standard.xml @@ -344,9 +344,20 @@ comparisons. 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. +consists of four colon-separated fields, + + +The name of a tree +A count of chunks containing files from the tree +A count of common lines from the tree +The total line count of the tree + + + + +a tree name and a line count. 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 ecd9a33..33d6a7a 100644 --- 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 */ -- 2.43.0