[comp.sources.games] v02i090: mines - minefield game for Suns

games-request@tekred.UUCP (11/19/87)

Submitted by: tc.fluke.COM!toma@uw-beaver (Tom Anderson)
Comp.sources.games: Volume 2, Issue 90
Archive-name: mines.shr


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  README Makefile blackSquare.icon board.c boardsw.c
#   crosshairs.cursor levelsw.c main.c mineSquare.icon mines.h
#   mines.icon msgsw.c playerSquare.icon safeSquare.icon tool.c
#   whiteSquare.icon
# Wrapped by billr@tekred on Thu Nov 19 10:28:11 1987
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f README -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"README\"
else
echo shar: Extracting \"README\" \(1878 characters\)
sed "s/^X//" >README <<'END_OF_README'
XHere are the sources for the mines game.  I hacked this up from the chess
Xtool - you might recognize the lineage.  I've been too lazy to write a 
Xmanual page for it; however, it's pretty simple:
X
XTop Subwindow (the "level" subwindow): Controls how many mines are hidden
Xin the array.  To change the level, just type a decimal number in this
Xwindow and hit return.  Typing return by itself will start a new game
Xat the same level as the previous one.  No path is guaranteed to exist;
Xhowever, the game is unplayable above about 80 mines or so, and at this
Xlevel the lack of a path is rare enough to not be frustrating.
X
XMiddle Subwindow (the "clairvoyance" subwindow):  Tells you how many 
Xmines are in immediately adjacent squares (including diagonals).  The
Xtop left four squares are always guaranteed to be free of mines.
X
XBottom Subwindow (the "minefield" subwindow):  The object is to get from 
Xthe upper left square to the lower right square without being blown up.
XClick:
X	- the left mouse button on any adjacent square to move there.  
X	Squares that you have occupied are highlighted.
X
X	- the middle mouse button on any square to mark the square as
X	"dangerous".  Once the square is marked as dangerous, you 
X	cannot accidentally move there.
X
X	- the right mouse button on any square to mark the square as 
X 	"safe".  This has no effect on your ability to move on the square,
X	but eliminates the need to keep a separate piece of paper around
X	or to have an excessively high IQ.
X
XThe middle and right mouse buttons are "toggles" - that is, clicking on
Xa square again toggles the square's designation or changes its type (i.e.,
Xfrom "safe" to "dangerous").  Both have no effect on squares you have
Xalready occupied.
X
XTom Anderson, (206) 356-5895
XJohn Fluke Mfg. Co., Inc.,  P.O. Box C9090 M/S 245F, Everett, Wa. 98206
X{ hplsla, microsoft, uw-beaver, sun, tikal }!fluke!toma
END_OF_README
if test 1878 -ne `wc -c <README`; then
    echo shar: \"README\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(676 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X#
X# Makefile for nchess package.
X#
X
XOBJS = board.o boardsw.o levelsw.o main.o msgsw.o tool.o
XSRCS = board.c boardsw.c levelsw.c main.c msgsw.c tool.c
XHDRS = mines.h
XICONS = blackSquare.icon whiteSquare.icon mineSquare.icon mines.icon \
X	playerSquare.icon safeSquare.icon
XCURSORS = crosshairs.cursor
X
X#CFLAGS = -g
XCFLAGS = -O
X
Xmines : $(OBJS)
X	cc $(CFLAGS) -o mines $(OBJS) -lsuntool -lsunwindow -lpixrect
X
Xlint : $(SRCS) $(HDRS)
X	lint $(SRCS)
X
Xlist : $(SRCS) $(HDRS)
X	lpr -x2 -p -J"mines" *.h *.c
X
Xclean : 
X	rm -f *.o mines
X
X$(OBJS) : $(HDRS)
X
Xshar : dist.sh
X
Xdist.sh : Makefile $(HDRS) $(SRCS) $(ICONS) $(CURSORS)
X	shar Makefile $(HDRS) $(SRCS) $(ICONS) $(CURSORS) > dist.sh
END_OF_Makefile
if test 676 -ne `wc -c <Makefile`; then
    echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f blackSquare.icon -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"blackSquare.icon\"
else
echo shar: Extracting \"blackSquare.icon\" \(1933 characters\)
sed "s/^X//" >blackSquare.icon <<'END_OF_blackSquare.icon'
X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
X */
X	0xFFFF,0x0000,0x0000,0x0000,0x8001,0x0000,0x0000,0x0000,
X	0xAAA9,0x0000,0x0000,0x0000,0x9555,0x0000,0x0000,0x0000,
X	0xAAA9,0x0000,0x0000,0x0000,0x9555,0x0000,0x0000,0x0000,
X	0xAAA9,0x0000,0x0000,0x0000,0x9555,0x0000,0x0000,0x0000,
X	0xAAA9,0x0000,0x0000,0x0000,0x9555,0x0000,0x0000,0x0000,
X	0xAAA9,0x0000,0x0000,0x0000,0x9555,0x0000,0x0000,0x0000,
X	0xAAA9,0x0000,0x0000,0x0000,0x9555,0x0000,0x0000,0x0000,
X	0x8001,0x0000,0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0xFFFF,0xFFFF,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0xAAAA,0xAAA9,0x0000,0x0000,0x9555,0x5555,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0xFFFF,0xFFFF
END_OF_blackSquare.icon
if test 1933 -ne `wc -c <blackSquare.icon`; then
    echo shar: \"blackSquare.icon\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f board.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"board.c\"
