[comp.windows.x] Xbob Driven to the brink of sanity by the conspiracy's false reality and the pressure of a crumbling world?? Then this may be for you!!

trainor@ucla-cs.UUCP (06/15/87)

#!/bin/sh
# to extract, remove the header and type "sh filename"
if `test ! -s ./README`
then
echo "writing ./README"
cat > ./README << '\X\X\'
Xbob.

\X\X\
else
  echo "will not over write ./README"
fi
if `test ! -s ./Makefile`
then
echo "writing ./Makefile"
cat > ./Makefile << '\X\X\'
INCLUDES = 

XLIB = /usr/lib/libX.a
CFLAGS = $(INCLUDES)
CLIBS = 

.SUFFIXES: .o .h .c .a

OBJS = xbob.o

all: xbob

xbob: $(OBJS)
	cc $(CFLAGS) -o xbob $(OBJS) $(XLIB) $(CLIBS)

\X\X\
else
  echo "will not over write ./Makefile"
fi
if `test ! -s ./xbob.c`
then
echo "writing ./xbob.c"
cat > ./xbob.c << '\X\X\'
/*
 * xbob.c  -  serves ``Bob's'' purpose...  -- Vulture of Light
 * 
 * resembling a program by John H. Bradley, bradley@cis.upenn.edu, March, 1987.
 */


#include <stdio.h>
#include <math.h>
#include <strings.h>
#include <signal.h>
#include <X/Xlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/timeb.h>


/* handy-dandy functions */
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? -(a) : (a))

#define sigmask(s)	(1L << ((s)-1))


/* colors */
int ForeColor, BackColor;

/* objects */
Window   theWindow;
Bitmap   bobBMask,bobrBMask,stipB;
Pixmap   stipP;
Cursor   curs;


#define cross_width 16
#define cross_height 16
#define cross_x_hot 7
#define cross_y_hot 7
static short cross_bits[] = {      /* ``Bob''-zappin' cursor */
   0x0000, 0x03e0, 0x0c98, 0x1084, 0x1414, 0x2082, 0x2082, 0x3b6e,
   0x2082, 0x2082, 0x1414, 0x1084, 0x0c98, 0x03e0, 0x0000, 0x0000};

static short cross_mask_bits[] = {
   0x07e0, 0x0ff8, 0x1ffc, 0x3ffe, 0x3ffe, 0x7fff, 0x7fff, 0x7fff,
   0x7fff, 0x7fff, 0x3ffe, 0x3ffe, 0x1ffc, 0x0ff8, 0x03e0, 0x0000};

