summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2014-05-31 22:38:12 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2014-05-31 22:38:12 -0700
commitd684b13c7b3b8fbdda6d84dae342ad901672eb1c (patch)
tree4dace20eed9a042b3c37a8bcca7921c46a95d673
parent9bb0fa36540533e776c59c0d33ed3f404956f44a (diff)
Print which option was in error along with usage message
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--xlsatoms.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/xlsatoms.c b/xlsatoms.c
index eb4e21d..717b42b 100644
--- a/xlsatoms.c
+++ b/xlsatoms.c
@@ -47,8 +47,11 @@ static void list_atoms ( xcb_connection_t *c, const char *format, int mask,
long low, long high );
static void
-usage(void)
+usage(const char *errmsg)
{
+ if (errmsg != NULL)
+ fprintf (stderr, "%s: %s\n\n", ProgramName, errmsg);
+
fprintf (stderr, "usage: %s [-options...]\n\n%s\n", ProgramName,
"where options include:\n"
" -display dpy X server to which to connect\n"
@@ -76,22 +79,22 @@ main(int argc, char *argv[])
if (arg[0] == '-') {
switch (arg[1]) {
case 'd': /* -display dpy */
- if (++i >= argc) usage ();
+ if (++i >= argc) usage ("-display requires an argument");
if (!doit) displayname = argv[i];
continue;
case 'f': /* -format string */
- if (++i >= argc) usage ();
+ if (++i >= argc) usage ("-format requires an argument");
if (doit) format = argv[i];
continue;
case 'r': /* -range num-[num] */
- if (++i >= argc) usage ();
+ if (++i >= argc) usage ("-range requires an argument");
if (doit) {
do_range (c, format, argv[i]);
didit = 1;
}
continue;
case 'n': /* -name string */
- if (++i >= argc) usage ();
+ if (++i >= argc) usage ("-name requires an argument");
if (doit) {
do_name (c, format, argv[i]);
didit = 1;
@@ -99,7 +102,9 @@ main(int argc, char *argv[])
continue;
}
}
- usage ();
+ fprintf (stderr, "%s: unrecognized argument %s\n\n",
+ ProgramName, arg);
+ usage (NULL);
}
if (!doit) {
DisplayString = displayname;