From b46789856b1fc9ee2a7a69990e9954640442c7a9 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 2 Sep 2003 08:08:35 +0000 Subject: [PATCH] Both now have percent prompts. --- Makefile | 18 ++++++++++++------ report.c | 7 ++++++- shredcompare.py | 19 ++++++++++--------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index d685582..319113b 100644 --- a/Makefile +++ b/Makefile @@ -19,15 +19,21 @@ shredcompare: shredcompare.o clean: rm -f shredtree shredcompare shredtree.o md5.o shredcompare.o -test: +test-a: shredtree -c test1 >TEST1 shredtree -c test2 >TEST2 shredcompare TEST1 TEST2 - -testgood: +test-b: shredtree -c test3 >TEST1 shredtree -c test4 >TEST2 - @echo "*** Python;" - shredcompare.py TEST1 TEST2 - @echo "*** C:" 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 >TEST.LOG + +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 diff --git a/report.c b/report.c index 4d27173..761dd43 100644 --- a/report.c +++ b/report.c @@ -28,6 +28,7 @@ struct shif_t int shred_size; char *hash_method; char *generator_program; + int hashcount; }; static struct shif_t *shiflist; @@ -190,7 +191,6 @@ void init_intern(const int count) stat(sp->name, &sb); total += sb.st_size - ftell(sp->fp); } - fprintf(stderr, "%% %ld bytes to be read.\n", total); init_intern(total/sizeof(struct hash_t)); /* real work done here */ /* read in all hashes */ @@ -199,6 +199,7 @@ void init_intern(const int count) { u_int32_t sectcount; + fprintf(stderr, "Reading %s... ", sp->name); fread(§count, sizeof(u_int32_t), 1, sp->fp); sectcount = ntohl(sectcount); while (sectcount--) @@ -221,8 +222,12 @@ void init_intern(const int count) this.end = FROMNET(this.end); hash_intern(&this); /* real work done here */ hashcount++; + sp->hashcount++; + if (hashcount % 10000 == 0) + fprintf(stderr, "\b\b\b%02.0f%%", (ftell(sp->fp) / (total * 0.01))); } } + fprintf(stderr, "\b\b\b100%%...done, %d entries\n", sp->hashcount); } } diff --git a/shredcompare.py b/shredcompare.py index a3d3e0c..8cd61c9 100755 --- a/shredcompare.py +++ b/shredcompare.py @@ -10,6 +10,7 @@ class SHIF: self.name = name self.fp = open(name) self.comments = [] + self.hashcount = 0 id = self.fp.readline() if not id.startswith("#SHIF-A "): sys.stderr.write("shredcompare: %s is not a SHIF-A file."%self.fp.name) @@ -78,27 +79,28 @@ class Shred: hashcount = total = 0 -def merge_hashes(fp, dict): +def merge_hashes(shif, dict): "Read and merge hashes corresponding to one file." global hashcount - file = fp.readline() + file = shif.fp.readline() if not file: return False file = file.strip() # Record count comes right after the filename - (record_count,) = struct.unpack("!H", fp.read(2)) + (record_count,) = struct.unpack("!H", shif.fp.read(2)) while record_count > 0: record_count -= 1 # 4 bytes of start line number + 4 of end line number + 16 of MD5 hash - (start, end, hashval) = struct.unpack("!HH16s", fp.read(20)) + (start, end, hashval) = struct.unpack("!HH16s", shif.fp.read(20)) if dict.has_key(hashval): oldval = dict[hashval] else: oldval = "" dict[hashval] = oldval + file + "\t" + `start` + "\t" + `end` + "\n" hashcount += 1 + shif.hashcount += 1 if hashcount % 10000 == 0: - sys.stderr.write("\b\b\b%02.0f%%" % (fp.tell() / (total * 0.01))) + sys.stderr.write("\b\b\b%02.0f%%" % (shif.fp.tell() / (total * 0.01))) return True def item_factory(db): @@ -153,17 +155,16 @@ if __name__ == '__main__': shiflist[i].compatible(shiflist[i+1]) # Compute amount of data to be read total = sum(map(lambda x: filesize(x.name) - x.fp.tell(), shiflist)) - sys.stderr.write("%d bytes of data to be read\n" % total) # Read in the filecounts, though this implementation won't use them. for shif in shiflist: shif.fp.read(struct.calcsize("!i")) # Read in all hashes hashdict = bsddb.hashopen(None, 'c') for shif in shiflist: - sys.stderr.write("Reading... ") - while merge_hashes(shif.fp, hashdict): + sys.stderr.write("Reading %s... " % shif.name) + while merge_hashes(shif, hashdict): continue - sys.stderr.write("\b\b\b100%...done\n") + sys.stderr.write("\b\b\b100%...done, %d entries\n" % shif->hashcount) report_time("Hash merge done, %d entries" % hashcount) # Nuke all unique hashes nonuniques = 0 -- 2.43.0