Expunge revision histories in files.
[xtoys] / xtell.c
CommitLineData
90b2c5d4 1/* -*-c-*-
2 *
47747dbe 3 * $Id: xtell.c,v 1.6 2004/04/08 01:36:29 mdw Exp $
90b2c5d4 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
90b2c5d4 29/*----- Header files ------------------------------------------------------*/
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34
90b2c5d4 35#include <X11/Xlib.h>
36#include <X11/Xutil.h>
37
c4efa11c 38#include <mLib/mdwopt.h>
39#include <mLib/quis.h>
d72bdcdb 40#include <mLib/report.h>
c4efa11c 41
d72bdcdb 42#include "xatom.h"
90b2c5d4 43#include "xwait.h"
44
45/*----- Main code ---------------------------------------------------------*/
46
f3b35b6b 47static void version(FILE *fp)
48{
49 fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS);
50}
51
52static void usage(FILE *fp)
53{
d72bdcdb 54 fprintf(fp, "Usage: %s [-d DISPLAY] [ATOM:MSG]\n", QUIS);
f3b35b6b 55}
56
90b2c5d4 57int main(int argc, char *argv[])
58{
59 char *display = 0;
60 Display *dpy;
d72bdcdb 61 Atom a, m;
90b2c5d4 62 char *atom = XWAIT_DIE;
63 char *msg = XWAIT_DIE_MSG;
64
65 /* --- Parse options --- */
66
f3b35b6b 67 ego(argv[0]);
68
90b2c5d4 69 for (;;) {
f3b35b6b 70 static struct option opt[] = {
d72bdcdb 71 { "help", 0, 0, 'h' },
72 { "usage", 0, 0, 'u' },
73 { "version", 0, 0, 'v' },
74 { "display", OPTF_ARGREQ, 0, 'd' },
75 { "atom", OPTF_ARGREQ, 0, 'a' },
76 { "msg", OPTF_ARGREQ, 0, 'm' },
77 { 0, 0, 0, 0 }
f3b35b6b 78 };
79
d72bdcdb 80 int i = mdwopt(argc, argv, "d:a:m:", opt, 0, 0, 0);
90b2c5d4 81 if (i < 0)
82 break;
83 switch (i) {
f3b35b6b 84 case 'h':
85 version(stdout);
86 fputs("\n", stdout);
87 usage(stdout);
88 fputs(
89"\n"
90"Signals a waiting `xwait' process. Specifically, writes a property\n"
91"named ATOM to the X root window, with value MSG.\n"
92"\n"
93"Options:\n"
94"\n"
95"-h, --help Display this help text\n"
96"-u, --usage Display a short usage summary\n"
97"-v, --version Display the program's version number\n"
98"\n"
99"-d, --display=DISPLAY Choose X display to connect to\n"
d72bdcdb 100"-a, --atom=ATOM\t Choose property name to set [deprecated]\n"
101"-m, --msg=MSG Choose value of property to set [deprecated]\n",
f3b35b6b 102 stdout);
103 exit(0);
104 break;
105 case 'u':
106 usage(stdout);
107 exit(0);
108 break;
109 case 'v':
110 version(stdout);
111 exit(0);
112 break;
113
90b2c5d4 114 case 'd':
115 display = optarg;
116 break;
117 case 'a':
118 atom = optarg;
119 break;
120 case 'm':
121 msg = optarg;
122 break;
123 default:
d72bdcdb 124 usage(stderr);
90b2c5d4 125 exit(EXIT_FAILURE);
126 break;
127 }
128 }
129
d72bdcdb 130 if (optind < argc) {
131 char *p;
132 if ((atom = strtok(argv[optind++], ":")) == 0)
133 die(EXIT_FAILURE, "missing atom name");
134 if ((p = strtok(0, ",")) != 0)
135 msg = p;
136 }
90b2c5d4 137
d72bdcdb 138 if (optind < argc) {
139 usage(stderr);
90b2c5d4 140 exit(EXIT_FAILURE);
141 }
142
d72bdcdb 143 /* --- Set the property value and exit --- */
90b2c5d4 144
d72bdcdb 145 if ((dpy = XOpenDisplay(display)) == 0)
146 die(EXIT_FAILURE, "couldn't open display");
90b2c5d4 147
d72bdcdb 148 a = XInternAtom(dpy, atom, False);
149 m = XInternAtom(dpy, msg, False);
150 xatom_set(dpy, DefaultRootWindow(dpy), a, m);
90b2c5d4 151
152 XCloseDisplay(dpy);
153 return (0);
154}
155
156/*----- That's all, folks -------------------------------------------------*/