Fix banners in man pages.
[xtoys] / xshutdown.c
index dd62b26..499ff7c 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.7 1999/08/20 07:29:19 mdw Exp $
  *
  * Pretty GTK interface to waking up an xwait
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: xshutdown.c,v $
+ * Revision 1.7  1999/08/20 07:29:19  mdw
+ * New command line syntax, and new atom protocol.
+ *
+ * Revision 1.6  1998/12/11 09:51:51  mdw
+ * Use mgLib's `msg' box rather than doing things the hard way.
+ *
+ * Revision 1.5  1998/12/03 01:00:19  mdw
+ * Honour escape presses in the dialogue boxes.
+ *
+ * Revision 1.4  1998/12/03 00:39:45  mdw
+ * Force focus when starting up.
+ *
+ * Revision 1.3  1998/11/30 22:36:49  mdw
+ * Tidy up tabbing in help texts very slightly.
+ *
+ * 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.
  *
 
 #include <gtk/gtk.h>
 #include <gdk/gdkprivate.h>
+#include <gdk/gdkkeysyms.h>
 
-#include "mdwopt.h"
-#include "xwait.h"
-
-/*----- Static variables --------------------------------------------------*/
+#include <mLib/mdwopt.h>
+#include <mLib/quis.h>
+#include <mLib/report.h>
 
-static char *atom = XWAIT_DIE;
-static char *msg = XWAIT_DIE_MSG;
+#include <mgLib/msg.h>
 
-static Atom xwait_die;
+#include "xatom.h"
+#include "xwait.h"
 
 /*----- Main code ---------------------------------------------------------*/
 
-/* --- @cancel@ --- *
- *
- * Just end the main loop.
- */
+/* --- @version@ --- */
 
-static void cancel(GtkWidget *w, gpointer *p)
+static void version(FILE *fp)
 {
-  gtk_main_quit();
+  fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS);
 }
 
-/* --- @ok@ --- *
- *
- * Send the xwait process a message.
- */
+/* --- @usage@ --- */
 
-static void ok(GtkWidget *w, gpointer *p)
+static void usage(FILE *fp)
 {
-  XTextProperty prop;
-  XStringListToTextProperty(&msg, 1, &prop);
-  XSetTextProperty(gdk_display, DefaultRootWindow(gdk_display),
-                  &prop, xwait_die);
-  gtk_main_quit();
+  fprintf(fp, "Usage: %s [-p PROMPT] [-t TITLE] [ATOM:MSG]\n", QUIS);
 }
 
 /* --- @main@ --- *
@@ -89,33 +98,71 @@ static void ok(GtkWidget *w, gpointer *p)
 
 int main(int argc, char *argv[])
 {
+  char *atom = XWAIT_DIE;
+  char *xmsg = XWAIT_DIE_MSG;
+  Atom xa, xm;
+
   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[] = {
-      { "atom",        required_argument,      0,      'a' },
-      { "msg", required_argument,      0,      'm' },
-      { "prompt", required_argument,   0,      'p' },
-      { "title", required_argument,    0,      't' },
-      { 0,     0,                      0,      0 }
+      { "help",                0,              0,      'h' },
+      { "usage",       0,              0,      'u' },
+      { "version",     0,              0,      'v' },
+      { "atom",                OPTF_ARGREQ,    0,      'a' },
+      { "msg",         OPTF_ARGREQ,    0,      'm' },
+      { "prompt",      OPTF_ARGREQ,    0,      'p' },
+      { "title",       OPTF_ARGREQ,    0,      't' },
+      { 0,             0,              0,      0 }
     };
     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\t     Select the property name atom [deprecated]\n"
+"-m, --msg=MSG         Select the message to send [deprecated]\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;
       case 'm':
-       msg = optarg;
+       xmsg = optarg;
        break;
       case 'p':
        prompt = optarg;
@@ -124,107 +171,42 @@ int main(int argc, char *argv[])
        title = optarg;
        break;
       default:
+       usage(stderr);
        exit(EXIT_FAILURE);
     }
   }
 
-  xwait_die = XInternAtom(gdk_display, atom, False);
+  if (optind < argc) {
+    char *p;
+    if ((atom = strtok(argv[optind++], ":")) == 0)
+      die(EXIT_FAILURE, "missing atom name");
+    if ((p = strtok(0, ",")) != 0)
+      xmsg = p;
+  }
+
+  if (optind < argc) {
+    usage(stderr);
+    exit(EXIT_FAILURE);
+  }
+
+  xa = XInternAtom(gdk_display, atom, False);
+  xm = XInternAtom(gdk_display, xmsg, False);
 
   /* --- Decide whether there's an xwait listening --- *
    *
    * If not, pop up an error box and quit.
    */
 