#define bob_width 61
#define bob_height 75
static short bobr_bits[] = {			/* a right-going ``Bob'' */
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffe0, 0x07ff, 0x0000,
   0x0000, 0xfffe, 0x1fff, 0x0000, 0x8000, 0xffff, 0xfbff, 0x0000,
   0xc000, 0xcfff, 0xd19f, 0x0003, 0xf000, 0x8c7f, 0x9133, 0x0007,
   0xf800, 0x18a7, 0xb127, 0x0006, 0xfc00, 0x3147, 0xa64e, 0x000e,
   0xfe00, 0x214f, 0xae4c, 0x003d, 0xff00, 0x23df, 0xbe8d, 0x007d,
   0xff80, 0x67ff, 0xfebd, 0x01ff, 0xff80, 0x7fff, 0xffbf, 0x03ff,
   0xffc0, 0xffff, 0xffbf, 0x07f8, 0xffc0, 0xffff, 0x3fbf, 0x07f8,
   0xffc0, 0xffff, 0x07ff, 0x0ff8, 0xffc0, 0xffff, 0x003f, 0x0ff8,
   0x7fe0, 0xf800, 0x0007, 0x0ff0, 0x3fe0, 0x0000, 0x0000, 0x07f0,
   0x3fe0, 0x0000, 0x0000, 0x07f0, 0x3fe0, 0x0000, 0x0000, 0x07f4,
   0x3fe0, 0x0000, 0x0000, 0x07e4, 0x3fe0, 0x0000, 0x0000, 0x07e4,
   0x3fe0, 0x0000, 0x0000, 0x07e6, 0x3fe0, 0x0000, 0x0000, 0x07e7,
   0x3fe0, 0x0000, 0x0000, 0x07e6, 0x3fe0, 0x0000, 0x0000, 0x07e6,
   0x3fe0, 0x0000, 0x0000, 0x07e6, 0x3fc0, 0x0000, 0x7800, 0x07f6,
   0xbfa0, 0x00ff, 0xff00, 0x07f7, 0x9f70, 0x01ff, 0xff80, 0x07ef,
   0x1cf0, 0x0380, 0x01e0, 0x07ef, 0x1ff0, 0x07be, 0x3ff0, 0x07ee,
   0x9de0, 0x1f83, 0xe1f8, 0x07dc, 0xc1e0, 0x1f7f, 0xfffc, 0x07c8,
   0xc1e0, 0x1e69, 0xca7e, 0x03c0, 0x81e0, 0x1fb8, 0x0ec0, 0x03c0,
   0x01e0, 0x1bc0, 0xcfc0, 0x03c1, 0x03c0, 0x11f7, 0x7f00, 0x03c0,
   0x03c0, 0x187c, 0x1c00, 0x02c0, 0x02c0, 0x0830, 0x0000, 0x0340,
   0x0340, 0x0800, 0x0000, 0x0240, 0x1340, 0x0c00, 0x0000, 0x0260,
   0x1240, 0x0e00, 0x0000, 0x03c0, 0x3380, 0x0e80, 0x0000, 0x01a8,
   0x3300, 0x0f40, 0x03a0, 0x002c, 0x7400, 0x0f30, 0x0738, 0x002e,
   0x7400, 0x1f98, 0x1e1e, 0x002f, 0xfc00, 0xff8f, 0xfc0f, 0x002f,
   0xf800, 0xffe3, 0xf803, 0x002f, 0xf800, 0xfffd, 0xff81, 0x003f,
   0xb800, 0x1ff9, 0x0ff8, 0x001e, 0x3000, 0xf0f1, 0x030f, 0x000e,
   0x3000, 0x01f1, 0x0180, 0x000f, 0x2000, 0xf7f1, 0x00ff, 0x0007,
   0x6000, 0x01e3, 0x8060, 0x0007, 0x6000, 0xefc3, 0x803f, 0x0003,
   0x4000, 0xffc2, 0xc00f, 0x0003, 0xc000, 0x1fe6, 0xc000, 0x0001,
   0x8000, 0xfef4, 0xe03f, 0x0000, 0x8000, 0xfe79, 0xe01f, 0x0000,
   0x01c0, 0x3e3d, 0x7000, 0x0000, 0x0630, 0x0f3e, 0x3800, 0x0000,
   0x8cc8, 0x071f, 0x3800, 0x0000, 0xccf4, 0x078f, 0x1c00, 0x0000,
   0xee72, 0x07f7, 0x0e00, 0x0000, 0xff02, 0x07e3, 0x0700, 0x0000,
   0xfe32, 0xffc1, 0x038f, 0x0000, 0xfe3e, 0xff80, 0x01ff, 0x0000,
   0x7c7e, 0x0000, 0x007e, 0x0000, 0x3c7c, 0x0000, 0x0000, 0x0000,
   0x1cfc, 0x0000, 0x0000, 0x0000, 0x1cf8, 0x0000, 0x0000, 0x0000,
   0x0ff0, 0x0000, 0x0000, 0x0000, 0x07e0, 0x0000, 0x0000, 0x0000,
   0x0000, 0x0000, 0x0000, 0x0000};

