From: Eric S. Raymond Date: Wed, 3 Sep 2003 10:32:53 +0000 (+0000) Subject: Special single-argument case. X-Git-Tag: 1.0~39 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=c9729489b11ce93d84e2f1fe05b8c75e14724d0c;p=comparator.git Special single-argument case. --- diff --git a/main.c b/main.c index c9bc862..2f83611 100644 --- a/main.c +++ b/main.c @@ -30,7 +30,9 @@ static int is_scf_file(const char *file) char buf[10]; FILE *fp = fopen(file, "r"); - if (!fgets(buf, sizeof(buf), fp)) + if (!fp) + return(0); + else if (!fgets(buf, sizeof(buf), fp)) { fclose(fp); return(0); @@ -196,8 +198,10 @@ main(int argc, char *argv[]) int status, file_only, compile_only; struct scf_t *scf; + char *dir; compile_only = file_only = 0; + dir = NULL; while ((status = getopt(argc, argv, "cd:hs:w")) != EOF) { switch (status) @@ -243,9 +247,18 @@ main(int argc, char *argv[]) } report_time(NULL); + + /* special case if user gave exactly one tree */ + if (optind == argc - 1) + { + generate_shredfile(argv[optind], stdout); + exit(0); + } + + /* two or more arguments */ for(; optind < argc; optind++) { - char *source = argv[optind]; + char *olddir, *source = argv[optind]; if (is_scf_file(source)) init_scf(source); @@ -263,7 +276,15 @@ main(int argc, char *argv[]) outfile); exit(1); } + + if (dir) + { + olddir = getcwd(NULL, 0); /* may fail off Linux */ + chdir(dir); + } generate_shredfile(source, ofp); + if (dir) + chdir(olddir); fclose(ofp); } else