else
echo shar: Extracting \"board.c\" \(4101 characters\)
sed "s/^X//" >board.c <<'END_OF_board.c'
X/*
X * manage the board state
X *
X * Copyright (c) 1987 Tom Anderson; 20831 Frank Waters Road;
X * Stanwood, WA  98282.   All rights reserved.
X */
Xstatic char copyright[] = "Copyright 1987 Tom Anderson";
X
X#include <stdio.h>
X#include <strings.h>
X#include <sys/types.h>
X
X#include "mines.h"
X
XSquare MainBoard[SIDE_SIZE][SIDE_SIZE];
XBoardCoordinate PlayerLocation;
XBOOL GameOver;
X
X/*
X * set up the playing surface at the beginning of the game
X */
Xvoid
XInitBoard(level)
X    int level;			/* number of mines */
X{
X    register int i, j, minesPlaced, cutoff;
X    register Square * sqp;
X    int pass = 0;
X    BOOL connected;
X
X    /* 
X     * retry mine placement until a route can be had from the entry to
X     * the exit (this needs work)
X     */
X    do {
X	/*
X	 * zero the board 
X	 */
X	for (i = 0 ; i < SIDE_SIZE ; i++) {
X	    for (j = 0 ; j < SIDE_SIZE ; j++) {
X		sqp = &MainBoard[i][j];
X		sqp->traversed = sqp->mined = sqp->occupied 
X		    = sqp->unsafe = sqp->safe = FALSE;
X	    }
X	}
X	/*
X	 * make several passes over the board, placing mines at
X	 * a probability calculated to require about 3 passes on the average
X	 */
X	cutoff = level / 3 + 1;
X	for (minesPlaced = 0 ; minesPlaced < level ; ) {
X	    for (i = 0 ; i < SIDE_SIZE ; i++) {
X		for (j = 0 ; j < SIDE_SIZE ; j++) {
X		    if ((random() % (SIDE_SIZE * SIDE_SIZE)) < cutoff
X		    && ! MainBoard[i][j].mined
X		    && minesPlaced < level
X		    && ! (i <= 1 && j <= 1)
X		    && ! (i == SIDE_SIZE-1 && j == SIDE_SIZE-1)) {
X			MainBoard[i][j].mined = TRUE;
X			minesPlaced++;
X		    }
X		}
X	    }
X	}
X	connected = TRUE;	/* ignore impossible mazes for now */
X    } while ( ! connected);
X    PlayerLocation.x = PlayerLocation.y = 0;
X    MainBoard[0][0].occupied = MainBoard[0][0].traversed = TRUE;
X    GameOver = FALSE;
X}
X
X/*
X * describe the state of the board square at x, y
X */
XSquare *
XGetSquare(bloc)
X    BoardCoordinate * bloc;
X{
X    return (&MainBoard[bloc->y][bloc->x]);
X}
X
X/*
X * toggle a square's marking as being probably safe or unsafe
X */
Xvoid
XMarkSquare(suspect, safe)
X    BoardCoordinate * suspect;
X    BOOL safe;
X{
X    register Square * sqp = &MainBoard[suspect->y][suspect->x];
X
X    if (sqp->traversed)
X	return;
X    if (safe) {
X	sqp->safe = ! sqp->safe;
X	sqp->unsafe = FALSE;
X    } else {
X	sqp->unsafe = ! sqp->unsafe;
X	sqp->safe = FALSE;
X    }
X    DrawSquare(suspect);
X}
X
X
X/*
X * try to move to a certain board coordinate
X */
Xvoid 
XDoMove(dest)
X    BoardCoordinate * dest;
X{
X    register int y, x;
X    register Square * sqp;
X
X    /*
X     * if not adjacent to or equal to our current position
X     * or the destination has been marked unsafe, ignore the move 
X     */
X    if (abs(dest->x - (x = PlayerLocation.x)) > 1
X    || abs(dest->y - (y = PlayerLocation.y)) > 1
X    || (dest->x == PlayerLocation.x && dest->y == PlayerLocation.y)
X    || MainBoard[dest->y][dest->x].unsafe)
X	return;
X    /*
X     * step off our current square
X     */
X    MainBoard[y][x].occupied = FALSE;
X    DrawSquare(&PlayerLocation);
X    sqp = &MainBoard[dest->y][dest->x];
X    /*
X     * if we stepped on a mine, blow him up
X     */
X    if (sqp->mined) {
X	GameOver = TRUE;
X	Message("You just exploded");
X	DrawBoard();
X    }
X    /*
X     * else if this is home, render congratulations
X     */
X    else if (dest->x == SIDE_SIZE-1 && dest->y == SIDE_SIZE-1) {
X	PlayerLocation = * dest;
X	sqp->traversed = sqp->occupied = TRUE;
X	GameOver = TRUE;
X	Message("You made it!");
X	DrawBoard();
X    }
X    /*
X     * else move onto the new square
X     */
X    else {
X	PlayerLocation = * dest;
X	sqp->traversed = sqp->occupied = TRUE;
X	DrawSquare(dest);
X	Message(MineWarningMessage());
X    }
X}
X
X/*
X * return a pointer to the warning message
X */
Xchar *
XMineWarningMessage()
X{
X    static char warning[128];
X    register int x, y;
X    int minesFound;
X
X    minesFound = 0;
X    for (x = PlayerLocation.x - 1 ; x <= PlayerLocation.x + 1 ; x++) {
X	for (y = PlayerLocation.y - 1 ; y <= PlayerLocation.y + 1 ; y++) {
X	    if (x >= 0 && x < SIDE_SIZE && y >= 0 && y < SIDE_SIZE && MainBoard[y][x].mined)
X		minesFound++;
X	}
X    }
X    sprintf(warning, "%d mine(s) nearby", minesFound);
X    return(warning);
X}
X
END_OF_board.c
if test 4101 -ne `wc -c <board.c`; then
    echo shar: \"board.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f boardsw.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"boardsw.c\"