static short bob_bits[] = {			/* a left-going ``Bob'' */
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffe0, 0x07ff, 0x0000,
   0x0000, 0xfffe, 0x1fff, 0x0000, 0x8000, 0xffff, 0xfbff, 0x0000,
   0xc000, 0xcfff, 0xd19f, 0x0003, 0xf000, 0x8c7f, 0x9133, 0x0007,
   0xf800, 0x18a7, 0xb127, 0x0006, 0xfc00, 0x3147, 0xa64e, 0x000e,
   0xfe00, 0x214f, 0xae4c, 0x003d, 0xff00, 0x23df, 0xbe8d, 0x007d,
   0xff80, 0x67ff, 0xfebd, 0x01ff, 0xff80, 0x7fff, 0xffbf, 0x03ff,
   0xffc0, 0xffff, 0xffbf, 0x07f8, 0xffc0, 0xffff, 0x3fbf, 0x07f8,
   0xffc0, 0xffff, 0x07ff, 0x0ff8, 0xffc0, 0xffff, 0x003f, 0x0ff8,
   0x7fe0, 0xf800, 0x0007, 0x0ff0, 0x3fe0, 0x0000, 0x0000, 0x07f0,
   0x3fe0, 0x0000, 0x0000, 0x07f0, 0x3fe0, 0x0000, 0x0000, 0x07f4,
   0x3fe0, 0x0000, 0x0000, 0x07e4, 0x3fe0, 0x0000, 0x0000, 0x07e4,
   0x3fe0, 0x0000, 0x0000, 0x07e6, 0x3fe0, 0x0000, 0x0000, 0x07e7,
   0x3fe0, 0x0000, 0x0000, 0x07e6, 0x3fe0, 0x0000, 0x0000, 0x07e6,
   0x3fe0, 0x0000, 0x0000, 0x07e6, 0x3fc0, 0x0000, 0x7800, 0x07f6,
   0xbfa0, 0x00ff, 0xff00, 0x07f7, 0x9f70, 0x01ff, 0xff80, 0x07ef,
   0x1cf0, 0x0380, 0x01e0, 0x07ef, 0x1ff0, 0x07be, 0x3ff0, 0x07ee,
   0x9de0, 0x1f83, 0xe1f8, 0x07dc, 0xc1e0, 0x1f7f, 0xfffc, 0x07c8,
   0xc1e0, 0x1e69, 0xca7e, 0x03c0, 0x81e0, 0x1fb8, 0x0ec0, 0x03c0,
   0x01e0, 0x1bc0, 0xcfc0, 0x03c1, 0x03c0, 0x11f7, 0x7f00, 0x03c0,
   0x03c0, 0x187c, 0x1c00, 0x02c0, 0x02c0, 0x0830, 0x0000, 0x0340,
   0x0340, 0x0800, 0x0000, 0x0240, 0x1340, 0x0c00, 0x0000, 0x0260,
   0x1240, 0x0e00, 0x0000, 0x03c0, 0x3380, 0x0e80, 0x0000, 0x01a8,
   0x3300, 0x0f40, 0x03a0, 0x002c, 0x7400, 0x0f30, 0x0738, 0x002e,
   0x7400, 0x1f98, 0x1e1e, 0x002f, 0xfc00, 0xff8f, 0xfc0f, 0x002f,
   0xf800, 0xffe3, 0xf803, 0x002f, 0xf800, 0xfffd, 0xff81, 0x003f,
   0xb800, 0x1ff9, 0x0ff8, 0x001e, 0x3000, 0xf0f1, 0x030f, 0x000e,
   0x3000, 0x01f1, 0x0180, 0x000f, 0x2000, 0xf7f1, 0x00ff, 0x0007,
   0x6000, 0x01e3, 0x8060, 0x0007, 0x6000, 0xefc3, 0x803f, 0x0003,
   0x4000, 0xffc2, 0xc00f, 0x0003, 0xc000, 0x1fe6, 0xc000, 0x0001,
   0x8000, 0xfef4, 0xe03f, 0x0000, 0x8000, 0xfe79, 0xe01f, 0x0000,
   0x01c0, 0x3e3d, 0x7000, 0x0000, 0x0630, 0x0f3e, 0x3800, 0x0000,
   0x8cc8, 0x071f, 0x3800, 0x0000, 0xccf4, 0x078f, 0x1c00, 0x0000,
   0xee72, 0x07f7, 0x0e00, 0x0000, 0xff02, 0x07e3, 0x0700, 0x0000,
   0xfe32, 0xffc1, 0x038f, 0x0000, 0xfe3e, 0xff80, 0x01ff, 0x0000,
   0x7c7e, 0x0000, 0x007e, 0x0000, 0x3c7c, 0x0000, 0x0000, 0x0000,
   0x1cfc, 0x0000, 0x0000, 0x0000, 0x1cf8, 0x0000, 0x0000, 0x0000,
   0x0ff0, 0x0000, 0x0000, 0x0000, 0x07e0, 0x0000, 0x0000, 0x0000,
   0x0000, 0x0000, 0x0000, 0x0000};

