]> thyrsus.com Git - comparator.git/commitdiff
We're back to working in file mode.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 2 Sep 2003 20:35:20 +0000 (20:35 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 2 Sep 2003 20:35:20 +0000 (20:35 +0000)
main.c
report.c
shred.h

diff --git a/main.c b/main.c
index 62b8d03071302b3da311fb900db3ed2271564ea6..f701b5ecc8a167c3757dc1193a45a626dbe43d2c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -178,19 +178,21 @@ main(int argc, char *argv[])
        report_time("Hash merge done, %d entries", sort_count);
        sort_hashes(sort_buffer, sort_count);
        report_time("Sort done");
-       emit_report(sort_buffer, sort_count);   
+       emit_report(NULL, sort_buffer, sort_count);     
     }
     else
     {
        int     hashcount;
        struct sorthash_t *obarray;
+       struct shif_t   *shiflist;
 
        report_time(NULL);
-       obarray = merge_hashes(argc-optind, argv+optind, &hashcount);
+       shiflist = init_merge(argc-optind, argv+optind);
+       obarray = merge_hashes(shiflist, argc-optind, &hashcount);
        report_time("Hash merge done, %d entries", hashcount);
        sort_hashes(obarray, hashcount);
        report_time("Sort done");
-       emit_report(obarray, hashcount);
+       emit_report(shiflist, obarray, hashcount);
     }
     exit(0);
 
index 9139a76448d33a6d1940b22ab5f42d1810a334b8..a69c612a9b06e091a182b2658a0d27f05c44a17b 100644 (file)
--- a/report.c
+++ b/report.c
@@ -19,16 +19,6 @@ struct item
 dummy_item;
 static struct item *head = &dummy_item;
 
-struct shif_t
-{
-    char       *name;
-    FILE       *fp;
-    char       *normalization;
-    int                shred_size;
-    char       *hash_method;
-    char       *generator_program;
-    int                hashcount;
-};
 static struct shif_t *shiflist;
 
 struct range_t
@@ -60,19 +50,9 @@ static void file_intern(const char *file)
     head = new;
 }
 
-void hash_intern(const struct hash_t *chunk)
-/* enter a has into the in-core array */
-{
-}
-
-struct sorthash_t *merge_hashes(int argc, char *argv[], int *count)
-/* merge hashes from specified files into an in-code list */
+struct shif_t *init_merge(int argc, char *argv[])
 {
     struct shif_t *sp;
-    struct stat sb;
-    long total;
-    struct sorthash_t *obarray;
-    int hashcount;
 
     /* set up metadata blocks for the hash files */
     shiflist = (struct shif_t *)calloc(sizeof(struct shif_t), argc);
@@ -142,14 +122,25 @@ struct sorthash_t *merge_hashes(int argc, char *argv[], int *count)
        }
     }
 
+    return(shiflist);
+}
+
+struct sorthash_t *merge_hashes(struct shif_t *shiflist, int shiflen, int *count)
+/* merge hashes from specified files into an in-code list */
+{
+    struct shif_t *sp;
+    long total;
+    struct sorthash_t *obarray;
+    int hashcount;
+    struct stat sb;
+
     /* compute total data to be read, we'll use this for the progress meter */
     total = 0;
-    for (sp = shiflist; sp < shiflist + argc; sp++)
+    for (sp = shiflist; sp < shiflist + shiflen; sp++)
     {
        stat(sp->name, &sb);
        total += sb.st_size - ftell(sp->fp);
     }
-
     obarray=(struct sorthash_t *)calloc(sizeof(struct sorthash_t),
                                           total/sizeof(struct hash_t));
     if (!obarray)
@@ -160,7 +151,7 @@ struct sorthash_t *merge_hashes(int argc, char *argv[], int *count)
 
     /* read in all hashes */
     hashcount = 0;
-    for (sp = shiflist; sp < shiflist + argc; sp++)
+    for (sp = shiflist; sp < shiflist + shiflen; sp++)
     {
        u_int32_t       sectcount;
 
@@ -423,7 +414,8 @@ static int sortmatch(void *a, void *b)
     return(0);
 }
 
-void emit_report(struct sorthash_t *obarray, int hashcount)
+void emit_report(struct shif_t *shif, 
+                struct sorthash_t *obarray, int hashcount)
 {
     struct match_t *hitlist, *sorted, *match;
     int i, matchcount;
@@ -455,10 +447,10 @@ void emit_report(struct sorthash_t *obarray, int hashcount)
     report_time("Reduction done");
 
     puts("#SHIF-B 1.0");
-    printf("Hash-Method: %s\n", shiflist[0].hash_method);
+    printf("Hash-Method: %s\n", shif->hash_method);
     puts("Merge-Program: shredcompare 1.0");
-    printf("Normalization: %s\n", shiflist[0].normalization);
-    printf("Shred-Size: %d\n", shiflist[0].shred_size);
+    printf("Normalization: %s\n", shif->normalization);
+    printf("Shred-Size: %d\n", shif->shred_size);
     puts("%%");
 
     /* we go through a little extra effort to emit a sorted list */
diff --git a/shred.h b/shred.h
index 1ac3635d28c056187400ab395df6e55781fc859f..b35c0959f777179fdfdf0a7593e6de64b07f56a4 100644 (file)
--- a/shred.h
+++ b/shred.h
@@ -30,6 +30,17 @@ struct sorthash_t
     char               *file;
 };
 
+struct shif_t
+{
+    char       *name;
+    FILE       *fp;
+    char       *normalization;
+    int                shred_size;
+    char       *hash_method;
+    char       *generator_program;
+    int                hashcount;
+};
+
 /* control bits, meant to be set at startup */
 extern int c_only;
 extern int rws;
@@ -39,9 +50,12 @@ extern int shredsize;
 /* shredtree.c functions */
 extern char **sorted_file_list(const char *, int *);
 extern void shredfile(const char *, void (*hook)(struct hash_t, const char *));
-extern struct sorthash_t *merge_hashes(int argc, char *argv[], int *count);
+extern struct shif_t *init_merge(int argc, char *argv[]);
+extern struct sorthash_t *merge_hashes(struct shif_t *shif, int shiflen, 
+                                      int *count);
 extern void sort_hashes(struct sorthash_t *hashlist, int hashcount);
-extern void emit_report(struct sorthash_t *obarray, int hashcount);
+extern void emit_report(struct shif_t *, 
+                       struct sorthash_t *obarray, int hashcount);
 extern void report_time(char *legend, ...);