Code update for Window Maker version 0.50.0
[wmaker-crm.git] / WPrefs.app / main.c
bloba80b2b0be6c09daebfc415933c1f3671569ec20f
1 /*
2 * WPrefs - Window Maker Preferences Program
3 *
4 * Copyright (c) 1998 Alfredo K. Kojima
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 * USA.
22 #include "WPrefs.h"
25 #include <assert.h>
27 #include <X11/Xlocale.h>
29 #include <sys/wait.h>
30 #include <unistd.h>
32 extern void Initialize(WMScreen *scr);
34 #define MAX_DEATHS 64
36 struct {
37 pid_t pid;
38 void *data;
39 void (*handler)(void*);
40 } DeadHandlers[MAX_DEATHS];
43 static pid_t DeadChildren[MAX_DEATHS];
44 static int DeadChildrenCount = 0;
47 void
48 wAbort(Bool foo)
50 exit(1);
54 static BOOL
55 stringCompareHook(proplist_t pl1, proplist_t pl2)
57 char *str1, *str2;
59 str1 = PLGetString(pl1);
60 str2 = PLGetString(pl2);
62 if (strcasecmp(str1, str2)==0)
63 return YES;
64 else
65 return NO;
69 static void
70 print_help(char *progname)
72 printf(_("usage: %s [options]\n"), progname);
73 puts(_("options:"));
74 puts(_(" -display <display> display to be used"));
75 puts(_(" -version print version number and exit"));
80 static RETSIGTYPE
81 handleDeadChild(int sig)
83 pid_t pid;
84 int status;
86 pid = waitpid(-1, &status, WNOHANG);
87 if (pid > 0) {
88 DeadChildren[DeadChildrenCount++] = pid;
93 void
94 AddDeadChildHandler(pid_t pid, void (*handler)(void*), void *data)
96 int i;
98 for (i = 0; i < MAX_DEATHS; i++) {
99 if (DeadHandlers[i].pid == 0) {
100 DeadHandlers[i].pid = pid;
101 DeadHandlers[i].handler = handler;
102 DeadHandlers[i].data = data;
103 break;
106 assert(i!=MAX_DEATHS);
111 int
112 main(int argc, char **argv)
114 Display *dpy;
115 WMScreen *scr;
116 char *locale;
117 int i;
118 char *display_name="";
120 memset(DeadHandlers, 0, sizeof(DeadHandlers));
122 WMInitializeApplication("WPrefs", &argc, argv);
124 if (argc>1) {
125 for (i=1; i<argc; i++) {
126 if (strcmp(argv[i], "-version")==0) {
127 printf("WPrefs %s\n", WVERSION);
128 exit(0);
129 } else if (strcmp(argv[i], "-display")==0) {
130 i++;
131 if (i>=argc) {
132 wwarning(_("too few arguments for %s"), argv[i-1]);
133 exit(0);
135 display_name = argv[i];
136 } else {
137 print_help(argv[0]);
138 exit(0);
143 locale = getenv("LANG");
144 setlocale(LC_ALL, "");
146 #ifdef I18N
147 if (getenv("NLSPATH"))
148 bindtextdomain("WPrefs", getenv("NLSPATH"));
149 else
150 bindtextdomain("WPrefs", NLSDIR);
151 textdomain("WPrefs");
153 if (!XSupportsLocale()) {
154 wwarning(_("X server does not support locale"));
156 if (XSetLocaleModifiers("") == NULL) {
157 wwarning(_("cannot set locale modifiers"));
159 #endif
161 dpy = XOpenDisplay(display_name);
162 if (!dpy) {
163 wfatal(_("could not open display %s"), XDisplayName(display_name));
164 exit(0);
166 #if 0
167 XSynchronize(dpy, 1);
168 #endif
169 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
170 if (!scr) {
171 wfatal(_("could not initialize application"));
172 exit(0);
175 PLSetStringCmpHook(stringCompareHook);
177 Initialize(scr);
179 while (1) {
180 XEvent event;
182 WMNextEvent(dpy, &event);
184 while (DeadChildrenCount-- > 0) {
185 int i;
187 for (i=0; i<MAX_DEATHS; i++) {
188 if (DeadChildren[i] == DeadHandlers[i].pid) {
189 (*DeadHandlers[i].handler)(DeadHandlers[i].data);
190 DeadHandlers[i].pid = 0;
195 WMHandleEvent(&event);