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

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


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 configure.ac |    2 +-
 fstobdf.c    |   19 ++++++++++---------
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1dbf55a..0ef434b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,7 +36,7 @@ XORG_DEFAULT_OPTIONS
 AC_CONFIG_HEADERS([config.h])
 
 # Checks for pkg-config packages
-PKG_CHECK_MODULES(FSTOBDF, [xproto >= 7.0.17 x11 libfs])
+PKG_CHECK_MODULES(FSTOBDF, [xproto >= 7.0.25 x11 libfs])
 
 AC_CONFIG_FILES([
 	Makefile
diff --git a/fstobdf.c b/fstobdf.c
index db168c9..bcdffbc 100644
--- a/fstobdf.c
+++ b/fstobdf.c
@@ -49,16 +49,18 @@ in this Software without prior written authorization from The Open Group.
 #include	"fstobdf.h"
 
 
-static void _X_NORETURN
-usage(char *progName)
+static void _X_NORETURN _X_COLD
+usage(const char *progName, const char *msg)
 {
+    if (msg)
+        fprintf(stderr, "%s: %s\n", progName, msg);
     fprintf(stderr, "Usage: %s [-server <font server>] -fn <font name>\n",
 	    progName);
     exit(0);
 }
 
-static void _X_NORETURN
-Fail(char *progName)
+static void _X_NORETURN _X_COLD
+Fail(const char *progName)
 {
     fprintf(stderr, "%s: unable to dump font\n", progName);
     exit(1);
@@ -90,17 +92,17 @@ main(int argc, char *argv[])
 	    if (argv[++i])
 		serverName = argv[i];
 	    else
-		usage(argv[0]);
+		usage(argv[0], "-server requires an argument");
 	} else if (!strncmp(argv[i], "-fn", 3)) {
 	    if (argv[++i])
 		fontName = argv[i];
 	    else
-		usage(argv[0]);
+		usage(argv[0], "-fn requires an argument");
 	}
     }
 
     if (fontName == NULL)
-	usage(argv[0]);
+	usage(argv[0], "No font name specified");
 
     fontServer = FSOpenServer(serverName);
     if (!fontServer) {
@@ -109,8 +111,7 @@ main(int argc, char *argv[])
 	    fprintf(stderr, "%s: can't open font server \"%s\"\n",
 	      	    argv[0], sn);
 	else
-	    fprintf(stderr, "%s:  No font server specified.\n",
-		    argv[0]);
+	    usage(argv[0], "No font server specified.");
 	exit(0);
     }
     bitmapFormat = 0;
-- 
1.7.9.2



More information about the xorg-devel mailing list