Support GNU-style long options throughout, and introduce proper help
authormdw <mdw>
Sat, 21 Nov 1998 22:30:27 +0000 (22:30 +0000)
committermdw <mdw>
Sat, 21 Nov 1998 22:30:27 +0000 (22:30 +0000)
text to all programs.  Update manual pages to match.

xgetline.1
xgetline.c
xscsize.1
xscsize.c
xshutdown.c
xtell.1
xtell.c
xwait.1
xwait.c

index aa454ff..2cc2079 100644 (file)
@@ -3,6 +3,7 @@
 xgetline \- request a line of text in an X dialogue box
 .SH SYNOPSIS
 .B xgetline
+.RB [ -i ]
 .RB [ \-t
 .IR title ]
 .RB [ \-p
@@ -43,6 +44,10 @@ cmd=`xgetline -t "Shell command in window" -p "Command:"` &&
 .fi
 .SS OPTIONS
 .TP 5
+.B \-i, \-\-invisible
+Don't echo characters to the screen when they're typed.  Useful when
+requesting passwords and similar secrets.
+.TP 5
 .BI "\-t, \-\-title " title
 Sets the title of the dialogue box to
 .IR title .
index 2647772..e05bc22 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: xgetline.c,v 1.2 1998/11/18 21:25:30 mdw Exp $
+ * $Id: xgetline.c,v 1.3 1998/11/21 22:30:20 mdw Exp $
  *
  * Fetch a line of text from the user
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: xgetline.c,v $
+ * Revision 1.3  1998/11/21 22:30:20  mdw
+ * Support GNU-style long options throughout, and introduce proper help
+ * text to all programs.  Update manual pages to match.
+ *
  * Revision 1.2  1998/11/18 21:25:30  mdw
  * Remove bogus `-h' option from the options list.
  *
@@ -47,6 +51,7 @@
 #include <gdk/gdkkeysyms.h>
 
 #include "mdwopt.h"
+#include "quis.h"
 
 /*----- Main code ---------------------------------------------------------*/
 
@@ -107,6 +112,34 @@ static gboolean check_escape(GtkWidget *w, GdkEventKey *ev, gpointer *p)
   return (0);
 }
 
+/* --- @version@ --- *
+ *
+ * Arguments:  @FILE *fp@ = output stream to print the message on
+ *
+ * Returns:    ---
+ *
+ * Use:                Spits out a version message.
+ */
+
+static void version(FILE *fp)
+{
+  fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS);
+}
+
+/* --- @usage@ --- *
+ *
+ * Arguments:  @FILE *fp@ = output stream to print the message on
+ *
+ * Returns:    ---
+ *
+ * Use:                Spits out a usage message.
+ */
+
+static void usage(FILE *fp)
+{
+  fprintf(fp, "Usage: %s [-i] [-t title] [-p prompt] [-d default]\n", QUIS);
+}
+
 /* --- @main@ --- *
  *
  * Arguments:  @int argc@ = number of command line arguments
@@ -148,6 +181,7 @@ int main(int argc, char *argv[])
    * parser would barf about.
    */   
 
+  ego(argv[0]);
   gtk_init(&argc, &argv);
 
   /* --- Parse options from command line --- */
@@ -158,6 +192,8 @@ int main(int argc, char *argv[])
 
     static struct option opt[] = {
       { "help",                0,                      0,      'h' },
+      { "usage",       0,                      0,      'u' },
+      { "version",     0,                      0,      'v' },
       { "title",       required_argument,      0,      't' },
       { "prompt",      required_argument,      0,      'p' },
       { "default",     required_argument,      0,      'd' },
@@ -169,13 +205,44 @@ int main(int argc, char *argv[])
 
     /* --- Fetch an option --- */
 
-    i = getopt_long(argc, argv, "t:p:d:i", opt, 0);
+    i = getopt_long(argc, argv, "huv t:p:d:i", opt, 0);
     if (i < 0)
       break;
 
     /* --- Work out what to do with it --- */
 
     switch (i) {
+      case 'h':
+       version(stdout);
+       fputs("\n", stdout);
+       usage(stdout);
+       fputs(
+"\n"
+"Pops up a small window requesting input from a user, and echoes the\n"
+"response to stdout, where it can be collected by a shell script.\n"
+"\n"
+"Options available are:\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"
+"-i, --invisible               Don't show the user's string as it's typed\n"
+"-t, --title=TITLE     Set the window's title string\n"
+"-p, --prompt=PROMPT   Set the window's prompt string\n"
+"-d, --default=DEFAULT Set the default string already in the window\n",
+          stdout);
+       exit(0);
+       break;
+      case 'u':
+       usage(stdout);
+       exit(0);
+       break;
+      case 'v':
+       version(stdout);
+       exit(0);
+       break;
+       
       case 't':
        title = optarg;
        break;
@@ -195,7 +262,7 @@ int main(int argc, char *argv[])
   }
 
   if (f & f_duff) {
-    fprintf(stderr, "xgetline: bad arguments\n");
+    usage(stderr);
     exit(EXIT_FAILURE);
   }
 
index 30caf39..3b61a04 100644 (file)
--- a/xscsize.1
+++ b/xscsize.1
@@ -33,15 +33,18 @@ eval `xscsize`
 .fi
 .SS OPTIONS
 .TP 5
-.B \-b
+.BI "\-d, \-\-display " display
+Choose which display to connect to.
+.TP 5
+.B \-b, --bourne-shell
 Output the assignments in Bourne shell syntax (usable by Bourne,
 POSIX, Korn, Z and Bourne Again shells).
 .TP 5
-.B \-c
+.B \-c, --c-shell
 Output the assignments in C shell syntax (usable by C and Terminal C
 shells).
 .TP 5
-.B \-x
+.B \-x, --export
 Output a variable export command, so that the screen size is inherited
 by child processes.  The default is to just set local shell variables.
 .SH ENVIRONMENT
index ace018e..93cac68 100644 (file)
--- a/xscsize.c
+++ b/xscsize.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: xscsize.c,v 1.1 1998/11/16 23:00:49 mdw Exp $
+ * $Id: xscsize.c,v 1.2 1998/11/21 22:30:22 mdw Exp $
  *
  * Return X display size to shell script
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: xscsize.c,v $
+ * Revision 1.2  1998/11/21 22:30:22  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 <getopt.h>
 #include <X11/Xlib.h>
 
+#include "mdwopt.h"
+#include "quis.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 [-bcx] [-d display]\n", QUIS);
+}
+
 int main(int argc, char *argv[])
 {
   const char *display = 0;
@@ -60,11 +76,56 @@ int main(int argc, char *argv[])
 
   /* --- Parse command line options --- */
 
+  ego(argv[0]);
+
   for (;;) {
-    int i = getopt(argc, argv, "d:bcx");
+    static struct option opt[] = {
+      { "help",        0,                      0,      'h' },
+      { "usage",       0,                      0,      'u' },
+      { "version",     0,                      0,      'v' },
+      { "display",     required_argument,      0,      'd' },
+      { "bourne-shell",        0,                      0,      'b' },
+      { "c-shell",     0,                      0,      'c' },
+      { "export",      0,                      0,      'x' },
+      {        0,              0,                      0,      0 }
+    };
+
+    int i = getopt_long(argc, argv, "huv d:bcx", opt, 0);
     if (i < 0)
       break;
     switch (i) {
+      case 'h':
+       version(stdout);
+       fputs("\n", stdout);
+       usage(stdout);
+       fputs(
+"\n"
+"Reads the size of the X root window and outputs it in a form suitable\n"
+"for use as a shell assignment statement, defining variables XWIDTH and\n"
+"XHEIGHT.\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"
+"-b, --bourne-shell    Output text suitable for a Bourne shell\n"
+"-c, --c-shell         Output text suitable for a C shell\n"
+"-x, --export          Export the variables into the environment\n",
+          stdout);
+       exit(0);
+       break;
+      case 'u':
+       usage(stdout);
+       exit(0);
+       break;
+      case 'v':
+       version(stdout);
+       exit(0);
+       break;
+       
       case 'd':
        display = optarg;
        break;
@@ -78,7 +139,7 @@ int main(int argc, char *argv[])
        f |= f_export;
        break;
       default:
-       fprintf(stderr, "Usage: xscsize [-bcx] [-d DISPLAY]\n");
+       usage(stderr);
        exit(EXIT_FAILURE);
        break;
     }
index dd62b26..d65a9bd 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: xshutdown.c,v 1.1 1998/11/16 23:00:49 mdw Exp $
+ * $Id: xshutdown.c,v 1.2 1998/11/21 22:30:23 mdw Exp $
  *
  * Pretty GTK interface to waking up an xwait
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: xshutdown.c,v $
+ * Revision 1.2  1998/11/21 22:30:23  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.
  *
@@ -47,6 +51,7 @@
 #include <gdk/gdkprivate.h>
 
 #include "mdwopt.h"
+#include "quis.h"
 #include "xwait.h"
 
 /*----- Static variables --------------------------------------------------*/
@@ -82,6 +87,20 @@ static void ok(GtkWidget *w, gpointer *p)
   gtk_main_quit();
 }
 
+/* --- @version@ --- */
+
+static void version(FILE *fp)
+{
+  fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS);
+}
+
+/* --- @usage@ --- */
+
+static void usage(FILE *fp)
+{
+  fprintf(fp, "Usage: %s [-a ATOM] [-m MSG] [-p PROMPT] [-t TITLE]\n", QUIS);
+}
+
 /* --- @main@ --- *
  *
  * Main program.
@@ -91,12 +110,16 @@ int main(int argc, char *argv[])
 {
   char *prompt = "Are you sure you want to shut down this session?";
   char *title = "xshutdown";
+  ego(argv[0]);
   gtk_init(&argc, &argv);
 
   /* --- Parse options --- */
 
   for (;;) {
     static struct option opt[] = {
+      { "help", 0,                     0,      'h' },
+      { "usage", 0,                    0,      'u' },
+      { "version", 0,                  0,      'v' },
       { "atom",        required_argument,      0,      'a' },
       { "msg", required_argument,      0,      'm' },
       { "prompt", required_argument,   0,      'p' },
@@ -105,12 +128,42 @@ int main(int argc, char *argv[])
     };
     int i;
 
-    i = getopt_long(argc, argv, "a:m:p:t:", opt, 0);
+    i = getopt_long(argc, argv, "huv a:m:p:t:", opt, 0);
 
     if (i < 0)
       break;
 
     switch (i) {
+      case 'h':
+       version(stdout);
+       fputs("\n", stdout);
+       usage(stdout);
+       fputs(
+"\n"
+"Kills a waiting `xwait' process.  Pops up a confirmation window first.\n"
+"\n"
+"Options available are:\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"
+"-a, --atom=ATOM               Select the atom that `xwait' is waiting for\n"
+"-m, --msg=MSG         Select the message to send to `xwait'\n"
+"-p, --prompt=PROMPT   Select the prompt string in the confirmation box\n"
+"-t, --title=TITLE     Select the title string in the confirmation box\n",
+          stdout);
+       exit(0);
+       break;
+      case 'u':
+       usage(stdout);
+       exit(0);
+       break;
+      case 'v':
+       version(stdout);
+       exit(0);
+       break;
+       
       case 'a':
        atom = optarg;
        break;
