Make flags be unsigned.
[xtoys] / xshutdown.c
CommitLineData
90b2c5d4 1/* -*-c-*-
2 *
bf980fa9 3 * $Id: xshutdown.c,v 1.8 2002/01/13 14:44:47 mdw Exp $
90b2c5d4 4 *
5 * Pretty GTK interface to waking up an xwait
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: xshutdown.c,v $
bf980fa9 32 * Revision 1.8 2002/01/13 14:44:47 mdw
33 * Track @msg@ change; make the `-t' option actually work.
34 *
d72bdcdb 35 * Revision 1.7 1999/08/20 07:29:19 mdw
36 * New command line syntax, and new atom protocol.
37 *
aa8f2c90 38 * Revision 1.6 1998/12/11 09:51:51 mdw
39 * Use mgLib's `msg' box rather than doing things the hard way.
40 *
87dabe6f 41 * Revision 1.5 1998/12/03 01:00:19 mdw
42 * Honour escape presses in the dialogue boxes.
43 *
7347b0d9 44 * Revision 1.4 1998/12/03 00:39:45 mdw
45 * Force focus when starting up.
46 *
d6130abd 47 * Revision 1.3 1998/11/30 22:36:49 mdw
48 * Tidy up tabbing in help texts very slightly.
49 *
f3b35b6b 50 * Revision 1.2 1998/11/21 22:30:23 mdw
51 * Support GNU-style long options throughout, and introduce proper help
52 * text to all programs. Update manual pages to match.
53 *
90b2c5d4 54 * Revision 1.1 1998/11/16 23:00:49 mdw
55 * Initial versions.
56 *
57 */
58
59/*----- Header files ------------------------------------------------------*/
60
61#include <stdio.h>
62#include <stdlib.h>
63#include <string.h>
64
65#include <X11/Xlib.h>
66#include <X11/Xutil.h>
67
68#include <gtk/gtk.h>
69#include <gdk/gdkprivate.h>
87dabe6f 70#include <gdk/gdkkeysyms.h>
90b2c5d4 71
aa8f2c90 72#include <mLib/mdwopt.h>
73#include <mLib/quis.h>
d72bdcdb 74#include <mLib/report.h>
aa8f2c90 75
76#include <mgLib/msg.h>
77
d72bdcdb 78#include "xatom.h"
90b2c5d4 79#include "xwait.h"
80
90b2c5d4 81/*----- Main code ---------------------------------------------------------*/
82
f3b35b6b 83/* --- @version@ --- */
84
85static void version(FILE *fp)
86{
87 fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS);
88}
89
90/* --- @usage@ --- */
91
92static void usage(FILE *fp)
93{
d72bdcdb 94 fprintf(fp, "Usage: %s [-p PROMPT] [-t TITLE] [ATOM:MSG]\n", QUIS);
f3b35b6b 95}
96
90b2c5d4 97/* --- @main@ --- *
98 *
99 * Main program.
100 */
101
102int main(int argc, char *argv[])
103{
bf980fa9 104 const char *atom = XWAIT_DIE;
105 const char *xmsg = XWAIT_DIE_MSG;
d72bdcdb 106 Atom xa, xm;
107
bf980fa9 108 const char *prompt = "Are you sure you want to shut down this session?";
109 const char *title;
f3b35b6b 110 ego(argv[0]);
90b2c5d4 111 gtk_init(&argc, &argv);
112
113 /* --- Parse options --- */
114
bf980fa9 115 title = QUIS;
90b2c5d4 116 for (;;) {
117 static struct option opt[] = {
d72bdcdb 118 { "help", 0, 0, 'h' },
119 { "usage", 0, 0, 'u' },
120 { "version", 0, 0, 'v' },
121 { "atom", OPTF_ARGREQ, 0, 'a' },
122 { "msg", OPTF_ARGREQ, 0, 'm' },
123 { "prompt", OPTF_ARGREQ, 0, 'p' },
124 { "title", OPTF_ARGREQ, 0, 't' },
125 { 0, 0, 0, 0 }
90b2c5d4 126 };
127 int i;
128
f3b35b6b 129 i = getopt_long(argc, argv, "huv a:m:p:t:", opt, 0);
90b2c5d4 130
131 if (i < 0)
132 break;
133
134 switch (i) {
f3b35b6b 135 case 'h':
136 version(stdout);
137 fputs("\n", stdout);
138 usage(stdout);
139 fputs(
140"\n"
141"Kills a waiting `xwait' process. Pops up a confirmation window first.\n"
142"\n"
143"Options available are:\n"
144"\n"
145"-h, --help Display this help text\n"
146"-u, --usage Display a short usage summary\n"
147"-v, --version Display the program's version number\n"
148"\n"
d72bdcdb 149"-a, --atom=ATOM\t Select the property name atom [deprecated]\n"
150"-m, --msg=MSG Select the message to send [deprecated]\n"
f3b35b6b 151"-p, --prompt=PROMPT Select the prompt string in the confirmation box\n"
152"-t, --title=TITLE Select the title string in the confirmation box\n",
153 stdout);
154 exit(0);
155 break;
156 case 'u':
157 usage(stdout);
158 exit(0);
159 break;
160 case 'v':
161 version(stdout);
162 exit(0);
163 break;
164
90b2c5d4 165 case 'a':
166 atom = optarg;
167 break;
168 case 'm':
aa8f2c90 169 xmsg = optarg;
90b2c5d4 170 break;
171 case 'p':
172 prompt = optarg;
173 break;
174 case 't':
175 title = optarg;
176 break;
177 default:
f3b35b6b 178 usage(stderr);
90b2c5d4 179 exit(EXIT_FAILURE);
180 }
181 }
182
d72bdcdb 183 if (optind < argc) {
184 char *p;
185 if ((atom = strtok(argv[optind++], ":")) == 0)
186 die(EXIT_FAILURE, "missing atom name");
187 if ((p = strtok(0, ",")) != 0)
188 xmsg = p;
189 }
190
191 if (optind < argc) {
192 usage(stderr);
193 exit(EXIT_FAILURE);
194 }
195
196 xa = XInternAtom(gdk_display, atom, False);
197 xm = XInternAtom(gdk_display, xmsg, False);
90b2c5d4 198
199 /* --- Decide whether there's an xwait listening --- *
200 *
201 * If not, pop up an error box and quit.
202 */
203
d72bdcdb 204 if (xatom_get(gdk_display, DefaultRootWindow(gdk_display), xa) == None) {
bf980fa9 205 msg(QUIS, "!:~OK", "no xwait listening for `%s'", atom);
d72bdcdb 206 exit(EXIT_FAILURE);
90b2c5d4 207 }
208
209 /* --- Main code --- */
210
bf980fa9 211 if (msg(title, "!:OK,~Cancel", "%s", prompt) == 0)
d72bdcdb 212 xatom_set(gdk_display, DefaultRootWindow(gdk_display), xa, xm);
90b2c5d4 213
90b2c5d4 214 return (0);
215}
216
217/*----- That's all, folks -------------------------------------------------*/