From: Eric S. Raymond Date: Thu, 4 Sep 2003 20:17:26 +0000 (+0000) Subject: Move all the file I/O stuff into main.c X-Git-Tag: 1.0~16 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=87bada304b6b4f49f474e2e3e7b64d0fd2d10b2d;p=comparator.git Move all the file I/O stuff into main.c --- diff --git a/main.c b/main.c index ab5271f..df192bc 100644 --- a/main.c +++ b/main.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "shred.h" int debug = 0; @@ -134,6 +135,44 @@ static void generate_shredfile(const char *tree, FILE *ofp) } } +void merge_scf(const char *name, FILE *fp) +/* merge hashes from specified files into an in-code list */ +{ + u_int32_t filecount; + int hashcount = 0; + struct stat sb; + + stat(name, &sb); + fprintf(stderr, "%% Reading hash list %s... ", name); + fread(&filecount, sizeof(u_int32_t), 1, fp); + filecount = ntohl(filecount); + while (filecount--) + { + char buf[BUFSIZ]; + linenum_t chunks; + struct item *new; + + fgets(buf, sizeof(buf), fp); + *strchr(buf, '\n') = '\0'; + fread(&chunks, sizeof(linenum_t), 1, fp); + chunks = FROMNET(chunks); + + while (chunks--) + { + struct hash_t this; + + fread(&this.hash, sizeof(struct hash_t), 1, fp); + this.start = FROMNET(this.start); + this.end = FROMNET(this.end); + corehook(this, buf); + hashcount++; + if (hashcount % 10000 == 0) + fprintf(stderr,"\b\b\b%02.0f%%",(ftell(fp) / (sb.st_size * 0.01))); + } + } + fprintf(stderr, "\b\b\b100%%...done, %d entries\n", hashcount); +} + static void merge_tree(char *tree) /* add to the in-core list of sorthash structures from a tree */ { diff --git a/report.c b/report.c index 69aad4e..158c5fa 100644 --- a/report.c +++ b/report.c @@ -5,22 +5,11 @@ #include #include #include -#include #include "shred.h" #define min(x, y) ((x < y) ? (x) : (y)) #define max(x, y) ((x > y) ? (x) : (y)) -struct item -{ - char *file; - struct item *next; -} -dummy_item; -static struct item *head = &dummy_item; - -static struct scf_t *scflist; - struct range_t { char *file; @@ -39,48 +28,6 @@ struct match_t dummy_match; 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 filecount; - int hashcount = 0; - struct stat sb; - - stat(name, &sb); - fprintf(stderr, "%% Reading hash list %s... ", name); - fread(&filecount, sizeof(u_int32_t), 1, fp); - filecount = ntohl(filecount); - while (filecount--) - { - char buf[BUFSIZ]; - linenum_t chunks; - struct item *new; - - fgets(buf, sizeof(buf), fp); - *strchr(buf, '\n') = '\0'; - new = (struct item *)malloc(sizeof(struct item)); - new->file = strdup(buf); - new->next = head; - head = new; - fread(&chunks, sizeof(linenum_t), 1, fp); - chunks = FROMNET(chunks); - - while (chunks--) - { - struct hash_t this; - - fread(&this.hash, sizeof(struct hash_t), 1, fp); - this.start = FROMNET(this.start); - this.end = FROMNET(this.end); - corehook(this, head->file); - hashcount++; - if (hashcount % 10000 == 0) - fprintf(stderr,"\b\b\b%02.0f%%",(ftell(fp) / (sb.st_size * 0.01))); - } - } - fprintf(stderr, "\b\b\b100%%...done, %d entries\n", hashcount); -} - static int merge_ranges(struct range_t *p, struct range_t *q, int nmatches) /* merge t into s, if the ranges in the match are compatible */ { diff --git a/shred.h b/shred.h index 5b32a38..894af03 100644 --- a/shred.h +++ b/shred.h @@ -46,7 +46,6 @@ extern void shredfile(const char *, void (*hook)(struct hash_t, const char *)); extern void sort_hashes(struct sorthash_t *hashlist, int hashcount); /* shredcompare.c functions */ -extern void merge_scf(const char *, FILE *); extern void emit_report(struct sorthash_t *obarray, int hashcount); /* shred.h ends here */