@@ -124,6 +177,7 @@ int main(int argc, char *argv[])
        title = optarg;
        break;
       default:
+       usage(stderr);
        exit(EXIT_FAILURE);
     }
   }
diff --git a/xtell.1 b/xtell.1
index b04d22f..2baef26 100644 (file)
--- a/xtell.1
+++ b/xtell.1
@@ -17,12 +17,12 @@ value.  This is primarily useful for communicating with
 .BR xwait (1).
 .SS OPTIONS
 .TP 5
-.BI "\-d " display
+.BI "\-d, \-\-display " display
 Attempt to connect to
 .I display
 rather than the display named in the usual environment variable.
 .TP 5
-.BI "\-a " atom
+.BI "\-a, \-\-atom " atom
 Sets
 .B xtell
 to to set the property named
@@ -30,7 +30,7 @@ to to set the property named
 The default property to set to is
 .BR XWAIT_PROPERTY .
 .TP 5
-.BI "\-m " message
+.BI "\-m, \-\-msg " message
 Sets
 .B xtell
 to set the given property to
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;
diff --git a/xwait.1 b/xwait.1
index f9b9ccb..348d701 100644 (file)
--- a/xwait.1
+++ b/xwait.1
@@ -29,18 +29,18 @@ the command line.  When
 exits, it removes the property from the root window.
 .SS OPTIONS
 .TP 5
