# 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
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 */
}
printf("-\n");
}
-
- exit(0);
}
+
/* 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.
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 */
-/* 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>
#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
{
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))
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;
}
}
-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 */