static short bob_mask_bits[] = {
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffe0, 0x07ff, 0x0000,
   0x0000, 0xfffe, 0x1fff, 0x0000, 0x8000, 0xffff, 0xffff, 0x0000,
   0xc000, 0xffff, 0xffff, 0x0003, 0xf000, 0xffff, 0xffff, 0x0007,
   0xf800, 0xffff, 0xffff, 0x0007, 0xfc00, 0xffff, 0xffff, 0x000f,
   0xfe00, 0xffff, 0xffff, 0x003f, 0xff00, 0xffff, 0xffff, 0x007f,
   0xff80, 0xffff, 0xffff, 0x01ff, 0xff80, 0xffff, 0xffff, 0x03ff,
   0xffc0, 0xffff, 0xffff, 0x07ff, 0xffc0, 0xffff, 0xffff, 0x07ff,
   0xffc0, 0xffff, 0xffff, 0x0fff, 0xffc0, 0xffff, 0xffff, 0x0fff,
   0xffe0, 0xffff, 0xffff, 0x0fff, 0xffe0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xffe0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xffe0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xffe0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xffe0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xffc0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xfff0, 0xffff, 0xffff, 0x07ff,
   0xfff0, 0xffff, 0xffff, 0x07ff, 0xfff0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xffe0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x03ff, 0xffe0, 0xffff, 0xffff, 0x03ff,
   0xffe0, 0xffff, 0xffff, 0x03ff, 0xffc0, 0xffff, 0xffff, 0x03ff,
   0xffc0, 0xffff, 0xffff, 0x03ff, 0xffc0, 0xffff, 0xffff, 0x03ff,
   0xffc0, 0xffff, 0xffff, 0x03ff, 0xffc0, 0xffff, 0xffff, 0x03ff,
   0xffc0, 0xffff, 0xffff, 0x03ff, 0xff80, 0xffff, 0xffff, 0x01bf,
   0xff00, 0xffff, 0xffff, 0x003f, 0xfc00, 0xffff, 0xffff, 0x003f,
   0xfc00, 0xffff, 0xffff, 0x003f, 0xfc00, 0xffff, 0xffff, 0x003f,
   0xf800, 0xffff, 0xffff, 0x003f, 0xf800, 0xffff, 0xffff, 0x003f,
   0xf800, 0xffff, 0xffff, 0x001f, 0xf000, 0xffff, 0xffff, 0x000f,
   0xf000, 0xffff, 0xffff, 0x000f, 0xe000, 0xffff, 0xffff, 0x0007,
   0xe000, 0xffff, 0xffff, 0x0007, 0xe000, 0xffff, 0xffff, 0x0003,
   0xc000, 0xffff, 0xffff, 0x0003, 0xc000, 0xffff, 0xffff, 0x0001,
   0x8000, 0xffff, 0xffff, 0x0000, 0x8000, 0xffff, 0xffff, 0x0000,
   0x01c0, 0xffff, 0x7fff, 0x0000, 0x07f0, 0xfffe, 0x3fff, 0x0000,
   0x8ff8, 0xffff, 0x3fff, 0x0000, 0xcffc, 0xffff, 0x1fff, 0x0000,
   0xeffe, 0xfff7, 0x0fff, 0x0000, 0xfffe, 0xffe3, 0x07ff, 0x0000,
   0xfffe, 0xffc1, 0x03ff, 0x0000, 0xfffe, 0xff80, 0x01ff, 0x0000,
   0x7ffe, 0x0000, 0x007e, 0x0000, 0x3ffc, 0x0000, 0x0000, 0x0000,
   0x1ffc, 0x0000, 0x0000, 0x0000, 0x1ff8, 0x0000, 0x0000, 0x0000,
   0x0ff0, 0x0000, 0x0000, 0x0000, 0x07e0, 0x0000, 0x0000, 0x0000,
   0x0000, 0x0000, 0x0000, 0x0000};

