wmaker: Added 'const' attribute to local variables
[wmaker-crm.git] / WPrefs.app / main.c
blobd6b3946f87f99949f8364d4282a83035061d8e82
1 /*
2 * WPrefs - Window Maker Preferences Program
4 * Copyright (c) 1998-2003 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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "WPrefs.h"
23 #include <assert.h>
25 #include <X11/Xlocale.h>
26 #include <X11/XKBlib.h>
28 #include <sys/wait.h>
29 #include <unistd.h>
31 char *NOptionValueChanged = "NOptionValueChanged";
32 Bool xext_xkb_supported = False;
35 #define MAX_DEATHS 64
37 struct {
38 pid_t pid;
39 void *data;
40 void (*handler) (void *);
41 } DeadHandlers[MAX_DEATHS];
43 static pid_t DeadChildren[MAX_DEATHS];
44 static int DeadChildrenCount = 0;
46 static void wAbort(Bool foo)
48 exit(1);
51 static void print_help(const char *progname)
53 printf(_("usage: %s [options]\n"), progname);
54 puts(_("options:"));
55 puts(_(" -display <display> display to be used"));
56 puts(_(" --version print version number and exit"));
57 puts(_(" --help print this message and exit"));
60 #if 0
61 static RETSIGTYPE handleDeadChild(int sig)
63 pid_t pid;
64 int status;
66 pid = waitpid(-1, &status, WNOHANG);
67 if (pid > 0) {
68 DeadChildren[DeadChildrenCount++] = pid;
71 #endif
73 void AddDeadChildHandler(pid_t pid, void (*handler) (void *), void *data)
75 int i;
77 for (i = 0; i < MAX_DEATHS; i++) {
78 if (DeadHandlers[i].pid == 0) {
79 DeadHandlers[i].pid = pid;
80 DeadHandlers[i].handler = handler;
81 DeadHandlers[i].data = data;
82 break;
85 assert(i != MAX_DEATHS);
88 int main(int argc, char **argv)
90 Display *dpy;
91 WMScreen *scr;
92 char *path;
93 int i;
94 char *display_name = "";
96 wsetabort(wAbort);
98 memset(DeadHandlers, 0, sizeof(DeadHandlers));
100 WMInitializeApplication("WPrefs", &argc, argv);
102 WMSetResourcePath(RESOURCE_PATH);
103 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
104 if (!path) {
105 /* maybe it is run directly from the source directory */
106 WMSetResourcePath(".");
107 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
108 if (!path) {
109 WMSetResourcePath("..");
112 if (path) {
113 wfree(path);
116 if (argc > 1) {
117 for (i = 1; i < argc; i++) {
118 if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
119 printf("WPrefs (Window Maker) %s\n", VERSION);
120 exit(0);
121 } else if (strcmp(argv[i], "-display") == 0) {
122 i++;
123 if (i >= argc) {
124 wwarning(_("too few arguments for %s"), argv[i - 1]);
125 exit(0);
127 display_name = argv[i];
128 } else {
129 print_help(argv[0]);
130 exit(0);
135 setlocale(LC_ALL, "");
137 #ifdef I18N
138 if (getenv("NLSPATH"))
139 bindtextdomain("WPrefs", getenv("NLSPATH"));
140 else
141 bindtextdomain("WPrefs", LOCALEDIR);
142 bind_textdomain_codeset("WPrefs", "UTF-8");
143 textdomain("WPrefs");
145 if (!XSupportsLocale()) {
146 wwarning(_("X server does not support locale"));
148 if (XSetLocaleModifiers("") == NULL) {
149 wwarning(_("cannot set locale modifiers"));
151 #endif
153 dpy = XOpenDisplay(display_name);
154 if (!dpy) {
155 wfatal(_("could not open display %s"), XDisplayName(display_name));
156 exit(0);
158 #if 0
159 XSynchronize(dpy, 1);
160 #endif
161 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
162 if (!scr) {
163 wfatal(_("could not initialize application"));
164 exit(0);
167 xext_xkb_supported = XkbQueryExtension(dpy, NULL, NULL, NULL, NULL, NULL);
169 WMPLSetCaseSensitive(False);
171 Initialize(scr);
173 while (1) {
174 XEvent event;
176 WMNextEvent(dpy, &event);
178 while (DeadChildrenCount-- > 0) {
179 int i;
181 for (i = 0; i < MAX_DEATHS; i++) {
182 if (DeadChildren[i] == DeadHandlers[i].pid) {
183 (*DeadHandlers[i].handler) (DeadHandlers[i].data);
184 DeadHandlers[i].pid = 0;
189 WMHandleEvent(&event);