diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2014-05-31 22:11:39 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2014-05-31 22:11:39 -0700 |
commit | 3115919a3bbb230b541b5ad8ccd2e363b8a4e4ab (patch) | |
tree | 554d7a11f938e8298383279fbd7bbb0ceff7d7dd | |
parent | b0970c3a99f8aeefe2f9890e87dabc6a1dd16cf6 (diff) |
Print which option was in error along with usage message
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | xkill.c | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -73,7 +73,7 @@ Exit(int code, Display *dpy) } static void _X_NORETURN -usage(void) +usage(const char *errmsg) { const char *options = "where options include:\n" @@ -85,6 +85,9 @@ usage(void) " -version print version and exit\n" "\n"; + if (errmsg != NULL) + fprintf (stderr, "%s: %s\n\n", ProgramName, errmsg); + fprintf (stderr, "usage: %s [-option ...]\n%s", ProgramName, options); Exit (1, NULL); @@ -112,11 +115,11 @@ main(int argc, char *argv[]) if (arg[0] == '-') { switch (arg[1]) { case 'd': /* -display displayname */ - if (++i >= argc) usage (); + if (++i >= argc) usage ("-display requires an argument"); displayname = argv[i]; continue; case 'i': /* -id resourceid */ - if (++i >= argc) usage (); + if (++i >= argc) usage ("-id requires an argument"); id = strtoul (argv[i], NULL, 0); if (id == 0 || id >= 0xFFFFFFFFU) { fprintf (stderr, "%s: invalid id \"%s\"\n", @@ -125,7 +128,7 @@ main(int argc, char *argv[]) } continue; case 'b': /* -button number */ - if (++i >= argc) usage (); + if (++i >= argc) usage ("-button requires an argument"); button_name = argv[i]; continue; case 'f': /* -frame */ @@ -138,10 +141,14 @@ main(int argc, char *argv[]) puts(PACKAGE_STRING); exit(0); default: - usage (); + fprintf(stderr, "%s: unrecognized argument %s\n\n", + ProgramName, arg); + usage (NULL); } } else { - usage (); + fprintf(stderr, "%s: unrecognized argument %s\n\n", + ProgramName, arg); + usage (NULL); } } /* end for */ |