else
echo shar: Extracting \"boardsw.c\" \(5429 characters\)
sed "s/^X//" >boardsw.c <<'END_OF_boardsw.c'
X/*
X * handle the board subwindow 
X *
X * Copyright (c) 1987 Tom Anderson; 20831 Frank Waters Road;
X * Stanwood, WA  98282.   All rights reserved.
X */
Xstatic char copyright[] = "Copyright 1987 Tom Anderson";
X
X#include <stdio.h>
X#include <suntool/tool_hs.h>
X#include <suntool/panel.h>
X#include <suntool/gfxsw.h>
X#include <sunwindow/win_cursor.h>
X#include <sys/resource.h>
X#include <sys/ioctl.h>
X#include <strings.h>
X
X#include "mines.h"
X
X/*
X * cross-hairs cursor
X */
Xstatic short CrosshairsImage[] = {
X#include "crosshairs.cursor"
X};
XDEFINE_CURSOR_FROM_IMAGE(CrosshairsCursor, 8, 8, PIX_SRC^PIX_DST, CrosshairsImage);
X
X/*
X * square pixrects
X */
Xunsigned short WhiteSquareImage[] = {
X#include "whiteSquare.icon"
X};
Xmpr_static(WhiteSquarePR, 64, 64, 1, WhiteSquareImage);
X
Xunsigned short BlackSquareImage[] = {
X#include "blackSquare.icon"
X};
Xmpr_static(BlackSquarePR, 64, 64, 1, BlackSquareImage);
X
Xunsigned short PlayerSquareImage[] = {
X#include "playerSquare.icon"
X};
Xmpr_static(PlayerSquarePR, 64, 64, 1, PlayerSquareImage);
X
Xunsigned short MineSquareImage[] = {
X#include "mineSquare.icon"
X};
Xmpr_static(MineSquarePR, 64, 64, 1, MineSquareImage);
X
Xunsigned short SafeSquareImage[] = {
X#include "safeSquare.icon"
X};
Xmpr_static(SafeSquarePR, 64, 64, 1, SafeSquareImage);
X
X/* board subwindow handles */
Xstruct toolsw * BoardSW;
Xstruct gfxsubwindow * Board;
X
X/* square sizes */
Xint SquareWidth = 32, SquareHeight = 32;
X/* icon offsets */
Xstruct pr_pos IconOffset = { 32, 32 };
X
X/*
X * board sigwinch handler 
X */
X/*ARGSUSED*/
XboardSigwinch(sw)
X    caddr_t sw;
X{
X    gfxsw_interpretesigwinch(Board);
X    gfxsw_handlesigwinch(Board);
X    if (Board->gfx_flags & GFX_RESTART) {
X	Board->gfx_flags &= ~ GFX_RESTART;
X	DrawBoard();
X    }
X}
X
X/*
X * map a mouse coordinate to a board coordinate
X */
Xvoid
XmapMouseToBoard(mlocp, blocp)
X    struct pr_pos * mlocp;
X    BoardCoordinate * blocp;
X{
X    blocp->x = mlocp->x / (SquareWidth-1);
X    blocp->y = mlocp->y / (SquareHeight-1);
X}
X
X/* 
X * map a board coordinate to a mouse coordinate
X */
Xvoid
XmapBoardToMouse(blocp, mlocp)
X    BoardCoordinate * blocp;
X    struct pr_pos * mlocp;
X{
X    mlocp->x = blocp->x * (SquareWidth-1) - 1;
X    mlocp->y = blocp->y * (SquareHeight-1) - 1;
X}
X
X/*
X * board select() handler 
X */
X/*ARGSUSED*/
XboardSelected(nullsw, ibits, obits, ebits, timer)
X    caddr_t * nullsw;
X    int * ibits, * obits, * ebits;
X    struct timeval ** timer;
X{
X    struct inputevent ie;
X    struct pr_pos mloc;
X    BoardCoordinate bloc;
X
X    /*
X     * read the input event
X     */
X    if (input_readevent(BoardSW->ts_windowfd, &ie) == -1) {
X	perror("input failed");
X	abort();
X    }
X    if (win_inputposevent(&ie)) { 
X	switch(ie.ie_code) {
X	/*
X	 * if it is an attempt to move
X	 */
X	case MS_LEFT:
X	    mloc.x = ie.ie_locx; mloc.y = ie.ie_locy;
X	    mapMouseToBoard(&mloc, &bloc);
X	    DoMove(&bloc);
X	    break;
X	/*
X	 * else if he is toggling a square's unsafe marking 
X	 */
X	case MS_MIDDLE:
X	    mloc.x = ie.ie_locx; mloc.y = ie.ie_locy;
X	    mapMouseToBoard(&mloc, &bloc);
X	    MarkSquare(&bloc, FALSE);
X	    break;
X	/*
X	 * else if he is toggling a square's safe marking 
X	 */
X	case MS_RIGHT:
X	    mloc.x = ie.ie_locx; mloc.y = ie.ie_locy;
X	    mapMouseToBoard(&mloc, &bloc);
X	    MarkSquare(&bloc, TRUE);
X	    break;
X	}
X    }
X    * ibits = * obits = * ebits = 0;
X}
X
X/*
X * initialize the board subwindow
X */
Xvoid
XInitBoardSW()
X{
X    struct inputmask mask;
X    register unsigned int i;
X
X    /*
X     * initialize the subwindow
X     */
X    if ((BoardSW = gfxsw_createtoolsubwindow(MinesTool, "",
X	TOOL_SWEXTENDTOEDGE, 
X	/* playing surface    +  victim area */
X	(SquareHeight-1) * SIDE_SIZE,
X	NULL)) == NULL) 
X    {
X	fprintf(stderr, "Can't create board subwindow\n");
X	exit(1);
X    }
X    Board = (struct gfxsubwindow *) BoardSW->ts_data;
X    gfxsw_getretained(Board); 
X    BoardSW->ts_io.tio_handlesigwinch = boardSigwinch;
X    BoardSW->ts_io.tio_selected = boardSelected;
X    input_imnull(&mask);
X    win_setinputcodebit(&mask, MS_LEFT);
X    win_setinputcodebit(&mask, MS_MIDDLE);
X    win_setinputcodebit(&mask, MS_RIGHT);
X    win_setinputcodebit(&mask, LOC_MOVEWHILEBUTDOWN);
X    win_setinputcodebit(&mask, LOC_WINEXIT);
X    mask.im_flags |= IM_NEGEVENT;
X    win_setinputmask(BoardSW->ts_windowfd, &mask, NULL, WIN_NULLLINK);
X    win_setcursor(BoardSW->ts_windowfd, &CrosshairsCursor);
X}
X
X/*
X * draw a square
X */
Xvoid
XDrawSquare(bloc)
X    BoardCoordinate * bloc;
X{
X    struct pr_pos mloc;
X    struct pixrect * pr;
X    Square * sqp = GetSquare(bloc);
X
X    /* determine which pixrect to paint the square with */
X    if (sqp->occupied)
X	pr = &PlayerSquarePR;
X    else if (sqp->traversed)
X	pr = &BlackSquarePR;
X    else if ( ! GameOver && sqp->unsafe || GameOver && sqp->mined)
X	pr = &MineSquarePR;
X    else if ( ! GameOver && sqp->safe)
X	pr = &SafeSquarePR;
X    else 
X	pr = &WhiteSquarePR;
X    /* paint the square */
X    mapBoardToMouse(bloc, &mloc);
X    pw_rop(Board->gfx_pixwin, 
X	mloc.x, mloc.y, SquareWidth, SquareHeight, PIX_SRC, pr, IconOffset.x, IconOffset.y);
X}
X
X/*
X * draw the playing surface and victim area
X */
Xvoid
XDrawBoard()
X{
X    BoardCoordinate bloc;
X
X    /* clear the board area */
X    pw_rop(Board->gfx_pixwin,
X	0, 0, Board->gfx_rect.r_width, Board->gfx_rect.r_height,
X	PIX_CLR, (struct pixrect *) 0, 0, 0);
X    /* draw the playing area */
X    for (bloc.x = 0 ; bloc.x < SIDE_SIZE ; bloc.x++) {
X	for (bloc.y = 0 ; bloc.y < SIDE_SIZE ; bloc.y++) {
X	    DrawSquare(&bloc);
X	}
X    }
X}
END_OF_boardsw.c
if test 5429 -ne `wc -c <boardsw.c`; then
    echo shar: \"boardsw.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f crosshairs.cursor -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"crosshairs.cursor\"