static short bobr_mask_bits[] = {
   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xffe0, 0x07ff, 0x0000,
   0x0000, 0xfffe, 0x1fff, 0x0000, 0x8000, 0xffff, 0xffff, 0x0000,
   0xc000, 0xffff, 0xffff, 0x0003, 0xf000, 0xffff, 0xffff, 0x0007,
   0xf800, 0xffff, 0xffff, 0x0007, 0xfc00, 0xffff, 0xffff, 0x000f,
   0xfe00, 0xffff, 0xffff, 0x003f, 0xff00, 0xffff, 0xffff, 0x007f,
   0xff80, 0xffff, 0xffff, 0x01ff, 0xff80, 0xffff, 0xffff, 0x03ff,
   0xffc0, 0xffff, 0xffff, 0x07ff, 0xffc0, 0xffff, 0xffff, 0x07ff,
   0xffc0, 0xffff, 0xffff, 0x0fff, 0xffc0, 0xffff, 0xffff, 0x0fff,
   0xffe0, 0xffff, 0xffff, 0x0fff, 0xffe0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xffe0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xffe0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xffe0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xffe0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xffc0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xfff0, 0xffff, 0xffff, 0x07ff,
   0xfff0, 0xffff, 0xffff, 0x07ff, 0xfff0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x07ff, 0xffe0, 0xffff, 0xffff, 0x07ff,
   0xffe0, 0xffff, 0xffff, 0x03ff, 0xffe0, 0xffff, 0xffff, 0x03ff,
   0xffe0, 0xffff, 0xffff, 0x03ff, 0xffc0, 0xffff, 0xffff, 0x03ff,
   0xffc0, 0xffff, 0xffff, 0x03ff, 0xffc0, 0xffff, 0xffff, 0x03ff,
   0xffc0, 0xffff, 0xffff, 0x03ff, 0xffc0, 0xffff, 0xffff, 0x03ff,
   0xffc0, 0xffff, 0xffff, 0x03ff, 0xff80, 0xffff, 0xffff, 0x01bf,
   0xff00, 0xffff, 0xffff, 0x003f, 0xfc00, 0xffff, 0xffff, 0x003f,
   0xfc00, 0xffff, 0xffff, 0x003f, 0xfc00, 0xffff, 0xffff, 0x003f,
   0xf800, 0xffff, 0xffff, 0x003f, 0xf800, 0xffff, 0xffff, 0x003f,
   0xf800, 0xffff, 0xffff, 0x001f, 0xf000, 0xffff, 0xffff, 0x000f,
   0xf000, 0xffff, 0xffff, 0x000f, 0xe000, 0xffff, 0xffff, 0x0007,
   0xe000, 0xffff, 0xffff, 0x0007, 0xe000, 0xffff, 0xffff, 0x0003,
   0xc000, 0xffff, 0xffff, 0x0003, 0xc000, 0xffff, 0xffff, 0x0001,
   0x8000, 0xffff, 0xffff, 0x0000, 0x8000, 0xffff, 0xffff, 0x0000,
   0x01c0, 0xffff, 0x7fff, 0x0000, 0x07f0, 0xfffe, 0x3fff, 0x0000,
   0x8ff8, 0xffff, 0x3fff, 0x0000, 0xcffc, 0xffff, 0x1fff, 0x0000,
   0xeffe, 0xfff7, 0x0fff, 0x0000, 0xfffe, 0xffe3, 0x07ff, 0x0000,
   0xfffe, 0xffc1, 0x03ff, 0x0000, 0xfffe, 0xff80, 0x01ff, 0x0000,
   0x7ffe, 0x0000, 0x007e, 0x0000, 0x3ffc, 0x0000, 0x0000, 0x0000,
   0x1ffc, 0x0000, 0x0000, 0x0000, 0x1ff8, 0x0000, 0x0000, 0x0000,
   0x0ff0, 0x0000, 0x0000, 0x0000, 0x07e0, 0x0000, 0x0000, 0x0000,
   0x0000, 0x0000, 0x0000, 0x0000};


#define MAXBOBS 1000
struct bobstr {  short x,y,dx,dy,fnum;  } bob[MAXBOBS];

int NUMBOBS=20, startnbob=20, shots=0;

/* checkerboard pattern (theoretically the same as the Root Window pattern) */
static short check_bits[] = {
   0xeeee, 0xdddd, 0x7777, 0xbbbb, 0xeeee, 0xdddd, 0x7777, 0xbbbb,
   0xeeee, 0xdddd, 0x7777, 0xbbbb, 0xeeee, 0xdddd, 0x7777, 0xbbbb};

long starttime;

/**************/
main(argc, argv)
    int   argc;
    char *argv[];
