home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Source: /mit/sipbsrc/uus/src/xscreensaver/RCS/main.c,v $
- * $Author: jik $
- *
- * This file is part of xscreensaver. It contains the code for main()
- * and a few other procedures used by main.
- *
- * Author: Jonathan Kamens, MIT Project Athena and
- * MIT Student Information Processing Board
- *
- * Copyright (c) 1989 by Jonathan Kamens. This code may be
- * distributed freely as long as this notice is kept intact in its
- * entirety and every effort is made to send all corrections and
- * improvements to the code back to the author. Also, don't try to
- * make any money off of it or pretend that you wrote it.
- */
-
- #ifndef lint
- static char rcsid_main_c[] = "$Header: main.c,v 1.9 89/02/28 06:55:05 jik Exp $";
- #endif
-
- #include <stdio.h>
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- #include <signal.h>
- #include "xsaver.h"
- #include "resources.h"
- #include "commLine.h"
- #define MAIN
- #include "globals.h"
- #include "action.h"
-
- #ifndef XAPPLRESDIR
- #define XAPPLRESDIR "/usr/sipb/lib/app-defaults/"
- #endif
-
- extern char *get_passwd();
- extern void build_menu(), build_icon(), init_scaling();
- Boolean signal_caught = False;
-
-
- #ifdef DEBUG
- handler(dpy, event)
- Display *dpy;
- XErrorEvent *event;
- {
- abort();
- }
-
-
- IOhandler(dpy)
- Display *dpy;
- {
- abort();
- }
- #endif
-
-
-
-
- clean_up()
- {
- wait(0);
- }
-
-
-
- /*
- * Commenting this out until we can get the signal stuff to work
- * properly. May end up needing a change in the toolkit :-)
- */
- #ifdef NOTDEF
- void SetSignal()
- {
- signal_caught = True;
- }
-
-
- /* ARGSUSED */
- Boolean CheckSignal(garbage)
- caddr_t garbage;
- {
- if (signal_caught) {
- lock_flag = True;
- signal_caught = False;
- ActivateRoot();
- return(True);
- }
- return(False);
- }
- #endif
-
-
-
-
-
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- int child;
- FILE *pid_file;
- char pid_file_name[50];
-
- #ifdef DEBUG
- XSetErrorHandler(handler);
- XSetIOErrorHandler(IOhandler);
- #endif
- whoami = argv[0];
- setenv("XAPPLRESDIR", XAPPLRESDIR, 1);
- srandom((int) time((long *)0));
- signal(SIGCHLD, clean_up);
-
- top_widget = XtInitialize("main", "Xsaver", app_options,
- XtNumber(app_options), &argc, argv);
-
- dpy = XtDisplay(top_widget);
- screen = DefaultScreen(dpy);
- real_root_window = RootWindow(dpy, screen);
- display_height = DisplayHeight(dpy, screen);
- display_width = DisplayWidth(dpy, screen);
-
- XtAddActions(actionTable, XtNumber(actionTable));
-
- XtGetApplicationResources(top_widget, &defs, app_resources,
- XtNumber(app_resources), NULL, 0);
- if ((! *defs.ekey) && defs.use_passwd && (! *defs.key))
- defs.ekey = get_passwd();
- else if ((! *defs.ekey) && (*defs.key))
- install_password();
-
- XGetScreenSaver(dpy, &saver.timeout, &saver.interval,
- &saver.prefer_blanking, &saver.allow_exposures);
- #ifdef MAXTIMEOUT
- if ((defs.timeout > MAXTIMEOUT) || (defs.timeout == 0)) {
- fprintf(stderr, "%s: Timeout cannot be greater than %d minutes.\n",
- whoami, MAXTIMEOUT);
- defs.timeout = MAXTIMEOUT;
- }
- #endif
-
- /* Init_scaling calculates various screen dimension proportion */
- /* necessary for the later calculation of the timeouts used for */
- /* the floating Form widget. */
- init_scaling ();
-
- build_icon();
- build_menu();
-
- XtRealizeWidget(top_widget);
-
- /*
- * Commenting this out until we can figure out how to get it to work right.
- signal (SIGUSR1, SetSignal);
- XtAddWorkProc(CheckSignal, NULL);
- */
-
- if (! defs.no_fork) if ((child = fork()) == -1) {
- fprintf(stderr, "%s: Error forking to go into the background.\n",
- whoami);
- exit(1);
- }
- else if (child)
- exit(0);
-
- if (pid_file = fopen(sprintf(pid_file_name, "/tmp/Xscreensaver.%s.pid",
- getenv("USER")), "w")) {
- fprintf(pid_file, "%d\n", getpid());
- fclose(pid_file);
- }
-
- XtMainLoop();
- } /* main */
-
-
-
-
-
-
-
-