else
echo shar: Extracting \"crosshairs.cursor\" \(193 characters\)
sed "s/^X//" >crosshairs.cursor <<'END_OF_crosshairs.cursor'
X/* Format_version=1, Width=16, Height=16, Depth=1, Valid_bits_per_item=16
X */
X	0x0000,0x0100,0x0100,0x0100,0x0100,0x0100,0x0000,0x7C7C,
X	0x0000,0x0100,0x0100,0x0100,0x0100,0x0100,0x0000,0x0000
END_OF_crosshairs.cursor
if test 193 -ne `wc -c <crosshairs.cursor`; then
    echo shar: \"crosshairs.cursor\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f levelsw.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"levelsw.c\"
else
echo shar: Extracting \"levelsw.c\" \(1738 characters\)
sed "s/^X//" >levelsw.c <<'END_OF_levelsw.c'
X/*
X * level display/control subwindow handling
X *
X * Copyright (c) 1987 Tom Anderson; 20831 Frank Waters Road;
X * Stanwood, WA  98282.   All rights reserved.
X */
Xstatic char copyright[] = "Copyright 1987 Tom Anderson";
X
X#include <stdio.h>
X#include <suntool/tool_hs.h>
X#include <suntool/panel.h>
X#include <strings.h>
X
X#include "mines.h"
X
X#define	MAX_SEND_LENGTH		60
X
Xstruct toolsw * LevelSW;
XPanel LevelPanel;
X
XPanel_item ChangeLevelItem;
X
X/*ARGSUSED*/
XlevelProc(item, event)
X    Panel_item item;
X    struct inputevent *event;
X{
X    char c[MAX_SEND_LENGTH+1];
X    static int oldLevel = DEFAULT_MINE_QTY;
X    int newLevel;
X
X    /* get the new level request text */
X    strcpy(c, (char *) panel_get_value(ChangeLevelItem));
X    /* set the new level text to nil */
X    panel_set_value(ChangeLevelItem, "");
X    if (sscanf(c, "%d", &newLevel) == 1
X    && newLevel >= 0 
X    && newLevel < SIDE_SIZE * SIDE_SIZE - 20) 
X	oldLevel = newLevel;
X    InitBoard(oldLevel);
X    DrawBoard(); 
X    Message(MineWarningMessage());
X    sprintf(c, "[%d]", oldLevel);
X    panel_set(ChangeLevelItem, 
X	PANEL_LABEL_STRING, c,
X	0);
X}
X
X/*
X * set up the level control subwindow
X * (if we are playing against the machine, leave them out)
X */
Xvoid
XInitLevelSW()
X{
X    char c[128];
X
X    if ((LevelSW = panel_create(MinesTool, 0)) == NULL) {
X	fprintf(stderr, "Can't create level control subwindow\n");
X	exit(1);
X    }
X    sprintf(c, "[%d]", DEFAULT_MINE_QTY);
X    LevelPanel = LevelSW->ts_data;
X    ChangeLevelItem = panel_create_item(LevelPanel, PANEL_TEXT,
X	PANEL_LABEL_STRING, c,
X	PANEL_NOTIFY_STRING, "\n\r",
X	PANEL_NOTIFY_LEVEL, PANEL_SPECIFIED,
X	PANEL_NOTIFY_PROC, levelProc,
X	PANEL_VALUE_STORED_LENGTH, MAX_SEND_LENGTH,
X	0);
X    panel_fit_height(LevelPanel); 
X}
END_OF_levelsw.c
if test 1738 -ne `wc -c <levelsw.c`; then
    echo shar: \"levelsw.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f main.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"main.c\"
