Support GNU-style long options throughout, and introduce proper help
[xtoys] / xtell.c
diff --git a/xtell.c b/xtell.c
index 7675814..6ca8a28 100644 (file)
--- a/xtell.c
+++ b/xtell.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: xtell.c,v 1.1 1998/11/16 23:00:49 mdw Exp $
+ * $Id: xtell.c,v 1.2 1998/11/21 22:30:25 mdw Exp $
  *
  * Wake up a waiting xwait process
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: xtell.c,v $
+ * Revision 1.2  1998/11/21 22:30:25  mdw
+ * Support GNU-style long options throughout, and introduce proper help
+ * text to all programs.  Update manual pages to match.
+ *
  * Revision 1.1  1998/11/16 23:00:49  mdw
  * Initial versions.
  *
 #include <stdlib.h>
 #include <string.h>
 
-#include <unistd.h>
-
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 
+#include "mdwopt.h"
+#include "quis.h"
 #include "xwait.h"
 
 /*----- Main code ---------------------------------------------------------*/
 
+static void version(FILE *fp)
+{
+  fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS);
+}
+
+static void usage(FILE *fp)
+{
+  fprintf(fp, "Usage: %s [-d DISPLAY] [-a ATOM] [-m MSG]\n", QUIS);
+}
+
 int main(int argc, char *argv[])
 {
   char *display = 0;
@@ -59,11 +73,53 @@ int main(int argc, char *argv[])
 
   /* --- Parse options --- */
 
+  ego(argv[0]);
+
   for (;;) {
-    int i = getopt(argc, argv, "d:a:m:");
+    static struct option opt[] = {
+      { "help",        0,                      0,      'h' },
+      { "usage",       0,                      0,      'u' },
+      { "version",     0,                      0,      'v' },
+      { "display",     required_argument,      0,      'd' },
+      { "atom",                required_argument,      0,      'a' },
+      { "msg",         required_argument,      0,      'm' },
+      {        0,              0,                      0,      0 }
+    };
+
+    int i = getopt_long(argc, argv, "d:a:m:", opt, 0);
     if (i < 0)
       break;
     switch (i) {
+      case 'h':
+       version(stdout);
+       fputs("\n", stdout);
+       usage(stdout);
+       fputs(
+"\n"
+"Signals a waiting `xwait' process.  Specifically, writes a property\n"
+"named ATOM to the X root window, with value MSG.\n"
+"\n"
+"Options:\n"
+"\n"
+"-h, --help            Display this help text\n"
+"-u, --usage           Display a short usage summary\n"
+"-v, --version         Display the program's version number\n"
+"\n"
+"-d, --display=DISPLAY Choose X display to connect to\n"
+"-a, --atom=ATOM               Choose property name to set\n"
+"-m, --msg=MSG         Choose value of property to set\n",
+          stdout);
+       exit(0);
+       break;
+      case 'u':
+       usage(stdout);
+       exit(0);
+       break;
+      case 'v':
+       version(stdout);
+       exit(0);
+       break;
+       
       case 'd':
        display = optarg;
        break;