From c1c3283b6b9e9e5be88ab72da1e739ed3c84f009 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 3 Sep 2003 10:42:34 +0000 Subject: [PATCH] More progress metering. --- Makefile | 2 ++ main.c | 27 ++++++++++++++++----------- report.c | 6 +++--- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 58ed316..0dceeae 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,8 @@ EXTRAS = shredtree.py shredcompare.py TEST = test1 test2 test3 test4 ALL = $(SOURCES) $(DOCS) $(EXTRAS) $(TEST) +CFLAGS=-g + all: comparator comparator.1 main.o: main.c shred.h diff --git a/main.c b/main.c index 2f83611..42757e6 100644 --- a/main.c +++ b/main.c @@ -191,6 +191,17 @@ void report_time(char *legend, ...) mark_time = endtime; } +static void usage(void) +{ + fprintf(stderr,"usage: shredtree [-c] [-d dir ] [-s shredsize] [-w] [-x] path...\n"); + fprintf(stderr," -c = generate SCF files\n"); + fprintf(stderr," -d dir = change directory before digesting.\n"); + fprintf(stderr," -s size = set shred size (default %d)\n", shredsize); + fprintf(stderr," -w = remove whitespace.\n"); + fprintf(stderr," -x = debug, display chunks in output.\n"); + exit(0); +} + main(int argc, char *argv[]) { extern char *optarg; /* set by getopt */ @@ -226,17 +237,8 @@ main(int argc, char *argv[]) debug = 1; break; - case 'h': default: - fprintf(stderr,"usage: shredtree [-c] [-d dir ] [-h] [-s shredsize] [-w] [-x] path\n"); - fprintf(stderr," -c = generate SCF files\n"); - fprintf(stderr," -d dir = change directory before digesting.\n"); - fprintf(stderr," -h = help (display this message).\n"); - fprintf(stderr," -s size = set shred size (default %d)\n", - shredsize); - fprintf(stderr," -w = remove whitespace.\n"); - fprintf(stderr," -x = debug, display chunks in output.\n"); - exit(0); + usage(); } } @@ -246,10 +248,13 @@ main(int argc, char *argv[]) sort_count = 0; } + if ((argc - optind) == 0) + usage(); + report_time(NULL); /* special case if user gave exactly one tree */ - if (optind == argc - 1) + if (!compile_only && optind == argc - 1) { generate_shredfile(argv[optind], stdout); exit(0); diff --git a/report.c b/report.c index 53b0ed4..d86476c 100644 --- a/report.c +++ b/report.c @@ -44,7 +44,9 @@ void merge_scf(const char *name, FILE *fp) { u_int32_t sectcount; int hashcount = 0; + struct stat sb; + stat(name, &sb); fprintf(stderr, "%% Reading hash list %s... ", name); fread(§count, sizeof(u_int32_t), 1, fp); sectcount = ntohl(sectcount); @@ -72,10 +74,8 @@ void merge_scf(const char *name, FILE *fp) this.end = FROMNET(this.end); corehook(this, head->file); hashcount++; -#ifdef FIXME if (hashcount % 10000 == 0) - fprintf(stderr,"\b\b\b%02.0f%%",(ftell(fp) / (total * 0.01))); -#endif + fprintf(stderr,"\b\b\b%02.0f%%",(ftell(fp) / (sb.st_size * 0.01))); } } fprintf(stderr, "\b\b\b100%%...done, %d entries\n", hashcount); -- 2.43.0