-.B \-f
+.B \-f, \-\-force
 Force 
 .B xwait
 to start up, even though there may be an existing process already
 listening for the particular atom in question.
 .TP 5
-.BI "\-d " display
+.BI "\-d, \-\-display " display
 Attempt to connect to
 .I display
 rather than the display named in the usual environment variable.
 .TP 5
-.BI "\-a " atom
+.BI "\-a, \-\-atom " atom
 Sets
 .B xwait
 to listen for the property named
@@ -48,7 +48,7 @@ to listen for the property named
 The default property to listen to is
 .BR XWAIT_PROPERTY .
 .TP 5
-.BI "\-m " message
+.BI "\-m, \-\-msg " message
 Sets
 .B xwait
 to wait for the given property to be set to
diff --git a/xwait.c b/xwait.c
index 45bb426..06e0e5c 100644 (file)
--- a/xwait.c
+++ b/xwait.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: xwait.c,v 1.2 1998/11/18 21:25:06 mdw Exp $
+ * $Id: xwait.c,v 1.3 1998/11/21 22:30:27 mdw Exp $
  *
  * Wait until prodded by another X client
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: xwait.c,v $
+ * Revision 1.3  1998/11/21 22:30:27  mdw
+ * Support GNU-style long options throughout, and introduce proper help
+ * text to all programs.  Update manual pages to match.
+ *
  * Revision 1.2  1998/11/18 21:25:06  mdw
  * Reap dead children as they arrive.  The previous shell may have
  * carelessly left them behind.
