90b2c5d4 |
1 | /* -*-c-*- |
2 | * |
d72bdcdb |
3 | * $Id: xtell.c,v 1.5 1999/08/20 07:29:19 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 | |
29 | /*----- Revision history --------------------------------------------------* |
30 | * |
31 | * $Log: xtell.c,v $ |
d72bdcdb |
32 | * Revision 1.5 1999/08/20 07:29:19 mdw |
33 | * New command line syntax, and new atom protocol. |
34 | * |
c4efa11c |
35 | * Revision 1.4 1998/12/11 09:50:06 mdw |
36 | * Minor modifications to work with mLib and mgLib. |
37 | * |
d6130abd |
38 | * Revision 1.3 1998/11/30 22:36:51 mdw |
39 | * Tidy up tabbing in help texts very slightly. |
40 | * |
f3b35b6b |
41 | * Revision 1.2 1998/11/21 22:30:25 mdw |
42 | * Support GNU-style long options throughout, and introduce proper help |
43 | * text to all programs. Update manual pages to match. |
44 | * |
90b2c5d4 |
45 | * Revision 1.1 1998/11/16 23:00:49 mdw |
46 | * Initial versions. |
47 | * |
48 | */ |
49 | |
50 | /*----- Header files ------------------------------------------------------*/ |
51 | |
52 | #include <stdio.h> |
53 | #include <stdlib.h> |
54 | #include <string.h> |
55 | |
90b2c5d4 |
56 | #include <X11/Xlib.h> |
57 | #include <X11/Xutil.h> |
58 | |
c4efa11c |
59 | #include <mLib/mdwopt.h> |
60 | #include <mLib/quis.h> |
d72bdcdb |
61 | #include <mLib/report.h> |
c4efa11c |
62 | |
d72bdcdb |
63 | #include "xatom.h" |
90b2c5d4 |
64 | #include "xwait.h" |
65 | |
66 | /*----- Main code ---------------------------------------------------------*/ |
67 | |
f3b35b6b |
68 | static void version(FILE *fp) |
69 | { |
70 | fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS); |
71 | } |
72 | |
73 | static void usage(FILE *fp) |
74 | { |
d72bdcdb |
75 | fprintf(fp, "Usage: %s [-d DISPLAY] [ATOM:MSG]\n", QUIS); |
f3b35b6b |
76 | } |
77 | |
90b2c5d4 |
78 | int main(int argc, char *argv[]) |
79 | { |
80 | char *display = 0; |
81 | Display *dpy; |
d72bdcdb |
82 | Atom a, m; |
90b2c5d4 |
83 | char *atom = XWAIT_DIE; |
84 | char *msg = XWAIT_DIE_MSG; |
85 | |
86 | /* --- Parse options --- */ |
87 | |
f3b35b6b |
88 | ego(argv[0]); |
89 | |
90b2c5d4 |
90 | for (;;) { |
f3b35b6b |
91 | static struct option opt[] = { |
d72bdcdb |
92 | { "help", 0, 0, 'h' }, |
93 | { "usage", 0, 0, 'u' }, |
94 | { "version", 0, 0, 'v' }, |
95 | { "display", OPTF_ARGREQ, 0, 'd' }, |
96 | { "atom", OPTF_ARGREQ, 0, 'a' }, |
97 | { "msg", OPTF_ARGREQ, 0, 'm' }, |
98 | { 0, 0, 0, 0 } |
f3b35b6b |
99 | }; |
100 | |
d72bdcdb |
101 | int i = mdwopt(argc, argv, "d:a:m:", opt, 0, 0, 0); |
90b2c5d4 |
102 | if (i < 0) |
103 | break; |
104 | switch (i) { |
f3b35b6b |
105 | case 'h': |
106 | version(stdout); |
107 | fputs("\n", stdout); |
108 | usage(stdout); |
109 | fputs( |
110 | "\n" |
111 | "Signals a waiting `xwait' process. Specifically, writes a property\n" |
112 | "named ATOM to the X root window, with value MSG.\n" |
113 | "\n" |
114 | "Options:\n" |
115 | "\n" |
116 | "-h, --help Display this help text\n" |
117 | "-u, --usage Display a short usage summary\n" |
118 | "-v, --version Display the program's version number\n" |
119 | "\n" |
120 | "-d, --display=DISPLAY Choose X display to connect to\n" |
d72bdcdb |
121 | "-a, --atom=ATOM\t Choose property name to set [deprecated]\n" |
122 | "-m, --msg=MSG Choose value of property to set [deprecated]\n", |
f3b35b6b |
123 | stdout); |
124 | exit(0); |
125 | break; |
126 | case 'u': |
127 | usage(stdout); |
128 | exit(0); |
129 | break; |
130 | case 'v': |
131 | version(stdout); |
132 | exit(0); |
133 | break; |
134 | |
90b2c5d4 |
135 | case 'd': |
136 | display = optarg; |
137 | break; |
138 | case 'a': |
139 | atom = optarg; |
140 | break; |
141 | case 'm': |
142 | msg = optarg; |
143 | break; |
144 | default: |
d72bdcdb |
145 | usage(stderr); |
90b2c5d4 |
146 | exit(EXIT_FAILURE); |
147 | break; |
148 | } |
149 | } |
150 | |
d72bdcdb |
151 | if (optind < argc) { |
152 | char *p; |
153 | if ((atom = strtok(argv[optind++], ":")) == 0) |
154 | die(EXIT_FAILURE, "missing atom name"); |
155 | if ((p = strtok(0, ",")) != 0) |
156 | msg = p; |
157 | } |
90b2c5d4 |
158 | |
d72bdcdb |
159 | if (optind < argc) { |
160 | usage(stderr); |
90b2c5d4 |
161 | exit(EXIT_FAILURE); |
162 | } |
163 | |
d72bdcdb |
164 | /* --- Set the property value and exit --- */ |
90b2c5d4 |
165 | |
d72bdcdb |
166 | if ((dpy = XOpenDisplay(display)) == 0) |
167 | die(EXIT_FAILURE, "couldn't open display"); |
90b2c5d4 |
168 | |
d72bdcdb |
169 | a = XInternAtom(dpy, atom, False); |
170 | m = XInternAtom(dpy, msg, False); |
171 | xatom_set(dpy, DefaultRootWindow(dpy), a, m); |
90b2c5d4 |
172 | |
173 | XCloseDisplay(dpy); |
174 | return (0); |
175 | } |
176 | |
177 | /*----- That's all, folks -------------------------------------------------*/ |