Support GNU-style long options throughout, and introduce proper help
[xtoys] / xshutdown.c
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);
     }
   }