Update Serbian translation from master branch
[wmaker-crm.git] / WPrefs.app / main.c
blob2a76a20305eeeaf866224c1f9678065073b56b8d
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 "config.h"
23 #include "WPrefs.h"
25 #include <assert.h>
27 #include <X11/Xlocale.h>
28 #include <X11/XKBlib.h>
30 #include <sys/wait.h>
31 #include <unistd.h>
33 #ifdef HAVE_STDNORETURN
34 #include <stdnoreturn.h>
35 #endif
37 char *NOptionValueChanged = "NOptionValueChanged";
39 #define MAX_DEATHS 64
41 struct {
42 pid_t pid;
43 void *data;
44 void (*handler) (void *);
45 } DeadHandlers[MAX_DEATHS];
47 static pid_t DeadChildren[MAX_DEATHS];
48 static int DeadChildrenCount = 0;
50 static noreturn void wAbort(Bool foo)
52 /* Parameter not used, but tell the compiler that it is ok */
53 (void) foo;
55 exit(1);
58 static void print_help(const char *progname)
60 printf(_("usage: %s [options]\n"), progname);
61 puts(_("options:"));
62 puts(_(" -display <display> display to be used"));
63 puts(_(" --version print version number and exit"));
64 puts(_(" --help print this message and exit"));
67 void AddDeadChildHandler(pid_t pid, void (*handler) (void *), void *data)
69 int i;
71 for (i = 0; i < MAX_DEATHS; i++) {
72 if (DeadHandlers[i].pid == 0) {
73 DeadHandlers[i].pid = pid;
74 DeadHandlers[i].handler = handler;
75 DeadHandlers[i].data = data;
76 break;
79 assert(i != MAX_DEATHS);
82 int main(int argc, char **argv)
84 Display *dpy;
85 WMScreen *scr;
86 char *path;
87 int i;
88 char *display_name = "";
90 wsetabort(wAbort);
92 memset(DeadHandlers, 0, sizeof(DeadHandlers));
94 WMInitializeApplication("WPrefs", &argc, argv);
96 WMSetResourcePath(RESOURCE_PATH);
97 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
98 if (!path) {
99 /* maybe it is run directly from the source directory */
100 WMSetResourcePath(".");
101 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
102 if (!path) {
103 WMSetResourcePath("..");
106 if (path) {
107 wfree(path);
110 if (argc > 1) {
111 for (i = 1; i < argc; i++) {
112 if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
113 printf("WPrefs (Window Maker) %s\n", VERSION);
114 exit(0);
115 } else if (strcmp(argv[i], "-display") == 0) {
116 i++;
117 if (i >= argc) {
118 wwarning(_("too few arguments for %s"), argv[i - 1]);
119 exit(0);
121 display_name = argv[i];
122 } else {
123 print_help(argv[0]);
124 exit(0);
129 setlocale(LC_ALL, "");
131 #ifdef I18N
132 if (getenv("NLSPATH"))
133 bindtextdomain("WPrefs", getenv("NLSPATH"));
134 else
135 bindtextdomain("WPrefs", LOCALEDIR);
136 bind_textdomain_codeset("WPrefs", "UTF-8");
137 textdomain("WPrefs");
139 if (!XSupportsLocale()) {
140 wwarning(_("X server does not support locale"));
142 if (XSetLocaleModifiers("") == NULL) {
143 wwarning(_("cannot set locale modifiers"));
145 #endif
147 dpy = XOpenDisplay(display_name);
148 if (!dpy) {
149 wfatal(_("could not open display %s"), XDisplayName(display_name));
150 exit(0);
152 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
153 if (!scr) {
154 wfatal(_("could not initialize application"));
155 exit(0);
158 WMPLSetCaseSensitive(False);
160 Initialize(scr);
162 while (1) {
163 XEvent event;
165 WMNextEvent(dpy, &event);
167 while (DeadChildrenCount-- > 0) {
168 int i;
170 for (i = 0; i < MAX_DEATHS; i++) {
171 if (DeadChildren[i] == DeadHandlers[i].pid) {
172 (*DeadHandlers[i].handler) (DeadHandlers[i].data);
173 DeadHandlers[i].pid = 0;
178 WMHandleEvent(&event);