From e1fecac03091ed41d403dcd77026519d8dcfcbe6 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 2 Sep 2003 17:18:32 +0000 Subject: [PATCH] Merge the two utilities. --- Makefile | 49 +++++++++++++++++++-------------------- report.c | 22 ++++-------------- shred.h | 16 +++++++++++++ shredtree.c | 67 ++++++++--------------------------------------------- 4 files changed, 55 insertions(+), 99 deletions(-) diff --git a/Makefile b/Makefile index 9363997..07f2779 100644 --- a/Makefile +++ b/Makefile @@ -1,39 +1,38 @@ # Makefile for shredcompare tools -SOURCES = shredtree.c md5.c md5.h +SOURCES = shredtree.c shredcompare.c main.c md5.c md5.h CFLAGS=-g -all: shredtree shredcompare +all: shredtree -shredtree: shredtree.o md5.o - $(CC) shredtree.o md5.o -o shredtree +main.o: main.c shred.h + $(CC) -c $(CFLAGS) main.c shredtree.o: shredtree.c shred.h $(CC) -c $(CFLAGS) shredtree.c - shredcompare.o: shredcompare.c shred.h $(CC) -c $(CFLAGS) shredcompare.c -shredcompare: shredcompare.o - $(CC) $(LFLAGS) shredcompare.o -o shredcompare +shredtree: main.o shredtree.o md5.o shredcompare.o + $(CC) main.o shredtree.o md5.o shredcompare.o -o shredtree clean: rm -f shredtree shredcompare shredtree.o md5.o shredcompare.o TEST1 TEST2 -test-a: - shredtree -c test1 >TEST1 - shredtree -c test2 >TEST2 - shredcompare TEST1 TEST2 -test-b: - shredtree -c test3 >TEST1 - shredtree -c test4 >TEST2 - shredcompare TEST1 TEST2 - -goodtest: - shredtree -c -d ~/src/unix src5r4/src/ucbhead >src5r4.shif - shredtree -c -d ~/src/unix linux-2.6.0-test4/include/linux >linux-2.6.0-test4.shif - shredcompare src5r4.shif linux-2.6.0-test4.shif - -bigtest: - shredtree -c -d ~/src/unix src5r4 >src5r4.shif - shredtree -c -d ~/src/unix linux-2.6.0-test4 >linux-2.6.0-test4.shif - shredcompare src5r4.shif linux-2.6.0-test4.shif >TEST.LOG +test-a: shredtree + shredtree -f -c test1 >TEST1 + shredtree -f -c test2 >TEST2 + shredtree TEST1 TEST2 +test-b: shredtree + shredtree -f -c test3 >TEST1 + shredtree -f -c test4 >TEST2 + shredtree TEST1 TEST2 + +goodtest: shredtree + shredtree -f -c -d ~/src/unix src5r4/src/ucbhead >src5r4.shif + shredtree -f -c -d ~/src/unix linux-2.6.0-test4/include/linux >linux-2.6.0-test4.shif + shredtree src5r4.shif linux-2.6.0-test4.shif + +bigtest: shredtree + shredtree -f -c -d ~/src/unix src5r4 >src5r4.shif + shredtree -f -c -d ~/src/unix linux-2.6.0-test4 >linux-2.6.0-test4.shif + shredtree src5r4.shif linux-2.6.0-test4.shif >TEST.LOG diff --git a/report.c b/report.c index 963008d..587b9cd 100644 --- a/report.c +++ b/report.c @@ -471,27 +471,16 @@ static int sortmatch(void *a, void *b) return(0); } -main(int argc, char *argv[]) +void shredreport(int argc, char *argv[]) +/* merge hashes from several files and generate a report to standard output */ { extern char *optarg; /* set by getopt */ extern int optind; /* set by getopt */ - int i, status, matchcount; + int i, matchcount; struct match_t *hitlist, *sorted, *match; - while ((status = getopt(argc, argv, "h")) != EOF) - { - switch (status) - { - case 'h': - default: - fprintf(stderr,"usage: shredtree hashfile...\n"); - fprintf(stderr," -h = help (display this message).\n"); - exit(0); - } - } - report_time(NULL); - merge_hashes(argc - optind, argv + optind); + merge_hashes(argc, argv); report_time("Hash merge done, %d entries", hashcount); /* the magic CPU-eating moment; sort the whole thing */ @@ -556,6 +545,5 @@ main(int argc, char *argv[]) } printf("-\n"); } - - exit(0); } + diff --git a/shred.h b/shred.h index 2746a2f..1285c22 100644 --- a/shred.h +++ b/shred.h @@ -1,5 +1,7 @@ /* shred.h -- types for shred similarity tools */ +#include + /* * 65,536 lines should be enough, but maybe someday this will be 32 bits. * The point of making it a short is that the data sets can get quite large. @@ -21,4 +23,18 @@ struct hash_t unsigned char hash[HASHSIZE]; }; +/* control bits, meant to be set at startup */ +extern int c_only; +extern int rws; +extern int debug; +extern int shredsize; + +/* globally visible data; chunk_buffer should be a malloc area set by the caller */ +extern int file_count, chunk_count; +extern struct hash_t *chunk_buffer; + +/* functions */ +extern void generate_shredfile(const char *, FILE *); +extern void shredreport(int argc, char *argv[]); + /* shred.h ends here */ diff --git a/shredtree.c b/shredtree.c index 3312ee6..99d2a92 100644 --- a/shredtree.c +++ b/shredtree.c @@ -1,4 +1,4 @@ -/* shedtree.c -- generate MD5 hash list in SHIF-A format from a file tree */ +/* shedtree.c -- generate MD5 hash list from a file tree */ #include #include @@ -7,19 +7,18 @@ #include #include #include -#include #include "md5.h" #include "shred.h" /* control bits, meant to be set at startup */ -static int c_only = 0; -static int rws = 0; -static int debug = 0; -static int shredsize = 5; +int c_only = 0; +int rws = 0; +int debug = 0; +int shredsize = 5; /* globally visible data; chunk_buffer should be a malloc area set by the caller */ -static int file_count, chunk_count; -static struct hash_t *chunk_buffer; +int file_count, chunk_count; +struct hash_t *chunk_buffer; struct item { @@ -152,7 +151,7 @@ static void shredfile(const char *file) fclose(fp); } -int treewalker(const char *file, const struct stat *sb, int flag) +static int treewalker(const char *file, const struct stat *sb, int flag) /* walk the tree, emitting hash sections for eligible files */ { if (flag == FTW_F && sb->st_size > 0 && eligible(file)) @@ -174,7 +173,7 @@ static int stringsort(void *a, void *b) return strcmp(*(char **)a, *(char **)b); } -static void generate_shredfile(const char *tree, FILE *ofp) +void generate_shredfile(const char *tree, FILE *ofp) /* generate shred file for given tree */ { char **place, **list; @@ -220,50 +219,4 @@ static void generate_shredfile(const char *tree, FILE *ofp) } } -main(int argc, char *argv[]) -{ - extern char *optarg; /* set by getopt */ - extern int optind; /* set by getopt */ - - int status; - while ((status = getopt(argc, argv, "cd:hs:w")) != EOF) - { - switch (status) - { - case 'c': - c_only = 1; - break; - - case 'd': - chdir(optarg); - break; - - case 's': - shredsize = atoi(optarg); - break; - - case 'w': - rws = 1; - break; - - case 'x': - debug = 1; - break; - - case 'h': - default: - fprintf(stderr,"usage: shredtree [-c] [-d dir ] [-s shredsize] [-w] [-x] path\n"); - fprintf(stderr," -c = check .c, .h, and .txt files only.\n"); - fprintf(stderr," -d dir = change directory before digesting.\n"); - fprintf(stderr," -h = help (display this message).\n"); - fprintf(stderr," -x = debug, display chunks in output.\n"); - fprintf(stderr," -s size = set shred size (default %d)\n", - shredsize); - fprintf(stderr," -w = remove whitespace.\n"); - exit(0); - } - } - - generate_shredfile(argv[optind], stdout); - exit(0); -} +/* shredtree.c ends here */ -- 2.43.0