chiark / gitweb /
Debianization fixes.
[xtoys] / xtell.c
1 /* -*-c-*-
2  *
3  * $Id: xtell.c,v 1.5 1999/08/20 07:29:19 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.5  1999/08/20 07:29:19  mdw
33  * New command line syntax, and new atom protocol.
34  *
35  * Revision 1.4  1998/12/11 09:50:06  mdw
36  * Minor modifications to work with mLib and mgLib.
37  *
38  * Revision 1.3  1998/11/30 22:36:51  mdw
39  * Tidy up tabbing in help texts very slightly.
40  *
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  *
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
56 #include <X11/Xlib.h>
57 #include <X11/Xutil.h>
58
59 #include <mLib/mdwopt.h>
60 #include <mLib/quis.h>
61 #include <mLib/report.h>
62
63 #include "xatom.h"
64 #include "xwait.h"
65
66 /*----- Main code ---------------------------------------------------------*/
67
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 {
75   fprintf(fp, "Usage: %s [-d DISPLAY] [ATOM:MSG]\n", QUIS);
76 }
77
78 int main(int argc, char *argv[])
79 {
80   char *display = 0;
81   Display *dpy;
82   Atom a, m;
83   char *atom = XWAIT_DIE;
84   char *msg = XWAIT_DIE_MSG;
85
86   /* --- Parse options --- */
87
88   ego(argv[0]);
89
90   for (;;) {
91     static struct option opt[] = {
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 }
99     };
100
101     int i = mdwopt(argc, argv, "d:a:m:", opt, 0, 0, 0);
102     if (i < 0)
103       break;
104     switch (i) {
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"
121 "-a, --atom=ATOM\t      Choose property name to set [deprecated]\n"
122 "-m, --msg=MSG          Choose value of property to set [deprecated]\n",
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         
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:
145         usage(stderr);
146         exit(EXIT_FAILURE);
147         break;
148     }
149   }
150
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   }
158
159   if (optind < argc) {
160     usage(stderr);
161     exit(EXIT_FAILURE);
162   }
163
164   /* --- Set the property value and exit --- */
165
166   if ((dpy = XOpenDisplay(display)) == 0)
167     die(EXIT_FAILURE, "couldn't open display");
168
169   a = XInternAtom(dpy, atom, False);
170   m = XInternAtom(dpy, msg, False);
171   xatom_set(dpy, DefaultRootWindow(dpy), a, m);
172
173   XCloseDisplay(dpy);
174   return (0);
175 }
176
177 /*----- That's all, folks -------------------------------------------------*/