Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / main.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/*
9af1c6c4 dan1998-10-21 14:43:47 +00002 * WPrefs - Window Maker Preferences Program
6830b057 dan2004-10-12 21:28:27 +00003 *
4153e2fd dan2003-01-16 23:30:45 +00004 * Copyright (c) 1998-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00005 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00006 * 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.
10 *
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.
15 *
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
6830b057 dan2004-10-12 21:28:27 +000018 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000019 * USA.
20 */
21
22#include "WPrefs.h"
23
0261c326 dan1999-01-06 15:22:33 +000024#include <assert.h>
25
9d2e6ef9 scottc1998-09-29 22:36:29 +000026#include <X11/Xlocale.h>
27
0261c326 dan1999-01-06 15:22:33 +000028#include <sys/wait.h>
29#include <unistd.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000030
ad6c5e0b kojima1999-04-12 04:54:50 +000031char *NOptionValueChanged = "NOptionValueChanged";
32
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020033extern void Initialize(WMScreen * scr);
9d2e6ef9 scottc1998-09-29 22:36:29 +000034
0261c326 dan1999-01-06 15:22:33 +000035#define MAX_DEATHS 64
36
37struct {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020038 pid_t pid;
39 void *data;
40 void (*handler) (void *);
0261c326 dan1999-01-06 15:22:33 +000041} DeadHandlers[MAX_DEATHS];
42
0261c326 dan1999-01-06 15:22:33 +000043static pid_t DeadChildren[MAX_DEATHS];
44static int DeadChildrenCount = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +000045
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020046void wAbort(Bool foo)
9d2e6ef9 scottc1998-09-29 22:36:29 +000047{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020048 exit(1);
9d2e6ef9 scottc1998-09-29 22:36:29 +000049}
50
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020051static void print_help(char *progname)
9d2e6ef9 scottc1998-09-29 22:36:29 +000052{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020053 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"));
9d2e6ef9 scottc1998-09-29 22:36:29 +000058}
59
416e3a82 dan1999-01-25 19:06:50 +000060#if 0
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020061static RETSIGTYPE handleDeadChild(int sig)
0261c326 dan1999-01-06 15:22:33 +000062{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020063 pid_t pid;
64 int status;
6830b057 dan2004-10-12 21:28:27 +000065
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020066 pid = waitpid(-1, &status, WNOHANG);
67 if (pid > 0) {
68 DeadChildren[DeadChildrenCount++] = pid;
69 }
0261c326 dan1999-01-06 15:22:33 +000070}
416e3a82 dan1999-01-25 19:06:50 +000071#endif
0261c326 dan1999-01-06 15:22:33 +000072
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020073void AddDeadChildHandler(pid_t pid, void (*handler) (void *), void *data)
0261c326 dan1999-01-06 15:22:33 +000074{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020075 int i;
76
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;
83 }
84 }
85 assert(i != MAX_DEATHS);
0261c326 dan1999-01-06 15:22:33 +000086}
87
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020088int main(int argc, char **argv)
9d2e6ef9 scottc1998-09-29 22:36:29 +000089{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020090 Display *dpy;
91 WMScreen *scr;
92 char *locale, *path;
93 int i;
94 char *display_name = "";
95
96 wsetabort(wAbort);
97
98 memset(DeadHandlers, 0, sizeof(DeadHandlers));
99
100 WMInitializeApplication("WPrefs", &argc, argv);
101
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("..");
110 }
111 }
112 if (path) {
113 wfree(path);
114 }
115
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);
126 }
127 display_name = argv[i];
128 } else {
129 print_help(argv[0]);
130 exit(0);
131 }
132 }
133 }
134
135 locale = getenv("LANG");
136 setlocale(LC_ALL, "");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000137
138#ifdef I18N
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200139 if (getenv("NLSPATH"))
140 bindtextdomain("WPrefs", getenv("NLSPATH"));
141 else
142 bindtextdomain("WPrefs", LOCALEDIR);
143 bind_textdomain_codeset("WPrefs", "UTF-8");
144 textdomain("WPrefs");
145
146 if (!XSupportsLocale()) {
147 wwarning(_("X server does not support locale"));
148 }
149 if (XSetLocaleModifiers("") == NULL) {
150 wwarning(_("cannot set locale modifiers"));
151 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000152#endif
153
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200154 dpy = XOpenDisplay(display_name);
155 if (!dpy) {
156 wfatal(_("could not open display %s"), XDisplayName(display_name));
157 exit(0);
158 }
e1001cb0 dan1999-03-30 22:14:17 +0000159#if 0
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200160 XSynchronize(dpy, 1);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000161#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200162 scr = WMCreateScreen(dpy, DefaultScreen(dpy));
163 if (!scr) {
164 wfatal(_("could not initialize application"));
165 exit(0);
166 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000167
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200168 WMPLSetCaseSensitive(False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000169
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200170 Initialize(scr);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000171
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200172 while (1) {
173 XEvent event;
6830b057 dan2004-10-12 21:28:27 +0000174
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200175 WMNextEvent(dpy, &event);
6830b057 dan2004-10-12 21:28:27 +0000176
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200177 while (DeadChildrenCount-- > 0) {
178 int i;
6830b057 dan2004-10-12 21:28:27 +0000179
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200180 for (i = 0; i < MAX_DEATHS; i++) {
181 if (DeadChildren[i] == DeadHandlers[i].pid) {
182 (*DeadHandlers[i].handler) (DeadHandlers[i].data);
183 DeadHandlers[i].pid = 0;
184 }
185 }
186 }
6830b057 dan2004-10-12 21:28:27 +0000187
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200188 WMHandleEvent(&event);
189 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000190}