From d26fb1c1ffefb8d53d8c9acb97effe7740bf1e4a Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 11 Sep 2003 07:13:45 +0000 Subject: [PATCH] Implemented a progress meter. --- main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 6907535..bfe6d3b 100644 --- a/main.c +++ b/main.c @@ -76,7 +76,7 @@ static void write_scf(const char *tree, FILE *ofp) /* generate shred file for given tree */ { char **place, **list; - int file_count; + int file_count, progress, totalchunks; u_int32_t netfile_count; char buf[BUFSIZ]; @@ -102,6 +102,8 @@ static void write_scf(const char *tree, FILE *ofp) netfile_count = htonl(file_count); fwrite(&netfile_count, sizeof(u_int32_t), 1, ofp); + fprintf(stderr, "%% Reading %s... ", tree); + progress = totalchunks = 0; for (place = list; place < list + file_count; place++) { linenum_t net_chunks; @@ -150,8 +152,12 @@ static void write_scf(const char *tree, FILE *ofp) fwrite(&this.end, sizeof(linenum_t), 1, ofp); fwrite(&this.hash, sizeof(char), HASHSIZE, ofp); } + totalchunks += chunk_count; free(chunk_buffer); + if (!debug && progress++ % 100 == 0) + fprintf(stderr, "\b\b\b%02.0f%%", progress / (file_count * 0.01)); } + fprintf(stderr, ", done, %d total chunks.\n", totalchunks); } void read_scf(const char *name, FILE *fp) -- 2.43.0