From: Tj Date: Tue, 29 Mar 2016 16:49:59 +0000 (+0100) Subject: modify usage() to optionally display help X-Git-Tag: v1.4~7 X-Git-Url: https://iam.tj/gitweb/gitweb.cgi?p=cfe_generate_password.git;a=commitdiff_plain;h=c9491adc74fd8da84ba0be76b1fefeac5b7488d5 modify usage() to optionally display help Signed-off-by: Tj --- diff --git a/cfe_generate_password.c b/cfe_generate_password.c index 904e04b..c1378e4 100644 --- a/cfe_generate_password.c +++ b/cfe_generate_password.c @@ -76,9 +76,9 @@ static const size_t MAC_ADDR_SIZE = 17; static const size_t DATESTRING_SIZE = 20; static void -pr_usage() +pr_usage(int verbose) { - fprintf(stderr, "%s\n", + fprintf(stderr, "Usage:\n" " -v show version\n" " -s 00:01:02:03:04:05 create seed from MAC address\n" @@ -87,6 +87,9 @@ pr_usage() " E.g. -s 01:02:03:04:05 \n" " -s 01:02:03:04:05 -p\n" " -p 000000030405\n" + "\n" + "%s", + verbose ? help : "" ); } @@ -103,7 +106,7 @@ pr_error_exit(unsigned int usage, const char *error, ...) va_end(args); fprintf(stderr, "Error: %s\n", error_message); - if (usage) pr_usage(); + if (usage) pr_usage(usage); exit(EXIT_FAILURE); } @@ -174,7 +177,7 @@ main(int argc, char **argv, char **env) int result = 0; if (argc == 1) { - pr_usage(); + pr_usage(0); } else { unsigned int arg; @@ -226,7 +229,7 @@ main(int argc, char **argv, char **env) } } if (! opt_seed && ! opt_pass) - pr_usage(); + pr_usage(0); else if (opt_seed && opt_seed != 2) pr_error_exit(1, "seed requires MAC-ADDRESS"); else if (! opt_seed && opt_pass && opt_pass != 2)