mikew@wyse.wyse.com (Mike Wexler) (12/06/88)
Submitted-by: aperez@blazer.prime.com (Arturo Perez Ext.) Posting-number: Volume 2, Issue 29 Archive-name: xchess/part02 #! /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 archive 2 (of 6)." # Contents: control.c parse.c popup.c record.c.UU window.c # Wrapped by mikew@wyse on Mon Dec 5 18:32:47 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'control.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'control.c'\" else echo shar: Extracting \"'control.c'\" \(11973 characters\) sed "s/^X//" >'control.c' <<'END_OF_FILE' X/* This file contains code for X-CHESS. X Copyright (C) 1986 Free Software Foundation, Inc. X XThis file is part of X-CHESS. X XX-CHESS is distributed in the hope that it will be useful, Xbut WITHOUT ANY WARRANTY. No author or distributor Xaccepts responsibility to anyone for the consequences of using it Xor for whether it serves any particular purpose or works at all, Xunless he says so in writing. Refer to the X-CHESS General Public XLicense for full details. X XEveryone is granted permission to copy, modify and redistribute XX-CHESS, but only under the conditions described in the XX-CHESS General Public License. A copy of this license is Xsupposed to have been given to you along with X-CHESS so you Xcan know your rights and responsibilities. It should be in a Xfile named COPYING. Among other things, the copyright notice Xand this notice must be preserved on all copies. */ X X X/* RCS Info: $Revision: 1.4 $ on $Date: 86/11/23 17:17:32 $ X * $Source: /users/faustus/xchess/RCS/control.c,v $ X * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group X * Permission is granted to do anything with this code except sell it X * or remove this message. X * X * Deal with input from the user. X */ X X#include "xchess.h" X Xmove *moves; Xmove *foremoves; Xcolor nexttomove = WHITE; Xbool noisyflag = false; X Xmove *lastmove; Xstatic move *thismove; X Xstatic void screen_move(); X Xvoid Xbutton_pressed(event, win) X XEvent *event; X windata *win; X{ X int x, y; X XKeyEvent *ev = (XKeyEvent *) event; X X if (!oneboard && (win->color != nexttomove)) { X message_add(win, "Wrong player!\n", true); X return; X } X if (progflag && (nexttomove == (blackflag ? WHITE : BLACK))) { X message_add(win, "Wait for the computer...\n", true); X return; X } X if (loading_flag) { X message_add(win, "You'd better not do that now...\n", true); X return; X } X X /* Figure out what piece he is pointing at. */ X x = ev->x / (SQUARE_WIDTH + BORDER_WIDTH); X y = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH); X X if (win->flipped) { X y = SIZE - y - 1; X x = SIZE - x - 1; X } X X if ((x < 0) || (x >= SIZE) || (y < 0) || (y >= SIZE)) { X fprintf(stderr, "Bad coords (%d, %d)\n", x, y); X return; X } X X if (oneboard && (chessboard->square[y][x].color != nexttomove)) { X message_add(win, "Wrong player!\n", true); X return; X } else if (!oneboard && (chessboard->square[y][x].color != X win->color)) { X message_add(win, "Can't move that\n", true); X return; X } X X thismove = alloc(move); X thismove->fromx = x; X thismove->fromy = y; X thismove->piece.color = chessboard->square[y][x].color; X thismove->piece.type = chessboard->square[y][x].type; X X if (debug) X fprintf(stderr, "%s selected his %s at (%d, %d)...\n", X colornames[(int) thismove->piece.color], X piecenames[(int) thismove->piece.type], X thismove->fromy, thismove->fromx); X return; X} X Xvoid Xbutton_released(event, win) X XEvent *event; X windata *win; X{ X int x, y; X XKeyEvent *ev = (XKeyEvent *) event; X X if (!thismove) { X /* fprintf(stderr, "Error: button hasn't been pressed\n"); */ X return; X } X if (loading_flag) X return; X X /* Figure out what piece he is pointing at. */ X x = ev->x / (SQUARE_WIDTH + BORDER_WIDTH); X y = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH); X X if (win->flipped) { X y = SIZE - y - 1; X x = SIZE - x - 1; X } X X if ((x < 0) || (x >= SIZE) || (y < 0) || (y >= SIZE)) { X fprintf(stderr, "Bad coords (%d, %d)\n", x, y); X return; X } X X if ((thismove->fromx == x) && (thismove->fromy == y)) { X message_add(win, "Hey, you touch it, you move it, buddy.\n", X true); X return; X } X if (chessboard->square[y][x].color == thismove->piece.color) { X message_add(win, "Can't put one piece on top of another\n", X true); X return; X } X X thismove->tox = x; X thismove->toy = y; X thismove->taken.color = chessboard->square[y][x].color; X thismove->taken.type = chessboard->square[y][x].type; X if (thismove->taken.color != NONE) X thismove->type = CAPTURE; X else if ((thismove->piece.type == KING) && (thismove->fromx == 4) && X (thismove->tox == 6) && X (thismove->toy == thismove->fromy)) X thismove->type = KCASTLE; X else if ((thismove->piece.type == KING) && (thismove->tox == 2) && X (thismove->fromx == 4) && X (thismove->toy == thismove->fromy)) X thismove->type = QCASTLE; X else X thismove->type = MOVE; X X /* Now check the en-passant case... */ X if ((thismove->type == MOVE) && ((thismove->tox == thismove->fromx + 1) X || (thismove->tox == thismove->fromx - 1)) && X (thismove->piece.type == PAWN) && lastmove && X (lastmove->tox == lastmove->fromx) && (lastmove->fromx X == thismove->tox) && ((lastmove->fromy + lastmove->toy) X / 2 == thismove->toy)) { X thismove->type = CAPTURE; X thismove->enpassant = true; X thismove->taken = lastmove->piece; X } X X if (!valid_move(thismove, chessboard)) { X message_add(win, "Invalid move.\n", true); X return; X } X X if (debug) X fprintf(stderr, "\t... and moved it to (%d, %d), type %s\n", X thismove->toy, thismove->tox, X movetypenames[(int) thismove->type]); X move_piece(thismove); X X if (thismove->check) { X message_add(win1, "Check.\n", true); X if (!oneboard) { X message_add(win2, "Check.\n", true); X } X } X X if (!moves) X moves = lastmove = thismove; X else X lastmove = lastmove->next = thismove; X X if (progflag) X program_send(thismove); X X thismove = NULL; X nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE); X clock_switch(); X X return; X} X Xvoid Xprog_move(m) X move *m; X{ X if (debug) X fprintf(stderr, "program moves from (%d, %d) to (%d, %d)\n", X m->fromy, m->fromx, m->toy, m->tox); X move_piece(m); X X if (!moves) X moves = lastmove = m; X else X lastmove = lastmove->next = m; X X nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE); X clock_switch(); X X return; X} X Xvoid Xmove_piece(m) X move *m; X{ X /* Update the screen... */ X screen_move(m); X X /* Move the piece on the board... */ X board_move(chessboard, m); X X /* And record it... */ X record_move(m); X X if (noisyflag) { X XBell(win1->display, 50); X XBell(win2->display, 50); X } X return; X} X Xstatic void Xscreen_move(m) X move *m; X{ X piece pp; X X switch (m->type) { X case CAPTURE: X jail_add(&m->taken); X /* FALLTHRU */ X X case MOVE: X win_erasepiece(m->fromy, m->fromx, WHITE); X if (win_flashmove) X win_flash(m, WHITE); X win_drawpiece(&m->piece, m->toy, m->tox, WHITE); X if (m->enpassant) X win_erasepiece(m->toy + ((m->piece.color == WHITE) ? X 1 : -1), m->tox, WHITE); X if (!oneboard) { X win_erasepiece(m->fromy, m->fromx, BLACK); X if (win_flashmove) X win_flash(m, BLACK); X win_drawpiece(&m->piece, m->toy, m->tox, BLACK); X if (m->enpassant) X win_erasepiece(m->toy + ((m->piece.color == X WHITE) ? 1 : -1), m->tox, WHITE); X } X if ((m->piece.type == PAWN) && (((m->piece.color == BLACK) && X (m->toy == 7)) || ((m->piece.color == WHITE) && X (m->toy == 0)))) { X pp.color = m->piece.color; X pp.type = QUEEN; X win_drawpiece(&pp, m->toy, m->tox, WHITE); X if (!oneboard) X win_drawpiece(&m->piece, m->toy, m->tox, BLACK); X } X break; X X case KCASTLE: X if (m->piece.color == WHITE) { X win_erasepiece(7, 4, WHITE); X win_erasepiece(7, 7, WHITE); X if (win_flashmove) X win_flash(m, WHITE); X win_drawpiece(&m->piece, 7, 6, WHITE); X win_drawpiece(&chessboard->square[7][7], 7, 5, WHITE); X if (!oneboard) { X win_erasepiece(7, 4, BLACK); X win_erasepiece(7, 7, BLACK); X if (win_flashmove) X win_flash(m, BLACK); X win_drawpiece(&m->piece, 7, 6, BLACK); X win_drawpiece(&chessboard->square[7][7], 7, 5, X BLACK); X } X } else { X win_erasepiece(0, 4, WHITE); X win_erasepiece(0, 7, WHITE); X if (win_flashmove) X win_flash(m, WHITE); X win_drawpiece(&m->piece, 0, 6, WHITE); X win_drawpiece(&chessboard->square[0][7], 0, 5, WHITE); X if (!oneboard) { X win_erasepiece(0, 4, BLACK); X win_erasepiece(0, 7, BLACK); X if (win_flashmove) X win_flash(m, BLACK); X win_drawpiece(&m->piece, 0, 6, BLACK); X win_drawpiece(&chessboard->square[0][7], 0, 5, X BLACK); X } X } X break; X X case QCASTLE: X if (m->piece.color == WHITE) { X win_erasepiece(7, 4, WHITE); X win_erasepiece(7, 0, WHITE); X if (win_flashmove) X win_flash(m, WHITE); X win_drawpiece(&m->piece, 7, 2, WHITE); X win_drawpiece(&chessboard->square[7][0], 7, 3, WHITE); X if (!oneboard) { X win_erasepiece(7, 4, BLACK); X win_erasepiece(7, 0, BLACK); X if (win_flashmove) X win_flash(m, BLACK); X win_drawpiece(&m->piece, 7, 2, BLACK); X win_drawpiece(&chessboard->square[7][7], 7, 3, X BLACK); X } X } else { X win_erasepiece(0, 4, WHITE); X win_erasepiece(0, 0, WHITE); X if (win_flashmove) X win_flash(m, WHITE); X win_drawpiece(&m->piece, 0, 2, WHITE); X win_drawpiece(&chessboard->square[0][0], 0, 3, WHITE); X if (!oneboard) { X win_erasepiece(0, 4, BLACK); X win_erasepiece(0, 0, BLACK); X if (win_flashmove) X win_flash(m, BLACK); X win_drawpiece(&m->piece, 0, 2, BLACK); X win_drawpiece(&chessboard->square[0][7], 0, 3, X BLACK); X } X } X break; X X default: X fprintf(stderr, "Bad move type %d\n", m->type); X } X return; X} X X/* Retract the last move made... */ X Xvoid Xreplay() X{ X move *m = lastmove, bm; X X memset(&bm, 0, sizeof(bm)); X switch (m->type) { X case MOVE: X bm.type = MOVE; X bm.piece = m->piece; X bm.fromx = m->tox; X bm.fromy = m->toy; X bm.tox = m->fromx; X bm.toy = m->fromy; X board_move(chessboard, &bm); X screen_move(&bm); X break; X X case CAPTURE: X bm.type = MOVE; X bm.piece = m->piece; X bm.fromx = m->tox; X bm.fromy = m->toy; X bm.tox = m->fromx; X bm.toy = m->fromy; X board_move(chessboard, &bm); X screen_move(&bm); X chessboard->square[m->toy][m->tox] = m->taken; X bm.piece = m->taken; X bm.fromx = bm.tox = m->tox; X bm.fromy = bm.toy = m->toy; X screen_move(&bm); X jail_remove(&m->taken); X break; X X case KCASTLE: X bm.type = MOVE; X bm.piece.type = KING; X bm.piece.color = m->piece.color; X bm.fromx = 6; X bm.tox = 4; X bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0; X board_move(chessboard, &bm); X screen_move(&bm); X bm.type = MOVE; X bm.piece.type = ROOK; X bm.piece.color = m->piece.color; X bm.fromx = 5; X bm.tox = 7; X bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0; X board_move(chessboard, &bm); X screen_move(&bm); X if (m->piece.color == WHITE) X chessboard->white_cant_castle_k = false; X else X chessboard->black_cant_castle_k = false; X break; X X case QCASTLE: X bm.type = MOVE; X bm.piece.type = KING; X bm.piece.color = m->piece.color; X bm.fromx = 2; X bm.tox = 4; X bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0; X board_move(chessboard, &bm); X screen_move(&bm); X bm.type = MOVE; X bm.piece.type = ROOK; X bm.piece.color = m->piece.color; X bm.fromx = 3; X bm.tox = 0; X bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0; X board_move(chessboard, &bm); X screen_move(&bm); X if (m->piece.color == WHITE) X chessboard->white_cant_castle_q = false; X else X chessboard->black_cant_castle_q = false; X break; X } X record_back(); X X nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE); X clock_switch(); X X if (!moves->next) { X moves->next = foremoves; X foremoves = moves; X moves = lastmove = NULL; X } else { X for (m = moves; m->next; m = m->next) X lastmove = m; X lastmove->next->next = foremoves; X foremoves = lastmove->next; X lastmove->next = NULL; X } X X if (progflag) X program_undo(); X X return; X} X X/* Put back the last move undone. */ X Xvoid Xforward() X{ X prog_move(foremoves); X foremoves = foremoves->next; X return; X} X X/* End the game. */ X Xvoid Xcleanup(s) X char *s; X{ X if (progflag) X program_end(); X record_end(s); X XSync(win1->display, 0); X if (!oneboard) { X XSync(win2->display, 0); X } X exit(0); X} X Xvoid Xrestart() X{ X moves = lastmove = thismove = NULL; X nexttomove = WHITE; X X clock_init(win1, WHITE); X clock_init(win1, BLACK); X jail_init(win1); X if (!oneboard) { X clock_init(win2, WHITE); X clock_init(win2, BLACK); X jail_init(win2); X } X board_init(chessboard); X win_restart(); X record_reset(); X if (progflag) { X program_end(); X program_init(progname); X } X return; X} X END_OF_FILE if test 11973 -ne `wc -c <'control.c'`; then echo shar: \"'control.c'\" unpacked with wrong size! fi # end of 'control.c' fi if test -f 'parse.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'parse.c'\" else echo shar: Extracting \"'parse.c'\" \(9117 characters\) sed "s/^X//" >'parse.c' <<'END_OF_FILE' X/* This file contains code for X-CHESS. X Copyright (C) 1986 Free Software Foundation, Inc. X XThis file is part of X-CHESS. X XX-CHESS is distributed in the hope that it will be useful, Xbut WITHOUT ANY WARRANTY. No author or distributor Xaccepts responsibility to anyone for the consequences of using it Xor for whether it serves any particular purpose or works at all, Xunless he says so in writing. Refer to the X-CHESS General Public XLicense for full details. X XEveryone is granted permission to copy, modify and redistribute XX-CHESS, but only under the conditions described in the XX-CHESS General Public License. A copy of this license is Xsupposed to have been given to you along with X-CHESS so you Xcan know your rights and responsibilities. It should be in a Xfile named COPYING. Among other things, the copyright notice Xand this notice must be preserved on all copies. */ X X X/* RCS Info: $Revision: 1.2 $ on $Date: 86/11/23 17:17:59 $ X * $Source: /users/faustus/xchess/RCS/parse.c,v $ X * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group X * Permission is granted to do anything with this code except sell it X * or remove this message. X * X * Parse a sequence of chess moves... X */ X X#include "xchess.h" X Xbool loading_flag = false; Xbool loading_paused = false; X Xstatic char *line; X X/* Load a record file in. This returns a number of things -- the board, the X * list of moves, and whose turn it is. X */ X Xvoid Xload_game(file) X char *file; X{ X FILE *fp; X char buf[BSIZE]; X bool eflag; X move *m; X board *tmpboard = alloc(board); X X if (eq(file, "xchess.game") && saveflag) { X message_add(win1, X "Oops, I just overwrote the\nfile xchess.game...\n", X true); X message_add(win1, "I hope you had another copy.\n", true); X return; X } X if (!(fp = fopen(file, "r"))) { X perror(file); X return; X } X X /* Get a few lines... */ X fgets(buf, BSIZE, fp); X message_add(win1, buf, false); X if (!oneboard) X message_add(win2, buf, false); X X fgets(buf, BSIZE, fp); X message_add(win1, buf, false); X if (!oneboard) X message_add(win2, buf, false); X X fgets(buf, BSIZE, fp); X if (eq(buf, "\tenglish\n")) X eflag = true; X else if (eq(buf, "\talgebraic\n")) X eflag = false; X else { X fprintf(stderr, "Can't decide whether this is english...\n"); X return; X } X X board_init(tmpboard); X line = NULL; X m = parse_file(fp, tmpboard, eflag); X tfree(tmpboard); X X /* Now apply these moves to the board we were given... */ X loading_flag = true; X while (m) { X if (!quickflag) X XSync(win1->display, 0); X win_process(true); X if (!quickflag) X sleep(1); X if (!loading_paused) { X prog_move(m); X m = m->next; X } X } X loading_flag = false; X if (line) X message_add(win1, line, false); X X while (fgets(buf, BSIZE, fp)) X message_add(win1, buf, false); X X fclose(fp); X X return; X} X X/* Given a starting position (usually the beginning board configuration), X * read in a file of moves. X */ X Xmove * Xparse_file(fp, b, english) X FILE *fp; X board *b; X bool english; X{ X move *mvs = NULL, *end = NULL; X char buf[BSIZE], *s, *t; X X while (fgets(buf, BSIZE, fp)) { X if (*buf == '#') X continue; X s = buf; X X /* The move number... */ X if (!(t = gettok(&s))) X break; X if (!isdigit(*t)) { X line = copy(buf); X break; X } X X if (!(t = gettok(&s))) X break; X if (end) X end = end->next = (english ? parse_move(b, t, WHITE) : X parse_imove(b, t, WHITE)); X else X mvs = end = (english ? parse_move(b, t, WHITE) : X parse_imove(b, t, WHITE)); X if (!end) { X fprintf(stderr, "Can't parse %s\n", buf); X return (NULL); X } X board_move(b, end); X X if (!(t = gettok(&s))) X break; X if (end) X end = end->next = (english ? parse_move(b, t, BLACK) : X parse_imove(b, t, BLACK)); X else X mvs = end = (english ? parse_move(b, t, BLACK) : X parse_imove(b, t, BLACK)); X if (!end) { X fprintf(stderr, "Can't parse %s\n", buf); X return (NULL); X } X board_move(b, end); X } X X return (mvs); X} X X/* Parse a move. The move format accepted is as follows - X * move: spec-spec X * capture: specxspec X * kcastle: 2 o's X * qcastle: 3 o's X * A spec is either piece/pos, piece, or just pos. A pos consists of a column X * name followed by a row number. If the column name is kr, kn, kb, k, q, X * qb, qn, or qr, then the row number is according to the english system, X * or if it is a-h then it is according to the international system. X * X *** As of now the spec must include the position. X */ X Xmove * Xparse_move(b, str, w) X board *b; X char *str; X color w; X{ X move *m = alloc(move); X char *s; X char spec1[16], spec2[16]; X int i, j; X Xif (debug) fprintf(stderr, "parsing %s\n", str); X X /* Check for castles. */ X for (s = str, i = 0; *s; s++) X if ((*s == 'o') || (*s == 'O')) X i++; X if (i == 2) { X m->type = KCASTLE; X m->piece.type = KING; X m->piece.color = w; X return (m); X } else if (i == 3) { X m->type = QCASTLE; X m->piece.type = KING; X m->piece.color = w; X return (m); X } X if (index(str, '-')) X m->type = MOVE; X else if (index(str, 'x')) X m->type = CAPTURE; X else X return (NULL); X for (i = 0; str[i]; i++) X if ((str[i] == 'x') || (str[i] == '-')) X break; X else X spec1[i] = str[i]; X spec1[i] = '\0'; X for (i++, j = 0; str[i]; i++, j++) X if ((str[i] == 'x') || (str[i] == '-')) X break; X else X spec2[j] = str[i]; X spec2[j] = '\0'; X X /* Now decode the specifications. */ X s = spec1; X switch (*s) { X case 'p': case 'P': X m->piece.type = PAWN; break; X case 'r': case 'R': X m->piece.type = ROOK; break; X case 'n': case 'N': X m->piece.type = KNIGHT; break; X case 'b': case 'B': X m->piece.type = BISHOP; break; X case 'q': case 'Q': X m->piece.type = QUEEN; break; X case 'k': case 'K': X m->piece.type = KING; break; X default: X return (NULL); X } X m->piece.color = w; X s += 2; X X /* Now get the {q,k}{,b,n,r}n string... */ X if ((s[0] == 'q') && (s[1] == 'r')) X m->fromx = 0, s += 2; X else if ((s[0] == 'q') && (s[1] == 'n')) X m->fromx = 1, s += 2; X else if ((s[0] == 'q') && (s[1] == 'b')) X m->fromx = 2, s += 2; X else if ((s[0] == 'q') && isdigit(s[1])) X m->fromx = 3, s += 1; X else if ((s[0] == 'k') && isdigit(s[1])) X m->fromx = 4, s += 1; X else if ((s[0] == 'k') && (s[1] == 'b')) X m->fromx = 5, s += 2; X else if ((s[0] == 'k') && (s[1] == 'n')) X m->fromx = 6, s += 2; X else if ((s[0] == 'k') && (s[1] == 'r')) X m->fromx = 7, s += 2; X m->fromy = ((w == WHITE) ? (SIZE - atoi(s)) : (atoi(s) - 1)); X X if ((b->square[m->fromy][m->fromx].color != w) || X (b->square[m->fromy][m->fromx].type != m->piece.type)) { X fprintf(stderr, "Error: bad stuff\n"); X return (NULL); X } X X s = spec2; X if (m->type == CAPTURE) { X switch (*s) { X case 'p': case 'P': X m->taken.type = PAWN; break; X case 'r': case 'R': X m->taken.type = ROOK; break; X case 'n': case 'N': X m->taken.type = KNIGHT; break; X case 'b': case 'B': X m->taken.type = BISHOP; break; X case 'q': case 'Q': X m->taken.type = QUEEN; break; X case 'k': case 'K': X m->taken.type = KING; break; X default: X return (NULL); X } X m->taken.color = ((w == WHITE) ? BLACK : WHITE); X s += 2; X } X X /* Now get the {q,k}{,b,n,r}n string... */ X if ((s[0] == 'q') && (s[1] == 'r')) X m->tox = 0, s += 2; X else if ((s[0] == 'q') && (s[1] == 'n')) X m->tox = 1, s += 2; X else if ((s[0] == 'q') && (s[1] == 'b')) X m->tox = 2, s += 2; X else if ((s[0] == 'q') && isdigit(s[1])) X m->tox = 3, s += 1; X else if ((s[0] == 'k') && isdigit(s[1])) X m->tox = 4, s += 1; X else if ((s[0] == 'k') && (s[1] == 'b')) X m->tox = 5, s += 2; X else if ((s[0] == 'k') && (s[1] == 'n')) X m->tox = 6, s += 2; X else if ((s[0] == 'k') && (s[1] == 'r')) X m->tox = 7, s += 2; X m->toy = ((w == WHITE) ? (SIZE - atoi(s)) : (atoi(s) - 1)); X X if ((m->type == CAPTURE) && ((b->square[m->toy][m->tox].color != X m->taken.color) || (b->square[m->toy][m->tox].type != X m->taken.type))) { X fprintf(stderr, "Error: bad stuff\n"); X return (NULL); X } X X return (m); X} X X/* Parse an algebraic notation move. This is a lot easier... */ X Xmove * Xparse_imove(b, buf, w) X board *b; X char *buf; X color w; X{ X char *s; X move *m = alloc(move); X int n; X Xif (debug) fprintf(stderr, "(alg) parsing %s\n", buf); X X for (s = buf, n = 0; *s; s++) X if ((*s == 'o') || (*s == 'O')) X n++; X s = buf; X X if (n == 2) X m->type = KCASTLE; X else if (n == 3) X m->type = QCASTLE; X else { X m->fromx = *s++ - 'a'; X m->fromy = SIZE - (*s++ - '0'); X m->tox = *s++ - 'a'; X m->toy = SIZE - (*s++ - '0'); X m->piece = b->square[m->fromy][m->fromx]; X m->taken = b->square[m->toy][m->tox]; X if (m->taken.color == NONE) X m->type = MOVE; X else X m->type = CAPTURE; X /* for pawns we must account for en passant */ X if (m->piece.type == PAWN) { X if (m->type == MOVE && m->fromx != m->tox) { X m->enpassant = 1; X m->type = CAPTURE; X } X } X } X X if (m->piece.color != w) { X fprintf(stderr, "Error: parse_imove: piece of wrong color!\n"); X return (NULL); X } X if ((m->piece.type == KING) && (m->fromy == m->toy) && (m->fromx == 4) X && (m->tox == 6)) X m->type = KCASTLE; X else if ((m->piece.type == KING) && (m->fromy == m->toy) && X (m->fromx == 4) && (m->tox == 2)) X m->type = QCASTLE; X X return (m); X} X END_OF_FILE if test 9117 -ne `wc -c <'parse.c'`; then echo shar: \"'parse.c'\" unpacked with wrong size! fi # end of 'parse.c' fi if test -f 'popup.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'popup.c'\" else echo shar: Extracting \"'popup.c'\" \(3227 characters\) sed "s/^X//" >'popup.c' <<'END_OF_FILE' X/* This file contains code for X-CHESS. X Copyright (C) 1986 Free Software Foundation, Inc. X XThis file is part of X-CHESS. X XX-CHESS is distributed in the hope that it will be useful, Xbut WITHOUT ANY WARRANTY. No author or distributor Xaccepts responsibility to anyone for the consequences of using it Xor for whether it serves any particular purpose or works at all, Xunless he says so in writing. Refer to the X-CHESS General Public XLicense for full details. X XEveryone is granted permission to copy, modify and redistribute XX-CHESS, but only under the conditions described in the XX-CHESS General Public License. A copy of this license is Xsupposed to have been given to you along with X-CHESS so you Xcan know your rights and responsibilities. It should be in a Xfile named COPYING. Among other things, the copyright notice Xand this notice must be preserved on all copies. */ X X X/* RCS Info: $Revision: 1.2 $ on $Date: 86/11/26 12:10:38 $ X * $Source: /users/faustus/xchess/RCS/popup.c,v $ X * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group X * faustus@cad.berkeley.edu, ucbvax!faustus X * Permission is granted to modify and re-distribute this code in any manner X * as long as this notice is preserved. All standard disclaimers apply. X * X * A simple pop-up menu system. X */ X X#include "xchess.h" X X/* Open a small window with some text in it and two buttons -- yes and no. X * Use black and white pixel, and the medium font. X */ X Xbool Xpop_question(win, text) X windata *win; X char *text; X{ X char *s, *t; X int nlines = 1, ncols = 0, i = 0, j; X int x, y; X Window w; X bool ch; X XEvent ev; X X for (s = text; *s; s++) { X if ((*s == '\n') && s[1]) X nlines++; X if ((*s == '\n') || !s[1]) { X if (i > ncols) X ncols = i; X i = 0; X } else X i++; X } X X if (ncols < 12) X ncols = 12; X nlines += 4; X ncols += 4; X X x = (BASE_WIDTH - ncols * win->medium->max_bounds.width) / 2; X y = (BASE_HEIGHT - nlines * win->medium->max_bounds.ascent) / 2; X X w = XCreateSimpleWindow(win->display, win->basewin, X x, y, ncols * win->medium->max_bounds.width, X nlines * win->medium->ascent, X BORDER_WIDTH, win->border.pixel, X win->textback.pixel); X XMapRaised(win->display, w); X XSetFont(win->display, DefaultGC(win->display, 0), X win->medium->fid); X X for (i = 0, s = text; i < nlines - 4; i++) { X for (t = s, j = 0; *t && (*t != '\n'); t++, j++) X ; X XDrawString(win->display, w, DefaultGC(win->display, 0), X (ncols - j) / 2 * win->medium->max_bounds.width, X (i + 1) * win->medium->ascent, X s, j); X s = t + 1; X } X XDrawString(win->display, w, DefaultGC(win->display, 0), X (ncols - 8) * win->medium->max_bounds.width / 4, X (nlines - 2) * win->medium->ascent, X "YES", 3); X XDrawString(win->display, w, DefaultGC(win->display, 0), X (ncols - 4) * win->medium->max_bounds.width * 3 / 4, X (nlines - 2) * win->medium->ascent, X "NO", 2); X X XSync(win->display, 0); X XSelectInput(win->display, w, ButtonPressMask); X XWindowEvent(win->display, w, ButtonPressMask, &ev); X x = ev.xkey.x; X y = ev.xkey.y; X X if (x > ncols * win->medium->max_bounds.width / 2) X ch = false; X else X ch = true; X X XDestroyWindow(win->display, w); X XSync(win->display, 0); X return (ch); X} X END_OF_FILE if test 3227 -ne `wc -c <'popup.c'`; then echo shar: \"'popup.c'\" unpacked with wrong size! fi # end of 'popup.c' fi if test -f 'record.c.UU' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'record.c.UU'\" else echo shar: Extracting \"'record.c.UU'\" \(9641 characters\) sed "s/^X//" >'record.c.UU' <<'END_OF_FILE' Xbegin 666 record.c XM+RH@5&AI<R!F:6QE(&-O;G1A:6YS(&-O9&4@9F]R(%@M0TA%4U,N"B`@($-O XM<'ER:6=H="`H0RD@,3DX-B!&<F5E(%-O9G1W87)E($9O=6YD871I;VXL($EN XM8RX*"E1H:7,@9FEL92!I<R!P87)T(&]F(%@M0TA%4U,N"@I8+4-(15-3(&ES XM(&1I<W1R:6)U=&5D(&EN('1H92!H;W!E('1H870@:70@=VEL;"!B92!U<V5F XM=6PL"F)U="!7251(3U54($%.62!705)204Y462X@($YO(&%U=&AO<B!O<B!D XM:7-T<FEB=71O<@IA8V-E<'1S(')E<W!O;G-I8FEL:71Y('1O(&%N>6]N92!F XM;W(@=&AE(&-O;G-E<75E;F-E<R!O9B!U<VEN9R!I=`IO<B!F;W(@=VAE=&AE XM<B!I="!S97)V97,@86YY('!A<G1I8W5L87(@<'5R<&]S92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DL('=I;C(M/G)E8W=I;BP@8G5F*3L*"7T*"6EF("AS879E XM9FQA9RD@>PH)"69P<FEN=&8H8F%C:W5P+"`B)7,B+"!B=68I.PH)"69F;'5S XM:"AB86-K=7`I.PH)?0H*"7)E='5R;CL*?0H*=F]I9`IR96-O<F1?8F%C:R@I XM"GL*("`@(&5X=&5R;B!M;W9E("IL87-T;6]V93L*("`@(&UO=F4@*FT@/2!L XM87-T;6]V93L*("`@(&-H87(@*G,@/2!M;W9E<W1R:6YG*&TI.PH@("`@8VAA XM<B!B=69;0E-)6D5=.PH@("`@;&]N9R!I.PH*("`@(&EF("AM+3YP:65C92YC XM;VQO<B`]/2!72$E412D@>PH)<W!R:6YT9BAB=68L("(E,F0N("4M,39S("(L XM(&UO=F5N=6TL(',I.PH@("`@?2!E;'-E('L*"7-P<FEN=&8H8G5F+"`B)7-< XM;B(L(',I.PH@("`@?0H@("`@<R`](&)U9CL*("`@(&9O<B`H:2`](#`[("IS XM("$]("=<,"<[(&DK*RD*"2IS*RL@/2`G""<["0DO*B!C;VYT<F]L($@L(&)A XM8VMS<&%C92`J+PH@("`*("`@(%1X=%=R:71E4W1R*'=I;C$M/F1I<W!L87DL XM('=I;C$M/G)E8W=I;BP@8G5F*3L*("`@(&EF("@A;VYE8F]A<F0I('L*"51X XM=%=R:71E4W1R*'=I;C(M/F1I<W!L87DL('=I;C(M/G)E8W=I;BP@8G5F*3L* XM("`@('T*"B`@("!I9B`H;F5X='1O;6]V92`]/2!"3$%#2RD*"6UO=F5N=6TM XM+3L*("`@(&EF("AS879E9FQA9RD@>PH)9G-E96LH8F%C:W5P+"`M:2P@,2D[ XM"@EF9FQU<V@H8F%C:W5P*3L*("`@('T*"B`@("!R971U<FX["GT*"G-T871I XM8R!C:&%R("H*;6]V97-T<FEN9RAM*0H);6]V92`J;3L*>PH):6YT(&9Y+"!T XM>3L*"7-T871I8R!C:&%R(&)U9EM"4TE:15T["@H):68@*"%R96-O<F1?96YG XM;&ES:"!\?"`H;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AB=68L("(A(2$B*3L*(V5N9&EF('-M87)T87-S"@H)<F5T XM=7)N("AB=68I.PI]"@IS=&%T:6,@8VAA<B`J"G1S=')I;F<H<RD*"6EN="!S XM.PI["@ES=&%T:6,@8VAA<B!B=69;-C1=.PH*"6EF("AS(#X@,S8P,"D*"0ES XM<')I;G1F*&)U9BP@(B5D:"`E9&T@)61S(BP@<R`O(#,V,#`L("AS("4@,S8P XM,"D@+R`V,"P@<R`E(#8P*3L*"65L<V4@:68@*',@/B`V,"D*"0ES<')I;G1F XM*&)U9BP@(B5D;2`E9',B+"`H<R`E(#,V,#`I("\@-C`L(',@)2`V,"D["@EE XM;'-E"@D)<W!R:6YT9BAB=68L("(E9',B+"!S*3L*"7)E='5R;B`H8G5F*3L* X#?0H* X` Xend END_OF_FILE if test 9641 -ne `wc -c <'record.c.UU'`; then echo shar: \"'record.c.UU'\" unpacked with wrong size! fi # end of 'record.c.UU' fi if test -f 'window.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'window.c'\" else echo shar: Extracting \"'window.c'\" \(25887 characters\) sed "s/^X//" >'window.c' <<'END_OF_FILE' X/* This file contains code for X-CHESS. X Copyright (C) 1986 Free Software Foundation, Inc. X XThis file is part of X-CHESS. X XX-CHESS is distributed in the hope that it will be useful, Xbut WITHOUT ANY WARRANTY. No author or distributor Xaccepts responsibility to anyone for the consequences of using it Xor for whether it serves any particular purpose or works at all, Xunless he says so in writing. Refer to the X-CHESS General Public XLicense for full details. X XEveryone is granted permission to copy, modify and redistribute XX-CHESS, but only under the conditions described in the XX-CHESS General Public License. A copy of this license is Xsupposed to have been given to you along with X-CHESS so you Xcan know your rights and responsibilities. It should be in a Xfile named COPYING. Among other things, the copyright notice Xand this notice must be preserved on all copies. */ X X X/* RCS Info: $Revision: 1.5 $ on $Date: 86/11/26 12:11:15 $ X * $Source: /users/faustus/xchess/RCS/window.c,v $ X * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group X * Permission is granted to do anything with this code except sell it X * or remove this message. X * X * Deal with the two (or one) windows. X */ X X#include "xchess.h" X#include <X11/Xutil.h> X#include <sys/time.h> X X#include "pawn.bitmap" X#include "rook.bitmap" X#include "knight.bitmap" X#include "bishop.bitmap" X#include "queen.bitmap" X#include "king.bitmap" X X#include "pawn_outline.bitmap" X#include "rook_outline.bitmap" X#include "knight_outline.bitmap" X#include "bishop_outline.bitmap" X#include "queen_outline.bitmap" X#include "king_outline.bitmap" X X#include "pawn_mask.bitmap" X#include "rook_mask.bitmap" X#include "knight_mask.bitmap" X#include "bishop_mask.bitmap" X#include "queen_mask.bitmap" X#include "king_mask.bitmap" X X#include "shade.bitmap" X X#include "xchess.cur" X#include "xchess_mask.cur" X X#include "xchess.icon" X Xwindata *win1, *win2; Xbool win_flashmove = false; X Xextern bool setup(); Xextern void service(), drawgrid(), icon_refresh(); X Xbool Xwin_setup(disp1, disp2) X char *disp1, *disp2; X{ X win1 = alloc(windata); X if (!oneboard) X win2 = alloc(windata); X X if (!setup(disp1, win1) || (!oneboard && !setup(disp2, win2))) X return (false); X X if (blackflag) { X win1->color = BLACK; X win1->flipped = true; X } else X win1->color = WHITE; X win_drawboard(win1); X X if (!oneboard) { X win2->color = BLACK; X win2->flipped = true; X win_drawboard(win2); X } X X return(true); X} X X/* Draw the chess board... */ X Xvoid Xwin_drawboard(win) X windata *win; X{ X int i, j; X X drawgrid(win); X X /* Now toss on the squares... */ X for (i = 0; i < SIZE; i++) X for (j = 0; j < SIZE; j++) X win_erasepiece(j, i, win->color); X X return; X} X X/* Draw one piece. */ X Xvoid Xwin_drawpiece(p, y, x, wnum) X piece *p; X int y, x; X color wnum; X{ X char *bits, *maskbits, *outline; X windata *win; X char buf[BSIZE]; X XImage *tmpImage; X Pixmap tmpPM, maskPM; X XGCValues gc; X X if (oneboard || (wnum == win1->color)) X win = win1; X else X win = win2; X X if (win->flipped) { X y = SIZE - y - 1; X x = SIZE - x - 1; X } X X /* X if (debug) X fprintf(stderr, "draw a %s at (%d, %d) on board %d\n", X piecenames[(int) p->type], y, x, wnum); X */ X X if ((x < 0) || (x > 7) || (y < 0) || (y > 7)) exit(1); X X switch (p->type) { X case PAWN: X bits = pawn_bits; X maskbits = pawn_mask_bits; X outline = pawn_outline_bits; X break; X X case ROOK: X bits = rook_bits; X maskbits = rook_mask_bits; X outline = rook_outline_bits; X break; X X case KNIGHT: X bits = knight_bits; X maskbits = knight_mask_bits; X outline = knight_outline_bits; X break; X X case BISHOP: X bits = bishop_bits; X maskbits = bishop_mask_bits; X outline = bishop_outline_bits; X break; X X case QUEEN: X bits = queen_bits; X maskbits = queen_mask_bits; X outline = queen_outline_bits; X break; X X case KING: X bits = king_bits; X maskbits = king_mask_bits; X outline = king_outline_bits; X break; X X default: X fprintf(stderr, X "Internal Error: win_drawpiece: bad piece type %d\n", X p->type); X } X X /* There are two things we can do... If this is a black and white X * display, we have to shade the square and use an outline if the piece X * is white. We also have to use a mask... Since we don't want X * to use up too many bitmaps, create the mask bitmap, put the bits, X * and then destroy it. X */ X if (win->bnw && (p->color == WHITE)) X bits = outline; X if (win->bnw && !iswhite(win, x, y)) { X XSetState(win->display, DefaultGC(win->display, 0), X BlackPixel(win->display, 0), X WhitePixel(win->display, 0), GXcopy, AllPlanes); X X tmpPM = XCreateBitmapFromData(win->display, win->boardwin, X shade_bits, SQUARE_WIDTH, SQUARE_HEIGHT); X X XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), X 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, X x * (SQUARE_WIDTH + BORDER_WIDTH), X y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); X X XFreePixmap(win->display, tmpPM); X X XSetFunction(win->display, DefaultGC(win->display, 0), X GXandInverted); X maskPM = XCreateBitmapFromData(win->display, win->boardwin, X maskbits, SQUARE_WIDTH, SQUARE_HEIGHT); X XCopyPlane(win->display, maskPM, win->boardwin, DefaultGC(win->display, 0), X 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, X x * (SQUARE_WIDTH + BORDER_WIDTH), X y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); X XFreePixmap(win->display, maskPM); X X XSetFunction(win->display, DefaultGC(win->display, 0), X GXor); X tmpPM = XCreateBitmapFromData(win->display, win->boardwin, X bits, SQUARE_WIDTH, SQUARE_HEIGHT); X XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), X 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, X x * (SQUARE_WIDTH + BORDER_WIDTH), X y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); X XFreePixmap(win->display, tmpPM); X X XSetFunction(win->display, DefaultGC(win->display, 0), GXcopy); X X } else if (win->bnw){ X XSetState(win->display, DefaultGC(win->display, 0), X BlackPixel(win->display, 0), X WhitePixel(win->display, 0), GXcopy, AllPlanes); X X tmpPM = XCreateBitmapFromData(win->display, win->boardwin, X bits, SQUARE_WIDTH, SQUARE_HEIGHT); X XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), X 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, X x * (SQUARE_WIDTH + BORDER_WIDTH), X y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); X XFreePixmap(win->display, tmpPM); X } else { X XSetState(win->display, DefaultGC(win->display, 0), X ((p->color == WHITE) ? win->whitepiece.pixel : X win->blackpiece.pixel), X (iswhite(win, x, y) ? win->whitesquare.pixel : X win->blacksquare.pixel), X GXcopy, AllPlanes); X tmpPM = XCreateBitmapFromData(win->display, win->boardwin, X bits, SQUARE_WIDTH, SQUARE_HEIGHT); X XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), X 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, X x * (SQUARE_WIDTH + BORDER_WIDTH), X y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); X XFreePixmap(win->display, tmpPM); X } X X if (!record_english) { X gc.foreground = win->textcolor.pixel; X if (iswhite(win, x, y) || win->bnw) X gc.background = win->whitesquare.pixel; X else X gc.background = win->blacksquare.pixel; X X gc.font = win->small->fid; X X XChangeGC(win->display, DefaultGC(win->display, 0), X GCForeground | GCBackground | GCFont, &gc); X X if (!x) { X sprintf(buf, " %d", SIZE - y); X XDrawImageString(win->display, win->boardwin, X DefaultGC(win->display, 0), X 1, (y + 1) * (SQUARE_HEIGHT + X BORDER_WIDTH) - BORDER_WIDTH + X win->small->max_bounds.ascent - 1, buf, 2); X } X if (y == SIZE - 1) { X sprintf(buf, "%c", 'A' + x); X XDrawImageString(win->display, win->boardwin, X DefaultGC(win->display, 0), X x * (SQUARE_WIDTH + BORDER_WIDTH) + 1, X SIZE * (SQUARE_HEIGHT + BORDER_WIDTH) - BORDER_WIDTH + X win->small->max_bounds.ascent - 1, buf, 1); X } X } X return; X} X Xvoid Xwin_erasepiece(y, x, wnum) X int y, x; X color wnum; X{ X windata *win; X char buf[BSIZE]; X XGCValues gc; X Pixmap tmpPM; X X if (oneboard || (wnum == win1->color)) X win = win1; X else X win = win2; X X if (win->flipped) { X y = SIZE - y - 1; X x = SIZE - x - 1; X } X X /* X if (debug) X fprintf(stderr, "erase square (%d, %d) on board %d\n", y, x, X wnum); X */ X X if ((x < 0) || (x > 7) || (y < 0) || (y > 7)) exit(1); X X if (win->bnw && !iswhite(win, x, y)) { X XSetState(win->display, DefaultGC(win->display, 0), X BlackPixel(win->display, 0), X WhitePixel(win->display, 0), GXcopy, AllPlanes); X tmpPM = XCreateBitmapFromData(win->display, win->boardwin, X shade_bits, SQUARE_WIDTH, SQUARE_HEIGHT); X X XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), X 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, X x * (SQUARE_WIDTH + BORDER_WIDTH), X y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); X X XFreePixmap(win->display, tmpPM); X } else { X XSetFillStyle(win->display, DefaultGC(win->display, 0), X FillSolid); X XSetForeground(win->display, DefaultGC(win->display, 0), X iswhite(win, x, y) ? win->whitesquare.pixel : X win->blacksquare.pixel); X XFillRectangle(win->display, win->boardwin, X DefaultGC(win->display, 0), X x * (SQUARE_WIDTH + BORDER_WIDTH), X y * (SQUARE_HEIGHT + BORDER_WIDTH), X SQUARE_WIDTH, SQUARE_HEIGHT); X } X X if (!record_english) { X gc.foreground = win->textcolor.pixel; X if (iswhite(win, x, y) || win->bnw) X gc.background = win->whitesquare.pixel; X else X gc.background = win->blacksquare.pixel; X X gc.font = win->small->fid; X X XChangeGC(win->display, DefaultGC(win->display, 0), X GCForeground | GCBackground | GCFont, &gc); X X if (!x) { X sprintf(buf, " %d", SIZE - y); X XDrawImageString(win->display, win->boardwin, X DefaultGC(win->display, 0), X 1, (y + 1) * (SQUARE_HEIGHT + X BORDER_WIDTH) - BORDER_WIDTH + X win->small->max_bounds.ascent - 1, buf, 2); X } X if (y == SIZE - 1) { X sprintf(buf, "%c", 'A' + x); X XDrawImageString(win->display, win->boardwin, X DefaultGC(win->display, 0), X x * (SQUARE_WIDTH + BORDER_WIDTH) + 1, X SIZE * (SQUARE_HEIGHT + BORDER_WIDTH) - BORDER_WIDTH + X win->small->max_bounds.ascent - 1, buf, 1); X } X } X X X return; X} X Xvoid Xwin_flash(m, wnum) X move *m; X color wnum; X{ X windata *win; X int sx, sy, ex, ey, i; X X if (oneboard || (wnum == win1->color)) X win = win1; X else X win = win2; X X if (win->flipped) { X sx = SIZE - m->fromx - 1; X sy = SIZE - m->fromy - 1; X ex = SIZE - m->tox - 1; X ey = SIZE - m->toy - 1; X } else { X sx = m->fromx; X sy = m->fromy; X ex = m->tox; X ey = m->toy; X } X sx = sx * (SQUARE_WIDTH + BORDER_WIDTH) + SQUARE_WIDTH / 2; X sy = sy * (SQUARE_HEIGHT + BORDER_WIDTH) + SQUARE_HEIGHT / 2; X ex = ex * (SQUARE_WIDTH + BORDER_WIDTH) + SQUARE_WIDTH / 2; X ey = ey * (SQUARE_HEIGHT + BORDER_WIDTH) + SQUARE_HEIGHT / 2; X X XSetFunction(win->display, DefaultGC(win->display, 0), GXinvert); X XSetLineAttributes(win->display, DefaultGC(win->display, 0), X 0, LineSolid, 0, 0); X for (i = 0; i < num_flashes * 2; i++) { X XDrawLine(win->display,win->boardwin, X DefaultGC(win->display, 0), X sx, sy, ex, ey); X } X X XSetFunction(win->display, DefaultGC(win->display, 0), GXcopy); X return; X} X X/* Handle input from the players. */ X Xvoid Xwin_process(quick) X bool quick; X{ X int i, rfd = 0, wfd = 0, xfd = 0; X struct timeval timeout; X X timeout.tv_sec = 0; X timeout.tv_usec = (quick ? 0 : 500000); X X if (XPending(win1->display)) X service(win1); X if (!oneboard) { X if (XPending(win1->display)) X service(win2); X } X X if (oneboard) X rfd = 1 << win1->display->fd; X else X rfd = (1 << win1->display->fd) | (1 << win2->display->fd); X if (!(i = select(32, &rfd, &wfd, &xfd, &timeout))) X return; X if (i == -1) { X perror("select"); X exit(1); X } X if (rfd & (1 << win1->display->fd)) X service(win1); X if (!oneboard && (rfd & (1 << win2->display->fd))) X service(win2); X X return; X} X Xstatic void Xservice(win) X windata *win; X{ X XEvent ev; X X while(XPending(win->display)) { X XNextEvent(win->display, &ev); X if (TxtFilter(win->display, &ev)) X continue; X X if (ev.xany.window == win->boardwin) { X switch (ev.type) { X case ButtonPress: X button_pressed(&ev, win); X break; X X case ButtonRelease: X button_released(&ev, win); X break; X X case Expose: X /* Redraw... */ X win_redraw(win, &ev); X break; X X case 0: X case NoExpose: X break; X default: X fprintf(stderr, "Bad event type %d\n", ev.type); X exit(1); X } X } else if (ev.xany.window == win->wclockwin) { X switch (ev.type) { X case Expose: X clock_draw(win, WHITE); X break; X X case 0: X case NoExpose: X break; X default: X fprintf(stderr, "Bad event type %d\n", ev.type); X exit(1); X } X } else if (ev.xany.window == win->bclockwin) { X switch (ev.type) { X case Expose: X clock_draw(win, BLACK); X break; X X case 0: X case NoExpose: X break; X default: X fprintf(stderr, "Bad event type %d\n", ev.type); X exit(1); X } X } else if (ev.xany.window == win->jailwin) { X switch (ev.type) { X case Expose: X jail_draw(win); X break; X X case 0: X case NoExpose: X break; X default: X fprintf(stderr, "Bad event type %d\n", ev.type); X exit(1); X } X } else if (ev.xany.window == win->buttonwin) { X switch (ev.type) { X case ButtonPress: X button_service(win, &ev); X break; X X case Expose: X button_draw(win); X break; X X case 0: X case NoExpose: X break; X default: X fprintf(stderr, "Bad event type %d\n", ev.type); X exit(1); X } X } else if (ev.xany.window == win->icon) { X icon_refresh(win); X } else if (ev.xany.window == win->basewin) { X message_send(win, &ev); X } else { X fprintf(stderr, "Internal Error: service: bad win\n"); X fprintf(stderr, "window = %d, event = %d\n", ev.xany.window, X ev.type); X } X } X return; X} X Xvoid Xwin_redraw(win, event) X windata *win; X XEvent *event; X{ X XExposeEvent *ev = &event->xexpose; X int x1, y1, x2, y2, i, j; X X drawgrid(win); X if (ev) { X x1 = ev->x / (SQUARE_WIDTH + BORDER_WIDTH); X y1 = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH); X x2 = (ev->x + ev->width) / (SQUARE_WIDTH + BORDER_WIDTH); X y2 = (ev->y + ev->height) / (SQUARE_HEIGHT + BORDER_WIDTH); X } else { X x1 = 0; X y1 = 0; X x2 = SIZE - 1; X y2 = SIZE - 1; X } X X if (x1 < 0) x1 = 0; X if (y1 < 0) y1 = 0; X if (x2 < 0) x2 = 0; X if (y2 < 0) y2 = 0; X if (x1 > SIZE - 1) x1 = SIZE - 1; X if (y1 > SIZE - 1) y1 = SIZE - 1; X if (x2 > SIZE - 1) x2 = SIZE - 1; X if (y2 > SIZE - 1) y2 = SIZE - 1; X X if (win->flipped) { X y1 = SIZE - y2 - 1; X y2 = SIZE - y1 - 1; X x1 = SIZE - x2 - 1; X x2 = SIZE - x1 - 1; X } X X for (i = x1; i <= x2; i++) X for (j = y1; j <= y2; j++) { X if (chessboard->square[j][i].color == NONE) X win_erasepiece(j, i, WHITE); X else X win_drawpiece(&chessboard->square[j][i], j, i, X WHITE); X if (!oneboard) { X if (chessboard->square[j][i].color == NONE) X win_erasepiece(j, i, BLACK); X else X win_drawpiece(&chessboard->square[j][i], X j, i, BLACK); X } X } X X return; X} X Xstatic bool Xsetup(dispname, win) X char *dispname; X windata *win; X{ X char buf[BSIZE], *s; X Pixmap bm, bmask; X Cursor cur; X extern char *program, *recfile; X XSizeHints xsizes; X X X if (!(win->display = XOpenDisplay(dispname))) X return (false); X X X /* Now get boolean defaults... */ X if ((s = XGetDefault(win->display, program, "noisy")) && eq(s, "on")) X noisyflag = true; X if ((s = XGetDefault(win->display, program, "savemoves")) && eq(s, "on")) X saveflag = true; X if ((s = XGetDefault(win->display, program, "algebraic")) && eq(s, "on")) X record_english = false; X if ((s = XGetDefault(win->display, program, "blackandwhite")) && eq(s, "on")) X bnwflag = true; X if ((s = XGetDefault(win->display, program, "quickrestore")) && eq(s, "on")) X quickflag = true; X if ((s = XGetDefault(win->display, program, "flash")) && eq(s, "on")) X win_flashmove = true; X X /* ... numeric variables ... */ X if (s = XGetDefault(win->display, program, "numflashes")) X num_flashes = atoi(s); X if (s = XGetDefault(win->display, program, "flashsize")) X flash_size = atoi(s); X X /* ... and strings. */ X if (s = XGetDefault(win->display, program, "progname")) X progname = s; X if (s = XGetDefault(win->display, program, "proghost")) X proghost = s; X if (s = XGetDefault(win->display, program, "recordfile")) X recfile = s; X if (s = XGetDefault(win->display, program, "blackpiece")) X black_piece_color = s; X if (s = XGetDefault(win->display, program, "whitepiece")) X white_piece_color = s; X if (s = XGetDefault(win->display, program, "blacksquare")) X black_square_color = s; X if (s = XGetDefault(win->display, program, "whitesquare")) X white_square_color = s; X if (s = XGetDefault(win->display, program, "bordercolor")) X border_color = s; X if (s = XGetDefault(win->display, program, "textcolor")) X text_color = s; X if (s = XGetDefault(win->display, program, "textback")) X text_back = s; X if (s = XGetDefault(win->display, program, "errortext")) X error_text = s; X if (s = XGetDefault(win->display, program, "playertext")) X player_text = s; X if (s = XGetDefault(win->display, program, "cursorcolor")) X cursor_color = s; X X if ((DisplayPlanes(win->display, 0) == 1) || bnwflag) X win->bnw = true; X X /* Allocate colors... */ X if (win->bnw) { X win->blackpiece.pixel = BlackPixel (win->display, 0); X win->whitepiece.pixel = WhitePixel (win->display, 0); X win->blacksquare.pixel = BlackPixel (win->display, 0); X win->whitesquare.pixel = WhitePixel (win->display, 0); X win->border.pixel = BlackPixel (win->display, 0); X win->textcolor.pixel = BlackPixel (win->display, 0); X win->textback.pixel = WhitePixel (win->display, 0); X win->playertext.pixel = BlackPixel (win->display, 0); X win->errortext.pixel = BlackPixel (win->display, 0); X win->cursorcolor.pixel = BlackPixel (win->display, 0) ; X } else { X if (!XParseColor(win->display, X DefaultColormap(win->display, 0), X black_piece_color, &win->blackpiece) || X !XParseColor(win->display, X DefaultColormap(win->display, 0), X white_piece_color, &win->whitepiece) || X !XParseColor(win->display, X DefaultColormap(win->display, 0), X black_square_color, &win->blacksquare) || X !XParseColor(win->display, X DefaultColormap(win->display, 0), X white_square_color, &win->whitesquare) || X !XParseColor(win->display, X DefaultColormap(win->display, 0), X border_color, &win->border) || X !XParseColor(win->display, X DefaultColormap(win->display, 0), X text_color, &win->textcolor) || X !XParseColor(win->display, X DefaultColormap(win->display, 0), X text_back, &win->textback) || X !XParseColor(win->display, X DefaultColormap(win->display, 0), X error_text, &win->errortext) || X !XParseColor(win->display, X DefaultColormap(win->display, 0), X player_text, &win->playertext) || X !XParseColor(win->display, X DefaultColormap(win->display, 0), X cursor_color, &win->cursorcolor) || X !XAllocColor(win->display, X DefaultColormap(win->display, 0), X &win->blackpiece) || X !XAllocColor(win->display, X DefaultColormap(win->display, 0), X &win->whitepiece) || X !XAllocColor(win->display, X DefaultColormap(win->display, 0), X &win->blacksquare) || X !XAllocColor(win->display, X DefaultColormap(win->display, 0), X &win->whitesquare) || X !XAllocColor(win->display, X DefaultColormap(win->display, 0), X &win->border) || X !XAllocColor(win->display, X DefaultColormap(win->display, 0), X &win->textcolor) || X !XAllocColor(win->display, X DefaultColormap(win->display, 0), X &win->textback) || X !XAllocColor(win->display, X DefaultColormap(win->display, 0), X &win->errortext) || X !XAllocColor(win->display, X DefaultColormap(win->display, 0), X &win->playertext) || X !XAllocColor(win->display, X DefaultColormap(win->display, 0), X &win->cursorcolor)) X fprintf(stderr, "Can't get colors...\n"); X } X X /* Get fonts... */ X if ((win->small = XLoadQueryFont(win->display,SMALL_FONT)) == X NULL) X fprintf(stderr, "Can't get small font...\n"); X X if ((win->medium = XLoadQueryFont(win->display,MEDIUM_FONT)) X == NULL) X fprintf(stderr, "Can't get medium font...\n"); X X if ((win->large = XLoadQueryFont(win->display,LARGE_FONT)) == X NULL) X fprintf(stderr, "Can't get large font...\n"); X X X /* Create the windows... */ X X win->basewin = X XCreateSimpleWindow(win->display,DefaultRootWindow(win->display), X BASE_XPOS, BASE_YPOS, X BASE_WIDTH, BASE_HEIGHT, 0, X BlackPixel(win->display, 0), X WhitePixel(win->display, 0)); X win->boardwin = XCreateSimpleWindow(win->display,win->basewin, X BOARD_XPOS, BOARD_YPOS, X BOARD_WIDTH, BOARD_HEIGHT, X BORDER_WIDTH, X win->border.pixel, X WhitePixel(win->display, 0)); X win->recwin = XCreateSimpleWindow(win->display,win->basewin, X RECORD_XPOS, RECORD_YPOS, X RECORD_WIDTH, RECORD_HEIGHT, X BORDER_WIDTH, win->border.pixel, X win->textback.pixel); X win->jailwin = XCreateSimpleWindow(win->display,win->basewin, X JAIL_XPOS, JAIL_YPOS, X JAIL_WIDTH, JAIL_HEIGHT, X BORDER_WIDTH, X win->border.pixel, X win->textback.pixel); X win->wclockwin = XCreateSimpleWindow(win->display,win->basewin, X WCLOCK_XPOS, WCLOCK_YPOS, X CLOCK_WIDTH, CLOCK_HEIGHT, X BORDER_WIDTH, win->border.pixel, X win->textback.pixel); X win->bclockwin = XCreateSimpleWindow(win->display,win->basewin, X BCLOCK_XPOS, BCLOCK_YPOS, X CLOCK_WIDTH, CLOCK_HEIGHT, X BORDER_WIDTH, win->border.pixel, X win->textback.pixel); X win->messagewin = XCreateSimpleWindow(win->display,win->basewin, X MESS_XPOS, MESS_YPOS, X MESS_WIDTH, MESS_HEIGHT, X BORDER_WIDTH, win->border.pixel, X win->textback.pixel); X win->buttonwin = XCreateSimpleWindow(win->display,win->basewin, X BUTTON_XPOS, BUTTON_YPOS, X BUTTON_WIDTH, BUTTON_HEIGHT, X BORDER_WIDTH, win->border.pixel, X win->textback.pixel); X X /* Let's define an icon... */ X win->iconpixmap = XCreatePixmapFromBitmapData(win->display, X win->basewin, icon_bits, X icon_width, icon_height, X win->blacksquare.pixel, X win->whitesquare.pixel, X 1); X xsizes.flags = PSize | PMinSize | PPosition; X xsizes.min_width = BASE_WIDTH; X xsizes.min_height = BASE_HEIGHT; X xsizes.x = BASE_XPOS; X xsizes.y = BASE_YPOS; X XSetStandardProperties(win->display, win->basewin, X program, program, win->iconpixmap, X 0, NULL, &xsizes); X X bm = XCreateBitmapFromData(win->display, X win->basewin, xchess_bits, X xchess_width, xchess_height); X bmask = XCreateBitmapFromData(win->display, X win->basewin, xchess_mask_bits, X xchess_width, xchess_height); X cur = XCreatePixmapCursor(win->display, bm, bmask, X &win->cursorcolor, X &WhitePixel(win->display, 0), X xchess_x_hot, xchess_y_hot); X XFreePixmap(win->display, bm); X XFreePixmap(win->display, bmask); X X XDefineCursor(win->display,win->basewin, cur); X X XMapSubwindows(win->display,win->basewin); X XMapRaised(win->display,win->basewin); X X XSelectInput(win->display,win->basewin, KeyPressMask); X XSelectInput(win->display,win->boardwin, X ButtonPressMask | ButtonReleaseMask | ExposureMask); X XSelectInput(win->display,win->recwin, X ButtonReleaseMask | ExposureMask); X XSelectInput(win->display,win->jailwin, ExposureMask); X XSelectInput(win->display,win->wclockwin, ExposureMask); X XSelectInput(win->display,win->bclockwin, ExposureMask); X XSelectInput(win->display,win->messagewin, X ButtonReleaseMask | ExposureMask); X XSelectInput(win->display,win->buttonwin, X ButtonPressMask | ExposureMask); X X message_init(win); X record_init(win); X button_draw(win); X jail_init(win); X clock_init(win, WHITE); X clock_init(win, BLACK); X if (timeunit) { X if (timeunit > 1800) X sprintf(buf, "%d moves every %.2lg hours.\n", X movesperunit, ((double) timeunit) / 3600); X else if (timeunit > 30) X sprintf(buf, "%d moves every %.2lg minutes.\n", X movesperunit, ((double) timeunit) / 60); X else X sprintf(buf, "%d moves every %d seconds.\n", X movesperunit, timeunit); X message_add(win, buf, false); X } X return (true); X} X Xstatic void Xdrawgrid(win) X windata *win; X{ X int i; X XGCValues gc; X X gc.function = GXcopy; X gc.plane_mask = AllPlanes; X gc.foreground = win->border.pixel; X gc.line_width = 0; X gc.line_style = LineSolid; X X XChangeGC(win->display, X DefaultGC(win->display, 0), X GCFunction | GCPlaneMask | GCForeground | X GCLineWidth | GCLineStyle, &gc); X X /* Draw the lines... horizontal, */ X for (i = 1; i < SIZE; i++) X XDrawLine(win->display, win->boardwin, X DefaultGC(win->display, 0), 0, X i * (SQUARE_WIDTH + BORDER_WIDTH) - X BORDER_WIDTH / 2, X SIZE * (SQUARE_WIDTH + BORDER_WIDTH), X i * (SQUARE_WIDTH + BORDER_WIDTH) - X BORDER_WIDTH / 2); X X /* and vertical... */ X for (i = 1; i < SIZE; i++) X XDrawLine(win->display, win->boardwin, X DefaultGC(win->display, 0), X i * (SQUARE_WIDTH + BORDER_WIDTH) - X BORDER_WIDTH / 2, 0, X i * (SQUARE_WIDTH + BORDER_WIDTH) - X BORDER_WIDTH / 2, X SIZE * (SQUARE_WIDTH + BORDER_WIDTH)); X return; X} X Xvoid Xwin_restart() X{ X win1->flipped = false; X win_redraw(win1, (XEvent *) NULL); X if (!oneboard) { X win2->flipped = true; X win_redraw(win2, (XEvent *) NULL); X } X return; X} X Xstatic void Xicon_refresh(win) X windata *win; X{ X XCopyArea(win->display, win->iconpixmap, win->icon, X DefaultGC(win->display, 0), X 0, 0, icon_width, icon_height, 0, 0); X return; X} X END_OF_FILE if test 25887 -ne `wc -c <'window.c'`; then echo shar: \"'window.c'\" unpacked with wrong size! fi # end of 'window.c' fi echo shar: End of archive 2 \(of 6\). cp /dev/null ark2isdone MISSING="" for I in 1 2 3 4 5 6 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 6 archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- Mike Wexler(wyse!mikew) Phone: (408)433-1000 x1330 Moderator of comp.sources.x