6ca8a283bfff5ad0eb545713af2cb5edbc05b2b0
[xtoys] / xtell.c
1 /* -*-c-*-
2 *
3 * $Id: xtell.c,v 1.2 1998/11/21 22:30:25 mdw Exp $
4 *
5 * Wake up a waiting xwait process
6 *
7 * (c) 1998 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the Edgeware X tools collection.
13 *
14 * X tools is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * X tools is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with X tools; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
29 /*----- Revision history --------------------------------------------------*
30 *
31 * $Log: xtell.c,v $
32 * Revision 1.2 1998/11/21 22:30:25 mdw
33 * Support GNU-style long options throughout, and introduce proper help
34 * text to all programs. Update manual pages to match.
35 *
36 * Revision 1.1 1998/11/16 23:00:49 mdw
37 * Initial versions.
38 *
39 */
40
41 /*----- Header files ------------------------------------------------------*/
42
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46
47 #include <X11/Xlib.h>
48 #include <X11/Xutil.h>
49
50 #include "mdwopt.h"
51 #include "quis.h"
52 #include "xwait.h"
53
54 /*----- Main code ---------------------------------------------------------*/
55
56 static void version(FILE *fp)
57 {
58 fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS);
59 }
60
61 static void usage(FILE *fp)
62 {
63 fprintf(fp, "Usage: %s [-d DISPLAY] [-a ATOM] [-m MSG]\n", QUIS);
64 }
65
66 int main(int argc, char *argv[])
67 {
68 char *display = 0;
69 Display *dpy;
70 Atom xwait_die;
71 char *atom = XWAIT_DIE;
72 char *msg = XWAIT_DIE_MSG;
73
74 /* --- Parse options --- */
75
76 ego(argv[0]);
77
78 for (;;) {
79 static struct option opt[] = {
80 { "help", 0, 0, 'h' },
81 { "usage", 0, 0, 'u' },
82 { "version", 0, 0, 'v' },
83 { "display", required_argument, 0, 'd' },
84 { "atom", required_argument, 0, 'a' },
85 { "msg", required_argument, 0, 'm' },
86 { 0, 0, 0, 0 }
87 };
88
89 int i = getopt_long(argc, argv, "d:a:m:", opt, 0);
90 if (i < 0)
91 break;
92 switch (i) {
93 case 'h':
94 version(stdout);
95 fputs("\n", stdout);
96 usage(stdout);
97 fputs(
98 "\n"
99 "Signals a waiting `xwait' process. Specifically, writes a property\n"
100 "named ATOM to the X root window, with value MSG.\n"
101 "\n"
102 "Options:\n"
103 "\n"
104 "-h, --help Display this help text\n"
105 "-u, --usage Display a short usage summary\n"
106 "-v, --version Display the program's version number\n"
107 "\n"
108 "-d, --display=DISPLAY Choose X display to connect to\n"
109 "-a, --atom=ATOM Choose property name to set\n"
110 "-m, --msg=MSG Choose value of property to set\n",
111 stdout);
112 exit(0);
113 break;
114 case 'u':
115 usage(stdout);
116 exit(0);
117 break;
118 case 'v':
119 version(stdout);
120 exit(0);
121 break;
122
123 case 'd':
124 display = optarg;
125 break;
126 case 'a':
127 atom = optarg;
128 break;
129 case 'm':
130 msg = optarg;
131 break;
132 default:
133 fprintf(stderr, "Usage: xtell [-d DISPLAY] [-a ATOM] [-m MSG]\n");
134 exit(EXIT_FAILURE);
135 break;
136 }
137 }
138
139 /* --- Connect to the display --- */
140
141 dpy = XOpenDisplay(display);
142 if (!dpy) {
143 fprintf(stderr, "xtell: couldn't open display\n");
144 exit(EXIT_FAILURE);
145 }
146
147 /* --- Find the right atom --- */
148
149 xwait_die = XInternAtom(dpy, atom, False);
150
151 /* --- Set the property value --- */
152
153 {
154 XTextProperty prop;
155 if (!XGetTextProperty(dpy, DefaultRootWindow(dpy), &prop, xwait_die)) {
156 fprintf(stderr, "xtell: no xwait listening for `%s'\n", atom);
157 exit(EXIT_FAILURE);
158 }
159 XStringListToTextProperty(&msg, 1, &prop);
160 XSetTextProperty(dpy, DefaultRootWindow(dpy), &prop, xwait_die);
161 }
162
163 /* --- Done --- */
164
165 XCloseDisplay(dpy);
166 return (0);
167 }
168
169 /*----- That's all, folks -------------------------------------------------*/