Files
wmaker/WPrefs.app/main.c
T

190 lines
4.2 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
/*
1998-10-21 14:43:47 +00:00
* WPrefs - Window Maker Preferences Program
2004-10-12 21:28:27 +00:00
*
2003-01-16 23:30:45 +00:00
* Copyright (c) 1998-2003 Alfredo K. Kojima
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2004-10-12 21:28:27 +00:00
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
1998-09-29 22:36:29 +00:00
* USA.
*/
#include "WPrefs.h"
1999-01-06 15:22:33 +00:00
#include <assert.h>
1998-09-29 22:36:29 +00:00
#include <X11/Xlocale.h>
1999-01-06 15:22:33 +00:00
#include <sys/wait.h>
#include <unistd.h>
1998-09-29 22:36:29 +00:00
1999-04-12 04:54:50 +00:00
char *NOptionValueChanged = "NOptionValueChanged";
1998-09-29 22:36:29 +00:00
extern void Initialize(WMScreen *scr);
1999-01-06 15:22:33 +00:00
#define MAX_DEATHS 64
struct {
pid_t pid;
void *data;
void (*handler)(void*);
} DeadHandlers[MAX_DEATHS];
static pid_t DeadChildren[MAX_DEATHS];
static int DeadChildrenCount = 0;
1998-09-29 22:36:29 +00:00
void
wAbort(Bool foo)
{
exit(1);
}
static void
print_help(char *progname)
{
printf(_("usage: %s [options]\n"), progname);
puts(_("options:"));
puts(_(" -display <display> display to be used"));
1999-01-25 19:06:50 +00:00
puts(_(" --version print version number and exit"));
puts(_(" --help print this message and exit"));
1998-09-29 22:36:29 +00:00
}
1999-01-25 19:06:50 +00:00
#if 0
1999-01-06 15:22:33 +00:00
static RETSIGTYPE
handleDeadChild(int sig)
{
pid_t pid;
int status;
2004-10-12 21:28:27 +00:00
1999-01-06 15:22:33 +00:00
pid = waitpid(-1, &status, WNOHANG);
if (pid > 0) {
2004-10-12 21:28:27 +00:00
DeadChildren[DeadChildrenCount++] = pid;
1999-01-06 15:22:33 +00:00
}
}
1999-01-25 19:06:50 +00:00
#endif
1999-01-06 15:22:33 +00:00
void
AddDeadChildHandler(pid_t pid, void (*handler)(void*), void *data)
{
int i;
for (i = 0; i < MAX_DEATHS; i++) {
2004-10-12 21:28:27 +00:00
if (DeadHandlers[i].pid == 0) {
DeadHandlers[i].pid = pid;
DeadHandlers[i].handler = handler;
DeadHandlers[i].data = data;
break;
}
1999-01-06 15:22:33 +00:00
}
assert(i!=MAX_DEATHS);
}
2004-10-12 21:28:27 +00:00
int
1998-09-29 22:36:29 +00:00
main(int argc, char **argv)
{
Display *dpy;
WMScreen *scr;
char *locale;
int i;
char *display_name="";
1999-01-25 19:06:50 +00:00
wsetabort(wAbort);
2004-10-12 21:28:27 +00:00
1999-01-06 15:22:33 +00:00
memset(DeadHandlers, 0, sizeof(DeadHandlers));
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WMInitializeApplication("WPrefs", &argc, argv);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (argc>1) {
2004-10-12 21:28:27 +00:00
for (i=1; i<argc; i++) {
if (strcmp(argv[i], "-version")==0
|| strcmp(argv[i], "--version")==0) {
2004-10-19 02:37:58 +00:00
printf("WPrefs (Window Maker) %s\n", VERSION);
2004-10-12 21:28:27 +00:00
exit(0);
} else if (strcmp(argv[i], "-display")==0) {
i++;
if (i>=argc) {
wwarning(_("too few arguments for %s"), argv[i-1]);
exit(0);
}
display_name = argv[i];
} else {
print_help(argv[0]);
exit(0);
}
}
1998-09-29 22:36:29 +00:00
}
locale = getenv("LANG");
setlocale(LC_ALL, "");
#ifdef I18N
if (getenv("NLSPATH"))
2004-10-12 21:28:27 +00:00
bindtextdomain("WPrefs", getenv("NLSPATH"));
1998-09-29 22:36:29 +00:00
else
2004-10-12 21:28:27 +00:00
bindtextdomain("WPrefs", LOCALEDIR);
bind_textdomain_codeset("WPrefs", "UTF-8");
1998-09-29 22:36:29 +00:00
textdomain("WPrefs");
if (!XSupportsLocale()) {
2004-10-12 21:28:27 +00:00
wwarning(_("X server does not support locale"));
1998-09-29 22:36:29 +00:00
}
if (XSetLocaleModifiers("") == NULL) {
2004-10-12 21:28:27 +00:00
wwarning(_("cannot set locale modifiers"));
1998-09-29 22:36:29 +00:00
}
#endif
dpy = XOpenDisplay(display_name);
if (!dpy) {
2004-10-12 21:28:27 +00:00
wfatal(_("could not open display %s"), XDisplayName(display_name));
exit(0);
1998-09-29 22:36:29 +00:00
}
1999-03-30 22:14:17 +00:00
#if 0
1998-09-29 22:36:29 +00:00
XSynchronize(dpy, 1);
#endif
scr = WMCreateScreen(dpy, DefaultScreen(dpy));
if (!scr) {
2004-10-12 21:28:27 +00:00
wfatal(_("could not initialize application"));
exit(0);
1998-09-29 22:36:29 +00:00
}
WMPLSetCaseSensitive(False);
1998-09-29 22:36:29 +00:00
Initialize(scr);
while (1) {
2004-10-12 21:28:27 +00:00
XEvent event;
WMNextEvent(dpy, &event);
while (DeadChildrenCount-- > 0) {
int i;
for (i=0; i<MAX_DEATHS; i++) {
if (DeadChildren[i] == DeadHandlers[i].pid) {
(*DeadHandlers[i].handler)(DeadHandlers[i].data);
DeadHandlers[i].pid = 0;
}
}
}
WMHandleEvent(&event);
1998-09-29 22:36:29 +00:00
}
}
2004-10-12 21:28:27 +00:00