chiark / gitweb /
New command line syntax, and new atom protocol.
authormdw <mdw>
Fri, 20 Aug 1999 07:29:19 +0000 (07:29 +0000)
committermdw <mdw>
Fri, 20 Aug 1999 07:29:19 +0000 (07:29 +0000)
xshutdown.1
xshutdown.c
xtell.1
xtell.c

index 30331804a3aa9b6c7c90dbe0dd5012fd286e4204..24c71cc1408a80695906537f63ddaca3340bae2a 100644 (file)
@@ -3,6 +3,7 @@
 .SH NAME
 xshutdown \- asks for user confirmation before waking an xwait process
 .SH SYNOPSIS
+.ll +5i
 .B xshutdown
 .RB [ \-\-display
 .IR display ]
@@ -10,8 +11,16 @@ xshutdown \- asks for user confirmation before waking an xwait process
 .IR atom ]
 .RB [ \-m
 .IR message ]
+.if n \{\
+.br
+\h'1i'
+..
 .RB [ \-t
 .IR title ]
+.RI [ \c
+.IB atom : msg , msg \c
+\&...]
+.ll -5i
 .SH DESCRIPTION
 The
 .B xshutdown
@@ -33,16 +42,14 @@ Sets
 .B xshutdown
 to to set the property named
 .IR atom .
-The default property to set is
-.BR XWAIT_PROPERTY .
+This option is deprecated.
 .TP 5
 .BI "\-m, \-\-msg " message
 Sets
 .B xshutdown
 to set the given property to
 .IR message .
-The default message to set is
-.BR XWAIT_MESSAGE .
+This option is deprecated.
 .TP 5
 .BI "\-p, \-\-prompt " prompt
 Sets the prompt in the confirmation box to
@@ -51,6 +58,19 @@ Sets the prompt in the confirmation box to
 .BI "\-t, \-\-title " title
 Sets the window title to be
 .IR title .
+.PP
+The
+.B \-a
+and
+.B \-m
+options are deprecated, though retained for compatibility reasons.  It's
+recommended that you use the non-option specification instead.
+.PP
+The argument specifies an atom name and a message string to set.  The
+default, if no atom or message is given, is to set
+.B XWAIT_PROPERTY
+to the value
+.BR XWAIT_MESSAGE .
 .SH AUTHOR
 Mark Wooding (mdw@nsict.org).
 .SH BUGS
index c66987172e61857244498fb622c7c956868b9fcd..499ff7ce093cb51b0222258ff5b9ecf6359e0a4d 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: xshutdown.c,v 1.6 1998/12/11 09:51:51 mdw Exp $
+ * $Id: xshutdown.c,v 1.7 1999/08/20 07:29:19 mdw Exp $
  *
  * Pretty GTK interface to waking up an xwait
  *
@@ -29,6 +29,9 @@
 /*----- 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.
  *
 
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
+#include <mLib/report.h>
 
 #include <mgLib/msg.h>
 
+#include "xatom.h"
 #include "xwait.h"
 
-/*----- Static variables --------------------------------------------------*/
-
-static char *atom = XWAIT_DIE;
-static char *xmsg = XWAIT_DIE_MSG;
-
-static Atom xwait_die;
-
 /*----- Main code ---------------------------------------------------------*/
 
 /* --- @version@ --- */
@@ -90,7 +88,7 @@ static void version(FILE *fp)
 
 static void usage(FILE *fp)
 {
-  fprintf(fp, "Usage: %s [-a ATOM] [-m MSG] [-p PROMPT] [-t TITLE]\n", QUIS);
+  fprintf(fp, "Usage: %s [-p PROMPT] [-t TITLE] [ATOM:MSG]\n", QUIS);
 }
 
 /* --- @main@ --- *
@@ -100,6 +98,10 @@ static void usage(FILE *fp)
 
 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]);
@@ -109,14 +111,14 @@ int main(int argc, char *argv[])
 
   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' },
-      { "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;
 
@@ -140,8 +142,8 @@ int main(int argc, char *argv[])
 "-u, --usage           Display a short usage summary\n"
 "-v, --version         Display the program's version number\n"
 "\n"
-"-a, --atom=ATOM\t     Select the atom that `xwait' is waiting for\n"
-"-m, --msg=MSG         Select the message to send to `xwait'\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);
@@ -174,31 +176,36 @@ int main(int argc, char *argv[])
     }
   }
 
-  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)) {
-      msg("!:~OK", "no xwait listening for `%s'", atom);
-      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 --- */
 
-  if (msg("!:OK,~Cancel", "%s", prompt) == 0) {
-    XTextProperty prop;
-    XStringListToTextProperty(&xmsg, 1, &prop);
-    XSetTextProperty(gdk_display, DefaultRootWindow(gdk_display),
-                    &prop, xwait_die);
-  }
+  if (msg("!:OK,~Cancel", "%s", prompt) == 0)
+    xatom_set(gdk_display, DefaultRootWindow(gdk_display), xa, xm);
 
   return (0);
 }
diff --git a/xtell.1 b/xtell.1
index 3329537b2792b9be0c7c33543a6d9376c8c56c02..2fd32a9a60f351293fdb068793c73e913f8b0068 100644 (file)
--- a/xtell.1
+++ b/xtell.1
@@ -3,6 +3,7 @@
 .SH NAME
 xtell \- prods a waiting xwait process
 .SH SYNOPSIS
+.ll +5i
 .B xtell
 .RB [ \-d
 .IR display ]
@@ -10,6 +11,10 @@ xtell \- prods a waiting xwait process
 .IR atom ]
 .RB [ \-m
 .IR message ]
+.RI [ \c
+.IB atom : msg , msg \c
+\&...]
+.ll -5i
 .SH DESCRIPTION
 The
 .B xtell
