summaryrefslogtreecommitdiff
path: root/xprop.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2014-06-03 18:26:19 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2014-06-03 18:26:19 -0700
commitfaa4fa7785addc2170d4de7bf13d377324597e99 (patch)
tree18da8b6fa1c5475500acd254a091a689ba24ee8d /xprop.c
parent5d4c35a6ad0823f9c921058fa6efb972b29da2d8 (diff)
Print which option was in error along with usage message
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'xprop.c')
-rw-r--r--xprop.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/xprop.c b/xprop.c
index 4b948fd..3885ddc 100644
--- a/xprop.c
+++ b/xprop.c
@@ -1552,11 +1552,11 @@ Handle_Prop_Requests (int argc, char **argv)
/* Get overriding formats, if any */
if (Is_A_Format(argv[0])) {
format = argv++[0]; argc--;
- if (!argc) usage();
+ if (!argc) usage("format specified without atom");
}
if (Is_A_DFormat(argv[0])) {
dformat = argv++[0]; argc--;
- if (!argc) usage();
+ if (!argc) usage("dformat specified without atom");
}
/* Get property name */
@@ -1768,9 +1768,9 @@ Set_Property (Display *dpy, Window w, const char *propname, const char *value)
*/
void
-usage (void)
+usage (const char *errmsg)
{
- static const char help_message[] =
+ static const char *help_message =
"where options include:\n"
" -grammar print out full grammar for command line\n"
" -display host:dpy the X server to contact\n"
@@ -1789,6 +1789,10 @@ usage (void)
fflush (stdout);
+
+ if (errmsg != NULL)
+ fprintf (stderr, "%s: %s\n\n", program_name, errmsg);
+
fprintf (stderr,
"usage: %s [-options ...] [[format [dformat]] atom] ...\n\n",
program_name);
@@ -1826,7 +1830,7 @@ Parse_Format_Mapping (int *argc, char ***argv)
#define ARGC (*argc)
#define ARGV (*argv)
#define OPTION ARGV[0]
-#define NXTOPT if (++ARGV, --ARGC==0) usage()
+#define NXTOPT if (++ARGV, --ARGC==0) usage("insufficent arguments for -format")
char *type_name, *format, *dformat;
NXTOPT; type_name = OPTION;
@@ -1922,12 +1926,12 @@ main (int argc, char **argv)
continue;
}
if (!strcmp(argv[0], "-len")) {
- if (++argv, --argc == 0) usage();
+ if (++argv, --argc == 0) usage("-len requires an argument");
max_len = atoi(argv[0]);
continue;
}
if (!strcmp(argv[0], "-formats") || !strcmp(argv[0], "-fs")) {
- if (++argv, --argc == 0) usage();
+ if (++argv, --argc == 0) usage("-fs requires an argument");
if (!(stream = fopen(argv[0], "r")))
Fatal_Error("unable to open file %s for reading.", argv[0]);
Read_Mappings(stream);
@@ -1935,14 +1939,14 @@ main (int argc, char **argv)
continue;
}
if (!strcmp(argv[0], "-font")) {
- if (++argv, --argc == 0) usage();
+ if (++argv, --argc == 0) usage("-font requires an argument");
font = Open_Font(argv[0]);
target_win = -1;
continue;
}
if (!strcmp(argv[0], "-remove")) {
thunk t = {0};
- if (++argv, --argc == 0) usage();
+ if (++argv, --argc == 0) usage("-remove requires an argument");
t.propname = argv[0];
if (remove_props == NULL) remove_props = Create_Thunk_List();
remove_props = Add_Thunk(remove_props, t);
@@ -1950,7 +1954,7 @@ main (int argc, char **argv)
}
if (!strcmp(argv[0], "-set")) {
thunk t = {0};
- if (argc < 3) usage();
+ if (argc < 3) usage("insufficent arguments for -set");
t.propname = argv[1];
t.extra_value = argv[2];
argv += 3; argc -= 3;
@@ -1966,11 +1970,16 @@ main (int argc, char **argv)
Parse_Format_Mapping(&argc, &argv);
continue;
}
- usage();
+ fprintf (stderr, "%s: unrecognized argument %s\n\n",
+ program_name, argv[0]);
+ usage(NULL);
}
- if ((remove_props != NULL || set_props != NULL) && argc > 0)
- usage();
+ if ((remove_props != NULL || set_props != NULL) && argc > 0) {
+ fprintf (stderr, "%s: unrecognized argument %s\n\n",
+ program_name, argv[0]);
+ usage(NULL);
+ }
if (target_win == None)
target_win = Select_Window(dpy, !frame_only);