home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume6 / xplumb / part01 / main.C < prev    next >
C/C++ Source or Header  |  1990-04-11  |  3KB  |  107 lines

  1. /*
  2.  * Copyright 1990 Digital Equipment Corporation
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and its
  5.  * documentation for any purpose and without fee is hereby granted,
  6.  * provided that the above copyright notice appear in all copies and that
  7.  * both that copyright notice and this permission notice appear in
  8.  * supporting documentation, and that the name of Digital Equipment
  9.  * Corporation not be used in advertising or publicity pertaining to
  10.  * distribution of the software without specific, written prior
  11.  * permission.  Digital Equipment Corporation makes no representations
  12.  * about the suitability of this software for any purpose.  It is
  13.  * provided "as is" without express or implied warranty.
  14.  *
  15.  * DIGITAL EQUIPMENT CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16.  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17.  * FITNESS, IN NO EVENT SHALL DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
  18.  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20.  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  21.  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Terry Weissman
  24.  *          weissman@wsl.dec.com
  25.  */
  26.  
  27. #define MAIN
  28.  
  29. #include <stream.h>
  30. #include "plumbing.h"
  31. #include <sys/time.h>
  32. #include <string.h>
  33.  
  34. extern int select(int, int *, int *, int *, struct timeval *);
  35.  
  36. static void Usage() {
  37.     cout << "Usage: " << progname << " [-d display]\n";
  38.     exit(1);
  39. }
  40.  
  41.  
  42.  
  43. void Punt(char *str) {
  44.     cout << progname << ": " << str << "\n";
  45.     exit(1);
  46. }
  47.  
  48. main(int argc, char **argv) {
  49.     char *displayname = NULL;
  50.     Bool sync = False;
  51.     int i;
  52.  
  53.     progname = argv[0];
  54.  
  55.     for (i=1 ; i<argc ; i++) {
  56.     if (i < argc - 1 && (strcmp(argv[i], "-d") == 0 ||
  57.                  strcmp(argv[i], "-display") == 0)) {
  58.         displayname = argv[++i];
  59.     } else if (strcmp(argv[i], "-sync") == 0) {
  60.         sync = True;
  61.     } else {
  62.         Usage();
  63.     }
  64.     }
  65.  
  66.     TimerInit();
  67.  
  68.     numscreens = 0;
  69.     Display *dpy = XOpenDisplay(displayname);
  70.     if (!dpy) {
  71.     Punt("Can't open display.");
  72.     }
  73.     XSynchronize(dpy, sync);
  74.  
  75.     screen[0] = new ScrnRec(dpy);
  76.     numscreens = 1;
  77.  
  78.     BoardInit();
  79.     PieceInit();
  80.     QueueInit();
  81.     ScoreInit();
  82.     prevscore = -1;
  83.  
  84.     queue = new QueueRec();
  85.     score = new ScoreRec();
  86.  
  87.     mode = ModeEndOfGame;
  88.     
  89.     struct timeval *timerec;
  90.     XEvent event;
  91.     int readmask = 0;
  92.  
  93.     for (;;) {
  94.     for (i=0 ; i<numscreens ; i++) {
  95.         while (XPending(screen[i]->GetDpy())) {
  96.         XNextEvent(dpy, &event);
  97.         screen[i]->HandleEvent(&event);
  98.         }
  99.         readmask |= (1 << ConnectionNumber(screen[i]->GetDpy()));
  100.     }
  101.     timerec = TimerGetInterval();
  102.     if (select(32, &readmask, NULL, NULL, timerec) == 0) {
  103.         TimerHandleTimeout();
  104.     }
  105.     }
  106. }
  107.