]> thyrsus.com Git - comparator.git/commitdiff
Move all the file I/O stuff into main.c
authorEric S. Raymond <esr@thyrsus.com>
Thu, 4 Sep 2003 20:17:26 +0000 (20:17 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 4 Sep 2003 20:17:26 +0000 (20:17 +0000)
main.c
report.c
shred.h

diff --git a/main.c b/main.c
index ab5271f272da87d3e46d6e7164871f39e087c5f8..df192bcc3b722554e7c3f7009dcc6604f11dc973 100644 (file)
--- a/main.c
+++ b/main.c
@@ -4,6 +4,7 @@
 #include <unistd.h>
 #include <stdarg.h>
 #include <string.h>
+#include <sys/stat.h>
 #include "shred.h"
 
 int debug = 0;
@@ -134,6 +135,44 @@ static void generate_shredfile(const char *tree, FILE *ofp)
     }
 }
 
+void merge_scf(const char *name, FILE *fp)
+/* merge hashes from specified files into an in-code list */
+{
+    u_int32_t  filecount;
+    int hashcount = 0;
+    struct stat sb;
+
+    stat(name, &sb);
+    fprintf(stderr, "%% Reading hash list %s...   ", name);
+    fread(&filecount, sizeof(u_int32_t), 1, fp);
+    filecount = ntohl(filecount);
+    while (filecount--)
+    {
+       char    buf[BUFSIZ];
+       linenum_t       chunks;
+       struct item *new;
+
+       fgets(buf, sizeof(buf), fp);
+       *strchr(buf, '\n') = '\0';
+       fread(&chunks, sizeof(linenum_t), 1, fp);
+       chunks = FROMNET(chunks);
+
+       while (chunks--)
+       {
+           struct hash_t       this;
+
+           fread(&this.hash, sizeof(struct hash_t), 1, fp);
+           this.start = FROMNET(this.start);
+           this.end = FROMNET(this.end);
+           corehook(this, buf);
+           hashcount++;
+           if (hashcount % 10000 == 0)
+               fprintf(stderr,"\b\b\b%02.0f%%",(ftell(fp) / (sb.st_size * 0.01)));
+       }
+    }
+    fprintf(stderr, "\b\b\b100%%...done, %d entries\n", hashcount);
+}
+
 static void merge_tree(char *tree)
 /* add to the in-core list of sorthash structures from a tree */
 {
index 69aad4e0df9de6497002931d4f4fcf1dc99251dd..158c5fae631c436db9d0e9ac64b1afddc1df59c2 100644 (file)
--- a/report.c
+++ b/report.c
@@ -5,22 +5,11 @@
 #include <time.h>
 #include <string.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include "shred.h"
 
 #define min(x, y)      ((x < y) ? (x) : (y)) 
 #define max(x, y)      ((x > y) ? (x) : (y)) 
 
-struct item
-{
-    char       *file;
-    struct item *next;
-}
-dummy_item;
-static struct item *head = &dummy_item;
-
-static struct scf_t *scflist;
-
 struct range_t
 {
     char       *file;
@@ -39,48 +28,6 @@ struct match_t
 dummy_match;
 static struct match_t *reduced = &dummy_match;
 
-void merge_scf(const char *name, FILE *fp)
-/* merge hashes from specified files into an in-code list */
-{
-    u_int32_t  filecount;
-    int hashcount = 0;
-    struct stat sb;
-
-    stat(name, &sb);
-    fprintf(stderr, "%% Reading hash list %s...   ", name);
-    fread(&filecount, sizeof(u_int32_t), 1, fp);
-    filecount = ntohl(filecount);
-    while (filecount--)
-    {
-       char    buf[BUFSIZ];
-       linenum_t       chunks;
-       struct item *new;
-
-       fgets(buf, sizeof(buf), fp);
-       *strchr(buf, '\n') = '\0';
-       new = (struct item *)malloc(sizeof(struct item));
-       new->file = strdup(buf);
-       new->next = head;
-       head = new;
-       fread(&chunks, sizeof(linenum_t), 1, fp);
-       chunks = FROMNET(chunks);
-
-       while (chunks--)
-       {
-           struct hash_t       this;
-
-           fread(&this.hash, sizeof(struct hash_t), 1, fp);
-           this.start = FROMNET(this.start);
-           this.end = FROMNET(this.end);
-           corehook(this, head->file);
-           hashcount++;
-           if (hashcount % 10000 == 0)
-               fprintf(stderr,"\b\b\b%02.0f%%",(ftell(fp) / (sb.st_size * 0.01)));
-       }
-    }
-    fprintf(stderr, "\b\b\b100%%...done, %d entries\n", hashcount);
-}
-
 static int merge_ranges(struct range_t *p, struct range_t *q, int nmatches)
 /* merge t into s, if the ranges in the match are compatible */
 {
diff --git a/shred.h b/shred.h
index 5b32a38060b1bc83c85c04ff74434d7fcb727a38..894af0387b19e00e4e791d694facf60b0a7dc24b 100644 (file)
--- a/shred.h
+++ b/shred.h
@@ -46,7 +46,6 @@ extern void shredfile(const char *, void (*hook)(struct hash_t, const char *));
 extern void sort_hashes(struct sorthash_t *hashlist, int hashcount);
 
 /* shredcompare.c functions */
-extern void merge_scf(const char *, FILE *);
 extern void emit_report(struct sorthash_t *obarray, int hashcount);
 
 /* shred.h ends here */