summaryrefslogtreecommitdiff
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
parent5d4c35a6ad0823f9c921058fa6efb972b29da2d8 (diff)
Print which option was in error along with usage message
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--configure.ac2
-rw-r--r--dsimple.c8
-rw-r--r--dsimple.h2
-rw-r--r--xprop.c35
4 files changed, 28 insertions, 19 deletions
diff --git a/configure.ac b/configure.ac
index 1931020..9246fd9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,7 +39,7 @@ XORG_DEFAULT_OPTIONS
AC_CHECK_HEADERS([wchar.h wctype.h langinfo.h])
# Checks for pkg-config packages
-PKG_CHECK_MODULES(XPROP, [x11 xproto >= 7.0.17])
+PKG_CHECK_MODULES(XPROP, [x11 xproto >= 7.0.25])
XORG_WITH_LINT
diff --git a/dsimple.c b/dsimple.c
index 669d02e..d721e46 100644
--- a/dsimple.c
+++ b/dsimple.c
@@ -75,7 +75,7 @@ char *Get_Display_Name(
char *arg = argv[i];
if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) {
- if (++i >= argc) usage ();
+ if (++i >= argc) usage ("-display requires an argument");
displayname = argv[i];
*pargc -= 2;
@@ -196,7 +196,7 @@ Window Select_Window_Args(
nargv = argv+1; argc = ARGC;
#define OPTION argv[0]
#define NXTOPTP ++argv, --argc>0
-#define NXTOPT if (++argv, --argc==0) usage()
+#define NXTOPT(arg) if (++argv, --argc==0) usage(arg " requires an argument")
#define COPYOPT nargv++[0]=OPTION, nargc++
while (NXTOPTP) {
@@ -211,7 +211,7 @@ Window Select_Window_Args(
continue;
}
if (!strcmp(OPTION, "-name")) {
- NXTOPT;
+ NXTOPT("-name");
w = Window_With_Name(dpy, RootWindow(dpy, screen),
OPTION);
if (!w)
@@ -219,7 +219,7 @@ Window Select_Window_Args(
continue;
}
if (!strcmp(OPTION, "-id")) {
- NXTOPT;
+ NXTOPT("-id");
w=0;
sscanf(OPTION, "0x%lx", &w);
if (!w)
diff --git a/dsimple.h b/dsimple.h
index ee12c6d..de934f4 100644
--- a/dsimple.h
+++ b/dsimple.h
@@ -64,7 +64,7 @@ void Setup_Display_And_Screen(int *, char **);
void Close_Display(void);
XFontStruct *Open_Font(const char *);
Window Select_Window_Args(int *, char **);
-void usage(void) _X_NORETURN;
+void usage(const char *errmsg) _X_NORETURN _X_COLD;
#define X_USAGE "[host:display]" /* X arguments handled by
Get_Display_Name */
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);