int debug = 0;
int shredsize = 5;
-/* globally visible data */
-int file_count, chunk_count, sort_count;
-struct hash_t *chunk_buffer;
-struct sorthash_t *sort_buffer;
-
struct item
{
char *file;
dummy;
static struct item *head = &dummy;
+static int file_count;
+
static int eligible(const char *file)
/* is the specified file eligible to be compared? */
{
return(out);
}
-/*
- * We differentiate these two functions in order to avaid the memory
- * overhead of the extra (char *) when assembling shred lists to be written
- * to a file. This is only worth bothering with because the data sets
- * can get quite large.
- */
-
-static void filehook(struct hash_t hash, const char *file)
-/* hook to store only hashes */
-{
- chunk_buffer = (struct hash_t *)realloc(chunk_buffer,
- sizeof(struct hash_t) * (chunk_count+1));
-
- chunk_buffer[chunk_count++] = hash;
-}
-
-
-static void corehook(struct hash_t hash, const char *file)
-/* hook to store hash and file */
-{
- sort_buffer = (struct sorthash_t *)realloc(sort_buffer,
- sizeof(struct sorthash_t) * (sort_count+1));
-
- sort_buffer[sort_count].hash = hash;
- sort_buffer[sort_count].file = (char *)file;
- sort_count++;
-}
-
-
-static void shredfile(const char *file,
+void shredfile(const char *file,
void (*hook)(struct hash_t, const char *))
/* emit hash section for specified file */
{
return strcmp(*(char **)a, *(char **)b);
}
-static char **sorted_file_list(const char *tree)
+char **sorted_file_list(const char *tree, int *fc)
/* generate a sorted list of files under the given tree */
{
char **place, **list;
/* make file list */
+ file_count = 0;
ftw(tree, treewalker, 16);
/* now that we know the length, copy into an array */
qsort(list, file_count, sizeof(char *), stringsort);
/* caller is responsible for freeing this */
+ *fc = file_count;
return(list);
}
-void generate_shredfile(const char *tree, FILE *ofp)
-/* generate shred file for given tree */
-{
- char **place, **list;
- u_int32_t netfile_count;
-
- list = sorted_file_list(tree);
-
- fputs("#SHIF-A 1.0\n", ofp);
- fputs("Generator-Program: shredtree 1.0\n", ofp);
- fputs("Hash-Method: MD5\n", ofp);
- fprintf(ofp, "Normalization: %s\n", rws ? "remove_whitespace" : "none");
- fprintf(ofp, "Shred-Size: %d\n", shredsize);
- fputs("%%\n", ofp);
-
- netfile_count = htonl(file_count);
- fwrite(&netfile_count, sizeof(u_int32_t), 1, ofp);
- for (place = list; place < list + file_count; place++)
- {
- linenum_t net_chunks;
-
- /* shredfile adds data to chunk_buffer */
- chunk_buffer = (struct hash_t *)calloc(sizeof(struct hash_t), 1);
- chunk_count = 0;
- shredfile(*place, filehook);
-
- /* the actual output */
- fputs(*place, ofp);
- fputc('\n', ofp);
- net_chunks = TONET(chunk_count);
- fwrite((char *)&net_chunks, sizeof(linenum_t), 1, ofp);
- fwrite(chunk_buffer, sizeof(struct hash_t), chunk_count, ofp);
- free(chunk_buffer);
- }
-}
-
-struct sorthash_t *generate_shredlist(const int argc, const char *argv[])
-/* generate an in-core list of sorthash structures */
-{
- int i;
-
- sort_buffer = (struct sorthash_t*)calloc(sizeof(struct sorthash_t),1);
- sort_count = 0;
-
- for (i = 0; i < argc; i++)
- {
- char **place, **list;
-
- list = sorted_file_list(argv[i]);
- for (place = list; place < list + file_count; place++)
- shredfile(*place, corehook);
- free(list);
- }
-
- /* caller is responsible for freeing this */
- return(sort_buffer);
-}
-
/* shredtree.c ends here */