else
echo shar: Extracting \"main.c\" \(1061 characters\)
sed "s/^X//" >main.c <<'END_OF_main.c'
X/*
X * main part of the mines program
X *
X * Copyright (c) 1987 Tom Anderson; 20831 Frank Waters Road;
X * Stanwood, WA  98282.   All rights reserved.
X */
Xstatic char copyright[] = "Copyright 1987 Tom Anderson";
X
X#include <stdio.h>
X#include <strings.h>
X#include <errno.h>
X#include <suntool/tool_hs.h>
X#include <pwd.h>
X
X#include "mines.h"
X
Xint errno;				/* global error number */
X
Xmain(argc, argv)
X    int argc;
X    char ** argv;
X{
X    register int i, j;
X    char * cp;
X
X    /* randomize things a bit */
X    (void) srandom((long) getpid());
X    /* parse and strip out the tool-related arguments */
X    ParseToolArgs(&argc, argv);
X    for (i = 1 ; i < argc ; i++) {
X	if (argv[i][0] == '-') {
X	    switch(argv[i][1]) {
X	    /* small (16 x 16) version */
X	    case 's':
X		IconOffset.x = IconOffset.y = 0;
X		SquareWidth = SquareHeight = 16;
X		break;
X	    }
X	}
X    }
X    /* initialize the board state */
X    InitBoard(DEFAULT_MINE_QTY);
X    /* initialize and install the tool */
X    InitTool();
X    tool_install(MinesTool);
X    /* now play the game */
X    RunTool();
X}
X
END_OF_main.c
if test 1061 -ne `wc -c <main.c`; then
    echo shar: \"main.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f mineSquare.icon -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"mineSquare.icon\"
else
echo shar: Extracting \"mineSquare.icon\" \(1933 characters\)
sed "s/^X//" >mineSquare.icon <<'END_OF_mineSquare.icon'
X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
X */
X	0xFFFF,0x0000,0x0000,0x0000,0x8101,0x0000,0x0000,0x0000,
X	0x9201,0x0000,0x0000,0x0000,0x8041,0x0000,0x0000,0x0000,
X	0x8481,0x0000,0x0000,0x0000,0xB401,0x0000,0x0000,0x0000,
X	0x8201,0x0000,0x0000,0x0000,0x93C1,0x0000,0x0000,0x0000,
X	0xA3E1,0x0000,0x0000,0x0000,0x87F1,0x0000,0x0000,0x0000,
X	0x87F1,0x0000,0x0000,0x0000,0x87F1,0x0000,0x0000,0x0000,
X	0x83E1,0x0000,0x0000,0x0000,0x81C1,0x0000,0x0000,0x0000,
X	0x8001,0x0000,0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0xFFFF,0xFFFF,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8180,0x0001,0x0000,0x0000,0x8540,0x0001,
X	0x0000,0x0000,0x840C,0x0001,0x0000,0x0000,0xA024,0x0001,
X	0x0000,0x0000,0x9C90,0x0001,0x0000,0x0000,0x8500,0x0001,
X	0x0000,0x0000,0x8100,0x0001,0x0000,0x0000,0x8100,0x0001,
X	0x0000,0x0000,0xA0E3,0xE001,0x0000,0x0000,0x9CF7,0xF801,
X	0x0000,0x0000,0x80FB,0xFC01,0x0000,0x0000,0x807B,0xFE01,
X	0x0000,0x0000,0x803B,0xFF01,0x0000,0x0000,0x8047,0xFF01,
X	0x0000,0x0000,0x80FF,0xFF81,0x0000,0x0000,0x80FF,0xFF81,
X	0x0000,0x0000,0x80FF,0xFF81,0x0000,0x0000,0x80FF,0xFF81,
X	0x0000,0x0000,0x80FF,0xFF81,0x0000,0x0000,0x807F,0xFF01,
X	0x0000,0x0000,0x807F,0xFF01,0x0000,0x0000,0x803F,0xFE01,
X	0x0000,0x0000,0x801F,0xFC01,0x0000,0x0000,0x800F,0xF801,
X	0x0000,0x0000,0x8003,0xE001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0xFFFF,0xFFFF
END_OF_mineSquare.icon
if test 1933 -ne `wc -c <mineSquare.icon`; then
    echo shar: \"mineSquare.icon\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f mines.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"mines.h\"
