From 0a4d55ff2d0953606a77892f61b2e2f7556a9e8c Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 4 Sep 2003 20:10:15 +0000 Subject: [PATCH] We can dump chunks now. --- main.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- report.c | 37 ++++--------------------- 2 files changed, 85 insertions(+), 34 deletions(-) diff --git a/main.c b/main.c index 6f745c9..ab5271f 100644 --- a/main.c +++ b/main.c @@ -55,7 +55,7 @@ static void filehook(struct hash_t hash, const char *file) sizeof(struct hash_t) * (chunk_count+1)); hash.start = TONET(hash.start); - hash.end = TONET(hash.end); + hash.end = TONET(hash.end); chunk_buffer[chunk_count++] = hash; } @@ -104,6 +104,32 @@ static void generate_shredfile(const char *tree, FILE *ofp) net_chunks = TONET(chunk_count); fwrite((char *)&net_chunks, sizeof(linenum_t), 1, ofp); fwrite(chunk_buffer, sizeof(struct hash_t), chunk_count, ofp); + if (debug) + { + struct hash_t *np; + fprintf(stderr, "Chunks for %s:\n", *place); + for (np = chunk_buffer; np < chunk_buffer + chunk_count; np++) + fprintf(stderr, + "%d: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s:%d:%d\n", + np-chunk_buffer, + np->hash[0], + np->hash[1], + np->hash[2], + np->hash[3], + np->hash[4], + np->hash[5], + np->hash[6], + np->hash[7], + np->hash[8], + np->hash[9], + np->hash[10], + np->hash[11], + np->hash[12], + np->hash[13], + np->hash[14], + np->hash[15], + *place, FROMNET(np->start), FROMNET(np->end)); + } free(chunk_buffer); } } @@ -175,6 +201,45 @@ static void init_scf(char *file) scf_head = new; } +static void dump_array(struct sorthash_t *obarray, + int hashcount, + linenum_t (*fn)(linenum_t)) +/* dump the contents of a sort_hash array */ +{ + struct sorthash_t *np; + + for (np = obarray; np < obarray + hashcount; np++) + { + struct hash_t scratch; + + scratch = np->hash; + if (fn) + { + scratch.start = fn(np->hash.start); + scratch.end = fn(np->hash.end); + } + printf("%d: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s:%d:%d\n", + np-obarray, + scratch.hash[0], + scratch.hash[1], + scratch.hash[2], + scratch.hash[3], + scratch.hash[4], + scratch.hash[5], + scratch.hash[6], + scratch.hash[7], + scratch.hash[8], + scratch.hash[9], + scratch.hash[10], + scratch.hash[11], + scratch.hash[12], + scratch.hash[13], + scratch.hash[14], + scratch.hash[15], + np->file, scratch.start, scratch.end); + } +} + void report_time(char *legend, ...) /* report on time since last report_mark */ { @@ -315,7 +380,6 @@ main(int argc, char *argv[]) /* consistency checks on the SCFs */ for (scf = scf_head; scf->next->next; scf = scf->next) { - printf("Foo\n"); if (strcmp(scf->normalization, scf->next->normalization)) { fprintf(stderr, @@ -351,6 +415,12 @@ main(int argc, char *argv[]) if (!compile_only) { + if (debug) + { + printf("Consolidated hash list:\n"); + dump_array(sort_buffer, sort_count, NULL); + } + /* now we're ready to emit the report */ puts("#SCF-B 1.0"); printf("Hash-Method: %s\n", scf_head->hash_method); @@ -363,6 +433,14 @@ main(int argc, char *argv[]) sort_hashes(sort_buffer, sort_count); report_time("Sort done"); +#ifdef DEBUG + if (debug) + { + puts("Chunk list before reduction."); + dump_array(obarray, hashcount, NULL); + } +#endif /* DEBUG */ + emit_report(sort_buffer, sort_count); } diff --git a/report.c b/report.c index d86476c..69aad4e 100644 --- a/report.c +++ b/report.c @@ -42,15 +42,15 @@ static struct match_t *reduced = &dummy_match; void merge_scf(const char *name, FILE *fp) /* merge hashes from specified files into an in-code list */ { - u_int32_t sectcount; + u_int32_t filecount; int hashcount = 0; struct stat sb; stat(name, &sb); fprintf(stderr, "%% Reading hash list %s... ", name); - fread(§count, sizeof(u_int32_t), 1, fp); - sectcount = ntohl(sectcount); - while (sectcount--) + fread(&filecount, sizeof(u_int32_t), 1, fp); + filecount = ntohl(filecount); + while (filecount--) { char buf[BUFSIZ]; linenum_t chunks; @@ -59,7 +59,7 @@ void merge_scf(const char *name, FILE *fp) fgets(buf, sizeof(buf), fp); *strchr(buf, '\n') = '\0'; new = (struct item *)malloc(sizeof(struct item)); - new->file = strdup(name); + new->file = strdup(buf); new->next = head; head = new; fread(&chunks, sizeof(linenum_t), 1, fp); @@ -312,33 +312,6 @@ void emit_report(struct sorthash_t *obarray, int hashcount) struct match_t *hitlist, *sorted, *match; int i, matchcount; - if (debug) - { - struct sorthash_t *np; - - puts("Chunk list before reduction."); - for (np = obarray; np < obarray + hashcount; np++) - printf("%d: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s:%d:%d\n", - np-obarray, - np->hash.hash[0], - np->hash.hash[1], - np->hash.hash[2], - np->hash.hash[3], - np->hash.hash[4], - np->hash.hash[5], - np->hash.hash[6], - np->hash.hash[7], - np->hash.hash[8], - np->hash.hash[9], - np->hash.hash[10], - np->hash.hash[11], - np->hash.hash[12], - np->hash.hash[13], - np->hash.hash[14], - np->hash.hash[15], - np->file, np->hash.start, np->hash.end); - } - hitlist = reduce_matches(obarray, hashcount); report_time("Reduction done"); -- 2.43.0