+/* --- @sigchld@ --- */
+
+static void sigchld(int sig)
+{
+ int e = errno;
+ while (waitpid(-1, 0, WNOHANG) > 0)
+ ;
+ errno = e;
+}
+
+/* --- @opendisplay@ --- */
+
+static void opendisplay(const char *d)
+{
+ if (dpy)
+ return;
+ if ((dpy = XOpenDisplay(d)) == 0)
+ die(EXIT_FAILURE, "couldn't open display");
+}
+
+/* --- @addatom@ --- */
+
+static xwait_atom *addatom(const char *a)
+{
+ xwait_atom *xa = CREATE(xwait_atom);
+ opendisplay(0);
+ xa->next = atoms;
+ xa->a = XInternAtom(dpy, a, False);
+ xa->m = 0;
+ atoms = xa;
+ return (xa);
+}
+
+/* --- @addmsg@ --- */
+
+static void addmsg(xwait_atom *xa, const char *a)
+{
+ xwait_msg *xm = CREATE(xwait_msg);
+ opendisplay(0);
+ xm->next = xa->m;
+ xm->a = XInternAtom(dpy, a, False);
+ xa->m = xm;
+}
+
+/* --- @tidy@ --- */
+
+static void tidy(int sig)
+{
+ int i;
+ int nsc = ScreenCount(dpy);
+ xwait_atom *xa;
+
+ for (i = 0; i < nsc; i++) {
+ for (xa = atoms; xa; xa = xa->next)
+ XDeleteProperty(dpy, RootWindow(dpy, i), xa->a);
+ }
+ XCloseDisplay(dpy);
+ exit(0);
+}
+
+/* --- @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] [ATOM:MSG,MSG]...\n", QUIS);
+}
+