@@ -52,6 +56,8 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 
+#include "mdwopt.h"
+#include "quis.h"
 #include "xwait.h"
 
 /*----- Main code ---------------------------------------------------------*/
@@ -66,6 +72,16 @@ static void sigchld(int sig)
 
 /* --- @main@ --- */
 
+static void version(FILE *fp)
+{
+  fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS);
+}
+
+static void usage(FILE *fp)
+{
+  fprintf(fp, "Usage: %s [-f] [-d DISPLAY] [-a ATOM] [-m MSG]\n", QUIS);
+}
+
 int main(int argc, char *argv[])
 {
   char *display = 0;
@@ -82,11 +98,57 @@ int main(int argc, char *argv[])
 
   /* --- Parse options --- */
 
+  ego(argv[0]);
+
   for (;;) {
-    int i = getopt(argc, argv, "d:a:m:f");
+    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' },
+      { "force",       0,                      0,      'f' },
+      {        0,              0,                      0,      0 }
+    };
+
+    int i = getopt_long(argc, argv, "d:a:m:f", opt, 0);
     if (i < 0)
       break;
     switch (i) {
+      case 'h':
+       version(stdout);
+       fputs("\n", stdout);
+       usage(stdout);
+       fputs(
+"\n"
+"Waits until signalled by `xtell' or `xshutdown'.  Specifically, waits\n"
+"until a property with name ATOM is written to the root window with\n"
+"contents 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"
+"-f, --force           Run even if this property is waited for by another\n"
+"                      process\n"
+"-a, --atom=ATOM               Choose property name to listen for\n"
+"-m, --msg=MSG         Choose value of property to wait for\n",
+          stdout);
+       exit(0);
+       break;
+      case 'u':
+       usage(stdout);
+       exit(0);
+       break;
+      case 'v':
+       version(stdout);
+       exit(0);
+       break;
+       
       case 'd':
        display = optarg;
        break;
@@ -100,8 +162,7 @@ int main(int argc, char *argv[])
        f |= f_force;
        break;
       default:
-       fprintf(stderr,
-               "Usage: xwait [-f] [-d DISPLAY] [-a ATOM] [-m MSG]\n");
+       usage(stderr);
        exit(EXIT_FAILURE);
        break;
     }