@@ -28,15 +33,26 @@ Sets
 .B xtell
 to to set the property named
 .IR atom .
-The default property to set to is
-.BR XWAIT_PROPERTY .
+Use of this option is deprecated.
 .TP 5
 .BI "\-m, \-\-msg " message
 Sets
 .B xtell
 to set the given property to
 .IR message .
-The default message to set is
+Use of this option is deprecated.
+.PP
+The
+.B \-a
+and
+.B \-m
+options are deprecated, though retained for compatibility reasons.  It's
+recommended that you use the non-option specification instead.
+.PP
+The argument specifies an atom name and a message string to set.  The
+default, if no atom or message is given, is to set
+.B XWAIT_PROPERTY
+to the value
 .BR XWAIT_MESSAGE .
 .SH AUTHOR
 Mark Wooding (mdw@nsict.org).
diff --git a/xtell.c b/xtell.c
index 76d53d380900bbb899322dace495044aa9f55822..79f2709ba9e7d597862aeb3ebafa06f52b99e6a1 100644 (file)
--- a/xtell.c
+++ b/xtell.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: xtell.c,v 1.4 1998/12/11 09:50:06 mdw Exp $
+ * $Id: xtell.c,v 1.5 1999/08/20 07:29:19 mdw Exp $
  *
  * Wake up a waiting xwait process
  *
@@ -29,6 +29,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: xtell.c,v $
+ * Revision 1.5  1999/08/20 07:29:19  mdw
+ * New command line syntax, and new atom protocol.
+ *
  * Revision 1.4  1998/12/11 09:50:06  mdw
  * Minor modifications to work with mLib and mgLib.
  *
@@ -55,7 +58,9 @@
 
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
+#include <mLib/report.h>
 
+#include "xatom.h"
 #include "xwait.h"
 
 /*----- Main code ---------------------------------------------------------*/
@@ -67,14 +72,14 @@ static void version(FILE *fp)
 
 static void usage(FILE *fp)
 {
-  fprintf(fp, "Usage: %s [-d DISPLAY] [-a ATOM] [-m MSG]\n", QUIS);
+  fprintf(fp, "Usage: %s [-d DISPLAY] [ATOM:MSG]\n", QUIS);
 }
 
 int main(int argc, char *argv[])
 {
   char *display = 0;
   Display *dpy;
-  Atom xwait_die;
+  Atom a, m;
   char *atom = XWAIT_DIE;
   char *msg = XWAIT_DIE_MSG;
 
@@ -84,16 +89,16 @@ int main(int argc, char *argv[])
 
   for (;;) {
     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 }
+      { "help",        0,              0,      'h' },
+      { "usage",       0,              0,      'u' },
+      { "version",     0,              0,      'v' },
+      { "display",     OPTF_ARGREQ,    0,      'd' },
+      { "atom",                OPTF_ARGREQ,    0,      'a' },
+      { "msg",         OPTF_ARGREQ,    0,      'm' },
+      {        0,              0,              0,      0 }
     };
 
-    int i = getopt_long(argc, argv, "d:a:m:", opt, 0);
+    int i = mdwopt(argc, argv, "d:a:m:", opt, 0, 0, 0);
     if (i < 0)
       break;
     switch (i) {
@@ -113,8 +118,8 @@ int main(int argc, char *argv[])
 "-v, --version         Display the program's version number\n"
 "\n"
 "-d, --display=DISPLAY Choose X display to connect to\n"
-"-a, --atom=ATOM\t     Choose property name to set\n"
-"-m, --msg=MSG         Choose value of property to set\n",
+"-a, --atom=ATOM\t     Choose property name to set [deprecated]\n"
+"-m, --msg=MSG         Choose value of property to set [deprecated]\n",
           stdout);
        exit(0);
        break;
@@ -137,37 +142,33 @@ int main(int argc, char *argv[])
        msg = optarg;
        break;
       default:
-       fprintf(stderr, "Usage: xtell [-d DISPLAY] [-a ATOM] [-m MSG]\n");
+       usage(stderr);
        exit(EXIT_FAILURE);
        break;
     }
   }
 
-  /* --- Connect to the display --- */
+  if (optind < argc) {
+    char *p;
+    if ((atom = strtok(argv[optind++], ":")) == 0)
+      die(EXIT_FAILURE, "missing atom name");
+    if ((p = strtok(0, ",")) != 0)
+      msg = p;
+  }
 
-  dpy = XOpenDisplay(display);
-  if (!dpy) {
-    fprintf(stderr, "xtell: couldn't open display\n");
+  if (optind < argc) {
+    usage(stderr);
     exit(EXIT_FAILURE);
   }
 
-  /* --- Find the right atom --- */
-
-  xwait_die = XInternAtom(dpy, atom, False);
+  /* --- Set the property value and exit --- */
 
-  /* --- Set the property value --- */
-
-  {
-    XTextProperty prop;
-    if (!XGetTextProperty(dpy, DefaultRootWindow(dpy), &prop, xwait_die)) {
-      fprintf(stderr, "xtell: no xwait listening for `%s'\n", atom);
-      exit(EXIT_FAILURE);
-    }
-    XStringListToTextProperty(&msg, 1, &prop);
-    XSetTextProperty(dpy, DefaultRootWindow(dpy), &prop, xwait_die);
-  }
+  if ((dpy = XOpenDisplay(display)) == 0)
+    die(EXIT_FAILURE, "couldn't open display");
 
-  /* --- Done --- */
+  a = XInternAtom(dpy, atom, False);
+  m = XInternAtom(dpy, msg, False);
+  xatom_set(dpy, DefaultRootWindow(dpy), a, m);
 
   XCloseDisplay(dpy);
   return (0);