From: Jason Self Date: Mon, 28 Sep 2015 00:59:09 +0000 (-0700) Subject: Better cmdline errors handling. X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=043c3bb487daea1b21c00443b8fd57bac9b20054;p=skeinsum.git Better cmdline errors handling. --- diff --git a/skein_cli.c b/skein_cli.c index 04f8156..4378da6 100644 --- a/skein_cli.c +++ b/skein_cli.c @@ -441,6 +441,27 @@ int is_goodfile(const char filename[]) return 1; /* try it as good */ } +int warn_check_opts(int quiet, int warn, int status) +{ + int n = 0; + if(quiet == 1) + n = WARN("the --quiet option is meaningful only when verifying checksums\n"); + if(status ==1) + n = WARN("the --status option is meaningful only when verifying checksums\n"); + if(warn == 1) + n = WARN("the --warn option is meaningful only when verifying checksums\n"); + return n; +} + +int warn_gen_opts(int tag, int binary) +{ + int n = 0; + if (tag == 1) + n = WARN("the --tag option is meaningful only when calculating file checksums\n"); + if (binary >= 0) + n = WARN("the --text and --binary options are meaningful only when calculating file checksums\n"); + return n; +} int main(int argc, char** argv) { @@ -485,6 +506,9 @@ int main(int argc, char** argv) if (hashString > 0) { + if (warn_check_opts(quiet, warn, status) + warn_gen_opts(tag, binary)) + TRYHELP_GOODBYE(); + int n = first_file; if (n >= argc) { WARN("command line should contain strings for hashing\n"); @@ -497,16 +521,8 @@ int main(int argc, char** argv) if (check < 0) /* READ FILES, GENERATE CHECKSUMS AND PRINT TO STDOUT.. */ { - if (quiet == 1 || warn == 1 || status == 1) - { - if(quiet == 1) - WARN("the --quiet option is meaningful only when verifying checksums\n"); - if(status ==1) - WARN("the --status option is meaningful only when verifying checksums\n"); - if(warn == 1) - WARN("the --warn option is meaningful only when verifying checksums\n"); + if (warn_check_opts(quiet, warn, status)) TRYHELP_GOODBYE(); - } char mode = binary > 0 ? 'b' : 't'; @@ -537,14 +553,8 @@ int main(int argc, char** argv) if (check == 1) /* READ LISTFILES, GENERATE HASHES, COMPARE WITH STORED, PRINT RESULT */ { - if (tag == 1 || binary >= 0) - { - if (tag == 1) - WARN("the --tag option is meaningless when verifying checksums\n"); - if (binary >= 0) - WARN("the --text and --binary options are meaningless when verifying checksums\n"); + if (warn_gen_opts(tag, binary)) TRYHELP_GOODBYE(); - } int file_index; for (file_index = first_file; file_index < argc; file_index++)