else
echo shar: Extracting \"mines.h\" \(1151 characters\)
sed "s/^X//" >mines.h <<'END_OF_mines.h'
X/*
X * mines header
X *
X * Copyright (c) 1987 Tom Anderson; 20831 Frank Waters Road;
X * Stanwood, WA  98282.   All rights reserved.
X */
X
X#define BOOL 			int
X#ifndef TRUE
X#define TRUE			1
X#endif
X#ifndef FALSE
X#define FALSE			0
X#endif
X
X/*
X * number of board squares per side 
X */
X#define	SIDE_SIZE		16
X
X/*
X * default number of mines
X */
X#define	DEFAULT_MINE_QTY	20
X
X/*
X * board coordinates
X */
Xtypedef struct {
X    int x;
X    int y;
X} BoardCoordinate;
X
X/*
X * square state
X */
Xtypedef struct {
X    BOOL traversed;		/* has the poor soul stepped here? */
X    BOOL mined;			/* is this square mined? */
X    BOOL occupied;		/* is this square occupied? */
X    BOOL unsafe;		/* has the player determined a mine here? */
X    BOOL safe;			/* has the player determined no mines here? */
X} Square;
X
Xextern void InitBoard(), DoMove(), InitBoardSW(), DrawSquare(),
X    DrawBoard(), InitLevelSW(), InitMsgSW(), Message(),
X    ParseToolArgs(), InitTool(), RunTool(), MarkSquare();
Xextern Square * GetSquare();
Xextern struct tool * MinesTool;
Xextern char * MineWarningMessage();
Xextern BOOL GameOver;
Xextern struct pr_pos IconOffset;
Xextern int SquareWidth, SquareHeight;
END_OF_mines.h
if test 1151 -ne `wc -c <mines.h`; then
    echo shar: \"mines.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f mines.icon -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"mines.icon\"
else
echo shar: Extracting \"mines.icon\" \(1933 characters\)
sed "s/^X//" >mines.icon <<'END_OF_mines.icon'
X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
X */
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xE000,0x0000,0x0000,0x0007,
X	0xE000,0x3800,0x0000,0x0007,0xE000,0x1C60,0x075D,0x4007,
X	0xE005,0x8760,0x0251,0x8007,0xE003,0x9B20,0x025D,0x4007,
X	0xE000,0x4100,0x0000,0x0007,0xE000,0x7F60,0x00EB,0xA807,
X	0xE000,0x0AC0,0x004A,0x3007,0xE000,0xE440,0x004B,0xA807,
X	0xE001,0xC6F0,0x0000,0x0007,0xE000,0x0620,0x001D,0x7507,
X	0xE000,0x0600,0x0009,0x4607,0xE000,0x0C00,0x0009,0x7507,
X	0xE000,0x1800,0x0000,0x0007,0xE000,0x3000,0x0000,0x0007,
X	0xE000,0x6000,0x0001,0x2407,0xE000,0xC00F,0xE000,0x0007,
X	0xE000,0xC03F,0xFC00,0x0007,0xE000,0xC0FF,0xFF00,0x0007,
X	0xE000,0x79FF,0xFFC0,0x0007,0xE000,0x7CFF,0xF3E2,0x4007,
X	0xE000,0x747F,0xEDF1,0x2007,0xE000,0x6D3F,0xD4F8,0x9007,
X	0xE000,0x3B9F,0xFB7C,0x0007,0xE000,0x07CF,0xF77E,0x0007,
X	0xE000,0xCFCF,0xFFFF,0x0007,0xE000,0xE7CF,0xFFFF,0x0007,
X	0xE001,0xF39F,0xFFFF,0x8007,0xE001,0xF81F,0xFFFF,0x8007,
X	0xE001,0xFC7F,0xFFFF,0xC007,0xE003,0xFFFF,0xFFFF,0xC007,
X	0xE003,0xFFFF,0xFFFF,0xE007,0xE003,0xFFFF,0xFFFF,0xE007,
X	0xE003,0xFFFF,0xFFFF,0xE007,0xE003,0xFFFF,0xFFFF,0xE007,
X	0xE003,0xFFFF,0xFFFF,0xE007,0xE003,0xFFFF,0xFFFF,0xE007,
X	0xE003,0xFFFF,0xFFFF,0xE007,0xE003,0xFFFF,0xFFFF,0xE007,
X	0xE001,0xFFFF,0xFFFF,0xE007,0xE009,0xFFFF,0xFFFF,0xC007,
X	0xE008,0xFFFF,0xFFFF,0xC007,0xE024,0xFFFF,0xFFFF,0xC007,
X	0xE022,0x7FFF,0xFFDF,0x8007,0xE010,0x7FFF,0xFFAB,0x8007,
X	0xE008,0x3FFF,0xFF77,0x0007,0xE000,0x1FFF,0xFFAE,0x0007,
X	0xE000,0x0FFF,0xFFFC,0x0007,0xE000,0x07FF,0xFFF8,0x0007,
X	0xE000,0x03FF,0xFFF0,0x0007,0xE000,0x00FF,0xFFC0,0x0007,
X	0xE000,0x007F,0xFF80,0x0007,0xE000,0x001F,0xFC00,0x0007,
X	0xE000,0x0000,0x0000,0x0007,0xE000,0x0000,0x0000,0x0007,
X	0xE000,0x0000,0x0000,0x0007,0xE000,0x0000,0x0000,0x0007,
X	0xE000,0x0000,0x0000,0x0007,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF
END_OF_mines.icon
if test 1933 -ne `wc -c <mines.icon`; then
    echo shar: \"mines.icon\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f msgsw.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"msgsw.c\"
