]> thyrsus.com Git - comparator.git/commitdiff
Merge the two utilities.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 2 Sep 2003 17:18:32 +0000 (17:18 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 2 Sep 2003 17:18:32 +0000 (17:18 +0000)
Makefile
report.c
shred.h
shredtree.c

index 93639974afd99be91cd9397372cb1a5855101a44..07f277916779879bbdc68702bf02478339215714 100644 (file)
--- 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
index 963008d7aff21797bfd8f11b98248d81d98c8f26..587b9cdfac848acc0dbd6296df129b76b90400a9 100644 (file)
--- 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 2746a2f49235ec9ffa451630775d11a4198145ba..1285c2213a500a9ac129dfb5ffbe09e50a79f83a 100644 (file)
--- a/shred.h
+++ b/shred.h
@@ -1,5 +1,7 @@
 /* shred.h -- types for shred similarity tools */
 
+#include <sys/types.h>
+
 /*
  * 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 */
index 3312ee68b09a3feef45dd043be2949b9d68ca574..99d2a92d64eaeda010c363e9d79565260e000698 100644 (file)
@@ -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 <stdio.h>
 #include <unistd.h>
@@ -7,19 +7,18 @@
 #include <errno.h>
 #include <alloca.h>
 #include <netinet/in.h>
-#include <sys/types.h>
 #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 */