/**************/
{
    int i,dpcs,n;
    char *strind;

    char *fc, *bc;
    char *display = NULL;
    int rvflag    = 0;      /* don't use reverse video as a default */

    Color cdef;
    WindowInfo winfo;

    char *def;
    short bot,right;


    /*********************Defaults*********************/
    
    if ((def=XGetDefault(argv[0],"ReverseVideo"))!=NULL)
         if (strcmp(def,"on")==0) rvflag=1;

    fc  = XGetDefault(argv[0], "Foreground");
    bc  = XGetDefault(argv[0], "Background");


    /*********************Options*********************/

    for (i = 1; i < argc; i++) {

        strind = index(argv[i], ':');       /* is it display address? */
        if(strind != NULL) {
            display = argv[i];
            continue;
            }

        if (strcmp(argv [i], "-rv") == 0) {
            rvflag++;
            continue;
            }

        if (n=atoi(argv[i])) {
            if (n<1) n=1;
            if (n>1000) n=1000;
            NUMBOBS=startnbob=n;
            continue;
            }

        Syntax(argv[0]);
    }


    /*****************************************************/

    /* Open up the display. */

    if (XOpenDisplay(display) == NULL) {
        fprintf(stderr, "%s: Can't open display '%s'\n",
                         argv[0], DisplayName());
        exit(1);
        }

    

    /* Set normal default colors */
    if (!rvflag) { ForeColor=BlackPixel;  BackColor=WhitePixel; }
            else { ForeColor=WhitePixel;  BackColor=BlackPixel; }


    /* Set up colors and pixmaps. */
    dpcs=DisplayCells();
    if (dpcs>2&&(fc !=NULL)&&XParseColor(fc ,&cdef)&&XGetHardwareColor(&cdef))
        ForeColor=cdef.pixel;

    if (dpcs>2&&(bc !=NULL)&&XParseColor(bc ,&cdef)&&XGetHardwareColor(&cdef))
        BackColor=cdef.pixel;


    /* Open the main window. */
    {
    int min_width, min_height;
    char default_geom[20];
    OpaqueFrame frame;
    
    min_width  = DisplayWidth();
    min_height = DisplayHeight();
    sprintf (default_geom, "%dx%d+0+0", min_width, min_height);

    stipB = XStoreBitmap(16,16,check_bits);
    stipP = XMakePixmap(stipB,ForeColor,BackColor);

    frame.bdrwidth   = 2;
    frame.border     = XMakeTile(ForeColor);
    frame.background = stipP;

    theWindow = XCreate("``Bobs''",argv[0],default_geom,default_geom,
                          &frame,min_width,min_height);

    if (!theWindow) XbobError("Can't open ``Bob'' window");
    }

    XQueryWindow(theWindow,&winfo);
    bot=winfo.height;  right=winfo.width;
    
    XMapWindow    (theWindow);
    XLowerWindow  (theWindow);

    bobBMask =XStoreBitmap(bob_width,bob_height,bob_mask_bits);
    bobrBMask=XStoreBitmap(bob_width,bob_height,bobr_mask_bits);
    
    /* init ``Bob'' */
    for (i=0; i<NUMBOBS; i++) {
        bob[i].x=rand()%(right-100)+50;
        bob[i].y=rand()%(bot-100)+50;
/*        bob[i].dx = (abs(rand()%4)+3);*/
        bob[i].dx = (abs(rand()%20)+3);
        if ((rand()%5)==0) bob[i].dx += 5;  /* hyper ``Bob'' */

	    /* pull the wool over your own eyes */
        /* switch direction based on a higher-order bit.  the low-order bit
           tended to be useless */
        if (rand()&0x10) bob[i].dx = -bob[i].dx;  

        bob[i].dy=rand()%7-3;  if (bob[i].dy==0) bob[i].dy=1;
        }

    XSelectInput(theWindow,ButtonPressed);
    curs = XCreateCursor(cross_width,cross_height,cross_bits,
                         cross_mask_bits, cross_x_hot, cross_y_hot,
                         ForeColor, BackColor, GXcopy);

    XDefineCursor(theWindow,curs);

    starttime=time(0);
    /**************** Main loop *****************/

    while (1) {
        XEvent event;
        short  x,y,bnum;

        if (XPending()) {
            XNextEvent(&event);
			/* everything you know is true */
            if (event.type == ButtonPressed) {
                XButtonEvent *butevent = (XButtonEvent *) &event;

                bnum = butevent->detail & 0xff;
                if ((bnum == LeftButton) || (bnum == RightButton)) {

                    if (bnum == RightButton) shots++;

                    /* find out what ``Bob'' was hit */

                    x = butevent->x;  y = butevent->y;
                    for (i=0; i<NUMBOBS; i++) {
						/* defy the sinister star forces which mock us all */
                        if ( (x >= bob[i].x) &&
                             (x <= bob[i].x+bob_width) &&
                             (y >= bob[i].y) &&
                             (y <= bob[i].y+bob_height) ) break;
                        }

                    if (i!=NUMBOBS) {  /* found one */
                        XFeep(0);
                        Erasebob(i);
						/* a self-perpetuating fascist state that will */
						/* last to the end of humanity */
                        if (bnum == LeftButton) {  /* bounce ``Bob'' */
                            bob[i].dx = -bob[i].dx;
                            bob[i].dy = -bob[i].dy;
                            Drawbob(i);
                            }
                        else {                     /* destroy ``Bob'' */
							/* at the mere sight of milk or cheese */
                            if (NUMBOBS==1) Stats();
                            bcopy(&bob[NUMBOBS-1],&bob[i],
                                  sizeof(struct bobstr)); /* ``Bob'' is a sex god!! */
                            NUMBOBS--;
                            }
                        }
                    }
                }
           }

        /* move ``Bob'' */
        for (i=0; i<NUMBOBS; i++) {
            Erasebob(i);

            bob[i].x += bob[i].dx;
            bob[i].y += bob[i].dy;
			/* adding up column after column of meaningless numbers */
            if (bob[i].x < -50 || bob[i].x > (right+50))
                bob[i].dx = -bob[i].dx;
            if (bob[i].y < 0 || bob[i].y > (bot-16))
                bob[i].dy = -bob[i].dy;

            Drawbob(i);
            }
        Timer(100000L);
    }  /* end main loop */
}

