home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume3 / xchess / part01 next >
Internet Message Format  |  1988-01-18  |  62KB

  1. Path: uunet!tektronix!tekgen!tekred!games-request
  2. From: games-request@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v03i042:  xchess - chess display program using X windows, Part01/06
  5. Message-ID: <2058@tekred.TEK.COM>
  6. Date: 18 Jan 88 17:04:37 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 2386
  9. Approved: billr@tekred.TEK.COM
  10.  
  11. Submitted by: faustus@ic.berkeley.edu (Wayne A. Christopher)
  12. Comp.sources.games: Volume 3, Issue 42
  13. Archive-name: xchess/Part01
  14.  
  15.     [This is a display program for chess programs (similar to
  16.      chesstool on the Suns).  This will work with the recently
  17.      posted gnuchess program, for example, on a X.10 system.
  18.      I have corresponded with the author and he indicated that he
  19.      hasn't made any recent changes and that I had his permission
  20.      to post it here.    -br]
  21.  
  22. #! /bin/sh
  23.  
  24. # This is a shell archive.  Remove anything before this line, then unpack
  25. # it by saving it into a file and typing "sh file".  To overwrite existing
  26. # files, type "sh file -c".  You can also feed this as standard input via
  27. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  28. # will see the following message at the end:
  29. #        "End of archive 1 (of 6)."
  30. # Contents:  README MANIFEST control.c parse.c scrollText
  31. #   scrollText/Makefile scrollText/codeview.c window.c
  32. # Wrapped by billr@tekred on Mon Jan 18 08:48:05 1988
  33. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  34. if test -f README -a "${1}" != "-c" ; then 
  35.   echo shar: Will not over-write existing file \"README\"
  36. else
  37. echo shar: Extracting \"README\" \(599 characters\)
  38. sed "s/^X//" >README <<'END_OF_README'
  39. XXchess is a chess display program which allows players to play a game on either
  40. Xone or two displays, or play a chess-playing program.  It uses the X
  41. Xwindow system.  If one or no display names are given, it will open up one
  42. Xwindow and both black and white at the same board.  If two displays are
  43. Xgiven, xchess will accept moves from each player in his turn.  Black's
  44. Xboard will be drawn with his pieces at the bottom.  xchess will not
  45. Xallow a player to make an illegal move.  It accepts all legal moves,
  46. Xincluding castling and pawn capture en passant.
  47. X
  48. XWayne A. Christopher (faustus@ic.berkeley.edu)
  49. END_OF_README
  50. if test 599 -ne `wc -c <README`; then
  51.     echo shar: \"README\" unpacked with wrong size!
  52. fi
  53. # end of overwriting check
  54. fi
  55. if test -f MANIFEST -a "${1}" != "-c" ; then 
  56.   echo shar: Will not over-write existing file \"MANIFEST\"
  57. else
  58. echo shar: Extracting \"MANIFEST\" \(2051 characters\)
  59. sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
  60. X   File Name        Archive #    Description
  61. X-----------------------------------------------------------
  62. X COPYING                   3    
  63. X MANIFEST                  1    
  64. X MANIFEST.BAK              6    
  65. X Makefile                  6    
  66. X README                    1    
  67. X XCircle.c                 6    
  68. X bishop.bitmap             5    
  69. X bishop_mask.bitmap        5    
  70. X bishop_outline.bitmap     4    
  71. X bishop_small.bitmap       6    
  72. X bishop_small_outline.bitmap 6    
  73. X board.c                   4    
  74. X button.c                  3    
  75. X clock.c                   4    
  76. X control.c                 1    
  77. X jail.c                    3    
  78. X king.bitmap               5    
  79. X king_mask.bitmap          5    
  80. X king_outline.bitmap       4    
  81. X king_small.bitmap         6    
  82. X king_small_outline.bitmap 6    
  83. X knight.bitmap             5    
  84. X knight_mask.bitmap        4    
  85. X knight_outline.bitmap     4    
  86. X knight_small.bitmap       6    
  87. X knight_small_outline.bitmap 6    
  88. X message.c                 6    
  89. X parse.c                   1    
  90. X pawn.bitmap               5    
  91. X pawn_mask.bitmap          5    
  92. X pawn_outline.bitmap       4    
  93. X pawn_small.bitmap         6    
  94. X pawn_small_outline.bitmap 6    
  95. X popup.c                   6    
  96. X program.c                 6    
  97. X queen.bitmap              5    
  98. X queen_mask.bitmap         5    
  99. X queen_outline.bitmap      4    
  100. X queen_small.bitmap        6    
  101. X queen_small_outline.bitmap 6    
  102. X record.c                  3    
  103. X rook.bitmap               5    
  104. X rook_mask.bitmap          5    
  105. X rook_outline.bitmap       4    
  106. X rook_small.bitmap         6    
  107. X rook_small_outline.bitmap 6    
  108. X scrollText                1    
  109. X scrollText/Makefile       1    
  110. X scrollText/codeview.1     5    
  111. X scrollText/codeview.c     1    
  112. X scrollText/scrollText.3   3    
  113. X scrollText/scrollText.c   2    
  114. X scrollText/scrollText.h   6    
  115. X scrollText/st.h           6    
  116. X shade.bitmap              5    
  117. X std.c                     3    
  118. X std.h                     6    
  119. X valid.c                   3    
  120. X window.c                  1    
  121. X xchess.1                  4    
  122. X xchess.c                  4    
  123. X xchess.cur                2    
  124. X xchess.h                  3    
  125. X xchess.icon               6    
  126. X xchess_mask.cur           4    
  127. END_OF_MANIFEST
  128. if test 2051 -ne `wc -c <MANIFEST`; then
  129.     echo shar: \"MANIFEST\" unpacked with wrong size!
  130. fi
  131. # end of overwriting check
  132. fi
  133. if test -f control.c -a "${1}" != "-c" ; then 
  134.   echo shar: Will not over-write existing file \"control.c\"
  135. else
  136. echo shar: Extracting \"control.c\" \(11864 characters\)
  137. sed "s/^X//" >control.c <<'END_OF_control.c'
  138. X/* This file contains code for X-CHESS.
  139. X   Copyright (C) 1986 Free Software Foundation, Inc.
  140. X
  141. XThis file is part of X-CHESS.
  142. X
  143. XX-CHESS is distributed in the hope that it will be useful,
  144. Xbut WITHOUT ANY WARRANTY.  No author or distributor
  145. Xaccepts responsibility to anyone for the consequences of using it
  146. Xor for whether it serves any particular purpose or works at all,
  147. Xunless he says so in writing.  Refer to the X-CHESS General Public
  148. XLicense for full details.
  149. X
  150. XEveryone is granted permission to copy, modify and redistribute
  151. XX-CHESS, but only under the conditions described in the
  152. XX-CHESS General Public License.   A copy of this license is
  153. Xsupposed to have been given to you along with X-CHESS so you
  154. Xcan know your rights and responsibilities.  It should be in a
  155. Xfile named COPYING.  Among other things, the copyright notice
  156. Xand this notice must be preserved on all copies.  */
  157. X
  158. X
  159. X/* RCS Info: $Revision: 1.4 $ on $Date: 86/11/23 17:17:32 $
  160. X *           $Source: /users/faustus/xchess/RCS/control.c,v $
  161. X * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
  162. X *    Permission is granted to do anything with this code except sell it
  163. X *    or remove this message.
  164. X *
  165. X * Deal with input from the user.
  166. X */
  167. X
  168. X#include "xchess.h"
  169. X
  170. Xmove *moves;
  171. Xmove *foremoves;
  172. Xcolor nexttomove = WHITE;
  173. Xbool noisyflag = false;
  174. X
  175. Xstatic move *lastmove;
  176. Xstatic move *thismove;
  177. X
  178. Xstatic void screen_move();
  179. X
  180. Xvoid
  181. Xbutton_pressed(event, win)
  182. X    XEvent *event;
  183. X    windata *win;
  184. X{
  185. X    int x, y;
  186. X    XKeyOrButtonEvent *ev = (XKeyOrButtonEvent *) event;
  187. X
  188. X    if (!oneboard && (win->color != nexttomove)) {
  189. X        message_add(win, "Wrong player!\n", true);
  190. X        return;
  191. X    }
  192. X    if (progflag && (nexttomove == (blackflag ? WHITE : BLACK))) {
  193. X        message_add(win, "Wait for the computer...\n", true);
  194. X        return;
  195. X    }
  196. X    if (loading_flag) {
  197. X        message_add(win, "You'd better not do that now...\n", true);
  198. X        return;
  199. X    }
  200. X
  201. X    /* Figure out what piece he is pointing at. */
  202. X    x = ev->x / (SQUARE_WIDTH + BORDER_WIDTH);
  203. X    y = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH);
  204. X
  205. X    if (win->flipped) {
  206. X        y = SIZE - y - 1;
  207. X        x = SIZE - x - 1;
  208. X    }
  209. X
  210. X    if ((x < 0) || (x >= SIZE) || (y < 0) || (y >= SIZE)) {
  211. X        fprintf(stderr, "Bad coords (%d, %d)\n", x, y);
  212. X        return;
  213. X    }
  214. X
  215. X    if (oneboard && (chessboard->square[y][x].color != nexttomove)) {
  216. X        message_add(win, "Wrong player!\n", true);
  217. X        return;
  218. X    } else if (!oneboard && (chessboard->square[y][x].color !=
  219. X            win->color)) {
  220. X        message_add(win, "Can't move that\n", true);
  221. X        return;
  222. X    }
  223. X
  224. X    thismove = alloc(move);
  225. X    thismove->fromx = x;
  226. X    thismove->fromy = y;
  227. X    thismove->piece.color = chessboard->square[y][x].color;
  228. X    thismove->piece.type = chessboard->square[y][x].type;
  229. X
  230. X    if (debug)
  231. X        fprintf(stderr, "%s selected his %s at (%d, %d)...\n",
  232. X                colornames[(int) thismove->piece.color],
  233. X                piecenames[(int) thismove->piece.type],
  234. X                thismove->fromy, thismove->fromx);
  235. X    return;
  236. X}
  237. X
  238. Xvoid
  239. Xbutton_released(event, win)
  240. X    XEvent *event;
  241. X    windata *win;
  242. X{
  243. X    int x, y;
  244. X    XKeyOrButtonEvent *ev = (XKeyOrButtonEvent *) event;
  245. X
  246. X    if (!thismove) {
  247. X        /* fprintf(stderr, "Error: button hasn't been pressed\n"); */
  248. X        return;
  249. X    }
  250. X    if (loading_flag)
  251. X        return;
  252. X
  253. X    /* Figure out what piece he is pointing at. */
  254. X    x = ev->x / (SQUARE_WIDTH + BORDER_WIDTH);
  255. X    y = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH);
  256. X
  257. X    if (win->flipped) {
  258. X        y = SIZE - y - 1;
  259. X        x = SIZE - x - 1;
  260. X    }
  261. X
  262. X    if ((x < 0) || (x >= SIZE) || (y < 0) || (y >= SIZE)) {
  263. X        fprintf(stderr, "Bad coords (%d, %d)\n", x, y);
  264. X        return;
  265. X    }
  266. X
  267. X    if ((thismove->fromx == x) && (thismove->fromy == y)) {
  268. X        message_add(win, "Hey, you touch it, you move it, buddy.\n",
  269. X                true);
  270. X        return;
  271. X    }
  272. X    if (chessboard->square[y][x].color == thismove->piece.color) {
  273. X        message_add(win, "Can't put one piece on top of another\n",
  274. X                true);
  275. X        return;
  276. X    }
  277. X
  278. X    thismove->tox = x;
  279. X    thismove->toy = y;
  280. X    thismove->taken.color = chessboard->square[y][x].color;
  281. X    thismove->taken.type = chessboard->square[y][x].type;
  282. X    if (thismove->taken.color != NONE)
  283. X        thismove->type = CAPTURE;
  284. X    else if ((thismove->piece.type == KING) && (thismove->fromx == 4) &&
  285. X            (thismove->tox == 6) &&
  286. X            (thismove->toy == thismove->fromy))
  287. X        thismove->type = KCASTLE;
  288. X    else if ((thismove->piece.type == KING) && (thismove->tox == 2) &&
  289. X            (thismove->fromx == 4) &&
  290. X            (thismove->toy == thismove->fromy))
  291. X        thismove->type = QCASTLE;
  292. X    else
  293. X        thismove->type = MOVE;
  294. X    
  295. X    /* Now check the en-passant case... */
  296. X    if ((thismove->type == MOVE) && ((thismove->tox == thismove->fromx + 1)
  297. X            || (thismove->tox == thismove->fromx - 1)) &&
  298. X            (thismove->piece.type == PAWN) && lastmove &&
  299. X            (lastmove->tox == lastmove->fromx) && (lastmove->fromx
  300. X            == thismove->tox) && ((lastmove->fromy + lastmove->toy)
  301. X            / 2 == thismove->toy)) {
  302. X        thismove->type = CAPTURE;
  303. X        thismove->enpassant = true;
  304. X        thismove->taken = lastmove->piece;
  305. X    }
  306. X
  307. X    if (!valid_move(thismove, chessboard)) {
  308. X        message_add(win, "Invalid move.\n", true);
  309. X        return;
  310. X    }
  311. X
  312. X    if (debug)
  313. X        fprintf(stderr, "\t... and moved it to (%d, %d), type %s\n",
  314. X                thismove->toy, thismove->tox,
  315. X                movetypenames[(int) thismove->type]);
  316. X    move_piece(thismove);
  317. X
  318. X    if (thismove->check) {
  319. X        message_add(win1, "Check.\n", true);
  320. X        if (!oneboard) {
  321. X            message_add(win2, "Check.\n", true);
  322. X        }
  323. X    }
  324. X
  325. X    if (!moves)
  326. X        moves = lastmove = thismove;
  327. X    else
  328. X        lastmove = lastmove->next = thismove;
  329. X
  330. X    if (progflag)
  331. X        program_send(thismove);
  332. X
  333. X    thismove = NULL;
  334. X    nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE);
  335. X    clock_switch();
  336. X
  337. X    return;
  338. X}
  339. X
  340. Xvoid
  341. Xprog_move(m)
  342. X    move *m;
  343. X{
  344. X    if (debug)
  345. X        fprintf(stderr, "program moves from (%d, %d) to (%d, %d)\n",
  346. X                m->fromy, m->fromx, m->toy, m->tox);
  347. X    move_piece(m);
  348. X
  349. X    if (!moves)
  350. X        moves = lastmove = m;
  351. X    else
  352. X        lastmove = lastmove->next = m;
  353. X
  354. X    nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE);
  355. X    clock_switch();
  356. X
  357. X    return;
  358. X}
  359. X
  360. Xvoid
  361. Xmove_piece(m)
  362. X    move *m;
  363. X{
  364. X    /* Update the screen... */
  365. X    screen_move(m);
  366. X
  367. X    /* Move the piece on the board... */
  368. X    board_move(chessboard, m);
  369. X
  370. X    /* And record it... */
  371. X    record_move(m);
  372. X
  373. X    if (noisyflag)
  374. X        XFeep(-4);
  375. X
  376. X    return;
  377. X}
  378. X
  379. Xstatic void
  380. Xscreen_move(m)
  381. X    move *m;
  382. X{
  383. X    piece pp;
  384. X
  385. X    switch (m->type) {
  386. X        case CAPTURE:
  387. X        jail_add(&m->taken);
  388. X        /* FALLTHRU */
  389. X
  390. X        case MOVE:
  391. X        win_erasepiece(m->fromy, m->fromx, WHITE);
  392. X        if (win_flashmove)
  393. X            win_flash(m, WHITE);
  394. X        win_drawpiece(&m->piece, m->toy, m->tox, WHITE);
  395. X        if (m->enpassant)
  396. X            win_erasepiece(m->toy + ((m->piece.color == WHITE) ?
  397. X                    1 : -1), m->tox, WHITE);
  398. X        if (!oneboard) {
  399. X            win_erasepiece(m->fromy, m->fromx, BLACK);
  400. X            if (win_flashmove)
  401. X                win_flash(m, BLACK);
  402. X            win_drawpiece(&m->piece, m->toy, m->tox, BLACK);
  403. X            if (m->enpassant)
  404. X                win_erasepiece(m->toy + ((m->piece.color ==
  405. X                    WHITE) ? 1 : -1), m->tox, WHITE);
  406. X        }
  407. X        if ((m->piece.type == PAWN) && (((m->piece.color == BLACK) &&
  408. X                (m->toy == 7)) || ((m->piece.color == WHITE) &&
  409. X                (m->toy == 0)))) {
  410. X            pp.color = m->piece.color;
  411. X            pp.type = QUEEN;
  412. X            win_drawpiece(&pp,  m->toy, m->tox, WHITE);
  413. X            if (!oneboard)
  414. X                win_drawpiece(&m->piece, m->toy, m->tox, BLACK);
  415. X        }
  416. X        break;
  417. X        
  418. X        case KCASTLE:
  419. X        if (m->piece.color == WHITE) {
  420. X            win_erasepiece(7, 4, WHITE);
  421. X            win_erasepiece(7, 7, WHITE);
  422. X            if (win_flashmove)
  423. X                win_flash(m, WHITE);
  424. X            win_drawpiece(&m->piece, 7, 6, WHITE);
  425. X            win_drawpiece(&chessboard->square[7][7], 7, 5, WHITE);
  426. X            if (!oneboard) {
  427. X                win_erasepiece(7, 4, BLACK);
  428. X                win_erasepiece(7, 7, BLACK);
  429. X                if (win_flashmove)
  430. X                    win_flash(m, BLACK);
  431. X                win_drawpiece(&m->piece, 7, 6, BLACK);
  432. X                win_drawpiece(&chessboard->square[7][7], 7, 5,
  433. X                        BLACK);
  434. X            }
  435. X        } else {
  436. X            win_erasepiece(0, 4, WHITE);
  437. X            win_erasepiece(0, 7, WHITE);
  438. X            if (win_flashmove)
  439. X                win_flash(m, WHITE);
  440. X            win_drawpiece(&m->piece, 0, 6, WHITE);
  441. X            win_drawpiece(&chessboard->square[0][7], 0, 5, WHITE);
  442. X            if (!oneboard) {
  443. X                win_erasepiece(0, 4, BLACK);
  444. X                win_erasepiece(0, 7, BLACK);
  445. X                if (win_flashmove)
  446. X                    win_flash(m, BLACK);
  447. X                win_drawpiece(&m->piece, 0, 6, BLACK);
  448. X                win_drawpiece(&chessboard->square[0][7], 0, 5,
  449. X                        BLACK);
  450. X            }
  451. X        }
  452. X        break;
  453. X
  454. X        case QCASTLE:
  455. X        if (m->piece.color == WHITE) {
  456. X            win_erasepiece(7, 4, WHITE);
  457. X            win_erasepiece(7, 0, WHITE);
  458. X            if (win_flashmove)
  459. X                win_flash(m, WHITE);
  460. X            win_drawpiece(&m->piece, 7, 2, WHITE);
  461. X            win_drawpiece(&chessboard->square[7][0], 7, 3, WHITE);
  462. X            if (!oneboard) {
  463. X                win_erasepiece(7, 4, BLACK);
  464. X                win_erasepiece(7, 0, BLACK);
  465. X                if (win_flashmove)
  466. X                    win_flash(m, BLACK);
  467. X                win_drawpiece(&m->piece, 7, 2, BLACK);
  468. X                win_drawpiece(&chessboard->square[7][7], 7, 3,
  469. X                        BLACK);
  470. X            }
  471. X        } else {
  472. X            win_erasepiece(0, 4, WHITE);
  473. X            win_erasepiece(0, 0, WHITE);
  474. X            if (win_flashmove)
  475. X                win_flash(m, WHITE);
  476. X            win_drawpiece(&m->piece, 0, 2, WHITE);
  477. X            win_drawpiece(&chessboard->square[0][0], 0, 3, WHITE);
  478. X            if (!oneboard) {
  479. X                win_erasepiece(0, 4, BLACK);
  480. X                win_erasepiece(0, 0, BLACK);
  481. X                if (win_flashmove)
  482. X                    win_flash(m, BLACK);
  483. X                win_drawpiece(&m->piece, 0, 2, BLACK);
  484. X                win_drawpiece(&chessboard->square[0][7], 0, 3,
  485. X                        BLACK);
  486. X            }
  487. X        }
  488. X        break;
  489. X
  490. X        default:
  491. X        fprintf(stderr, "Bad move type %d\n", m->type);
  492. X    }
  493. X    return;
  494. X}
  495. X
  496. X/* Retract the last move made... */
  497. X
  498. Xvoid
  499. Xreplay()
  500. X{
  501. X    move *m = lastmove, bm;
  502. X
  503. X    switch (m->type) {
  504. X        case MOVE:
  505. X        bm.type = MOVE;
  506. X        bm.piece = m->piece;
  507. X        bm.fromx = m->tox;
  508. X        bm.fromy = m->toy;
  509. X        bm.tox = m->fromx;
  510. X        bm.toy = m->fromy;
  511. X        board_move(chessboard, &bm);
  512. X        screen_move(&bm);
  513. X        break;
  514. X
  515. X        case CAPTURE:
  516. X        bm.type = MOVE;
  517. X        bm.piece = m->piece;
  518. X        bm.fromx = m->tox;
  519. X        bm.fromy = m->toy;
  520. X        bm.tox = m->fromx;
  521. X        bm.toy = m->fromy;
  522. X        board_move(chessboard, &bm);
  523. X        screen_move(&bm);
  524. X        chessboard->square[m->toy][m->tox] = m->taken;
  525. X        bm.piece = m->taken;
  526. X        bm.fromx = bm.tox = m->tox;
  527. X        bm.fromy = bm.toy = m->toy;
  528. X        screen_move(&bm);
  529. X        jail_remove(&m->taken);
  530. X        break;
  531. X
  532. X        case KCASTLE:
  533. X        bm.type = MOVE;
  534. X        bm.piece.type = KING;
  535. X        bm.piece.color = m->piece.color;
  536. X        bm.fromx = 6;
  537. X        bm.tox = 4;
  538. X        bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0;
  539. X        board_move(chessboard, &bm);
  540. X        screen_move(&bm);
  541. X        bm.type = MOVE;
  542. X        bm.piece.type = ROOK;
  543. X        bm.piece.color = m->piece.color;
  544. X        bm.fromx = 5;
  545. X        bm.tox = 7;
  546. X        bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0;
  547. X        board_move(chessboard, &bm);
  548. X        screen_move(&bm);
  549. X        if (m->piece.color == WHITE)
  550. X            chessboard->white_cant_castle_k = false;
  551. X        else
  552. X            chessboard->black_cant_castle_k = false;
  553. X        break;
  554. X
  555. X        case QCASTLE:
  556. X        bm.type = MOVE;
  557. X        bm.piece.type = KING;
  558. X        bm.piece.color = m->piece.color;
  559. X        bm.fromx = 2;
  560. X        bm.tox = 4;
  561. X        bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0;
  562. X        board_move(chessboard, &bm);
  563. X        screen_move(&bm);
  564. X        bm.type = MOVE;
  565. X        bm.piece.type = ROOK;
  566. X        bm.piece.color = m->piece.color;
  567. X        bm.fromx = 3;
  568. X        bm.tox = 0;
  569. X        bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0;
  570. X        board_move(chessboard, &bm);
  571. X        screen_move(&bm);
  572. X        if (m->piece.color == WHITE)
  573. X            chessboard->white_cant_castle_q = false;
  574. X        else
  575. X            chessboard->black_cant_castle_q = false;
  576. X        break;
  577. X    }
  578. X    record_back();
  579. X
  580. X    nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE);
  581. X    clock_switch();
  582. X
  583. X    if (!moves->next) {
  584. X        moves->next = foremoves;
  585. X        foremoves = moves;
  586. X        moves = lastmove = NULL;
  587. X    } else {
  588. X        for (m = moves; m->next; m = m->next)
  589. X            lastmove = m;
  590. X        lastmove->next->next = foremoves;
  591. X        foremoves = lastmove->next;
  592. X        lastmove->next = NULL;
  593. X    }
  594. X
  595. X    if (progflag)
  596. X        program_undo();
  597. X
  598. X    return;
  599. X}
  600. X
  601. X/* Put back the last move undone. */
  602. X
  603. Xvoid
  604. Xforward()
  605. X{
  606. X    prog_move(foremoves);
  607. X    foremoves = foremoves->next;
  608. X    return;
  609. X}
  610. X
  611. X/* End the game. */
  612. X
  613. Xvoid
  614. Xcleanup(s)
  615. X    char *s;
  616. X{
  617. X    if (progflag)
  618. X        program_end();
  619. X    record_end(s);
  620. X    XSync(0);
  621. X    exit(0);
  622. X}
  623. X
  624. Xvoid
  625. Xrestart()
  626. X{
  627. X    moves = lastmove = thismove = NULL;
  628. X    nexttomove = WHITE;
  629. X
  630. X    clock_init(win1, WHITE);
  631. X    clock_init(win1, BLACK);
  632. X    jail_init(win1);
  633. X    if (!oneboard) {
  634. X        clock_init(win2, WHITE);
  635. X        clock_init(win2, BLACK);
  636. X        jail_init(win2);
  637. X    }
  638. X    board_init(chessboard);
  639. X    win_restart();
  640. X    record_reset();
  641. X    if (progflag) {
  642. X        program_end();
  643. X        program_init(progname);
  644. X    }
  645. X    return;
  646. X}
  647. X
  648. END_OF_control.c
  649. if test 11864 -ne `wc -c <control.c`; then
  650.     echo shar: \"control.c\" unpacked with wrong size!
  651. fi
  652. # end of overwriting check
  653. fi
  654. if test -f parse.c -a "${1}" != "-c" ; then 
  655.   echo shar: Will not over-write existing file \"parse.c\"
  656. else
  657. echo shar: Extracting \"parse.c\" \(8945 characters\)
  658. sed "s/^X//" >parse.c <<'END_OF_parse.c'
  659. X/* This file contains code for X-CHESS.
  660. X   Copyright (C) 1986 Free Software Foundation, Inc.
  661. X
  662. XThis file is part of X-CHESS.
  663. X
  664. XX-CHESS is distributed in the hope that it will be useful,
  665. Xbut WITHOUT ANY WARRANTY.  No author or distributor
  666. Xaccepts responsibility to anyone for the consequences of using it
  667. Xor for whether it serves any particular purpose or works at all,
  668. Xunless he says so in writing.  Refer to the X-CHESS General Public
  669. XLicense for full details.
  670. X
  671. XEveryone is granted permission to copy, modify and redistribute
  672. XX-CHESS, but only under the conditions described in the
  673. XX-CHESS General Public License.   A copy of this license is
  674. Xsupposed to have been given to you along with X-CHESS so you
  675. Xcan know your rights and responsibilities.  It should be in a
  676. Xfile named COPYING.  Among other things, the copyright notice
  677. Xand this notice must be preserved on all copies.  */
  678. X
  679. X
  680. X/* RCS Info: $Revision: 1.2 $ on $Date: 86/11/23 17:17:59 $
  681. X *           $Source: /users/faustus/xchess/RCS/parse.c,v $
  682. X * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
  683. X *    Permission is granted to do anything with this code except sell it
  684. X *    or remove this message.
  685. X *
  686. X * Parse a sequence of chess moves...
  687. X */
  688. X
  689. X#include "xchess.h"
  690. X
  691. Xbool loading_flag = false;
  692. Xbool loading_paused = false;
  693. X
  694. Xstatic char *line;
  695. X
  696. X/* Load a record file in.  This returns a number of things -- the board, the
  697. X * list of moves, and whose turn it is.
  698. X */
  699. X
  700. Xvoid
  701. Xload_game(file)
  702. X    char *file;
  703. X{
  704. X    FILE *fp;
  705. X    char buf[BSIZE];
  706. X    bool eflag;
  707. X    move *m;
  708. X    board *tmpboard = alloc(board);
  709. X
  710. X    if (eq(file, "xchess.game") && saveflag) {
  711. X        message_add(win1,
  712. X            "Oops, I just overwrote the\nfile xchess.game...\n",
  713. X                true);
  714. X        message_add(win1, "I hope you had another copy.\n", true);
  715. X        return;
  716. X    }
  717. X    if (!(fp = fopen(file, "r"))) {
  718. X        perror(file);
  719. X        return;
  720. X    }
  721. X
  722. X    /* Get a few lines... */
  723. X    fgets(buf, BSIZE, fp);
  724. X    message_add(win1, buf, false);
  725. X    if (!oneboard)
  726. X        message_add(win2, buf, false);
  727. X
  728. X    fgets(buf, BSIZE, fp);
  729. X    message_add(win1, buf, false);
  730. X    if (!oneboard)
  731. X        message_add(win2, buf, false);
  732. X    
  733. X    fgets(buf, BSIZE, fp);
  734. X    if (eq(buf, "\tenglish\n"))
  735. X        eflag = true;
  736. X    else if (eq(buf, "\talgebraic\n"))
  737. X        eflag = false;
  738. X    else {
  739. X        fprintf(stderr, "Can't decide whether this is english...\n");
  740. X        return;
  741. X    }
  742. X
  743. X    board_init(tmpboard);
  744. X    line = NULL;
  745. X    m = parse_file(fp, tmpboard, eflag);
  746. X    tfree(tmpboard);
  747. X
  748. X    /* Now apply these moves to the board we were given... */
  749. X    loading_flag = true;
  750. X    while (m) {
  751. X        if (!quickflag)
  752. X            XSync(0);
  753. X        win_process(true);
  754. X        if (!quickflag)
  755. X            sleep(1);
  756. X        if (!loading_paused) {
  757. X            prog_move(m);
  758. X            m = m->next;
  759. X        }
  760. X    }
  761. X    loading_flag = false;
  762. X    if (line)
  763. X        message_add(win1, line, false);
  764. X
  765. X    while (fgets(buf, BSIZE, fp))
  766. X        message_add(win1, buf, false);
  767. X    
  768. X    fclose(fp);
  769. X
  770. X    return;
  771. X}
  772. X
  773. X/* Given a starting position (usually the beginning board configuration),
  774. X * read in a file of moves.
  775. X */
  776. X
  777. Xmove *
  778. Xparse_file(fp, b, english)
  779. X    FILE *fp;
  780. X    board *b;
  781. X    bool english;
  782. X{
  783. X    move *mvs = NULL, *end = NULL;
  784. X    char buf[BSIZE], *s, *t;
  785. X    color whosemove = WHITE;
  786. X    int c, i, j;
  787. X
  788. X    while (fgets(buf, BSIZE, fp)) {
  789. X        if (*buf == '#')
  790. X            continue;
  791. X        s = buf;
  792. X
  793. X        /* The move number... */
  794. X        if (!(t = gettok(&s)))
  795. X            break;
  796. X        if (!isdigit(*t)) {
  797. X            line = copy(buf);
  798. X            break;
  799. X        }
  800. X
  801. X        if (!(t = gettok(&s)))
  802. X            break;
  803. X        if (end)
  804. X            end = end->next = (english ? parse_move(b, t, WHITE) :
  805. X                    parse_imove(b, t, WHITE));
  806. X        else
  807. X            mvs = end = (english ? parse_move(b, t, WHITE) :
  808. X                    parse_imove(b, t, WHITE));
  809. X        if (!end) {
  810. X            fprintf(stderr, "Can't parse %s\n", buf);
  811. X            return (NULL);
  812. X        }
  813. X        board_move(b, end);
  814. X
  815. X        if (!(t = gettok(&s)))
  816. X            break;
  817. X        if (end)
  818. X            end = end->next = (english ? parse_move(b, t, BLACK) :
  819. X                    parse_imove(b, t, BLACK));
  820. X        else
  821. X            mvs = end = (english ? parse_move(b, t, BLACK) :
  822. X                    parse_imove(b, t, BLACK));
  823. X        if (!end) {
  824. X            fprintf(stderr, "Can't parse %s\n", buf);
  825. X            return (NULL);
  826. X        }
  827. X        board_move(b, end);
  828. X    }
  829. X
  830. X    return (mvs);
  831. X}
  832. X
  833. X/* Parse a move.  The move format accepted is as follows -
  834. X *    move:        spec-spec
  835. X *    capture:    specxspec
  836. X *    kcastle:    2 o's
  837. X *    qcastle:    3 o's
  838. X * A spec is either piece/pos, piece, or just pos.  A pos consists of a column
  839. X * name followed by a row number.  If the column name is kr, kn, kb, k, q,
  840. X * qb, qn, or qr, then the row number is according to the english system,
  841. X * or if it is a-h then it is according to the international system.
  842. X * 
  843. X *** As of now the spec must include the position.
  844. X */
  845. X
  846. Xmove *
  847. Xparse_move(b, str, w)
  848. X    board *b;
  849. X    char *str;
  850. X    color w;
  851. X{
  852. X    move *m = alloc(move);
  853. X    char *s;
  854. X    char spec1[16], spec2[16];
  855. X    int i, j;
  856. X
  857. Xif (debug) fprintf(stderr, "parsing %s\n", str);
  858. X
  859. X    /* Check for castles. */
  860. X    for (s = str, i = 0; *s; s++)
  861. X        if ((*s == 'o') || (*s == 'O'))
  862. X            i++;
  863. X    if (i == 2) {
  864. X        m->type = KCASTLE;
  865. X        m->piece.type = KING;
  866. X        m->piece.color = w;
  867. X        return (m);
  868. X    } else if (i == 3) {
  869. X        m->type = QCASTLE;
  870. X        m->piece.type = KING;
  871. X        m->piece.color = w;
  872. X        return (m);
  873. X    }
  874. X    if (index(str, '-'))
  875. X        m->type = MOVE;
  876. X    else if (index(str, 'x'))
  877. X        m->type = CAPTURE;
  878. X    else
  879. X        return (NULL);
  880. X    for (i = 0; str[i]; i++)
  881. X        if ((str[i] == 'x') || (str[i] == '-'))
  882. X            break;
  883. X        else
  884. X            spec1[i] = str[i];
  885. X    spec1[i] = '\0';
  886. X    for (i++, j = 0; str[i]; i++, j++)
  887. X        if ((str[i] == 'x') || (str[i] == '-'))
  888. X            break;
  889. X        else
  890. X            spec2[j] = str[i];
  891. X    spec2[j] = '\0';
  892. X
  893. X    /* Now decode the specifications. */
  894. X    s = spec1;
  895. X    switch (*s) {
  896. X        case 'p': case 'P':
  897. X        m->piece.type = PAWN; break;
  898. X        case 'r': case 'R':
  899. X        m->piece.type = ROOK; break;
  900. X        case 'n': case 'N':
  901. X        m->piece.type = KNIGHT; break;
  902. X        case 'b': case 'B':
  903. X        m->piece.type = BISHOP; break;
  904. X        case 'q': case 'Q':
  905. X        m->piece.type = QUEEN; break;
  906. X        case 'k': case 'K':
  907. X        m->piece.type = KING; break;
  908. X        default:
  909. X        return (NULL);
  910. X    }
  911. X    m->piece.color = w;
  912. X    s += 2;
  913. X
  914. X    /* Now get the {q,k}{,b,n,r}n string... */
  915. X    if ((s[0] == 'q') && (s[1] == 'r'))
  916. X        m->fromx = 0, s += 2;
  917. X    else if ((s[0] == 'q') && (s[1] == 'n'))
  918. X        m->fromx = 1, s += 2;
  919. X    else if ((s[0] == 'q') && (s[1] == 'b'))
  920. X        m->fromx = 2, s += 2;
  921. X    else if ((s[0] == 'q') && isdigit(s[1]))
  922. X        m->fromx = 3, s += 1;
  923. X    else if ((s[0] == 'k') && isdigit(s[1]))
  924. X        m->fromx = 4, s += 1;
  925. X    else if ((s[0] == 'k') && (s[1] == 'b'))
  926. X        m->fromx = 5, s += 2;
  927. X    else if ((s[0] == 'k') && (s[1] == 'n'))
  928. X        m->fromx = 6, s += 2;
  929. X    else if ((s[0] == 'k') && (s[1] == 'r'))
  930. X        m->fromx = 7, s += 2;
  931. X    m->fromy = ((w == WHITE) ? (SIZE - atoi(s)) : (atoi(s) - 1));
  932. X
  933. X    if ((b->square[m->fromy][m->fromx].color != w) ||
  934. X             (b->square[m->fromy][m->fromx].type != m->piece.type)) {
  935. X        fprintf(stderr, "Error: bad stuff\n");
  936. X        return (NULL);
  937. X    }
  938. X
  939. X    s = spec2;
  940. X    if (m->type == CAPTURE) {
  941. X        switch (*s) {
  942. X            case 'p': case 'P':
  943. X            m->taken.type = PAWN; break;
  944. X            case 'r': case 'R':
  945. X            m->taken.type = ROOK; break;
  946. X            case 'n': case 'N':
  947. X            m->taken.type = KNIGHT; break;
  948. X            case 'b': case 'B':
  949. X            m->taken.type = BISHOP; break;
  950. X            case 'q': case 'Q':
  951. X            m->taken.type = QUEEN; break;
  952. X            case 'k': case 'K':
  953. X            m->taken.type = KING; break;
  954. X            default:
  955. X            return (NULL);
  956. X        }
  957. X        m->taken.color = ((w == WHITE) ? BLACK : WHITE);
  958. X        s += 2;
  959. X    }
  960. X
  961. X    /* Now get the {q,k}{,b,n,r}n string... */
  962. X    if ((s[0] == 'q') && (s[1] == 'r'))
  963. X        m->tox = 0, s += 2;
  964. X    else if ((s[0] == 'q') && (s[1] == 'n'))
  965. X        m->tox = 1, s += 2;
  966. X    else if ((s[0] == 'q') && (s[1] == 'b'))
  967. X        m->tox = 2, s += 2;
  968. X    else if ((s[0] == 'q') && isdigit(s[1]))
  969. X        m->tox = 3, s += 1;
  970. X    else if ((s[0] == 'k') && isdigit(s[1]))
  971. X        m->tox = 4, s += 1;
  972. X    else if ((s[0] == 'k') && (s[1] == 'b'))
  973. X        m->tox = 5, s += 2;
  974. X    else if ((s[0] == 'k') && (s[1] == 'n'))
  975. X        m->tox = 6, s += 2;
  976. X    else if ((s[0] == 'k') && (s[1] == 'r'))
  977. X        m->tox = 7, s += 2;
  978. X    m->toy = ((w == WHITE) ? (SIZE - atoi(s)) : (atoi(s) - 1));
  979. X
  980. X    if ((m->type == CAPTURE) && ((b->square[m->toy][m->tox].color !=
  981. X            m->taken.color) || (b->square[m->toy][m->tox].type !=
  982. X            m->taken.type))) {
  983. X        fprintf(stderr, "Error: bad stuff\n");
  984. X        return (NULL);
  985. X    }
  986. X
  987. X    return (m);
  988. X}
  989. X
  990. X/* Parse an algebraic notation move.  This is a lot easier... */
  991. X
  992. Xmove *
  993. Xparse_imove(b, buf, w)
  994. X    board *b;
  995. X    char *buf;
  996. X    color w;
  997. X{
  998. X    char *s;
  999. X    move *m = alloc(move);
  1000. X    int n;
  1001. X
  1002. Xif (debug) fprintf(stderr, "(alg) parsing %s\n", buf);
  1003. X
  1004. X    for (s = buf, n = 0; *s; s++)
  1005. X        if ((*s == 'o') || (*s == 'O'))
  1006. X            n++;
  1007. X    s = buf;
  1008. X
  1009. X    if (n == 2)
  1010. X        m->type = KCASTLE;
  1011. X    else if (n == 3)
  1012. X        m->type = QCASTLE;
  1013. X    else {
  1014. X        m->fromx = *s++ - 'a';
  1015. X        m->fromy = SIZE - (*s++ - '0');
  1016. X        m->tox = *s++ - 'a';
  1017. X        m->toy = SIZE - (*s++ - '0');
  1018. X        m->piece = b->square[m->fromy][m->fromx];
  1019. X        m->taken = b->square[m->toy][m->tox];
  1020. X        if (m->taken.color == NONE)
  1021. X            m->type = MOVE;
  1022. X        else
  1023. X            m->type = CAPTURE;
  1024. X    }
  1025. X    if (m->piece.color != w) {
  1026. X        fprintf(stderr, "Error: parse_imove: piece of wrong color!\n");
  1027. X        return (NULL);
  1028. X    }
  1029. X    if ((m->piece.type == KING) && (m->fromy == m->toy) && (m->fromx == 4)
  1030. X            && (m->tox == 6))
  1031. X        m->type = KCASTLE;
  1032. X    else if ((m->piece.type == KING) && (m->fromy == m->toy) &&
  1033. X            (m->fromx == 4) && (m->tox == 2))
  1034. X        m->type = QCASTLE;
  1035. X    
  1036. X    return (m);
  1037. X}
  1038. X
  1039. END_OF_parse.c
  1040. if test 8945 -ne `wc -c <parse.c`; then
  1041.     echo shar: \"parse.c\" unpacked with wrong size!
  1042. fi
  1043. # end of overwriting check
  1044. fi
  1045. if test ! -d scrollText ; then
  1046.     echo shar: Creating directory \"scrollText\"
  1047.     mkdir scrollText
  1048. fi
  1049. if test -f scrollText/Makefile -a "${1}" != "-c" ; then 
  1050.   echo shar: Will not over-write existing file \"scrollText/Makefile\"
  1051. else
  1052. echo shar: Extracting \"scrollText/Makefile\" \(294 characters\)
  1053. sed "s/^X//" >scrollText/Makefile <<'END_OF_scrollText/Makefile'
  1054. X#
  1055. X# Makefile for the scrollable text output system
  1056. X#
  1057. X
  1058. XCFLAGS = -g
  1059. X
  1060. XLIBS = libScroll.a /users/davidh/test/libCreate/libCreate.a -lX
  1061. X
  1062. X
  1063. XlibScroll.a:    scrollText.o
  1064. X    ar r libScroll.a scrollText.o
  1065. X    ranlib libScroll.a
  1066. X
  1067. Xcodeview:    codeview.o libScroll.a
  1068. X    cc $(CFLAGS) -o codeview codeview.o st.o $(LIBS)
  1069. END_OF_scrollText/Makefile
  1070. if test 294 -ne `wc -c <scrollText/Makefile`; then
  1071.     echo shar: \"scrollText/Makefile\" unpacked with wrong size!
  1072. fi
  1073. # end of overwriting check
  1074. fi
  1075. if test -f scrollText/codeview.c -a "${1}" != "-c" ; then 
  1076.   echo shar: Will not over-write existing file \"scrollText/codeview.c\"
  1077. else
  1078. echo shar: Extracting \"scrollText/codeview.c\" \(13042 characters\)
  1079. sed "s/^X//" >scrollText/codeview.c <<'END_OF_scrollText/codeview.c'
  1080. X/*
  1081. X * C Code Viewer for X
  1082. X *
  1083. X * David Harrison
  1084. X * University of California,  1986
  1085. X */
  1086. X
  1087. X#include <stdio.h>
  1088. X#include <ctype.h>
  1089. X#include <X/Xlib.h>
  1090. X#include "st.h"
  1091. X
  1092. Xst_table *keywords = (st_table *) 0;
  1093. Xint in_comment = 0;
  1094. Xint in_string  = 0;
  1095. X
  1096. X/* Table to define which delimiters are interesting */
  1097. X#define MAXCHARS    256
  1098. Xchar specialChar[MAXCHARS];
  1099. X
  1100. Xextern int strcmp();
  1101. Xextern char *strcpy();
  1102. Xextern char *strncpy();
  1103. X
  1104. Xmain(argc,argv)
  1105. Xint argc;
  1106. Xchar *argv[];
  1107. X{
  1108. X    FILE *incFile;
  1109. X    Display *theDisp;
  1110. X    Window theWin;
  1111. X    OpaqueFrame theFrame;
  1112. X    XEvent theEvent;
  1113. X    FontInfo *theFont;
  1114. X    char *dispname;
  1115. X    char *fontNames[4];
  1116. X    int colorPixels[4];
  1117. X    char *filename;
  1118. X    char *ProcessLine();
  1119. X    char linebuf[2048];
  1120. X    int index, count;
  1121. X    int bgPixel, fgPixel, curPixel, borPixel;
  1122. X
  1123. X    /* read the argument list */
  1124. X    dispname = "";
  1125. X    filename = (char *) 0;
  1126. X    fontNames[0] = "timrom12";
  1127. X    fontNames[1] = "timrom12i";
  1128. X    fontNames[2] = "timrom12b";
  1129. X    fontNames[3] = "helv12";
  1130. X    for (index = 0;  index < 4;  index++) colorPixels[index] = BlackPixel;
  1131. X    bgPixel = WhitePixel;
  1132. X    curPixel = BlackPixel;
  1133. X    borPixel = BlackPixel;
  1134. X    index = 1;
  1135. X    while (index < argc) {
  1136. X    if (argv[index][0] == '-') {
  1137. X        /* Its an option */
  1138. X        switch (argv[index][1]) {
  1139. X        case 'f':
  1140. X        /* Read file into buffer */
  1141. X        filename = argv[index + 1];
  1142. X        index += 2;
  1143. X        break;
  1144. X        default:
  1145. X        printf("Unknown option\n");
  1146. X        printf("format: %s [-f file] [host:display]\n",
  1147. X               argv[0]);
  1148. X        exit(1);
  1149. X        }
  1150. X    } else {
  1151. X        /* Its the display */
  1152. X        dispname = argv[index];
  1153. X        index++;
  1154. X    }
  1155. X    }
  1156. X
  1157. X    theDisp = XOpenDisplay(dispname);
  1158. X    if (!theDisp) {
  1159. X    printf("Unable to open display\n");
  1160. X    exit(1);
  1161. X    }
  1162. X    readDefaults(argv[0], fontNames, colorPixels, &bgPixel, &fgPixel,
  1163. X         &curPixel, &borPixel);
  1164. X    theFrame.bdrwidth = 2;
  1165. X    theFrame.border = XMakeTile(borPixel);
  1166. X    theFrame.background = XMakeTile(bgPixel);
  1167. X    theWin = XCreate("C Code Viewer", "codeView",
  1168. X             "", "400x400+100+100", &theFrame, 50, 50);
  1169. X    XFreePixmap(theFrame.border);
  1170. X    XFreePixmap(theFrame.background);
  1171. X    if (!theWin) exit(1);
  1172. X    XSelectInput(theWin, ExposeRegion|ExposeCopy|ButtonReleased);
  1173. X    XMapWindow(theWin);
  1174. X
  1175. X    theFont = XOpenFont(fontNames[0]);
  1176. X    if (!TxtGrab(theWin, "codeView", theFont,
  1177. X         bgPixel, fgPixel, curPixel)) {
  1178. X    printf("Text grab failed\n");
  1179. X    exit(1);
  1180. X    }
  1181. X    XFlush();
  1182. X
  1183. X    for (index = 0;  index < 4;  index++) {
  1184. X    if (fontNames[index]) {
  1185. X        TxtAddFont(theWin, index, XOpenFont(fontNames[index]),
  1186. X               colorPixels[index]);
  1187. X    }
  1188. X    }
  1189. X
  1190. X    incFile = stdin;
  1191. X    if (filename) {
  1192. X    incFile = fopen(filename, "r");
  1193. X    if (!incFile) {
  1194. X        printf("can't read %s\n", filename);
  1195. X        exit(1);
  1196. X    }
  1197. X    }
  1198. X
  1199. X    /* Initialize tables */
  1200. X    InitTable();
  1201. X
  1202. X    /* Jam in the text */
  1203. X    while (fgets(linebuf, 2047, incFile)) {
  1204. X    TxtJamStr(theWin, ProcessLine(linebuf));
  1205. X    }
  1206. X
  1207. X    /* Main event loop */
  1208. X    count = 0;
  1209. X    for (;;) {
  1210. X    XNextEvent(&theEvent);
  1211. X    if (!TxtFilter(&theEvent)) {
  1212. X        switch (theEvent.type) {
  1213. X        case ButtonReleased:
  1214. X        if ((((XButtonEvent *) &theEvent)->detail & ValueMask) ==
  1215. X            MiddleButton)
  1216. X          {
  1217. X              count++;
  1218. X              if (count > 1) {
  1219. X              printf("done\n");
  1220. X              exit(0);
  1221. X              }
  1222. X          }
  1223. X        else {
  1224. X            XFeep(0);
  1225. X        }
  1226. X        }
  1227. X    }
  1228. X    }
  1229. X}
  1230. X
  1231. XreadDefaults(name, fontNames, colorPixels, bg, fg, cur, bor)
  1232. Xchar *name;
  1233. Xchar *fontNames[3];
  1234. Xint colorPixels[3];
  1235. Xint *bg, *fg, *cur, *bor;
  1236. X/*
  1237. X * Reads all of the X defaults
  1238. X */
  1239. X{
  1240. X    char *value;
  1241. X    char buffer[1024];
  1242. X    Color clrdef;
  1243. X
  1244. X    value = XGetDefault(name, "Normal.Font");
  1245. X    if (value) fontNames[0] = value;
  1246. X    value = XGetDefault(name, "Comment.Font");
  1247. X    if (value) fontNames[1] = value;
  1248. X    value = XGetDefault(name, "Keyword.Font");
  1249. X    if (value) fontNames[2] = value;
  1250. X    value = XGetDefault(name, "String.Font");
  1251. X    if (value) fontNames[3] = value;
  1252. X
  1253. X    value = XGetDefault(name, "Background");
  1254. X    strcpy(buffer, value);
  1255. X    if (value && XParseColor(buffer, &clrdef) && XGetHardwareColor(&clrdef)) {
  1256. X    *bg = clrdef.pixel;
  1257. X    }
  1258. X    value = XGetDefault(name, "Foreground");
  1259. X    strcpy(buffer, value);
  1260. X    if (value && XParseColor(buffer, &clrdef) && XGetHardwareColor(&clrdef)) {
  1261. X    *fg = clrdef.pixel;
  1262. X    colorPixels[0] = clrdef.pixel;
  1263. X    }
  1264. X    value = XGetDefault(name, "Border");
  1265. X    strcpy(buffer, value);
  1266. X    if (value && XParseColor(buffer, &clrdef) && XGetHardwareColor(&clrdef)) {
  1267. X    *bor = clrdef.pixel;
  1268. X    }
  1269. X    value = XGetDefault(name, "Cursor");
  1270. X    strcpy(buffer, value);
  1271. X    if (value && XParseColor(buffer, &clrdef) && XGetHardwareColor(&clrdef)) {
  1272. X    *cur = clrdef.pixel;
  1273. X    }
  1274. X
  1275. X    value = XGetDefault(name, "Normal.Color");
  1276. X    strcpy(buffer, value);
  1277. X    if (value && XParseColor(buffer, &clrdef) && XGetHardwareColor(&clrdef)) {
  1278. X    colorPixels[0] = clrdef.pixel;
  1279. X    }
  1280. X    value = XGetDefault(name, "Comment.Color");
  1281. X    strcpy(buffer, value);
  1282. X    if (value && XParseColor(buffer, &clrdef) && XGetHardwareColor(&clrdef)) {
  1283. X    colorPixels[1] = clrdef.pixel;
  1284. X    }
  1285. X    value = XGetDefault(name, "Keyword.Color");
  1286. X    strcpy(buffer, value);
  1287. X    if (value && XParseColor(buffer, &clrdef) && XGetHardwareColor(&clrdef)) {
  1288. X    colorPixels[2] = clrdef.pixel;
  1289. X    }
  1290. X    value = XGetDefault(name, "String.Color");
  1291. X    strcpy(buffer, value);
  1292. X    if (value && XParseColor(buffer, &clrdef) && XGetHardwareColor(&clrdef)) {
  1293. X    colorPixels[3] = clrdef.pixel;
  1294. X    }
  1295. X}
  1296. X
  1297. X
  1298. XInitTable()
  1299. X/*
  1300. X * Initializes hash table of keywords and special character array
  1301. X */
  1302. X{
  1303. X    int index;
  1304. X
  1305. X    for (index = 0;  index < MAXCHARS;  index++) {
  1306. X    specialChar[index] = 0;
  1307. X    }
  1308. X    specialChar['\0'] = 1;    /* End of file */
  1309. X    specialChar[ ' '] = 1;    /* Space       */
  1310. X    specialChar['\t'] = 1;    /* Tab           */
  1311. X    specialChar['\n'] = 1;    /* End of line */
  1312. X    specialChar[ '/'] = 1;    /* Slash       */
  1313. X    specialChar[ '*'] = 1;    /* Star        */
  1314. X    specialChar[ '"'] = 1;    /* Quote       */
  1315. X
  1316. X    keywords = st_init_table(strcmp, st_strhash);
  1317. X    st_insert(keywords, "int", (char *) 0);
  1318. X    st_insert(keywords, "char", (char *) 0);
  1319. X    st_insert(keywords, "float", (char *) 0);
  1320. X    st_insert(keywords, "double", (char *) 0);
  1321. X    st_insert(keywords, "struct", (char *) 0);
  1322. X    st_insert(keywords, "union", (char *) 0);
  1323. X    st_insert(keywords, "long", (char *) 0);
  1324. X    st_insert(keywords, "short", (char *) 0);
  1325. X    st_insert(keywords, "unsigned", (char *) 0);
  1326. X    st_insert(keywords, "auto", (char *) 0);
  1327. X    st_insert(keywords, "extern", (char *) 0);
  1328. X    st_insert(keywords, "register", (char *) 0);
  1329. X    st_insert(keywords, "typedef", (char *) 0);
  1330. X    st_insert(keywords, "static", (char *) 0);
  1331. X    st_insert(keywords, "goto", (char *) 0);
  1332. X    st_insert(keywords, "return", (char *) 0);
  1333. X    st_insert(keywords, "sizeof", (char *) 0);
  1334. X    st_insert(keywords, "break", (char *) 0);
  1335. X    st_insert(keywords, "continue", (char *) 0);
  1336. X    st_insert(keywords, "if", (char *) 0);
  1337. X    st_insert(keywords, "else", (char *) 0);
  1338. X    st_insert(keywords, "for", (char *) 0);
  1339. X    st_insert(keywords, "do", (char *) 0);
  1340. X    st_insert(keywords, "while", (char *) 0);
  1341. X    st_insert(keywords, "switch", (char *) 0);
  1342. X    st_insert(keywords, "case", (char *) 0);
  1343. X    st_insert(keywords, "default", (char *) 0);
  1344. X    st_insert(keywords, "entry", (char *) 0);
  1345. X}
  1346. X
  1347. X
  1348. X#define SPACE        1
  1349. X#define TAB        2
  1350. X#define COMBEGIN    3
  1351. X#define COMEND        4
  1352. X#define IDENT        5
  1353. X#define USRIDENT    6
  1354. X#define STR        7
  1355. X#define OTHER        8
  1356. X#define ENDLINE        9
  1357. X
  1358. Xchar *ProcessLine(someline)
  1359. Xchar *someline;
  1360. X/*
  1361. X * This routine takes a line,  expands out its tabs into spaces
  1362. X * italicizes comments and boldfaces keywords.
  1363. X */
  1364. X{
  1365. X    static char outbuf[2048];
  1366. X    int start, len, token, outspot, index, target;
  1367. X
  1368. X    /* Reinitializes the token generator */
  1369. X    get_token((char *) 0, (int *) 0, (int *) 0, (int *) 0);
  1370. X    outspot = 0;
  1371. X
  1372. X    while (get_token(someline, &start, &len, &token)) {
  1373. X#ifdef
  1374. Xprint_token(someline, start, len, token);
  1375. X#endif
  1376. X    switch (token) {
  1377. X    case SPACE:
  1378. X        for (index = 0;  index < len;  index++) {
  1379. X        outbuf[outspot] = ' ';
  1380. X        outspot++;
  1381. X        }
  1382. X        break;
  1383. X    case TAB:
  1384. X        /* Expand out using spaces */
  1385. X        target = ((outspot / 8) + 1) * 8;
  1386. X        for (index = outspot;  index < target;  index++) {
  1387. X        outbuf[index] = ' ';
  1388. X        outspot++;
  1389. X        }
  1390. X        break;
  1391. X    case COMBEGIN:
  1392. X        /* Put it in and then change fonts */
  1393. X        if (!in_string) {
  1394. X        outbuf[outspot++] = '\006';
  1395. X        outbuf[outspot++] = '1';
  1396. X        in_comment = 1;
  1397. X        }
  1398. X        outbuf[outspot++] = '/';
  1399. X        outbuf[outspot++] = '*';
  1400. X        break;
  1401. X    case COMEND:
  1402. X        /* Change font back to normal and output */
  1403. X        outbuf[outspot++] = '*';
  1404. X        outbuf[outspot++] = '/';
  1405. X        if (!in_string) {
  1406. X        outbuf[outspot++] = '\006';
  1407. X        outbuf[outspot++] = '0';
  1408. X        in_comment = 0;
  1409. X        }
  1410. X        break;
  1411. X    case STR:
  1412. X        if (in_comment) {
  1413. X        outbuf[outspot++] = '"';
  1414. X        } else {
  1415. X        if (in_string) {
  1416. X            /* Change font back to normal and output */
  1417. X            outbuf[outspot++] = '"';
  1418. X            outbuf[outspot++] = '\006';
  1419. X            outbuf[outspot++] = '0';
  1420. X            in_string = 0;
  1421. X        } else {
  1422. X            /* Put in string mode and change fonts */
  1423. X            outbuf[outspot++] = '\006';
  1424. X            outbuf[outspot++] = '3';
  1425. X            outbuf[outspot++] = '"';
  1426. X            in_string = 1;
  1427. X        }
  1428. X        }
  1429. X        break;
  1430. X    case IDENT:
  1431. X        /* Output in boldface if not in comment */
  1432. X        if (!(in_comment || in_string)) {
  1433. X        outbuf[outspot++] = '\006';
  1434. X        outbuf[outspot++] = '2';
  1435. X        }
  1436. X        for (index = 0;  index < len;  index++) {
  1437. X        outbuf[outspot++] = someline[start+index];
  1438. X        }
  1439. X        if (!(in_comment || in_string)) {
  1440. X        outbuf[outspot++] = '\006';
  1441. X        outbuf[outspot++] = '0';
  1442. X        }
  1443. X        break;
  1444. X    case USRIDENT:
  1445. X    case OTHER:
  1446. X        /* Simply output */
  1447. X        for (index = 0;  index < len;  index++) {
  1448. X        outbuf[outspot++] = someline[start+index];
  1449. X        }
  1450. X        break;
  1451. X    case ENDLINE:
  1452. X        /* Output it */
  1453. X        outbuf[outspot++] = '\n';
  1454. X        break;
  1455. X    }
  1456. X    }
  1457. X    outbuf[outspot] = '\0';
  1458. X    return outbuf;
  1459. X}
  1460. X
  1461. X
  1462. X
  1463. X
  1464. X/* Macro to find special delimiters - see table initialization in main */
  1465. X#define isspecial(c)    (specialChar[c])
  1466. X
  1467. X/* Macro to ram don't care delimiters into an OTHER token */
  1468. X#define EATDELIM \
  1469. X  while (!isalnum(line[pos]) && !isspecial(line[pos])) pos++; \
  1470. X  *len = pos - *start; \
  1471. X  *token = OTHER;
  1472. X
  1473. Xint get_token(line, start, len, token)
  1474. Xchar *line;
  1475. Xint *start, *len, *token;
  1476. X/*
  1477. X * Reads a token from 'line'.  If all are zero,  resets the lexing
  1478. X * system.
  1479. X */
  1480. X{
  1481. X    static int pos;
  1482. X    static char ident[2048];
  1483. X    char *item;
  1484. X
  1485. X    if ((line == 0) && (start == 0) && (len == 0) && (token == 0)) {
  1486. X    pos = 0;
  1487. X    return 0;
  1488. X    }
  1489. X
  1490. X    *start = pos;
  1491. X    if (isspecial(line[pos])) {
  1492. X    /* One of the special punctuation characters */
  1493. X    if (line[pos] == '\0') {
  1494. X        return 0;
  1495. X    } else if (line[pos] == '\t') {
  1496. X        /* Generate a tab token */
  1497. X        pos++;
  1498. X        *len = 1;
  1499. X        *token = TAB;
  1500. X    } else if (line[pos] == '\n') {
  1501. X        /* End of line */
  1502. X        *len = 1;
  1503. X        *token = ENDLINE;
  1504. X        pos++;
  1505. X    } else if (line[pos] == ' ') {
  1506. X        /* Generate a space token */
  1507. X        while (line[pos] == ' ') pos++;
  1508. X        *len = pos - *start;
  1509. X        *token = SPACE;
  1510. X    } else if (line[pos] == '/') {
  1511. X        /* Possible beginning of comment */
  1512. X        if (line[++pos] == '*') {
  1513. X        /* Start of comment */
  1514. X        *len = 2;
  1515. X        *token = COMBEGIN;
  1516. X        pos++;
  1517. X        } else {
  1518. X        /* Something else */
  1519. X        EATDELIM;
  1520. X        }
  1521. X    } else if (line[pos] == '*') {
  1522. X        /* Could be an end to a comment */
  1523. X        if (line[++pos] == '/') {
  1524. X        /* End of a comment */
  1525. X        *len = 2;
  1526. X        *token = COMEND;
  1527. X        pos++;
  1528. X        } else {
  1529. X        /* Something else */
  1530. X        EATDELIM;
  1531. X        }
  1532. X    } else if (line[pos] == '"') {
  1533. X        /* Possible start or end of string */
  1534. X        if ((pos == 0) ||
  1535. X        (((line[pos-1] == '\'') ? (line[pos+1] != '\'') : 1)
  1536. X         && (line[pos] != '\\')))
  1537. X          {
  1538. X          *len = 1;
  1539. X          *token = STR;
  1540. X          pos++;
  1541. X          } else {
  1542. X          /* Something else */
  1543. X          pos++;
  1544. X          EATDELIM;
  1545. X          }
  1546. X    }
  1547. X    } else if (isalnum(line[pos])) {
  1548. X    /* Go get an identifier */
  1549. X    do pos++; while (isalnum(line[pos]));
  1550. X    *len = pos - *start;
  1551. X    strncpy(ident, &(line[*start]), *len);
  1552. X    ident[*len] = '\0';
  1553. X    /* Try to look it up */
  1554. X    if (st_lookup(keywords, ident, &item)) {
  1555. X        *token = IDENT;
  1556. X    } else {
  1557. X        *token = USRIDENT;
  1558. X    }
  1559. X    } else {
  1560. X    /* Random delimiters */
  1561. X    pos++;
  1562. X    EATDELIM;
  1563. X    }
  1564. X    return 1;
  1565. X}
  1566. X
  1567. X
  1568. X/* Debugging */
  1569. X
  1570. Xprint_token(someline, start, len, token)
  1571. Xchar *someline;
  1572. Xint start, len, token;
  1573. X/* Prints out a token */
  1574. X{
  1575. X    char buffer[1024];
  1576. X    int index;
  1577. X
  1578. X    switch (token) {
  1579. X    case SPACE:
  1580. X    printf("space\n");
  1581. X    break;
  1582. X    case TAB:
  1583. X    printf("tab\n");
  1584. X    break;
  1585. X    /*
  1586. X     * We try to break it by doing this
  1587. X     * many times over.
  1588. X     */
  1589. X    case COMBEGIN:
  1590. X    printf("start comment\n");
  1591. X    break;
  1592. X    case COMEND:
  1593. X    printf("end comment\n");
  1594. X    break;
  1595. X    case STR:
  1596. X    printf("string\n");
  1597. X    break;
  1598. X    case IDENT:
  1599. X    printf("identifier: '");
  1600. X    for (index = start;  index < start+len;  index++) {
  1601. X        putchar(someline[index]);
  1602. X    }
  1603. X    printf("'\n");
  1604. X    break;
  1605. X    case USRIDENT:
  1606. X    printf("user identifier: '");
  1607. X    for (index = start;  index < start+len;  index++) {
  1608. X        putchar(someline[index]);
  1609. X    }
  1610. X    printf("'\n");
  1611. X    break;
  1612. X    case OTHER:
  1613. X    printf("delimiters: I");
  1614. X    for (index = start;  index < start+len;  index++) {
  1615. X        putchar(someline[index]);
  1616. X    }
  1617. X    printf("I\n");
  1618. X    break;
  1619. X    }
  1620. X}
  1621. END_OF_scrollText/codeview.c
  1622. if test 13042 -ne `wc -c <scrollText/codeview.c`; then
  1623.     echo shar: \"scrollText/codeview.c\" unpacked with wrong size!
  1624. fi
  1625. # end of overwriting check
  1626. fi
  1627. if test -f window.c -a "${1}" != "-c" ; then 
  1628.   echo shar: Will not over-write existing file \"window.c\"
  1629. else
  1630. echo shar: Extracting \"window.c\" \(18431 characters\)
  1631. sed "s/^X//" >window.c <<'END_OF_window.c'
  1632. X/* This file contains code for X-CHESS.
  1633. X   Copyright (C) 1986 Free Software Foundation, Inc.
  1634. X
  1635. XThis file is part of X-CHESS.
  1636. X
  1637. XX-CHESS is distributed in the hope that it will be useful,
  1638. Xbut WITHOUT ANY WARRANTY.  No author or distributor
  1639. Xaccepts responsibility to anyone for the consequences of using it
  1640. Xor for whether it serves any particular purpose or works at all,
  1641. Xunless he says so in writing.  Refer to the X-CHESS General Public
  1642. XLicense for full details.
  1643. X
  1644. XEveryone is granted permission to copy, modify and redistribute
  1645. XX-CHESS, but only under the conditions described in the
  1646. XX-CHESS General Public License.   A copy of this license is
  1647. Xsupposed to have been given to you along with X-CHESS so you
  1648. Xcan know your rights and responsibilities.  It should be in a
  1649. Xfile named COPYING.  Among other things, the copyright notice
  1650. Xand this notice must be preserved on all copies.  */
  1651. X
  1652. X
  1653. X/* RCS Info: $Revision: 1.5 $ on $Date: 86/11/26 12:11:15 $
  1654. X *           $Source: /users/faustus/xchess/RCS/window.c,v $
  1655. X * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
  1656. X *    Permission is granted to do anything with this code except sell it
  1657. X *    or remove this message.
  1658. X *
  1659. X * Deal with the two (or one) windows.
  1660. X */
  1661. X
  1662. X#include "xchess.h"
  1663. X#include <sys/time.h>
  1664. X
  1665. X#include "pawn.bitmap"
  1666. X#include "rook.bitmap"
  1667. X#include "knight.bitmap"
  1668. X#include "bishop.bitmap"
  1669. X#include "queen.bitmap"
  1670. X#include "king.bitmap"
  1671. X
  1672. X#include "pawn_outline.bitmap"
  1673. X#include "rook_outline.bitmap"
  1674. X#include "knight_outline.bitmap"
  1675. X#include "bishop_outline.bitmap"
  1676. X#include "queen_outline.bitmap"
  1677. X#include "king_outline.bitmap"
  1678. X
  1679. X#include "pawn_mask.bitmap"
  1680. X#include "rook_mask.bitmap"
  1681. X#include "knight_mask.bitmap"
  1682. X#include "bishop_mask.bitmap"
  1683. X#include "queen_mask.bitmap"
  1684. X#include "king_mask.bitmap"
  1685. X
  1686. X#include "shade.bitmap"
  1687. X
  1688. X#include "xchess.cur"
  1689. X#include "xchess_mask.cur"
  1690. X
  1691. X#include "xchess.icon"
  1692. X
  1693. Xwindata *win1, *win2;
  1694. Xbool win_flashmove = false;
  1695. X
  1696. Xextern bool setup();
  1697. Xextern void service(), drawgrid(), icon_refresh();
  1698. X
  1699. Xbool
  1700. Xwin_setup(disp1, disp2)
  1701. X    char *disp1, *disp2;
  1702. X{
  1703. X    win1 = alloc(windata);
  1704. X    if (!oneboard)
  1705. X        win2 = alloc(windata);
  1706. X
  1707. X    if (!setup(disp1, win1) || (!oneboard && !setup(disp2, win2)))
  1708. X        return (false);
  1709. X
  1710. X    if (blackflag) {
  1711. X        win1->color = BLACK;
  1712. X        win1->flipped = true;
  1713. X    } else
  1714. X        win1->color = WHITE;
  1715. X    win_drawboard(win1);
  1716. X
  1717. X    if (!oneboard) {
  1718. X        win2->color = BLACK;
  1719. X        win2->flipped = true;
  1720. X        win_drawboard(win2);
  1721. X    }
  1722. X    
  1723. X    return(true);
  1724. X}
  1725. X
  1726. X/* Draw the chess board... */
  1727. X
  1728. Xvoid
  1729. Xwin_drawboard(win)
  1730. X    windata *win;
  1731. X{
  1732. X    int i, j;
  1733. X
  1734. X    XSetDisplay(win->display);
  1735. X
  1736. X    drawgrid(win);
  1737. X
  1738. X    /* Now toss on the squares... */
  1739. X    for (i = 0; i < SIZE; i++)
  1740. X        for (j = 0; j < SIZE; j++)
  1741. X            win_erasepiece(j, i, win->color);
  1742. X
  1743. X    return;
  1744. X}
  1745. X
  1746. X/* Draw one piece. */
  1747. X
  1748. Xvoid
  1749. Xwin_drawpiece(p, y, x, wnum)
  1750. X    piece *p;
  1751. X    int y, x;
  1752. X    color wnum;
  1753. X{
  1754. X    short *bits, *maskbits, *outline;
  1755. X    windata *win;
  1756. X    Bitmap mask;
  1757. X    char buf[BSIZE];
  1758. X
  1759. X    if (oneboard || (wnum == win1->color))
  1760. X        win = win1;
  1761. X    else
  1762. X        win = win2;
  1763. X
  1764. X    XSetDisplay(win->display);
  1765. X
  1766. X    if (win->flipped) {
  1767. X        y = SIZE - y - 1;
  1768. X        x = SIZE - x - 1;
  1769. X    }
  1770. X
  1771. X    /*
  1772. X    if (debug)
  1773. X        fprintf(stderr, "draw a %s at (%d, %d) on board %d\n",
  1774. X                piecenames[(int) p->type], y, x, wnum);
  1775. X     */
  1776. X
  1777. Xif ((x < 0) || (x > 7) || (y < 0) || (y > 7)) exit(1);
  1778. X
  1779. X    switch (p->type) {
  1780. X        case PAWN:
  1781. X        bits = pawn_bits;
  1782. X        maskbits = pawn_mask_bits;
  1783. X        outline = pawn_outline_bits;
  1784. X        break;
  1785. X
  1786. X        case ROOK:
  1787. X        bits = rook_bits;
  1788. X        maskbits = rook_mask_bits;
  1789. X        outline = rook_outline_bits;
  1790. X        break;
  1791. X
  1792. X        case KNIGHT:
  1793. X        bits = knight_bits;
  1794. X        maskbits = knight_mask_bits;
  1795. X        outline = knight_outline_bits;
  1796. X        break;
  1797. X
  1798. X        case BISHOP:
  1799. X        bits = bishop_bits;
  1800. X        maskbits = bishop_mask_bits;
  1801. X        outline = bishop_outline_bits;
  1802. X        break;
  1803. X
  1804. X        case QUEEN:
  1805. X        bits = queen_bits;
  1806. X        maskbits = queen_mask_bits;
  1807. X        outline = queen_outline_bits;
  1808. X        break;
  1809. X
  1810. X        case KING:
  1811. X        bits = king_bits;
  1812. X        maskbits = king_mask_bits;
  1813. X        outline = king_outline_bits;
  1814. X        break;
  1815. X
  1816. X        default:
  1817. X        fprintf(stderr,
  1818. X            "Internal Error: win_drawpiece: bad piece type %d\n",
  1819. X            p->type);
  1820. X    }
  1821. X
  1822. X    /* There are two things we can do... If this is a black and white
  1823. X     * display, we have to shade the square and use an outline if the piece
  1824. X     * is white.  We also have to use a mask...  Since we don't want
  1825. X     * to use up too many bitmaps, create the mask bitmap, put the bits,
  1826. X     * and then destroy it.
  1827. X     */
  1828. X    if (win->bnw && (p->color == WHITE))
  1829. X        bits = outline;
  1830. X    if (win->bnw && !iswhite(win, x, y)) {
  1831. X        XBitmapBitsPut(win->boardwin, x * (SQUARE_WIDTH + BORDER_WIDTH),
  1832. X            y * (SQUARE_HEIGHT + BORDER_WIDTH), SQUARE_WIDTH,
  1833. X            SQUARE_HEIGHT, shade_bits, BlackPixel, WhitePixel,
  1834. X            0, GXcopy, AllPlanes);
  1835. X        mask = XStoreBitmap(SQUARE_WIDTH, SQUARE_HEIGHT, maskbits);
  1836. X        XBitmapBitsPut(win->boardwin, x * (SQUARE_WIDTH + BORDER_WIDTH),
  1837. X            y * (SQUARE_HEIGHT + BORDER_WIDTH), SQUARE_WIDTH,
  1838. X            SQUARE_HEIGHT, bits, BlackPixel, WhitePixel,
  1839. X            mask, GXcopy, AllPlanes);
  1840. X        XFreeBitmap(mask);
  1841. X    } else if (win->bnw){
  1842. X        XBitmapBitsPut(win->boardwin, x * (SQUARE_WIDTH + BORDER_WIDTH),
  1843. X            y * (SQUARE_HEIGHT + BORDER_WIDTH), SQUARE_WIDTH,
  1844. X            SQUARE_HEIGHT, bits, BlackPixel, WhitePixel,
  1845. X            0, GXcopy, AllPlanes);
  1846. X    } else {
  1847. X        XBitmapBitsPut(win->boardwin, x * (SQUARE_WIDTH + BORDER_WIDTH),
  1848. X            y * (SQUARE_HEIGHT + BORDER_WIDTH), SQUARE_WIDTH,
  1849. X            SQUARE_HEIGHT, bits, ((p->color == WHITE) ?
  1850. X            win->whitepiece.pixel : win->blackpiece.pixel),
  1851. X            (iswhite(win, x, y) ? win->whitesquare.pixel :
  1852. X            win->blacksquare.pixel), 0, GXcopy, AllPlanes);
  1853. X    }
  1854. X
  1855. X    if (!record_english) {
  1856. X        if (!x) {
  1857. X            sprintf(buf, " %d", SIZE - y);
  1858. X            XText(win->boardwin, 1, (y + 1) * (SQUARE_HEIGHT + 
  1859. X                    BORDER_WIDTH) - BORDER_WIDTH - 
  1860. X                    win->small->height - 1, buf, 2,
  1861. X                    win->small->id, win->textcolor.pixel, 
  1862. X                    ((iswhite(win, x, y) || win->bnw) ?
  1863. X                    win->whitesquare.pixel : 
  1864. X                    win->blacksquare.pixel));
  1865. X        }
  1866. X        if (y == SIZE - 1) {
  1867. X            sprintf(buf, "%c", 'A' + x);
  1868. X            XText(win->boardwin, x * (SQUARE_WIDTH + BORDER_WIDTH)
  1869. X                    + 1, SIZE * (SQUARE_HEIGHT + 
  1870. X                    BORDER_WIDTH) - BORDER_WIDTH - 
  1871. X                    win->small->height - 1, buf, 1,
  1872. X                    win->small->id, win->textcolor.pixel,
  1873. X                    ((iswhite(win, x, y) || win->bnw) ? 
  1874. X                    win->whitesquare.pixel : 
  1875. X                    win->blacksquare.pixel));
  1876. X        }
  1877. X    }
  1878. X    return;
  1879. X}
  1880. X
  1881. Xvoid
  1882. Xwin_erasepiece(y, x, wnum)
  1883. X    int y, x;
  1884. X    color wnum;
  1885. X{
  1886. X    windata *win;
  1887. X    char buf[BSIZE];
  1888. X
  1889. X    if (oneboard || (wnum == win1->color))
  1890. X        win = win1;
  1891. X    else
  1892. X        win = win2;
  1893. X        
  1894. X    XSetDisplay(win->display);
  1895. X
  1896. X    if (win->flipped) {
  1897. X        y = SIZE - y - 1;
  1898. X        x = SIZE - x - 1;
  1899. X    }
  1900. X
  1901. X    /*
  1902. X    if (debug)
  1903. X        fprintf(stderr, "erase square (%d, %d) on board %d\n", y, x,
  1904. X                wnum);
  1905. X     */
  1906. X
  1907. Xif ((x < 0) || (x > 7) || (y < 0) || (y > 7)) exit(1);
  1908. X
  1909. X    if (win->bnw && !iswhite(win, x, y)) {
  1910. X        XBitmapBitsPut(win->boardwin, x * (SQUARE_WIDTH + BORDER_WIDTH),
  1911. X            y * (SQUARE_HEIGHT + BORDER_WIDTH), SQUARE_WIDTH,
  1912. X            SQUARE_HEIGHT, shade_bits, BlackPixel, WhitePixel,
  1913. X            0, GXcopy, AllPlanes);
  1914. X    } else {
  1915. X        XPixSet(win->boardwin, x * (SQUARE_WIDTH + BORDER_WIDTH),
  1916. X                y * (SQUARE_HEIGHT + BORDER_WIDTH),
  1917. X                SQUARE_WIDTH, SQUARE_HEIGHT, iswhite(win, x, y)
  1918. X                ? win->whitesquare.pixel :
  1919. X                win->blacksquare.pixel);
  1920. X    }
  1921. X
  1922. X    if (!record_english) {
  1923. X        if (!x) {
  1924. X            sprintf(buf, " %d", SIZE - y);
  1925. X            XText(win->boardwin, 1, (y + 1) * (SQUARE_HEIGHT + 
  1926. X                    BORDER_WIDTH) - BORDER_WIDTH - 
  1927. X                    win->small->height - 1, buf, 2,
  1928. X                    win->small->id, win->textcolor.pixel, 
  1929. X                    ((iswhite(win, x, y) || win->bnw) ? 
  1930. X                    win->whitesquare.pixel : 
  1931. X                    win->blacksquare.pixel));
  1932. X        }
  1933. X        if (y == SIZE - 1) {
  1934. X            sprintf(buf, "%c", 'A' + x);
  1935. X            XText(win->boardwin, x * (SQUARE_WIDTH + BORDER_WIDTH)
  1936. X                    + 1, SIZE * (SQUARE_HEIGHT + 
  1937. X                    BORDER_WIDTH) - BORDER_WIDTH - 
  1938. X                    win->small->height - 1, buf, 1,
  1939. X                    win->small->id, win->textcolor.pixel,
  1940. X                    ((iswhite(win, x, y) || win->bnw) ? 
  1941. X                    win->whitesquare.pixel : 
  1942. X                    win->blacksquare.pixel));
  1943. X        }
  1944. X    }
  1945. X
  1946. X    return;
  1947. X}
  1948. X
  1949. Xvoid
  1950. Xwin_flash(m, wnum)
  1951. X    move *m;
  1952. X    color wnum;
  1953. X{
  1954. X    windata *win;
  1955. X    int sx, sy, ex, ey, i;
  1956. X
  1957. X    if (oneboard || (wnum == win1->color))
  1958. X        win = win1;
  1959. X    else
  1960. X        win = win2;
  1961. X        
  1962. X    XSetDisplay(win->display);
  1963. X
  1964. X    if (win->flipped) {
  1965. X        sx = SIZE - m->fromx - 1;
  1966. X        sy = SIZE - m->fromy - 1;
  1967. X        ex = SIZE - m->tox - 1;
  1968. X        ey = SIZE - m->toy - 1;
  1969. X    } else {
  1970. X        sx = m->fromx;
  1971. X        sy = m->fromy;
  1972. X        ex = m->tox;
  1973. X        ey = m->toy;
  1974. X    }
  1975. X    sx = sx * (SQUARE_WIDTH + BORDER_WIDTH) + SQUARE_WIDTH / 2;
  1976. X    sy = sy * (SQUARE_HEIGHT + BORDER_WIDTH) + SQUARE_HEIGHT / 2;
  1977. X    ex = ex * (SQUARE_WIDTH + BORDER_WIDTH) + SQUARE_WIDTH / 2;
  1978. X    ey = ey * (SQUARE_HEIGHT + BORDER_WIDTH) + SQUARE_HEIGHT / 2;
  1979. X
  1980. X    for (i = 0; i < num_flashes * 2; i++)
  1981. X        XLine(win->boardwin, sx, sy, ex, ey, flash_size, flash_size,
  1982. X                BlackPixel, GXinvert, AllPlanes);
  1983. X    return;
  1984. X}
  1985. X
  1986. X/* Handle input from the players. */
  1987. X
  1988. Xvoid
  1989. Xwin_process(quick)
  1990. X    bool quick;
  1991. X{
  1992. X    int i, rfd = 0, wfd = 0, xfd = 0;
  1993. X    struct timeval timeout;
  1994. X
  1995. X    timeout.tv_sec = 0;
  1996. X    timeout.tv_usec = (quick ? 0 : 500000);
  1997. X
  1998. X    XSetDisplay(win1->display);
  1999. X    if (XPending())
  2000. X        service(win1);
  2001. X    if (!oneboard) {
  2002. X        XSetDisplay(win2->display);
  2003. X        if (XPending())
  2004. X            service(win2);
  2005. X    }
  2006. X
  2007. X    if (oneboard)
  2008. X        rfd = 1 << win1->display->fd;
  2009. X    else
  2010. X        rfd = (1 << win1->display->fd) | (1 << win2->display->fd);
  2011. X    if (!(i = select(32, &rfd, &wfd, &xfd, &timeout)))
  2012. X        return;
  2013. X    if (i == -1) {
  2014. X        perror("select");
  2015. X        exit(1);
  2016. X    }
  2017. X    if (rfd & (1 << win1->display->fd))
  2018. X        service(win1);
  2019. X    if (!oneboard && (rfd & (1 << win2->display->fd)))
  2020. X        service(win2);
  2021. X
  2022. X    return;
  2023. X}
  2024. X
  2025. Xstatic void
  2026. Xservice(win)
  2027. X    windata *win;
  2028. X{
  2029. X    XEvent ev;
  2030. X
  2031. X    XSetDisplay(win->display);
  2032. X
  2033. X    while(XPending()) {
  2034. X        XNextEvent(&ev);
  2035. X        if (TxtFilter(&ev))
  2036. X            continue;
  2037. X
  2038. X        if (ev.window == win->boardwin) {
  2039. X            switch (ev.type) {
  2040. X                case ButtonPressed:
  2041. X                button_pressed(&ev, win);
  2042. X                break;
  2043. X
  2044. X                case ButtonReleased:
  2045. X                button_released(&ev, win);
  2046. X                break;
  2047. X
  2048. X                case ExposeRegion:
  2049. X                case ExposeWindow:
  2050. X                /* Redraw... */
  2051. X                win_redraw(win, &ev);
  2052. X                break;
  2053. X
  2054. X                case 0:
  2055. X                break;
  2056. X                default:
  2057. X                fprintf(stderr, "Bad event type %d\n", ev.type);
  2058. X                exit(1);
  2059. X            }
  2060. X        } else if (ev.window == win->wclockwin) {
  2061. X            switch (ev.type) {
  2062. X                case ExposeRegion:
  2063. X                case ExposeWindow:
  2064. X                clock_draw(win, WHITE);
  2065. X                break;
  2066. X
  2067. X                case 0:
  2068. X                break;
  2069. X                default:
  2070. X                fprintf(stderr, "Bad event type %d\n", ev.type);
  2071. X                exit(1);
  2072. X            }
  2073. X        } else if (ev.window == win->bclockwin) {
  2074. X            switch (ev.type) {
  2075. X                case ExposeRegion:
  2076. X                case ExposeWindow:
  2077. X                clock_draw(win, BLACK);
  2078. X                break;
  2079. X
  2080. X                case 0:
  2081. X                break;
  2082. X                default:
  2083. X                fprintf(stderr, "Bad event type %d\n", ev.type);
  2084. X                exit(1);
  2085. X            }
  2086. X        } else if (ev.window == win->jailwin) {
  2087. X            switch (ev.type) {
  2088. X                case ExposeRegion:
  2089. X                case ExposeWindow:
  2090. X                jail_draw(win);
  2091. X                break;
  2092. X
  2093. X                case 0:
  2094. X                break;
  2095. X                default:
  2096. X                fprintf(stderr, "Bad event type %d\n", ev.type);
  2097. X                exit(1);
  2098. X            }
  2099. X        } else if (ev.window == win->buttonwin) {
  2100. X            switch (ev.type) {
  2101. X                case ButtonPressed:
  2102. X                button_service(win, &ev);
  2103. X                break;
  2104. X
  2105. X                case ExposeRegion:
  2106. X                case ExposeWindow:
  2107. X                button_draw(win, &ev);
  2108. X                break;
  2109. X
  2110. X                case 0:
  2111. X                break;
  2112. X                default:
  2113. X                fprintf(stderr, "Bad event type %d\n", ev.type);
  2114. X                exit(1);
  2115. X            }
  2116. X        } else if (ev.window == win->icon) {
  2117. X            icon_refresh(win);
  2118. X        } else if (ev.window == win->basewin) {
  2119. X            message_send(win, &ev);
  2120. X        } else {
  2121. X            fprintf(stderr, "Internal Error: service: bad win\n");
  2122. X            fprintf(stderr, "window = %d, event = %d\n", ev.window,
  2123. X                    ev.type);
  2124. X        }
  2125. X    }
  2126. X    return;
  2127. X}
  2128. X
  2129. Xvoid
  2130. Xwin_redraw(win, event)
  2131. X    windata *win;
  2132. X    XEvent *event;
  2133. X{
  2134. X    XExposeEvent *ev = (XExposeEvent *) event;
  2135. X    int x1, y1, x2, y2, i, j;
  2136. X
  2137. X    drawgrid(win);
  2138. X    if (ev) {
  2139. X        x1 = ev->x / (SQUARE_WIDTH + BORDER_WIDTH);
  2140. X        y1 = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH);
  2141. X        x2 = (ev->x + ev->width) / (SQUARE_WIDTH + BORDER_WIDTH);
  2142. X        y2 = (ev->y + ev->height) / (SQUARE_HEIGHT + BORDER_WIDTH);
  2143. X    } else {
  2144. X        x1 = 0;
  2145. X        y1 = 0;
  2146. X        x2 = SIZE - 1;
  2147. X        y2 = SIZE - 1;
  2148. X    }
  2149. X
  2150. X    if (x1 < 0) x1 = 0;
  2151. X    if (y1 < 0) y1 = 0;
  2152. X    if (x2 < 0) x2 = 0;
  2153. X    if (y2 < 0) y2 = 0;
  2154. X    if (x1 > SIZE - 1) x1 = SIZE - 1;
  2155. X    if (y1 > SIZE - 1) y1 = SIZE - 1;
  2156. X    if (x2 > SIZE - 1) x2 = SIZE - 1;
  2157. X    if (y2 > SIZE - 1) y2 = SIZE - 1;
  2158. X
  2159. X    if (win->flipped) {
  2160. X        y1 = SIZE - y2 - 1;
  2161. X        y2 = SIZE - y1 - 1;
  2162. X        x1 = SIZE - x2 - 1;
  2163. X        x2 = SIZE - x1 - 1;
  2164. X    }
  2165. X
  2166. X    for (i = x1; i <= x2; i++) 
  2167. X        for (j = y1; j <= y2; j++) {
  2168. X            if (chessboard->square[j][i].color == NONE)
  2169. X                win_erasepiece(j, i, WHITE);
  2170. X            else
  2171. X                win_drawpiece(&chessboard->square[j][i], j, i,
  2172. X                        WHITE);
  2173. X            if (!oneboard) {
  2174. X                if (chessboard->square[j][i].color == NONE)
  2175. X                    win_erasepiece(j, i, BLACK);
  2176. X                else
  2177. X                    win_drawpiece(&chessboard->square[j][i],
  2178. X                            j, i, BLACK);
  2179. X            }
  2180. X        }
  2181. X    
  2182. X    return;
  2183. X}
  2184. X
  2185. Xstatic bool
  2186. Xsetup(dispname, win)
  2187. X    char *dispname;
  2188. X    windata *win;
  2189. X{
  2190. X    Pixmap btile, ttile;
  2191. X    char buf[BSIZE];
  2192. X    Bitmap bm;
  2193. X    Cursor cur;
  2194. X
  2195. X    if (!(win->display = XOpenDisplay(dispname)))
  2196. X        return (false);
  2197. X    
  2198. X    if ((DisplayPlanes() == 1) || bnwflag)
  2199. X        win->bnw = true;
  2200. X    
  2201. X    /* Allocate colors... */
  2202. X    if (win->bnw) {
  2203. X        win->blackpiece.pixel = BlackPixel;
  2204. X        win->whitepiece.pixel = WhitePixel;
  2205. X        win->blacksquare.pixel = BlackPixel;
  2206. X        win->whitesquare.pixel = WhitePixel;
  2207. X        win->border.pixel = BlackPixel;
  2208. X        win->textcolor.pixel = BlackPixel;
  2209. X        win->textback.pixel = WhitePixel;
  2210. X        win->playertext.pixel = BlackPixel;
  2211. X        win->errortext.pixel = BlackPixel;
  2212. X        win->cursorcolor.pixel = BlackPixel;
  2213. X    } else {
  2214. X        if (!XParseColor(black_piece_color, &win->blackpiece) ||
  2215. X            !XParseColor(white_piece_color, &win->whitepiece) ||
  2216. X            !XParseColor(black_square_color, &win->blacksquare) ||
  2217. X            !XParseColor(white_square_color, &win->whitesquare) ||
  2218. X            !XParseColor(border_color, &win->border) ||
  2219. X            !XParseColor(text_color, &win->textcolor) ||
  2220. X            !XParseColor(text_back, &win->textback) ||
  2221. X            !XParseColor(error_text, &win->errortext) ||
  2222. X            !XParseColor(player_text, &win->playertext) ||
  2223. X            !XParseColor(cursor_color, &win->cursorcolor) ||
  2224. X            !XGetHardwareColor(&win->blackpiece) ||
  2225. X            !XGetHardwareColor(&win->whitepiece) ||
  2226. X            !XGetHardwareColor(&win->blacksquare) ||
  2227. X            !XGetHardwareColor(&win->whitesquare) ||
  2228. X            !XGetHardwareColor(&win->border) ||
  2229. X            !XGetHardwareColor(&win->textcolor) ||
  2230. X            !XGetHardwareColor(&win->textback) ||
  2231. X            !XGetHardwareColor(&win->errortext) ||
  2232. X            !XGetHardwareColor(&win->playertext) ||
  2233. X            !XGetHardwareColor(&win->cursorcolor))
  2234. X            fprintf(stderr, "Can't get color...\n");
  2235. X    }
  2236. X
  2237. X    /* Get fonts... */
  2238. X    win->small = XOpenFont(SMALL_FONT);
  2239. X    win->medium = XOpenFont(MEDIUM_FONT);
  2240. X    win->large = XOpenFont(LARGE_FONT);
  2241. X    
  2242. X    /* Create the windows... */
  2243. X
  2244. X    btile = XMakeTile(win->border.pixel);
  2245. X    ttile = XMakeTile(win->textback.pixel);
  2246. X    win->basewin = XCreateWindow(RootWindow, BASE_XPOS, BASE_YPOS,
  2247. X            BASE_WIDTH, BASE_HEIGHT, 0, WhitePixmap, WhitePixmap);
  2248. X    win->boardwin = XCreateWindow(win->basewin, BOARD_XPOS, BOARD_YPOS,
  2249. X            BOARD_WIDTH, BOARD_HEIGHT, BORDER_WIDTH, btile,
  2250. X            WhitePixmap);
  2251. X    win->recwin = XCreateWindow(win->basewin, RECORD_XPOS, RECORD_YPOS,
  2252. X            RECORD_WIDTH, RECORD_HEIGHT, BORDER_WIDTH,
  2253. X            btile, ttile);
  2254. X    win->jailwin = XCreateWindow(win->basewin, JAIL_XPOS, JAIL_YPOS,
  2255. X            JAIL_WIDTH, JAIL_HEIGHT, BORDER_WIDTH,
  2256. X            btile, ttile);
  2257. X    win->wclockwin = XCreateWindow(win->basewin, WCLOCK_XPOS, WCLOCK_YPOS,
  2258. X            CLOCK_WIDTH, CLOCK_HEIGHT, BORDER_WIDTH, btile,
  2259. X            ttile);
  2260. X    win->bclockwin = XCreateWindow(win->basewin, BCLOCK_XPOS, BCLOCK_YPOS,
  2261. X            CLOCK_WIDTH, CLOCK_HEIGHT, BORDER_WIDTH, btile,
  2262. X            ttile);
  2263. X    win->messagewin = XCreateWindow(win->basewin, MESS_XPOS, MESS_YPOS,
  2264. X            MESS_WIDTH, MESS_HEIGHT, BORDER_WIDTH, btile, ttile);
  2265. X    win->buttonwin = XCreateWindow(win->basewin, BUTTON_XPOS, BUTTON_YPOS,
  2266. X            BUTTON_WIDTH, BUTTON_HEIGHT, BORDER_WIDTH, btile,
  2267. X            ttile);
  2268. X    
  2269. X    /* Let's define an icon... */
  2270. X    bm = XStoreBitmap(icon_width, icon_height, icon_bits);
  2271. X    win->iconpixmap = XMakePixmap(bm, win->blacksquare.pixel,
  2272. X            win->whitesquare.pixel);
  2273. X    win->icon = XCreateWindow(RootWindow, BASE_XPOS, BASE_YPOS, icon_width,
  2274. X            icon_height, 2, btile, WhitePixmap);
  2275. X    XSetIconWindow(win->basewin, win->icon);
  2276. X    XSelectInput(win->icon, ExposeRegion);
  2277. X
  2278. X    cur = XCreateCursor(xchess_width, xchess_height, xchess_bits,
  2279. X            xchess_mask_bits, xchess_x_hot, xchess_y_hot,
  2280. X            win->cursorcolor.pixel, WhitePixel, GXcopy);
  2281. X    XDefineCursor(win->basewin, cur);
  2282. X
  2283. X    XMapWindow(win->basewin);
  2284. X    XMapSubwindows(win->basewin);
  2285. X
  2286. X    XSelectInput(win->basewin, KeyPressed);
  2287. X    XSelectInput(win->boardwin, ButtonPressed | ButtonReleased |
  2288. X            ExposeRegion | ExposeWindow);
  2289. X    XSelectInput(win->recwin, ButtonReleased | ExposeRegion |
  2290. X            ExposeWindow | ExposeCopy);
  2291. X    XSelectInput(win->jailwin, ExposeRegion | ExposeWindow);
  2292. X    XSelectInput(win->wclockwin, ExposeRegion | ExposeWindow);
  2293. X    XSelectInput(win->bclockwin, ExposeRegion | ExposeWindow);
  2294. X    XSelectInput(win->messagewin, ButtonReleased | ExposeRegion |
  2295. X            ExposeWindow | ExposeCopy);
  2296. X    XSelectInput(win->buttonwin, ButtonPressed | ExposeRegion |
  2297. X            ExposeWindow);
  2298. X    
  2299. X    message_init(win);
  2300. X    record_init(win);
  2301. X    button_draw(win);
  2302. X    jail_init(win);
  2303. X    clock_init(win, WHITE);
  2304. X    clock_init(win, BLACK);
  2305. X    if (timeunit) {
  2306. X        if (timeunit > 1800)
  2307. X            sprintf(buf, "%d moves every %.2lg hours.\n",
  2308. X                movesperunit, ((double) timeunit) / 3600);
  2309. X        else if (timeunit > 30)
  2310. X            sprintf(buf, "%d moves every %.2lg minutes.\n",
  2311. X                movesperunit, ((double) timeunit) / 60);
  2312. X        else
  2313. X            sprintf(buf, "%d moves every %d seconds.\n",
  2314. X                movesperunit, timeunit);
  2315. X        message_add(win, buf, false);
  2316. X    }
  2317. X
  2318. X    XFreePixmap(btile);
  2319. X    XFreePixmap(ttile);
  2320. X    
  2321. X    return (true);
  2322. X}
  2323. X
  2324. Xstatic void
  2325. Xdrawgrid(win)
  2326. X    windata *win;
  2327. X{
  2328. X    int i;
  2329. X
  2330. X    XSetDisplay(win->display);
  2331. X    /* Draw the lines... horizontal, */
  2332. X    for (i = 1; i < SIZE; i++)
  2333. X        XLine(win->boardwin, 0, i * (SQUARE_WIDTH + BORDER_WIDTH) -
  2334. X                (BORDER_WIDTH + 1) / 2 - 1, SIZE *
  2335. X                (SQUARE_WIDTH + BORDER_WIDTH),
  2336. X                i * (SQUARE_WIDTH +
  2337. X                BORDER_WIDTH) - (BORDER_WIDTH + 1) / 2 - 1,
  2338. X                BORDER_WIDTH, BORDER_WIDTH, win->border.pixel,
  2339. X                GXcopy, AllPlanes);
  2340. X
  2341. X    /* and vertical... */
  2342. X    for (i = 1; i < SIZE; i++)
  2343. X        XLine(win->boardwin, i * (SQUARE_WIDTH + BORDER_WIDTH) -
  2344. X                (BORDER_WIDTH + 1) / 2 - 1, 0,
  2345. X                i * (SQUARE_WIDTH +
  2346. X                BORDER_WIDTH) - (BORDER_WIDTH + 1) / 2 - 1,
  2347. X                SIZE * (SQUARE_WIDTH + BORDER_WIDTH),
  2348. X                BORDER_WIDTH, BORDER_WIDTH, win->border.pixel,
  2349. X                GXcopy, AllPlanes);
  2350. X    return;
  2351. X}
  2352. X
  2353. Xvoid
  2354. Xwin_restart()
  2355. X{
  2356. X    win1->flipped = false;
  2357. X    win_redraw(win1, (XEvent *) NULL);
  2358. X    if (!oneboard) {
  2359. X        win2->flipped = true;
  2360. X        win_redraw(win2, (XEvent *) NULL);
  2361. X    }
  2362. X    return;
  2363. X}
  2364. X
  2365. Xstatic void
  2366. Xicon_refresh(win)
  2367. X    windata *win;
  2368. X{
  2369. X    XPixmapPut(win->icon, 0, 0, 0, 0, icon_width, icon_height,
  2370. X            win->iconpixmap, GXcopy, AllPlanes);
  2371. X    return;
  2372. X}
  2373. X
  2374. END_OF_window.c
  2375. if test 18431 -ne `wc -c <window.c`; then
  2376.     echo shar: \"window.c\" unpacked with wrong size!
  2377. fi
  2378. # end of overwriting check
  2379. fi
  2380. echo shar: End of archive 1 \(of 6\).
  2381. cp /dev/null ark1isdone
  2382. MISSING=""
  2383. for I in 1 2 3 4 5 6 ; do
  2384.     if test ! -f ark${I}isdone ; then
  2385.     MISSING="${MISSING} ${I}"
  2386.     fi
  2387. done
  2388. if test "${MISSING}" = "" ; then
  2389.     echo You have unpacked all 6 archives.
  2390.     rm -f ark[1-9]isdone
  2391. else
  2392.     echo You still need to unpack the following archives:
  2393.     echo "        " ${MISSING}
  2394. fi
  2395. ##  End of shell archive.
  2396. exit 0
  2397.