home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / xsaver / part02 / main.c next >
Encoding:
C/C++ Source or Header  |  1989-03-10  |  3.9 KB  |  182 lines

  1. /*
  2.  * $Source: /mit/sipbsrc/uus/src/xscreensaver/RCS/main.c,v $
  3.  * $Author: jik $
  4.  *
  5.  * This file is part of xscreensaver.  It contains the code for main()
  6.  * and a few other procedures used by main.
  7.  *
  8.  * Author: Jonathan Kamens, MIT Project Athena and
  9.  *                          MIT Student Information Processing Board
  10.  *
  11.  * Copyright (c) 1989 by Jonathan Kamens.  This code may be
  12.  * distributed freely as long as this notice is kept intact in its
  13.  * entirety and every effort is made to send all corrections and
  14.  * improvements to the code back to the author.  Also, don't try to
  15.  * make any money off of it or pretend that you wrote it.
  16.  */
  17.  
  18. #ifndef lint
  19.      static char rcsid_main_c[] = "$Header: main.c,v 1.9 89/02/28 06:55:05 jik Exp $";
  20. #endif
  21.  
  22. #include <stdio.h>
  23. #include <X11/Intrinsic.h>
  24. #include <X11/StringDefs.h>
  25. #include <signal.h>
  26. #include "xsaver.h"
  27. #include "resources.h"
  28. #include "commLine.h"
  29. #define MAIN
  30. #include "globals.h"
  31. #include "action.h"
  32.  
  33. #ifndef XAPPLRESDIR
  34. #define XAPPLRESDIR "/usr/sipb/lib/app-defaults/"
  35. #endif
  36.  
  37. extern char *get_passwd();
  38. extern void build_menu(), build_icon(), init_scaling();
  39. Boolean signal_caught = False;
  40.  
  41.  
  42. #ifdef DEBUG
  43. handler(dpy, event)
  44. Display *dpy;
  45. XErrorEvent *event;
  46. {
  47.      abort();
  48. }
  49.  
  50.  
  51. IOhandler(dpy)
  52. Display *dpy;
  53. {
  54.      abort();
  55. }
  56. #endif
  57.      
  58.  
  59.  
  60.  
  61. clean_up()
  62. {
  63.      wait(0);
  64. }
  65.  
  66.  
  67.  
  68. /*
  69.  * Commenting this out until we can get the signal stuff to work
  70.  * properly.  May end up needing a change in the toolkit :-)
  71.  */
  72. #ifdef NOTDEF
  73. void SetSignal()
  74. {     
  75.      signal_caught = True;
  76. }
  77.  
  78.  
  79. /* ARGSUSED */
  80. Boolean CheckSignal(garbage)
  81. caddr_t garbage;
  82. {
  83.      if (signal_caught) {
  84.       lock_flag = True;
  85.       signal_caught = False;
  86.       ActivateRoot();
  87.       return(True);
  88.      }
  89.      return(False);
  90. }
  91. #endif
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. main(argc, argv)
  99. int argc;
  100. char *argv[];
  101. {
  102.      int child;
  103.      FILE *pid_file;
  104.      char pid_file_name[50];
  105.      
  106. #ifdef DEBUG
  107.      XSetErrorHandler(handler);
  108.      XSetIOErrorHandler(IOhandler);
  109. #endif
  110.      whoami = argv[0];
  111.      setenv("XAPPLRESDIR", XAPPLRESDIR, 1);
  112.      srandom((int) time((long *)0));
  113.      signal(SIGCHLD, clean_up);
  114.      
  115.      top_widget = XtInitialize("main", "Xsaver", app_options,
  116.                    XtNumber(app_options), &argc, argv);
  117.  
  118.      dpy = XtDisplay(top_widget);
  119.      screen = DefaultScreen(dpy);
  120.      real_root_window = RootWindow(dpy, screen);
  121.      display_height = DisplayHeight(dpy, screen);
  122.      display_width = DisplayWidth(dpy, screen);
  123.  
  124.      XtAddActions(actionTable, XtNumber(actionTable));
  125.  
  126.      XtGetApplicationResources(top_widget, &defs, app_resources,
  127.                    XtNumber(app_resources), NULL, 0);
  128.      if ((! *defs.ekey) && defs.use_passwd  && (! *defs.key))
  129.       defs.ekey = get_passwd();
  130.      else if ((! *defs.ekey) && (*defs.key))
  131.       install_password();
  132.      
  133.      XGetScreenSaver(dpy, &saver.timeout, &saver.interval,
  134.              &saver.prefer_blanking, &saver.allow_exposures);
  135. #ifdef MAXTIMEOUT
  136.      if ((defs.timeout > MAXTIMEOUT) || (defs.timeout == 0)) {
  137.       fprintf(stderr, "%s: Timeout cannot be greater than %d minutes.\n",
  138.           whoami, MAXTIMEOUT);
  139.       defs.timeout = MAXTIMEOUT;
  140.      }
  141. #endif
  142.      
  143.      /* Init_scaling calculates various screen dimension proportion */
  144.      /* necessary for the later calculation of the timeouts used for */
  145.      /* the floating Form widget. */
  146.      init_scaling ();
  147.  
  148.      build_icon();
  149.      build_menu();
  150.  
  151.      XtRealizeWidget(top_widget);
  152.  
  153. /*
  154.  * Commenting this out until we can figure out how to get it to work right.
  155.      signal (SIGUSR1, SetSignal);
  156.      XtAddWorkProc(CheckSignal, NULL);
  157. */
  158.      
  159.      if (! defs.no_fork) if ((child = fork()) == -1) {
  160.       fprintf(stderr, "%s: Error forking to go into the background.\n",
  161.           whoami);
  162.       exit(1);
  163.      }
  164.      else if (child)
  165.       exit(0);
  166.  
  167.      if (pid_file = fopen(sprintf(pid_file_name, "/tmp/Xscreensaver.%s.pid",
  168.                   getenv("USER")), "w")) {
  169.       fprintf(pid_file, "%d\n", getpid());
  170.       fclose(pid_file);
  171.      }
  172.  
  173.      XtMainLoop();
  174. } /* main */
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.