0.51.1 pre snapshot. Be careful, it may be buggy. It fixes some bugs though.
[wmaker-crm.git] / WPrefs.app / main.c
blobfc7e8870c406d9645bca0434d948eaaa81f52309
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;
46 void
47 wAbort(Bool foo)
49 exit(1);
53 static BOOL
54 stringCompareHook(proplist_t pl1, proplist_t pl2)
56 char *str1, *str2;
58 str1 = PLGetString(pl1);
59 str2 = PLGetString(pl2);
61 if (strcasecmp(str1, str2)==0)
62 return YES;
63 else
64 return NO;
68 static void
69 print_help(char *progname)
71 printf(_("usage: %s [options]\n"), progname);
72 puts(_("options:"));
73 puts(_(" -display <display> display to be used"));
74 puts(_(" --version print version number and exit"));
75 puts(_(" --help print this message and exit"));
79 #if 0
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;
91 #endif
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);
110 int
111 main(int argc, char **argv)
113 Display *dpy;
114 WMScreen *scr;
115 char *locale;
116 int i;
117 char *display_name="";
119 wsetabort(wAbort);
121 memset(DeadHandlers, 0, sizeof(DeadHandlers));
123 WMInitializeApplication("WPrefs", &argc, argv);
125 if (argc>1) {
126 for (i=1; i<argc; i++) {
127 if (strcmp(argv[i], "-version")==0
128 || strcmp(argv[i], "--version")==0) {
129 printf("WPrefs (Window Maker) %s\n", WVERSION);
130 exit(0);
131 } else if (strcmp(argv[i], "-display")==0) {
132 i++;
133 if (i>=argc) {
134 wwarning(_("too few arguments for %s"), argv[i-1]);
135 exit(0);
137 display_name = argv[i];
138 } else {
139 print_help(argv[0]);
140 exit(0);
145 locale = getenv("LANG");
146 setlocale(LC_ALL, "");
148 #ifdef I18N
149 if (getenv("NLSPATH"))
150 bindtextdomain("WPrefs", getenv("NLSPATH"));
151 else
152 bindtextdomain("WPrefs", LOCALEDIR);
153 textdomain("WPrefs");
155 if (!XSupportsLocale()) {
156 wwarning(_("X server does not support locale"));
158 if (XSetLocaleModifiers("") == NULL) {
159 wwarning(_("cannot set locale modifiers"));
161 #endif
163 dpy = XOpenDisplay(display_name);
164 if (!dpy) {
165 wfatal(_("could not open display %s"), XDisplayName(display_name));
166 exit(0);
168 #if 1
169 XSynchronize(dpy, 1);
170 #endif
171 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
172 if (!scr) {
173 wfatal(_("could not initialize application"));
174 exit(0);
177 PLSetStringCmpHook(stringCompareHook);
179 Initialize(scr);
181 while (1) {
182 XEvent event;
184 WMNextEvent(dpy, &event);
186 while (DeadChildrenCount-- > 0) {
187 int i;
189 for (i=0; i<MAX_DEATHS; i++) {
190 if (DeadChildren[i] == DeadHandlers[i].pid) {
191 (*DeadHandlers[i].handler)(DeadHandlers[i].data);
192 DeadHandlers[i].pid = 0;
197 WMHandleEvent(&event);