wmgenmenu: Add French and Spanish translations
[wmaker-crm.git] / WPrefs.app / main.c
blob40e01345172137207fc12d24b6ad425d49cfac09
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>
27 #include <sys/wait.h>
28 #include <unistd.h>
30 char *NOptionValueChanged = "NOptionValueChanged";
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];
42 static pid_t DeadChildren[MAX_DEATHS];
43 static int DeadChildrenCount = 0;
45 void wAbort(Bool foo)
47 exit(1);
50 static void print_help(char *progname)
52 printf(_("usage: %s [options]\n"), progname);
53 puts(_("options:"));
54 puts(_(" -display <display> display to be used"));
55 puts(_(" --version print version number and exit"));
56 puts(_(" --help print this message and exit"));
59 #if 0
60 static RETSIGTYPE handleDeadChild(int sig)
62 pid_t pid;
63 int status;
65 pid = waitpid(-1, &status, WNOHANG);
66 if (pid > 0) {
67 DeadChildren[DeadChildrenCount++] = pid;
70 #endif
72 void AddDeadChildHandler(pid_t pid, void (*handler) (void *), void *data)
74 int i;
76 for (i = 0; i < MAX_DEATHS; i++) {
77 if (DeadHandlers[i].pid == 0) {
78 DeadHandlers[i].pid = pid;
79 DeadHandlers[i].handler = handler;
80 DeadHandlers[i].data = data;
81 break;
84 assert(i != MAX_DEATHS);
87 int main(int argc, char **argv)
89 Display *dpy;
90 WMScreen *scr;
91 char *locale, *path;
92 int i;
93 char *display_name = "";
95 wsetabort(wAbort);
97 memset(DeadHandlers, 0, sizeof(DeadHandlers));
99 WMInitializeApplication("WPrefs", &argc, argv);
101 WMSetResourcePath(RESOURCE_PATH);
102 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
103 if (!path) {
104 /* maybe it is run directly from the source directory */
105 WMSetResourcePath(".");
106 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
107 if (!path) {
108 WMSetResourcePath("..");
111 if (path) {
112 wfree(path);
115 if (argc > 1) {
116 for (i = 1; i < argc; i++) {
117 if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
118 printf("WPrefs (Window Maker) %s\n", VERSION);
119 exit(0);
120 } else if (strcmp(argv[i], "-display") == 0) {
121 i++;
122 if (i >= argc) {
123 wwarning(_("too few arguments for %s"), argv[i - 1]);
124 exit(0);
126 display_name = argv[i];
127 } else {
128 print_help(argv[0]);
129 exit(0);
134 locale = getenv("LANG");
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 WMPLSetCaseSensitive(False);
169 Initialize(scr);
171 while (1) {
172 XEvent event;
174 WMNextEvent(dpy, &event);
176 while (DeadChildrenCount-- > 0) {
177 int i;
179 for (i = 0; i < MAX_DEATHS; i++) {
180 if (DeadChildren[i] == DeadHandlers[i].pid) {
181 (*DeadHandlers[i].handler) (DeadHandlers[i].data);
182 DeadHandlers[i].pid = 0;
187 WMHandleEvent(&event);