[PATCH:iceauth 13/17] Print which option was in error along with usage message

Alan Coopersmith alan.coopersmith at oracle.com
Fri Nov 15 18:38:42 PST 2013


Special case -u, since it's documented as printing the usage message
(sort of like an ancient --help), so shouldn't be called unrecognized.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 iceauth.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/iceauth.c b/iceauth.c
index c1688c0..dfd1269 100644
--- a/iceauth.c
+++ b/iceauth.c
@@ -53,7 +53,7 @@ static const char *defsource = "(stdin)";
  * utility routines
  */
 static void _X_NORETURN
-usage (void)
+usage (int exitcode)
 {
     static const char prefixmsg[] = 
 "\n"
@@ -75,7 +75,7 @@ usage (void)
     fprintf (stderr, "%s", prefixmsg);
     print_help (stderr, NULL);
     fprintf (stderr, "\n%s\n", suffixmsg);
-    exit (1);
+    exit (exitcode);
 }
 
 
@@ -102,7 +102,11 @@ main (int argc, char *argv[])
 	    for (flag = (arg + 1); *flag; flag++) {
 		switch (*flag) {
 		  case 'f':		/* -f authfilename */
-		    if (++i >= argc) usage ();
+		    if (++i >= argc) {
+			fprintf(stderr, "%s: -f requires an argument\n",
+				ProgramName);
+			usage (1);
+		    }
 		    authfilename = argv[i];
 		    continue;
 		  case 'V':		/* -V */
@@ -120,8 +124,12 @@ main (int argc, char *argv[])
 		  case 'i':		/* -i */
 		    ignore_locks = True;
 		    continue;
+		  case 'u':		/* -u */
+		    usage (0);
 		  default:
-		    usage ();
+		    fprintf(stderr, "%s: unrecognized option '%s'\n",
+			    ProgramName, flag);
+		    usage (1);
 		}
 	    }
 	} else {
-- 
1.7.9.2



More information about the xorg-devel mailing list