/*****************/
Erasebob(i)
      int i;
{
	/* burn the candle at both ends */
    if (bob[i].dx<0)
        XTileFill(theWindow,bob[i].x,bob[i].y,bob_width,bob_height,
					/* an inherently bogus religion */
                    stipP,bobBMask,GXcopy,AllPlanes);
	/* avert the rupture ofthe equilibrium
    else
        XTileFill(theWindow,bob[i].x,bob[i].y,bob_width,bob_height,
                    stipP,bobrBMask,GXcopy,AllPlanes);
}

/*****************/
Drawbob(i)
     int i;
{
    if (bob[i].dx<0) 
		/* instant instructions for those who follow no master!! */
        XBitmapBitsPut(theWindow,bob[i].x,bob[i].y,
            bob_width,bob_height,bob_bits,ForeColor,BackColor,
            bobBMask,GXcopy,AllPlanes);
    else
        XBitmapBitsPut(theWindow,bob[i].x,bob[i].y,
            bob_width,bob_height,bobr_bits,ForeColor,BackColor,
            bobrBMask,GXcopy,AllPlanes);
}


/***********************************/
Syntax(call)
 char *call;
{
	/* are alien space monsters bringing a startling new world */
    printf ("Usage: %s [-rv] [host:display] [number of bob] \n",call);
    exit(0);
}


/***********************************/
XbobError (identifier)
       char *identifier;
{
    fprintf(stderr, "xbob: %s\n", identifier);
    exit(1);
}



/*******/
Stats()
{
    long curtime;
    float acc;

    curtime=time(0);	/* time control */
    acc = (float) shots  / (float) startnbob;
    XFeep(0);  XFeep(0);  XFeep(0);  XFlush();
    printf("You used %d shots to hit %d ``Bobs''.  (in %d seconds)\n",
            shots,startnbob,curtime-starttime);
	/* are we controled by secret forces */
    printf("  For an accuracy ratio of: %f\n", acc);

    if (acc < 1.5) printf("Nice shootin', Tex!\n");
    exit(0);
}



static int timerdone;

/*******/
onalarm()
/*******/
{
  timerdone=1;
}

/*******/
Timer(val)
 long val;
/*******/
{
    /* waits 'val' microseconds */

    struct itimerval it;

    bzero(&it, sizeof(it));
    it.it_value.tv_usec = val;
    timerdone=0;
    signal(SIGALRM,onalarm);
	/* act like you aren't reading this */
    setitimer(ITIMER_REAL, &it, (struct itimerval *)0);
    while (1) {
        sigblock(sigmask(SIGALRM)); /* note:  have to block, so that ALRM */
        if (timerdone) break;       /* doesn't occur between 'if (timerdone)'*/
        else sigpause(0);           /* and calling sigpause(0) */
        }
    sigblock(0);                    /* turn ALRM blocking off */
    signal(SIGALRM,SIG_DFL);
}

\X\X\
else
  echo "will not over write ./xbob.c"
fi
echo "Finished archive 1 of 1"
exit