summaryrefslogtreecommitdiff
path: root/xkill.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2014-05-31 22:11:39 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2014-05-31 22:11:39 -0700
commit3115919a3bbb230b541b5ad8ccd2e363b8a4e4ab (patch)
tree554d7a11f938e8298383279fbd7bbb0ceff7d7dd /xkill.c
parentb0970c3a99f8aeefe2f9890e87dabc6a1dd16cf6 (diff)
Print which option was in error along with usage message
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'xkill.c')
-rw-r--r--xkill.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/xkill.c b/xkill.c
index 2270dcd..32cb0cc 100644
--- a/xkill.c
+++ b/xkill.c
@@ -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 */