From f1a8af69ea9c5bf1eefb1ac33fdc0076cf9d4402 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 31 Aug 2003 20:49:21 +0000 Subject: [PATCH] Let's move. --- Makefile | 6 ++-- report.c | 105 ++++++++++++++++++++++++++++++++++++++----------------- shred.h | 4 +-- 3 files changed, 76 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index 9998127..58d6702 100644 --- a/Makefile +++ b/Makefile @@ -11,12 +11,10 @@ shredtree: shredtree.o md5.o shredtree.o: shredtree.c shred.h $(CC) -c $(CFLAGS) shredtree.c -hashmap.o: hashmap.c shred.h - $(CC) -c $(CFLAGS) hashmap.c shredcompare.o: shredcompare.c shred.h $(CC) -c $(CFLAGS) shredcompare.c -shredcompare: shredcompare.o hashmap.o - $(CC) $(LFLAGS) shredcompare.o hashmap.o -o shredcompare +shredcompare: shredcompare.o + $(CC) $(LFLAGS) shredcompare.o -o shredcompare clean: rm -f shredtree shredcompare shredtree.o md5.o shredcompare.o diff --git a/report.c b/report.c index 81679d1..71bfaa7 100644 --- a/report.c +++ b/report.c @@ -10,6 +10,14 @@ static int local_duplicates; +struct item +{ + char *file; + struct item *next; +} +dummy; +static struct item *head = &dummy; + struct shif_t { char *name; @@ -20,6 +28,12 @@ struct shif_t char *generator_program; }; +struct sorthash_t +{ + struct hash_t hash; + char *file; +}; + static report_time(char *legend) { static time_t mark_time; @@ -38,42 +52,20 @@ static report_time(char *legend) mark_time = endtime; } -main(int argc, char *argv[]) +static void merge_hashes(int argc, char *argv[]) +/* merge hashes from specified files into an in-code list */ { - extern char *optarg; /* set by getopt */ - extern int optind; /* set by getopt */ - int status, filecount; struct shif_t *shiflist, *sp; struct stat sb; long total; - while ((status = getopt(argc, argv, "dh")) != EOF) - { - switch (status) - { - case 'd': - local_duplicates = 1; - break; - - case 'h': - default: - fprintf(stderr,"usage: shredtree [-d] hashfile...\n"); - fprintf(stderr," -d = remove local duplicates.\n"); - fprintf(stderr," -h = help (display this message).\n"); - exit(0); - } - } - - report_time(NULL); - /* set up metadata blocks for the hash files */ - filecount = argc - optind; - shiflist = (struct shif_t *)calloc(sizeof(struct shif_t), filecount); - for (sp = shiflist; sp < shiflist + filecount; sp++) + shiflist = (struct shif_t *)calloc(sizeof(struct shif_t), argc); + for (sp = shiflist; sp < shiflist + argc; sp++) { char buf[BUFSIZ]; - sp->name = strdup(argv[optind++]); + sp->name = strdup(argv[sp - shiflist]); sp->fp = fopen(sp->name, "r"); fgets(buf, sizeof(buf), sp->fp); if (strncmp(buf, "#SHIF-A ", 8)) @@ -105,7 +97,7 @@ main(int argc, char *argv[]) } /* consistency checks */ - for (sp = shiflist; sp < shiflist + filecount-1; sp++) + for (sp = shiflist; sp < shiflist + argc-1; sp++) { struct shif_t *next = sp + 1; @@ -135,7 +127,7 @@ main(int argc, char *argv[]) /* compute total data to be read, we'll use this for the progress meter */ total = 0; - for (sp = shiflist; sp < shiflist + filecount; sp++) + for (sp = shiflist; sp < shiflist + argc; sp++) { stat(sp->name, &sb); total += sb.st_size; @@ -143,7 +135,7 @@ main(int argc, char *argv[]) fprintf(stderr, "%ld bytes to be read.\n", total); /* read in all hashes */ - for (sp = shiflist; sp < shiflist + filecount; sp++) + for (sp = shiflist; sp < shiflist + argc; sp++) { u_int32_t sectcount; @@ -155,7 +147,8 @@ main(int argc, char *argv[]) linenum_t chunks; fgets(buf, sizeof(buf), sp->fp); - file_intern(buf); + *strchr(buf, '\n') = '\0'; + file_intern(buf); /* real work done here */ fread(&chunks, sizeof(linenum_t), 1, sp->fp); chunks = FROMNET(chunks); @@ -166,11 +159,57 @@ main(int argc, char *argv[]) fread(&this, sizeof(struct hash_t), 1, sp->fp); this.start = FROMNET(this.start); this.end = FROMNET(this.end); - hash_intern(&this); + hash_intern(&this); /* real work done here */ } } } +} + +void file_intern(const char *file) +/* stash the name of a file */ +{ + struct item *new; + + printf("Interning: %s\n", file); + new = (struct item *)malloc(sizeof(new)); + new->file = strdup(file); + new->next = head; + head = new; +} + +void hash_intern(const struct hash_t *chunk) +{ + printf("Chunk: %d, %d\n", chunk->start, chunk->end); +} + +main(int argc, char *argv[]) +{ + extern char *optarg; /* set by getopt */ + extern int optind; /* set by getopt */ + int status, filecount; + + while ((status = getopt(argc, argv, "dh")) != EOF) + { + switch (status) + { + case 'd': + local_duplicates = 1; + break; + + case 'h': + default: + fprintf(stderr,"usage: shredtree [-d] hashfile...\n"); + fprintf(stderr," -d = remove local duplicates.\n"); + fprintf(stderr," -h = help (display this message).\n"); + exit(0); + } + } + + report_time(NULL); + merge_hashes(argc - optind, argv + optind); report_time("Hash merge done."); - /* more... */ + /* list files (DEBUG ONLY) */ + for (; head->next; head = head->next) + printf("I see: %s\n", head->file); } diff --git a/shred.h b/shred.h index bd27cc8..3609783 100644 --- a/shred.h +++ b/shred.h @@ -17,8 +17,8 @@ typedef u_int16_t linenum_t; #define HASHSIZE 16 struct hash_t { - linenum_t start, end; - char hash[HASHSIZE]; + linenum_t start, end; + unsigned char hash[HASHSIZE]; }; /* hashmap.c */ -- 2.43.0