From 3e0d5a8eccb7146a60a4d7f35199eed163c5ca72 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 31 Aug 2003 09:50:50 +0000 Subject: [PATCH] Change everything to use shorts for line indices. --- report.c | 5 ++++- shredcompare.py | 7 +++++-- shredtree.c | 4 ++++ shredtree.py | 5 +++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/report.c b/report.c index bf8096c..d57bccd 100644 --- a/report.c +++ b/report.c @@ -134,7 +134,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-1; sp++) + for (sp = shiflist; sp < shiflist + filecount; sp++) { stat(sp->name, &sb); total += sb.st_size; @@ -142,4 +142,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++) + { + } } diff --git a/shredcompare.py b/shredcompare.py index c9e0e09..6f85fdb 100755 --- a/shredcompare.py +++ b/shredcompare.py @@ -86,11 +86,11 @@ def merge_hashes(fp, dict): return False file = file.strip() # Record count comes right after the filename - (record_count,) = struct.unpack("!i", fp.read(4)) + (record_count,) = struct.unpack("!H", 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("!ii16s", fp.read(24)) + (start, end, hashval) = struct.unpack("!HH16s", fp.read(20)) if dict.has_key(hashval): oldval = dict[hashval] else: @@ -155,6 +155,9 @@ if __name__ == '__main__': # Compute amount of data to be read total = sum(map(filesize, args)) 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: diff --git a/shredtree.c b/shredtree.c index e5d9f29..0ff4181 100644 --- a/shredtree.c +++ b/shredtree.c @@ -187,6 +187,7 @@ main(int argc, char *argv[]) extern int optind; /* set by getopt */ int status; + u_int32_t netfilecount; char **place, **list, *dir = "."; while ((status = getopt(argc, argv, "cd:hs:w")) != EOF) { @@ -244,6 +245,9 @@ main(int argc, char *argv[]) /* the objective -- sort */ qsort(list, filecount, sizeof(char *), stringsort); + /* generate the list */ + netfilecount = htonl(filecount); + fwrite(&netfilecount, sizeof(u_int32_t), 1, stdout); for (place = list; place < list + filecount; place++) shredfile(*place); diff --git a/shredtree.py b/shredtree.py index 56b423e..d9b9685 100755 --- a/shredtree.py +++ b/shredtree.py @@ -32,7 +32,7 @@ def emit_chunk(display, file, linecount): if debug: sys.stderr.write(`line[0]` + "\n") m.update(line[0]) - return struct.pack("!ii", startline, linecount) + m.digest() + return struct.pack("!HH", startline, linecount) + m.digest() def shredfile(file): "Emit shred tuples corresponding to a specified file." @@ -67,7 +67,7 @@ def shredfile(file): outdata += emit_chunk(display, file, linecount) chunk_count += 1 # Write the actual data - sys.stdout.write(file + "\n" + struct.pack("!i", chunk_count) + outdata) + sys.stdout.write(file + "\n" + struct.pack("!H", chunk_count) + outdata) if __name__ == '__main__': try: @@ -116,6 +116,7 @@ if __name__ == '__main__': if eligible(fullpath): filenames.append(fullpath) filenames.sort() + sys.stdout.write(struct.pack("!i", len(filenames))) for path in filenames: shredfile(path) # End -- 2.43.0