diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-11-05 23:48:50 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-11-22 22:30:04 -0800 |
commit | f6316d16b2239220dd9f043bcc628a503f89ab5c (patch) | |
tree | 4ec99686c0b08fe51cd3349301a0f73c5e0ad34b | |
parent | acee3b71b38ba4bcdd0b46557546e22dcdc320cb (diff) | |
download | iceauth-f6316d16b2239220dd9f043bcc628a503f89ab5c.tar.gz |
Print which option was in error along with usage message
Special case -u, since it's documented as printing the usage message
(sort of like an ancient --help), so shouldn't be called unrecognized.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Gaetan Nadon <memsize@videotron.ca>
-rw-r--r-- | iceauth.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -53,7 +53,7 @@ static const char *defsource = "(stdin)"; * utility routines */ static void _X_NORETURN -usage (void) +usage (int exitcode) { static const char prefixmsg[] = "\n" @@ -75,7 +75,7 @@ usage (void) fprintf (stderr, "%s", prefixmsg); print_help (stderr, NULL); fprintf (stderr, "\n%s\n", suffixmsg); - exit (1); + exit (exitcode); } @@ -102,7 +102,11 @@ main (int argc, char *argv[]) for (flag = (arg + 1); *flag; flag++) { switch (*flag) { case 'f': /* -f authfilename */ - if (++i >= argc) usage (); + if (++i >= argc) { + fprintf(stderr, "%s: -f requires an argument\n", + ProgramName); + usage (1); + } authfilename = argv[i]; continue; case 'V': /* -V */ @@ -120,8 +124,12 @@ main (int argc, char *argv[]) case 'i': /* -i */ ignore_locks = True; continue; + case 'u': /* -u */ + usage (0); default: - usage (); + fprintf(stderr, "%s: unrecognized option '%s'\n", + ProgramName, flag); + usage (1); } } } else { |