-  {
-    XTextProperty prop;
-
-    if (!XGetTextProperty(gdk_display, DefaultRootWindow(gdk_display),
-                         &prop, xwait_die)) {
-      char buf[64];
-      GtkWidget *win = gtk_dialog_new();
-      GtkWidget *w;
-
-      /* --- Make the main window --- */
-
-      gtk_window_set_title(GTK_WINDOW(win), "xshutdown");
-      gtk_signal_connect(GTK_OBJECT(win), "destroy",
-                      GTK_SIGNAL_FUNC(cancel), 0);
-
-      gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win)->action_area), 0);
-
-      /* --- Make the label --- */
-
-      sprintf(buf, "no xwait listening for `%s'\n", atom);
-      w = gtk_label_new(buf);
-      gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win)->vbox), w, 1, 1, 0);
-      gtk_misc_set_padding(GTK_MISC(w), 8, 8);
-      gtk_widget_show(w);
-
-      /* --- Make the little button --- */
-
-      w = gtk_button_new_with_label("OK");
-      gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win)->action_area), w, 0, 0, 0);
-      GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT);
-      gtk_widget_grab_default(w);
-      gtk_signal_connect(GTK_OBJECT(w), "clicked",
-                        GTK_SIGNAL_FUNC(cancel), 0);
-      gtk_widget_show(w);
-
-      /* --- Make everything work --- */
-
-      gtk_widget_show(win);
-      gtk_main();
-      exit(EXIT_FAILURE);
-    }
+  if (xatom_get(gdk_display, DefaultRootWindow(gdk_display), xa) == None) {
+    msg("!:~OK", "no xwait listening for `%s'", atom);
+    exit(EXIT_FAILURE);
   }
 
   /* --- Main code --- */
 
-  {
-    GtkWidget *win;
-    GtkWidget *w;
-
-    /* --- Make the main dialogue box --- */
-
-    win = gtk_dialog_new();
-    gtk_window_set_title(GTK_WINDOW(win), title);
-    gtk_signal_connect(GTK_OBJECT(win), "destroy",
-                      GTK_SIGNAL_FUNC(cancel), 0);
-
-    gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win)->action_area), 0);
-
-    /* --- Make the prompt label --- */
-
-    w = gtk_label_new(prompt);
-    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win)->vbox), w, 1, 1, 0);
-    gtk_misc_set_padding(GTK_MISC(w), 8, 8);
-    gtk_widget_show(w);
-
-    /* --- Make the OK button --- */
-
-    w = gtk_button_new_with_label("OK");
-    gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win)->action_area), w, 0, 0, 0);
-    gtk_signal_connect(GTK_OBJECT(w), "clicked", GTK_SIGNAL_FUNC(ok), 0);
-    GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT);
-    gtk_widget_show(w);
-    gtk_widget_grab_default(w);
-
-    /* --- And the cancel button --- */
-
-    w = gtk_button_new_with_label("Cancel");
-    gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win)->action_area), w, 0, 0, 0);
-    gtk_signal_connect(GTK_OBJECT(w), "clicked", GTK_SIGNAL_FUNC(cancel), 0);
-    GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT);
-    gtk_widget_show(w);
-
-    /* --- Show the completed window --- */
-
-    gtk_widget_show(win);
-  }
-
-  /* --- Let rip --- */
+  if (msg("!:OK,~Cancel", "%s", prompt) == 0)
+    xatom_set(gdk_display, DefaultRootWindow(gdk_display), xa, xm);
 
-  gtk_main();
   return (0);
 }