[PATCH:xdpyinfo 1/2] Print which option was in error along with usage message

Alan Coopersmith alan.coopersmith at oracle.com
Tue Nov 26 22:36:27 PST 2013


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 xdpyinfo.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/xdpyinfo.c b/xdpyinfo.c
index f161a97..84d5b2a 100644
--- a/xdpyinfo.c
+++ b/xdpyinfo.c
@@ -1466,18 +1466,29 @@ main(int argc, char *argv[])
 	size_t len = strlen(arg);
 
 	if (!strncmp("-display", arg, len)) {
-	    if (++i >= argc) usage ();
+	    if (++i >= argc) {
+		fprintf (stderr, "%s: -display requires an argument\n",
+			 ProgramName);
+		usage ();
+	    }
 	    displayname = argv[i];
 	} else if (!strncmp("-queryExtensions", arg, len)) {
 	    queryExtensions = True;
 	} else if (!strncmp("-ext", arg, len)) {
-	    if (++i >= argc) usage ();
+	    if (++i >= argc) {
+		fprintf (stderr, "%s: -ext requires an argument\n",
+			 ProgramName);
+		usage ();
+	    }
 	    mark_extension_for_printing(argv[i]);
         } else if (!strncmp("-version", arg, len)) {
             printf("%s\n", PACKAGE_STRING);
             exit (0);
-	} else
+	} else {
+	    fprintf (stderr, "%s: unrecognized argument '%s'\n",
+		     ProgramName, arg);
 	    usage ();
+	}
     }
 
     dpy = XOpenDisplay (displayname);
-- 
1.7.9.2



More information about the xorg-devel mailing list