else
echo shar: Extracting \"msgsw.c\" \(973 characters\)
sed "s/^X//" >msgsw.c <<'END_OF_msgsw.c'
X/*
X * message subwindow handling
X *
X * Copyright (c) 1987 Tom Anderson; 20831 Frank Waters Road;
X * Stanwood, WA  98282.   All rights reserved.
X */
Xstatic char copyright[] = "Copyright 1987 Tom Anderson";
X
X#include <stdio.h>
X#include <ctype.h>
X#include <suntool/tool_hs.h>
X#include <suntool/panel.h>
X#include <strings.h>
X
X#include "mines.h"
X
Xstruct toolsw * MessageSW;
XPanel MessagePanel;
X
XPanel_item MessageItem;
X
X/*
X * set up the message subwindow
X */
Xvoid
XInitMsgSW()
X{
X    if ((MessageSW = panel_create(MinesTool, 0)) == NULL) {
X	fprintf(stderr, "Can't create message panel\n");
X	exit(1);
X    }
X    MessagePanel = MessageSW->ts_data;
X    /* create the message panel item */
X    MessageItem = panel_create_item(MessagePanel, PANEL_MESSAGE,
X	PANEL_LABEL_STRING, MineWarningMessage(),
X	PANEL_SHOW_ITEM, TRUE,
X	0);
X    panel_fit_height(MessagePanel); 
X}
X
Xvoid 
XMessage(cp)
X    char * cp;
X{
X    panel_set(MessageItem,
X	PANEL_LABEL_STRING, cp,
X	PANEL_SHOW_ITEM, TRUE,
X	0);
X}
END_OF_msgsw.c
if test 973 -ne `wc -c <msgsw.c`; then
    echo shar: \"msgsw.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f playerSquare.icon -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"playerSquare.icon\"
else
echo shar: Extracting \"playerSquare.icon\" \(1933 characters\)
sed "s/^X//" >playerSquare.icon <<'END_OF_playerSquare.icon'
X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
X */
X	0xFFFF,0x0000,0x0000,0x0000,0x8001,0x0000,0x0000,0x0000,
X	0x8081,0x0000,0x0000,0x0000,0x81C1,0x0000,0x0000,0x0000,
X	0x81C1,0x0000,0x0000,0x0000,0x8081,0x0000,0x0000,0x0000,
X	0x8081,0x0000,0x0000,0x0000,0x83E1,0x0000,0x0000,0x0000,
X	0x8491,0x0000,0x0000,0x0000,0x8081,0x0000,0x0000,0x0000,
X	0x81C1,0x0000,0x0000,0x0000,0x81C1,0x0000,0x0000,0x0000,
X	0x8221,0x0000,0x0000,0x0000,0x8221,0x0000,0x0000,0x0000,
X	0x8001,0x0000,0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0xFFFF,0xFFFF,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8003,0x8001,
X	0x0000,0x0000,0x8004,0x4001,0x0000,0x0000,0x8004,0x4001,
X	0x0000,0x0000,0x8004,0x4001,0x0000,0x0000,0x8003,0x8001,
X	0x0000,0x0000,0x8001,0x0001,0x0000,0x0000,0x8001,0x0001,
X	0x0000,0x0000,0x8001,0x0001,0x0000,0x0000,0x800F,0xE001,
X	0x0000,0x0000,0x8001,0x0001,0x0000,0x0000,0x8001,0x0001,
X	0x0000,0x0000,0x8001,0x0001,0x0000,0x0000,0x8001,0x0001,
X	0x0000,0x0000,0x8001,0x0001,0x0000,0x0000,0x8001,0x0001,
X	0x0000,0x0000,0x8001,0x0001,0x0000,0x0000,0x8002,0x8001,
X	0x0000,0x0000,0x8004,0x4001,0x0000,0x0000,0x8004,0x4001,
X	0x0000,0x0000,0x8008,0x2001,0x0000,0x0000,0x8010,0x1001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0xFFFF,0xFFFF
END_OF_playerSquare.icon
if test 1933 -ne `wc -c <playerSquare.icon`; then
    echo shar: \"playerSquare.icon\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f safeSquare.icon -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"safeSquare.icon\"
else
echo shar: Extracting \"safeSquare.icon\" \(1933 characters\)
sed "s/^X//" >safeSquare.icon <<'END_OF_safeSquare.icon'
X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
X */
X	0xFFFF,0x0000,0x0000,0x0000,0x8001,0x0000,0x0000,0x0000,
X	0x8001,0x0000,0x0000,0x0000,0x8001,0x0000,0x0000,0x0000,
X	0x800D,0x0000,0x0000,0x0000,0x801D,0x0000,0x0000,0x0000,
X	0x803D,0x0000,0x0000,0x0000,0x8071,0x0000,0x0000,0x0000,
X	0x8061,0x0000,0x0000,0x0000,0x98C1,0x0000,0x0000,0x0000,
X	0x8D81,0x0000,0x0000,0x0000,0x8701,0x0000,0x0000,0x0000,
X	0x8201,0x0000,0x0000,0x0000,0x8201,0x0000,0x0000,0x0000,
X	0x8001,0x0000,0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0xFFFF,0xFFFF,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x4001,
X	0x0000,0x0000,0x8000,0x4001,0x0000,0x0000,0x801C,0x4801,
X	0x0000,0x0000,0x8022,0x5001,0x0000,0x0000,0x8022,0x6001,
X	0x0000,0x0000,0x8022,0x6001,0x0000,0x0000,0x8022,0x5001,
X	0x0000,0x0000,0x8022,0x4801,0x0000,0x0000,0x801C,0x4401,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0xFFFF,0xFFFF
END_OF_safeSquare.icon
if test 1933 -ne `wc -c <safeSquare.icon`; then
    echo shar: \"safeSquare.icon\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f tool.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"tool.c\"
