2 * WPrefs - Window Maker Preferences Program
4 * Copyright (c) 1998 Alfredo K. Kojima
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,
27 #include <X11/Xlocale.h>
32 extern void Initialize(WMScreen
*scr
);
39 void (*handler
)(void*);
40 } DeadHandlers
[MAX_DEATHS
];
43 static pid_t DeadChildren
[MAX_DEATHS
];
44 static int DeadChildrenCount
= 0;
54 stringCompareHook(proplist_t pl1
, proplist_t pl2
)
58 str1
= PLGetString(pl1
);
59 str2
= PLGetString(pl2
);
61 if (strcasecmp(str1
, str2
)==0)
69 print_help(char *progname
)
71 printf(_("usage: %s [options]\n"), progname
);
73 puts(_(" -display <display> display to be used"));
74 puts(_(" --version print version number and exit"));
75 puts(_(" --help print this message and exit"));
81 handleDeadChild(int sig
)
86 pid
= waitpid(-1, &status
, WNOHANG
);
88 DeadChildren
[DeadChildrenCount
++] = pid
;
94 AddDeadChildHandler(pid_t pid
, void (*handler
)(void*), void *data
)
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
;
106 assert(i
!=MAX_DEATHS
);
111 main(int argc
, char **argv
)
117 char *display_name
="";
121 memset(DeadHandlers
, 0, sizeof(DeadHandlers
));
123 WMInitializeApplication("WPrefs", &argc
, argv
);
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
);
131 } else if (strcmp(argv
[i
], "-display")==0) {
134 wwarning(_("too few arguments for %s"), argv
[i
-1]);
137 display_name
= argv
[i
];
145 locale
= getenv("LANG");
146 setlocale(LC_ALL
, "");
149 if (getenv("NLSPATH"))
150 bindtextdomain("WPrefs", getenv("NLSPATH"));
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"));
163 dpy
= XOpenDisplay(display_name
);
165 wfatal(_("could not open display %s"), XDisplayName(display_name
));
169 XSynchronize(dpy
, 1);
171 scr
= WMCreateScreen(dpy
, DefaultScreen(dpy
));
173 wfatal(_("could not initialize application"));
177 PLSetStringCmpHook(stringCompareHook
);
184 WMNextEvent(dpy
, &event
);
186 while (DeadChildrenCount
-- > 0) {
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
);