else
echo shar: Extracting \"tool.c\" \(2847 characters\)
sed "s/^X//" >tool.c <<'END_OF_tool.c'
X/*
X * handle the tool environment 
X *
X * Copyright (c) 1987 Tom Anderson; 20831 Frank Waters Road;
X * Stanwood, WA  98282.   All rights reserved.
X */
Xstatic char copyright[] = "Copyright 1987 Tom Anderson";
X
X#include <stdio.h>
X#include <suntool/tool_hs.h>
X#include <suntool/panel.h>
X#include <suntool/gfxsw.h>
X#include <sys/resource.h>
X#include <sys/ioctl.h>
X#include <strings.h>
X
X#include "mines.h"
X
Xstruct tool * MinesTool;
Xchar ** ToolAttrs = (char **) NULL;
Xchar * ToolName;
X
X/*
X * iconic form of window
X */
Xunsigned short IconImage[] = {
X#include "mines.icon"
X};
X
XDEFINE_ICON_FROM_IMAGE(WindowIcon, IconImage);
X
Xsigwinched()
X{
X    tool_sigwinch(MinesTool);
X}
X
X/*
X * parse the tool args.
X */
Xvoid 
XParseToolArgs(argc, argv)
X    int *argc;
X    char **argv;
X{
X    ToolName = argv[0];
X    (*argc)--;
X    argv++;
X    if (tool_parse_all(argc, argv, &ToolAttrs, ToolName) == -1) {
X	tool_usage(ToolName);
X	exit(1);
X    }
X    (*argc)++;
X}
X
X/*
X * set up the tool environment
X */
Xvoid
XInitTool()
X{
X    register unsigned int height;
X    register struct toolsw * twsp;
X
X    if ((MinesTool = tool_make( 
X	WIN_LABEL, ToolName,
X	WIN_ICON, &WindowIcon, 
X	WIN_ATTR_LIST, ToolAttrs,
X	WIN_WIDTH, SIDE_SIZE * (SquareWidth-1) + 2 * tool_borderwidth(MinesTool) - 1,
X	/*
X	 * NOTE: The following line was unnecessary in Sun release 2.2,
X	 * but is necessary in release 3.0.  For some unknown reason, the
X	 * call to tool_set_attributes following the call to InitBoardSW
X	 * now fails to uncover the board area that was obscured by the 
X	 * default tool height being too small (note that the tool has not 
X	 * been installed yet).
X	 */
X	WIN_HEIGHT, 2000,
X	0)) == (struct tool *) NULL) 
X    {
X	fputs("Can't make tool\n", stderr);
X	exit(1);
X    }
X    tool_free_attribute_list(ToolAttrs);
X    /* initialize the subwindows */
X    InitLevelSW();
X    InitMsgSW();
X    InitBoardSW();
X    /* 
X     * add up subwindow heights and force the tool to the resulting size 
X     */
X    height = tool_stripeheight(MinesTool) + tool_borderwidth(MinesTool) - tool_subwindowspacing(MinesTool);
X    for (twsp = MinesTool->tl_sw ; twsp != (struct toolsw *) 0 ; twsp = twsp->ts_next) 
X	height += twsp->ts_height + tool_subwindowspacing(MinesTool);
X    /*
X     * NOTE: under 2.2, the above calculation yielded the correct height.
X     * under 3.0, we need to add a few pixels to make it come out right (the
X     * reason is not yet known).
X     */
X    height += 2;
X    tool_set_attributes(MinesTool, WIN_HEIGHT, height, 0); 
X    signal(SIGWINCH, sigwinched);
X}
X
Xvoid
XRunTool()
X{
X    /*
X     * NOTE: this is another difference between release 2.2 and 3.0:
X     * in release 2.2, the SIGWINCH handler would get called once at the
X     * outset to draw the board area; in release 3.0, this doesn't happen.
X     */
X    DrawBoard();
X    tool_select(MinesTool, 0);
X    tool_destroy(MinesTool);
X}
X
END_OF_tool.c
if test 2847 -ne `wc -c <tool.c`; then
    echo shar: \"tool.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f whiteSquare.icon -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"whiteSquare.icon\"
else
echo shar: Extracting \"whiteSquare.icon\" \(1933 characters\)
sed "s/^X//" >whiteSquare.icon <<'END_OF_whiteSquare.icon'
X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
X */
X	0xFFFF,0x0000,0x0000,0x0000,0x8001,0x0000,0x0000,0x0000,
X	0x8001,0x0000,0x0000,0x0000,0x8001,0x0000,0x0000,0x0000,
X	0x8001,0x0000,0x0000,0x0000,0x8001,0x0000,0x0000,0x0000,
X	0x8001,0x0000,0x0000,0x0000,0x8001,0x0000,0x0000,0x0000,
X	0x8001,0x0000,0x0000,0x0000,0x8001,0x0000,0x0000,0x0000,
X	0x8001,0x0000,0x0000,0x0000,0x8001,0x0000,0x0000,0x0000,
X	0x8001,0x0000,0x0000,0x0000,0x8001,0x0000,0x0000,0x0000,
X	0x8001,0x0000,0x0000,0x0000,0xFFFF,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X	0x0000,0x0000,0xFFFF,0xFFFF,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0x8000,0x0001,
X	0x0000,0x0000,0x8000,0x0001,0x0000,0x0000,0xFFFF,0xFFFF
END_OF_whiteSquare.icon
if test 1933 -ne `wc -c <whiteSquare.icon`; then
    echo shar: \"whiteSquare.icon\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0