home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / x / volume13 / xboard / part02 < prev    next >
Text File  |  1991-06-26  |  51KB  |  2,001 lines

  1. Path: uunet!uunet!cs.utexas.edu!sun-barr!cronkite!exodus!Pa.dec.com!dbs
  2. From: dbs@Pa.dec.com
  3. Newsgroups: comp.sources.x
  4. Subject: v13i058: xboard, Part02/06
  5. Message-ID: <15683@exodus.Eng.Sun.COM>
  6. Date: 24 Jun 91 13:40:28 GMT
  7. References: <csx-13i057-xboard@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 1989
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: dbs@Pa.dec.com
  13. Posting-number: Volume 13, Issue 58
  14. Archive-name: xboard/part02
  15.  
  16. ---- Cut Here and feed the following to sh ----
  17. #!/bin/sh
  18. # this is xx.02 (part 2 of a multipart archive)
  19. # do not concatenate these parts, unpack them in order with /bin/sh
  20. # file xboard/xboard.c continued
  21. #
  22. if test ! -r _shar_seq_.tmp; then
  23.     echo 'Please unpack part 1 first!'
  24.     exit 1
  25. fi
  26. (read Scheck
  27.  if test "$Scheck" != 2; then
  28.     echo Please unpack part "$Scheck" next!
  29.     exit 1
  30.  else
  31.     exit 0
  32.  fi
  33. ) < _shar_seq_.tmp || exit 1
  34. if test ! -f _shar_wnt_.tmp; then
  35.     echo 'x - still skipping xboard/xboard.c'
  36. else
  37. echo 'x - continuing file xboard/xboard.c'
  38. sed 's/^X//' << 'SHAR_EOF' >> 'xboard/xboard.c' &&
  39. X        boards[currentMove][to_y][to_x] = WhitePawn;
  40. X        boards[currentMove][to_y - 1][to_x] = EmptySquare;
  41. X        DrawSquare(from_y, from_x, boards[currentMove][from_y][from_x]);
  42. X        DrawSquare(to_y, to_x, boards[currentMove][to_y][to_x]);
  43. X        DrawSquare(to_y - 1, to_x, boards[currentMove][to_y - 1][to_x]);
  44. X        if (gameMode == PlayFromGameFile)
  45. X            sprintf(message, "%d. %s", move, yytext);
  46. X        else
  47. X            sprintf(message, "%d. %c%c ep", move, from_x + 'a', to_x + 'a');
  48. X    } else if (from_y == 7 && from_x == 4        /* black king-side castle */
  49. X            && boards[currentMove][from_y][from_x] == BlackKing
  50. X            && to_y == 7 && to_x == 6) {
  51. X        *move_type = BlackKingSideCastle;
  52. X        boards[currentMove][7][4] = EmptySquare;
  53. X        boards[currentMove][7][5] = BlackRook;
  54. X        boards[currentMove][7][6] = BlackKing;
  55. X        boards[currentMove][7][7] = EmptySquare;
  56. X        DrawSquare(7, 7, boards[currentMove][7][7]);
  57. X        DrawSquare(7, 6, boards[currentMove][7][6]);
  58. X        DrawSquare(7, 5, boards[currentMove][7][5]);
  59. X        DrawSquare(7, 4, boards[currentMove][7][4]);
  60. X        if (gameMode == PlayFromGameFile)
  61. X            sprintf(message, "%d. ... %s", move, yytext);
  62. X        else
  63. X            sprintf(message, "%d. ... 0-0", move);
  64. X    } else if (from_y == 7 && from_x == 4        /* black queen-side castle */
  65. X            && boards[currentMove][from_y][from_x] == BlackKing
  66. X            && to_y == 7 && to_x == 2) {
  67. X        *move_type = BlackQueenSideCastle;
  68. X        boards[currentMove][7][0] = EmptySquare;
  69. X        boards[currentMove][7][2] = BlackKing;
  70. X        boards[currentMove][7][3] = BlackRook;
  71. X        boards[currentMove][7][4] = EmptySquare;
  72. X        DrawSquare(7, 0, boards[currentMove][7][0]);
  73. X        DrawSquare(7, 2, boards[currentMove][7][2]);
  74. X        DrawSquare(7, 3, boards[currentMove][7][3]);
  75. X        DrawSquare(7, 4, boards[currentMove][7][4]);
  76. X        if (gameMode == PlayFromGameFile)
  77. X            sprintf(message, "%d. ... %s", move, yytext);
  78. X        else
  79. X            sprintf(message, "%d. ... 0-0-0", move);
  80. X    } else if (from_y == 1                        /* black pawn promotion */
  81. X            && boards[currentMove][from_y][from_x] == BlackPawn && to_y == 0) {
  82. X        *move_type = BlackPromotionQueen;        /* TODO: gnuchess limitation */
  83. X        boards[currentMove][1][from_x] = EmptySquare;
  84. X        boards[currentMove][0][to_x] = BlackQueen;
  85. X        DrawSquare(1, from_x, boards[currentMove][1][from_x]);
  86. X        DrawSquare(0, to_x, boards[currentMove][0][to_x]);
  87. X        if (gameMode == PlayFromGameFile)
  88. X            sprintf(message, "%d. ... %s", move, yytext);
  89. X        else
  90. X            sprintf(message, "%d. ... %c8(Q)", move, from_x + 'a');
  91. X    } else if ((from_y == 3)                    /* black captures en passant */
  92. X            && (to_x != from_x)
  93. X            && (boards[currentMove][from_y][from_x] == BlackPawn)
  94. X            && (boards[currentMove][to_y][to_x] == EmptySquare)) {
  95. X        *move_type = BlackCapturesEnPassant;
  96. X        boards[currentMove][from_y][from_x] = EmptySquare;
  97. X        boards[currentMove][to_y][to_x] = BlackPawn;
  98. X        boards[currentMove][to_y + 1][to_x] = EmptySquare;
  99. X        DrawSquare(from_y, from_x, boards[currentMove][from_y][from_x]);
  100. X        DrawSquare(to_y, to_x, boards[currentMove][to_y][to_x]);
  101. X        DrawSquare(to_y + 1, to_x, boards[currentMove][to_y + 1][to_x]);
  102. X        if (gameMode == PlayFromGameFile)
  103. X            sprintf(message, "%d. ... %s", move, yytext);
  104. X        else
  105. X            sprintf(message, "%d. ... %c%c ep", move, from_x + 'a', to_x + 'a');
  106. X    } else {
  107. X        *move_type = NormalMove;
  108. X        boards[currentMove][to_y][to_x] = boards[currentMove][from_y][from_x];
  109. X        boards[currentMove][from_y][from_x] = EmptySquare;
  110. X        DrawSquare(to_y, to_x, boards[currentMove][to_y][to_x]);
  111. X        DrawSquare(from_y, from_x, boards[currentMove][from_y][from_x]);
  112. X        if (gameMode == PlayFromGameFile)
  113. X            sprintf(message, "%d. %s%s", move,
  114. X                WHITE_ON_MOVE ? "... " : "", yytext);
  115. X        else
  116. X            sprintf(message, "%d. %s%c%c%c%c", move, WHITE_ON_MOVE ? "... "
  117. X                : "", from_x + 'a', from_y + '1', to_x + 'a', to_y + '1');
  118. X    }
  119. X
  120. X    DisplayMessage(message);
  121. X    strcpy(parseList[currentMove - 1], message);
  122. X    XSync(xDisplay, False);
  123. }
  124. X
  125. void
  126. InitChessProgram(host_name, program_name, pid, to, from, xid)
  127. X    char *host_name, *program_name;
  128. X    int *pid;
  129. X    FILE **to, **from;
  130. X    XtIntervalId *xid;
  131. {
  132. X    char time_control[10], moves_per_session[10], time_search[10];
  133. X    int to_prog[2], from_prog[2];
  134. X    FILE *from_fp, *to_fp;
  135. X
  136. #if    SYSTEM_FIVE || SYSV
  137. X    if ((ttyname = PseudoTTY(&to_prog[1])) == NULL) {
  138. X        perror(program_name);
  139. X        exit(1);
  140. X    }
  141. X
  142. X    from_prog[0] = to_prog[1];
  143. X    to_prog[0] = from_prog[1] = open(ttyname, O_RDWR, 0);
  144. #else
  145. X    signal(SIGPIPE, CatchPipeSignal);
  146. X    pipe(to_prog);
  147. X    pipe(from_prog);
  148. #endif
  149. X
  150. X    if ((*pid = fork()) == 0) {
  151. #if    !SYSTEM_FIVE && !SYSV
  152. X        signal(SIGPIPE, CatchPipeSignal);
  153. #ifdef    O_NDELAY
  154. X        fcntl(from_prog[0], F_SETFL, O_NDELAY);
  155. #endif
  156. #endif
  157. X        dup2(to_prog[0], 0);
  158. X        dup2(from_prog[1], 1);
  159. X        close(to_prog[0]);
  160. X        close(to_prog[1]);
  161. X        close(from_prog[0]);
  162. X        close(from_prog[1]);
  163. X        dup2(1, fileno(stderr));    /* force stderr to the pipe */
  164. X        sprintf(time_control, "%d", appData.timeControl);
  165. X        sprintf(time_search, "%d", appData.searchTime);
  166. X        sprintf(moves_per_session, "%d", appData.movesPerSession);
  167. X        if (strcmp(host_name, "localhost") == 0) {
  168. X            if (appData.searchTime <= 0)
  169. X                execlp(program_name, program_name,
  170. X                    moves_per_session, time_control, (char *) NULL);
  171. X            else
  172. X                execlp(program_name, program_name, time_search, (char *) NULL);
  173. X        } else {
  174. X            if (appData.searchTime <= 0)
  175. X                execlp(appData.remoteShell, appData.remoteShell,
  176. X                    host_name, program_name, moves_per_session,
  177. X                    time_control, (char *) NULL);
  178. X            else
  179. X                execlp(appData.remoteShell, appData.remoteShell,
  180. X                    host_name, program_name, time_search, (char *) NULL);
  181. X        }
  182. X
  183. X        perror(program_name);
  184. X        exit(1);
  185. X    }
  186. X
  187. X    close(to_prog[0]);
  188. X    close(from_prog[1]);
  189. X
  190. X    *from = from_fp = fdopen(from_prog[0], "r");
  191. X    *to = to_fp = fdopen(to_prog[1], "w");
  192. X    setbuf(from_fp, NULL); setbuf(to_fp, NULL);
  193. X
  194. X    *xid = XtAppAddInput(appContext, fileno(from_fp), XtInputReadMask,
  195. X        ReceiveFromProgram, from_fp);
  196. X
  197. X    SendToProgram(appData.initString, to_fp);
  198. }
  199. X
  200. void
  201. ShutdownChessPrograms(message)
  202. X    char *message;
  203. {
  204. X    lastGameMode = gameMode;
  205. X    gameMode = EndOfGame;
  206. X    DisplayMessage(message);
  207. X
  208. X    if (firstProgramPID != 0) {
  209. X        fclose(fromFirstProgFP);
  210. X        fclose(toFirstProgFP);
  211. X        fromFirstProgFP = toFirstProgFP = NULL;
  212. X        kill(firstProgramPID, SIGTERM);
  213. X    }
  214. X
  215. X    if (secondProgramPID != 0) {
  216. X        fclose(fromSecondProgFP);
  217. X        fclose(toSecondProgFP);
  218. X        fromSecondProgFP = toSecondProgFP = NULL;
  219. X        kill(secondProgramPID, SIGTERM);
  220. X    }
  221. X
  222. X    if (firstProgramXID != NULL)
  223. X        XtRemoveInput(firstProgramXID);
  224. X    if (secondProgramXID != NULL)
  225. X        XtRemoveInput(secondProgramXID);
  226. X    if (readGameXID != NULL)
  227. X        XtRemoveTimeOut(readGameXID);
  228. X
  229. X    firstProgramXID = secondProgramXID = readGameXID = NULL;
  230. X    firstProgramPID = secondProgramPID = 0;
  231. X
  232. X    DisplayClocks(StopTimers);
  233. }
  234. X
  235. void
  236. CommentPopUp(label)
  237. X    char *label;
  238. {
  239. X    Arg args[2];
  240. X    Position x, y;
  241. X    Dimension bw_width, pw_width;
  242. X
  243. X    if (commentUp) {
  244. X        XtPopdown(commentShell);
  245. X        XtDestroyWidget(commentShell);
  246. X        commentUp = False;
  247. X    }
  248. X
  249. X    DisplayMessage("Comment");
  250. X
  251. X    XtSetArg(args[0], XtNwidth, &bw_width);
  252. X    XtGetValues(boardWidget, args, 1);
  253. X
  254. X    XtSetArg(args[0], XtNresizable, True);
  255. X    XtSetArg(args[1], XtNwidth, bw_width);
  256. X
  257. X    commentShell = XtCreatePopupShell("Comment",
  258. X        transientShellWidgetClass, commandsWidget, args, 2);
  259. X
  260. X    XtSetArg(args[0], XtNlabel, label);
  261. X
  262. X    (void) XtCreateManagedWidget("commentLabel", labelWidgetClass,
  263. X        commentShell, args, 1);
  264. X
  265. X    XtRealizeWidget(commentShell);
  266. X
  267. X    XtSetArg(args[0], XtNwidth, &pw_width);
  268. X    XtGetValues(commentShell, args, 1);
  269. X
  270. X    XtTranslateCoords(shellWidget, (bw_width - pw_width) / 2, -50, &x, &y);
  271. X
  272. X    XtSetArg(args[0], XtNx, x);
  273. X    XtSetArg(args[1], XtNy, y);
  274. X    XtSetValues(commentShell, args, 2);
  275. X
  276. X    XtPopup(commentShell, XtGrabNone);
  277. X    commentUp = True;
  278. }
  279. X
  280. void
  281. FileNamePopUp(label, proc)
  282. X    char *label;
  283. X    void (*proc) P((char *name));
  284. {
  285. X    Arg args[2];
  286. X    Widget popup, dialog;
  287. X    Position x, y;
  288. X    Dimension bw_width, pw_width;
  289. X
  290. X    fileProc = (XtCallbackProc) proc;
  291. X
  292. X    XtSetArg(args[0], XtNwidth, &bw_width);
  293. X    XtGetValues(boardWidget, args, 1);
  294. X
  295. X    XtSetArg(args[0], XtNresizable, True);
  296. X    XtSetArg(args[1], XtNwidth, DIALOG_SIZE);
  297. X
  298. X    popup = XtCreatePopupShell("File Name Prompt",
  299. X        transientShellWidgetClass, commandsWidget, args, 2);
  300. X
  301. X    XtSetArg(args[0], XtNlabel, label);
  302. X    XtSetArg(args[1], XtNvalue, "");
  303. X
  304. X    dialog = XtCreateManagedWidget("dialog", dialogWidgetClass,
  305. X        popup, args, 2);
  306. X
  307. X    XawDialogAddButton(dialog, "ok", FileNameCallback, (XtPointer) dialog);
  308. X    XawDialogAddButton(dialog, "cancel", FileNameCallback, (XtPointer) dialog);
  309. X
  310. X    XtRealizeWidget(popup);
  311. X
  312. X    XtSetArg(args[0], XtNwidth, &pw_width);
  313. X    XtGetValues(popup, args, 1);
  314. X
  315. X    XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2, 10, &x, &y);
  316. X
  317. X    XtSetArg(args[0], XtNx, x);
  318. X    XtSetArg(args[1], XtNy, y);
  319. X    XtSetValues(popup, args, 2);
  320. X
  321. X    XtPopup(popup, XtGrabExclusive);
  322. X
  323. X    XtSetKeyboardFocus(shellWidget, popup);
  324. }
  325. X
  326. void
  327. FileNameCallback(w, client_data, call_data)
  328. X    Widget w;
  329. X    XtPointer client_data, call_data;
  330. {
  331. X    String name;
  332. X    Arg args[1];
  333. X
  334. X    XtSetArg(args[0], XtNlabel, &name);
  335. X    XtGetValues(w, args, 1);
  336. X
  337. X    if (strcmp(name, "cancel") == 0) {
  338. X        XtPopdown(w = XtParent(XtParent(w)));
  339. X        XtDestroyWidget(w);
  340. X        return;
  341. X    }
  342. X
  343. X    FileNameAction(w, NULL);
  344. }
  345. X
  346. void
  347. FileNameAction(w, event)
  348. X    Widget w;
  349. X    XEvent *event;
  350. {
  351. X    char buf[MSG_SIZ];
  352. X    String name;
  353. X
  354. X    name = XawDialogGetValueString(w = XtParent(w));
  355. X
  356. X    if ((name != NULL) && (*name != '\0')) {
  357. X        strcpy(buf, name);
  358. X        XtPopdown(w = XtParent(w));
  359. X        XtDestroyWidget(w);
  360. X        (*fileProc)(buf);    /* I can't see a way not to use a global here */
  361. X        return;
  362. X    }
  363. X
  364. X    XtPopdown(w = XtParent(w));
  365. X    XtDestroyWidget(w);
  366. }
  367. X
  368. void
  369. SelectCommand(w, client_data, call_data)
  370. X    Widget w;
  371. X    XtPointer client_data, call_data;
  372. {
  373. X    XawListReturnStruct *list_return = XawListShowCurrent(w);
  374. X
  375. X    fromX = fromY = -1;
  376. X
  377. X    if ((gameMode == PauseGame)
  378. X        && (list_return->list_index != (int) ButtonPause))
  379. X        PauseProc();
  380. X
  381. X    switch ((Button) list_return->list_index) {
  382. X    case ButtonQuit:
  383. X        QuitProc();
  384. X        break;
  385. X    case ButtonBackward:
  386. X        BackwardProc();
  387. X        break;
  388. X    case ButtonForward:
  389. X        ForwardProc();
  390. X        break;
  391. X    case ButtonFlip:
  392. X        FlipProc();
  393. X        break;
  394. X    case ButtonReset:
  395. X        ResetFileProc();
  396. X        ResetProc();
  397. X        break;
  398. X    case ButtonSaveGame:
  399. X        if (appData.saveGameFile[0] == '\0')
  400. X            FileNamePopUp("Filename for saved game?", SaveGameProc);
  401. X        else
  402. X            SaveGameProc(appData.saveGameFile);
  403. X        break;
  404. X    case ButtonSavePosition:
  405. X        if (appData.savePositionFile[0] == '\0')
  406. X            FileNamePopUp("Filename for saved position?", SavePositionProc);
  407. X        else
  408. X            SaveGameProc(appData.savePositionFile);
  409. X        break;
  410. X    case ButtonHint:
  411. X        HintProc();
  412. X        break;
  413. X    case ButtonSwitch:
  414. X        SwitchProc();
  415. X        break;
  416. X    case ButtonSetupFromFile:
  417. X        if (gameMode != BeginningOfGame)
  418. X            break;
  419. X        if (appData.readPositionFile == NULL)
  420. X            FileNamePopUp("Position file name?",
  421. X                VOID_PROC SetupPositionFromFileProc);
  422. X        else
  423. X            (void) SetupPositionFromFileProc(appData.readPositionFile);
  424. X        break;
  425. X    case ButtonPlayFromFile:
  426. X        GameProc();
  427. X        break;
  428. X    case ButtonMachinePlaysBlack:
  429. X        MachinePlaysBlackProc();
  430. X        break;
  431. X    case ButtonMachinePlaysWhite:
  432. X        MachinePlaysWhiteProc();
  433. X        break;
  434. X    case ButtonTwoMachinesPlay:
  435. X        TwoMachinesPlayProc();
  436. X        break;
  437. X    case ButtonForce:
  438. X        ForceProc();
  439. X        break;
  440. X    case ButtonPause:
  441. X        PauseProc();
  442. X        break;
  443. X    }
  444. X
  445. X    XawListUnhighlight(w);
  446. }
  447. X
  448. /*
  449. X * Button procedures
  450. X */
  451. void
  452. QuitProc()
  453. {
  454. X    ShutdownChessPrograms("Quitting");
  455. X    exit(0);
  456. }
  457. X
  458. int
  459. PlayFromGameFileProc(name)
  460. X    char *name;
  461. {
  462. X    char buf[MSG_SIZ], error_buf[MSG_SIZ];
  463. X    Arg args[1];
  464. X
  465. X    if (gameMode != BeginningOfGame)
  466. X        return (int) False;
  467. X
  468. X    if (appData.readGameFile != name) {
  469. X        if (appData.readGameFile)
  470. X            XtFree(appData.readGameFile);
  471. X        appData.readGameFile = XtMalloc(strlen(name));
  472. X        strcpy(appData.readGameFile, name);
  473. X    }
  474. X
  475. X    if (name[0] == '/')
  476. X        strcpy(buf, name);
  477. X    else {
  478. X        strcpy(buf, chessDir);
  479. X        strcat(buf, "/");
  480. X        strcat(buf, name);
  481. X    }
  482. X
  483. X    if ((gameFileFP = fopen(buf, "r")) == NULL) {
  484. X        strcpy(error_buf, buf);
  485. X        sprintf(buf, "Can't open %s", error_buf);
  486. X        DisplayMessage(buf);
  487. X        return (int) False;
  488. X    }
  489. X
  490. X    lastGameMode = gameMode;
  491. X    gameMode = PlayFromGameFile;
  492. X    InitPosition();
  493. X    DisplayClocks(StopTimers);
  494. X    if (firstProgramXID == NULL)
  495. X        InitChessProgram(appData.firstHost, appData.firstChessProgram,
  496. X            &firstProgramPID, &toFirstProgFP, &fromFirstProgFP,
  497. X            &firstProgramXID);
  498. X    SendToProgram(appData.initString, toFirstProgFP);
  499. X    SendToProgram("force\n", toFirstProgFP);
  500. X
  501. X    /*
  502. X     * If the file doesn't immediately start with what looks like a game ...
  503. X     */
  504. X    if (fgetc(gameFileFP) != '1') {
  505. X        fseek(gameFileFP, 0, 0);
  506. X        fgets(buf, MSG_SIZ, gameFileFP);
  507. X        buf[strlen(buf) - 1] = '\0';
  508. X        XtSetArg(args[0], XtNlabel, buf);
  509. X        XtSetValues(nameWidget, args, 1);
  510. X    } else
  511. X        fseek(gameFileFP, 0, 0);
  512. X
  513. X    for (;;)
  514. X        if ((ChessMove) yylex() == StartGame)
  515. X            break;
  516. X
  517. X    ReadGameFile();
  518. X
  519. X    return (int) True;
  520. }
  521. X
  522. void
  523. MachinePlaysBlackProc()
  524. {
  525. X    if ((gameMode == EndOfGame) || (gameMode == PlayFromGameFile)
  526. X        || (matchMode != MatchFalse) || WHITE_ON_MOVE)
  527. X        return;
  528. X
  529. X    undoMode = False;
  530. X    lastGameMode = gameMode = MachinePlaysBlack;
  531. X    SendToProgram(appData.blackString, toFirstProgFP);
  532. }
  533. X
  534. void
  535. ForwardProc()
  536. {
  537. X    char buf[MSG_SIZ];
  538. X    int i, j;
  539. X
  540. X    if (gameMode == BeginningOfGame) {
  541. X        if (currentMove != 0)
  542. X            return;
  543. X        if (appData.readGameFile != NULL) {
  544. X            if (PlayFromGameFileProc(appData.readGameFile)) {
  545. X                XtRemoveTimeOut(readGameXID);
  546. X                readGameXID = NULL;
  547. X            }
  548. X        }
  549. X        return;
  550. X    }
  551. X
  552. X    if ((gameMode == EndOfGame) || (matchMode != MatchFalse)
  553. X        || ((currentMove == 0) && (forwardMostMove == 0)))
  554. X        return;
  555. X
  556. X    if (gameMode != PauseGame) {
  557. X        PauseProc();
  558. X        if (readGameXID != NULL) {
  559. X            XtRemoveTimeOut(readGameXID);
  560. X            readGameXID = NULL;
  561. X        }
  562. X    }
  563. X
  564. X    if (currentMove >= forwardMostMove) {
  565. X        ReadGameFileProc();
  566. X        if ((strcmp(parseList[currentMove], "1-0") == 0)
  567. X            || (strcmp(parseList[currentMove], "0-1") == 0)
  568. X            || (strcmp(parseList[currentMove], "1/2") == 0)
  569. X            || (strcmp(parseList[currentMove], "End Of Game") == 0))
  570. X            DisplayMessage(parseList[currentMove]);
  571. X        return;
  572. X    }
  573. X
  574. X    if ((forwardForce == False) && (gameMode != PlayFromGameFile)) {
  575. X        forwardForce = True;
  576. X        SendToProgram("force\n", toFirstProgFP);
  577. X    }
  578. X
  579. X    for (i = 0; i < BOARD_SIZE; i++)
  580. X        for (j = 0; j < BOARD_SIZE; j++)
  581. X            if (boards[currentMove + 1][i][j] != boards[currentMove][i][j])
  582. X                DrawSquare(i, j, boards[currentMove + 1][i][j]);
  583. X
  584. X    DisplayMessage(parseList[currentMove]);
  585. X    strcpy(buf, moveList[currentMove++]);
  586. X    SendToProgram(buf, toFirstProgFP);
  587. }
  588. X
  589. void
  590. ResetFileProc()
  591. {
  592. X    Arg args[1];
  593. X    char *buf = "";
  594. X
  595. X    if (appData.readGameFile);
  596. X        XtFree(appData.readGameFile);
  597. X    if (appData.readPositionFile);
  598. X        XtFree(appData.readPositionFile);
  599. X    appData.readGameFile = appData.readPositionFile = NULL;
  600. X    XtSetArg(args[0], XtNlabel, buf);
  601. X    XtSetValues(nameWidget, args, 1);
  602. X    if (gameFileFP != NULL) {
  603. X        fclose(gameFileFP);
  604. X        gameFileFP = NULL;
  605. X    }
  606. }
  607. X
  608. void
  609. ResetProc()
  610. {
  611. X    twoProgramState = flipView = forwardForce = False;
  612. X    matchMode = MatchFalse;
  613. X    firstMove = True;
  614. X
  615. X    ShutdownChessPrograms("");
  616. X    lastGameMode = gameMode = BeginningOfGame;
  617. X    InitPosition();
  618. X    InitChessProgram(appData.firstHost, appData.firstChessProgram,
  619. X        &firstProgramPID, &toFirstProgFP, &fromFirstProgFP, &firstProgramXID);
  620. X    DisplayClocks(ResetTimers);
  621. }
  622. X
  623. int
  624. SetupPositionFromFileProc(name)
  625. X    char *name;
  626. {
  627. X    char *p, line[MSG_SIZ], buf[MSG_SIZ];
  628. X    Board initial_position;
  629. X    Arg args[1];
  630. X    FILE *fp;
  631. X    int i, j;
  632. X
  633. X    if (gameMode != BeginningOfGame)
  634. X        return (int) False;
  635. X
  636. X    if (appData.readPositionFile != name) {
  637. X        if (appData.readPositionFile)
  638. X            XtFree(appData.readPositionFile);
  639. X        appData.readPositionFile = XtMalloc(strlen(name));
  640. X        strcpy(appData.readPositionFile, name);
  641. X    }
  642. X
  643. X    if (name[0] == '/')
  644. X        strcpy(buf, name);
  645. X    else {
  646. X        strcpy(buf, chessDir);
  647. X        strcat(buf, "/");
  648. X        strcat(buf, name);
  649. X    }
  650. X
  651. X    if ((fp = fopen(buf, "r")) == NULL) {
  652. X        strcpy(line, buf);
  653. X        sprintf(buf, "Can't open %s", line);
  654. X        DisplayMessage(buf);
  655. X        return (int) False;
  656. X    }
  657. X
  658. X    lastGameMode = gameMode = SetupPosition;
  659. X
  660. X    if (firstProgramXID == NULL)
  661. X        InitChessProgram(appData.firstHost, appData.firstChessProgram,
  662. X            &firstProgramPID, &toFirstProgFP, &fromFirstProgFP,
  663. X            &firstProgramXID);
  664. X
  665. X    /*
  666. X     * skip header information in position file
  667. X     */
  668. X    fgets(line, MSG_SIZ, fp);
  669. X    line[strlen(line) - 1] = '\0';
  670. X    XtSetArg(args[0], XtNlabel, line);
  671. X    XtSetValues(nameWidget, args, 1);
  672. X    fgets(line, MSG_SIZ, fp);
  673. X    fgets(line, MSG_SIZ, fp);
  674. X
  675. X    for (i = BOARD_SIZE - 1; i >= 0; i--) {
  676. X        fgets(line, MSG_SIZ, fp);
  677. X        for (p = line, j = 0; j < BOARD_SIZE; p++) {
  678. X            if (*p == ' ')
  679. X                continue;
  680. X            initial_position[i][j++] = CharToPiece(*p);
  681. X        }
  682. X    }
  683. X    fclose(fp);
  684. X
  685. X    currentMove = forwardMostMove = 0;
  686. X    CopyBoard(boards[0], initial_position);
  687. X    SendCurrentBoard(toFirstProgFP);
  688. X    DrawPosition(boardWidget, (XExposeEvent *) NULL);
  689. X
  690. X    return (int) True;
  691. }
  692. X
  693. void
  694. MachinePlaysWhiteProc()
  695. {
  696. X    if ((gameMode == EndOfGame) || (gameMode == PlayFromGameFile)
  697. X        || (matchMode != MatchFalse) || !WHITE_ON_MOVE)
  698. X        return;
  699. X
  700. X    undoMode = False;
  701. X    lastGameMode = gameMode = MachinePlaysWhite;
  702. X    SendToProgram(appData.whiteString, toFirstProgFP);
  703. }
  704. X
  705. void
  706. BackwardProc()
  707. {
  708. X    int i, j;
  709. X
  710. X    if ((currentMove <= 0) || (matchMode != MatchFalse)
  711. X        || (gameMode == EndOfGame))
  712. X        return;
  713. X
  714. X    if (currentMove == 1) {
  715. X        ResetProc();
  716. X        return;
  717. X    }
  718. X
  719. X    if (gameMode == BeginningOfGame)
  720. X        gameMode = lastGameMode;
  721. X    else
  722. X        SendToProgram("undo\n", toFirstProgFP);
  723. X
  724. X    if (gameMode != PauseGame) {
  725. X        PauseProc();
  726. X        if (readGameXID != NULL) {
  727. X            XtRemoveTimeOut(readGameXID);
  728. X            readGameXID = NULL;
  729. X        }
  730. X    }
  731. X
  732. X    undoMode = True;
  733. X    currentMove--;
  734. X    DisplayMessage(parseList[currentMove - 1]);
  735. X
  736. X    for (i = 0; i < BOARD_SIZE; i++)
  737. X        for (j = 0; j < BOARD_SIZE; j++)
  738. X            if (boards[currentMove][i][j] != boards[currentMove + 1][i][j])
  739. X                DrawSquare(i, j, boards[currentMove][i][j]);
  740. }
  741. X
  742. void
  743. FlipProc()
  744. {
  745. X    flipView = !flipView;
  746. X    DrawPosition(boardWidget, (XExposeEvent *) NULL);
  747. }
  748. X
  749. void
  750. SaveGameProc(name)
  751. X    char *name;
  752. {
  753. X    char buf[MSG_SIZ], white_move[MSG_SIZ], black_move[MSG_SIZ];
  754. X    int i, len, move = 0;
  755. X    time_t tm;
  756. X
  757. X    if ((gameFileFP = fopen(name, "w")) == NULL) {
  758. X        sprintf(buf, "Can't open %s", name);
  759. X        DisplayMessage(buf);
  760. X        return;
  761. X    }
  762. X
  763. X    tm = time((time_t *) NULL);
  764. X    gethostname(buf, MSG_SIZ);
  765. X
  766. X    fprintf(gameFileFP, "%s game file -- %s", programName, ctime(&tm));
  767. X    switch (lastGameMode) {
  768. X    case MachinePlaysWhite:
  769. X        fprintf(gameFileFP, "\t%s@%s vs. %s@%s\n", appData.firstChessProgram,
  770. X            appData.firstHost, getpwuid(getuid())->pw_name, buf);
  771. X        break;
  772. X    case MachinePlaysBlack:
  773. X        fprintf(gameFileFP, "\t%s@%s vs. %s@%s\n", getpwuid(getuid())->pw_name,
  774. X            buf, appData.firstChessProgram, appData.firstHost);
  775. X        break;
  776. X    case TwoMachinesPlay:
  777. X        fprintf(gameFileFP, "\t%s@%s vs. %s@%s\n",
  778. X            appData.secondChessProgram, appData.secondHost,
  779. X            appData.firstChessProgram, appData.firstHost);
  780. X        break;
  781. X    default:
  782. X        fprintf(gameFileFP, "\n");
  783. X        break;
  784. X    }
  785. X    fprintf(gameFileFP, "\talgebraic\n");
  786. X
  787. X    for (i = 0; i < currentMove;) {
  788. X        /*
  789. X         * get rid of '\n' added to send the move to GNU Chess
  790. X         */
  791. X        len = strlen(moveList[i]);
  792. X        strcpy(white_move, moveList[i++]);
  793. X        if (white_move[len - 1] == '\n')
  794. X            white_move[len - 1] = NULL;
  795. X        fprintf(gameFileFP, "%d. %s ", ++move, white_move);
  796. X
  797. X        if (i >= currentMove) {
  798. X            fprintf(gameFileFP, "\n");
  799. X            break;
  800. X        }
  801. X
  802. X        if ((len = strlen(moveList[i])) == 0) {
  803. X            fprintf(gameFileFP, "\n");
  804. X            break;
  805. X        }
  806. X        strcpy(black_move, moveList[i++]);
  807. X        if (black_move[len - 1] == '\n')
  808. X            black_move[len - 1] = NULL;
  809. X        fprintf(gameFileFP, "%s\n", black_move);
  810. X    }
  811. X
  812. X    fclose(gameFileFP);
  813. X    gameFileFP = NULL;
  814. }
  815. X
  816. void
  817. SwitchProc()
  818. {
  819. X    switch (gameMode) {
  820. X    default:
  821. X        return;
  822. X    case MachinePlaysWhite:
  823. X        lastGameMode = gameMode = MachinePlaysBlack;
  824. X        break;
  825. X    case BeginningOfGame:
  826. X    case MachinePlaysBlack:
  827. X        if (currentMove == 0) {
  828. X            MachinePlaysWhiteProc();
  829. X            return;
  830. X        }
  831. X        lastGameMode = gameMode = MachinePlaysWhite;
  832. X        break;
  833. X    }
  834. X
  835. X    SendToProgram("switch\n", toFirstProgFP);
  836. }
  837. X
  838. void
  839. ForceProc()
  840. {
  841. X    if ((gameMode == EndOfGame) || (gameMode == PlayFromGameFile))
  842. X        return;
  843. X
  844. X    switch (gameMode) {
  845. X    case MachinePlaysWhite:
  846. X        if (WHITE_ON_MOVE && !undoMode) {
  847. X            DisplayMessage("Wait until your move");
  848. X            return;
  849. X        }
  850. X        break;
  851. X    case MachinePlaysBlack:
  852. X        if (!WHITE_ON_MOVE && !undoMode) {
  853. X            DisplayMessage("Wait until your move");
  854. X            return;
  855. X        }
  856. X    case BeginningOfGame:
  857. X        break;
  858. X    default:
  859. X        return;
  860. X    }
  861. X
  862. X    lastGameMode = gameMode = ForceMoves;
  863. X    DisplayClocks(StopTimers);
  864. X    SendToProgram("force\n", toFirstProgFP);
  865. }
  866. X
  867. void
  868. HintProc()
  869. {
  870. X    switch (gameMode) {
  871. X    case MachinePlaysWhite:
  872. X    case MachinePlaysBlack:
  873. X    case BeginningOfGame:
  874. X        SendToProgram("hint\n", toFirstProgFP);
  875. X    default:
  876. X        return;
  877. X    }
  878. }
  879. X
  880. void
  881. SavePositionProc(name)
  882. X    char *name;
  883. {
  884. X    char buf[MSG_SIZ], host_name[MSG_SIZ];
  885. X    FILE *fp;
  886. X    time_t tm;
  887. X    int i, j;
  888. X
  889. X    if ((fp = fopen(name, "w")) == NULL) {
  890. X        sprintf(buf, "Can't open %s", name);
  891. X        DisplayMessage(buf);
  892. X        return;
  893. X    }
  894. X
  895. X    tm = time((time_t *) NULL);
  896. X    gethostname(host_name, MSG_SIZ);
  897. X
  898. X    fprintf(fp, "%s position file -- %s", programName, ctime(&tm));
  899. X    switch (gameMode) {
  900. X    case MachinePlaysWhite:
  901. X        fprintf(fp, "\t%s@%s vs. %s@%s\n", appData.firstChessProgram,
  902. X            appData.firstHost, getpwuid(getuid())->pw_name, host_name);
  903. X        break;
  904. X    case MachinePlaysBlack:
  905. X        fprintf(fp, "\t%s@%s vs. %s@%s\n", getpwuid(getuid())->pw_name,
  906. X            host_name, appData.firstChessProgram, appData.firstHost);
  907. X        break;
  908. X    case TwoMachinesPlay:
  909. X        fprintf(fp, "\t%s@%s vs. %s@%s\n", appData.secondChessProgram,
  910. X            appData.secondHost, appData.firstChessProgram, appData.firstHost);
  911. X        break;
  912. X    default:
  913. X        fprintf(fp, "\n");
  914. X        break;
  915. X    }
  916. X    fprintf(fp, "\n");
  917. X
  918. X    for (i = BOARD_SIZE - 1; i >= 0; i--) {
  919. X        for (j = 0; j < BOARD_SIZE; j++) {
  920. X            fprintf(fp, "%c", pieceToChar[(int) boards[currentMove][i][j]]);
  921. X            fputc(j == BOARD_SIZE - 1 ? '\n' : ' ', fp);
  922. X        }
  923. X    }
  924. X
  925. X    fclose(fp);
  926. }
  927. X
  928. void
  929. TwoMachinesPlayProc()
  930. {
  931. X    int i;
  932. X
  933. X    if ((gameMode == EndOfGame) || (twoProgramState == True))
  934. X        return;
  935. X
  936. X    if (!WHITE_ON_MOVE) {
  937. X        DisplayMessage("White must be on move");
  938. X        return;
  939. X    }
  940. X
  941. X    twoProgramState = True;
  942. X
  943. X    if (matchMode == MatchFalse) {
  944. X        switch (gameMode) {
  945. X        case MachinePlaysWhite:
  946. X        case MachinePlaysBlack:
  947. X        case PauseGame:
  948. X        case TwoMachinesPlay:
  949. X        case PlayFromGameFile:
  950. X            return;
  951. X        case ForceMoves:
  952. X            matchMode = MatchOpening;
  953. X            break;
  954. X        case SetupPosition:
  955. X            matchMode = MatchPosition;
  956. X            break;
  957. X        case BeginningOfGame:
  958. X        default:
  959. X            matchMode = MatchInit;
  960. X            break;
  961. X        }
  962. X    }
  963. X
  964. X    flipView = forwardForce = False;
  965. X    firstMove = False;
  966. X    DisplayClocks(ResetTimers);
  967. X    DisplayClocks(ReStartTimers);
  968. X
  969. X    switch (matchMode) {
  970. X    case MatchOpening:
  971. X        if (firstProgramXID == NULL) {
  972. X            if (appData.readGameFile == NULL) {
  973. X                DisplayMessage("Select game file first");
  974. X                return;
  975. X            }
  976. X            InitChessProgram(appData.firstHost, appData.firstChessProgram,
  977. X                &firstProgramPID, &toFirstProgFP, &fromFirstProgFP,
  978. X                &firstProgramXID);
  979. X            if (!PlayFromGameFileProc(appData.readGameFile)) {
  980. X                ShutdownChessPrograms("Bad game file");
  981. X                return;
  982. X            }
  983. X            DrawPosition(boardWidget, (XExposeEvent *) NULL);
  984. X        }
  985. X        InitChessProgram(appData.secondHost, appData.secondChessProgram,
  986. X            &secondProgramPID, &toSecondProgFP, &fromSecondProgFP,
  987. X            &secondProgramXID);
  988. X        SendToProgram("force\n", toSecondProgFP);
  989. X        for (i = 0; i < currentMove; i++)
  990. X            SendToProgram(moveList[i], toSecondProgFP);
  991. X        lastGameMode = gameMode = TwoMachinesPlay;
  992. X        firstMove = True;
  993. X        SendToProgram(appData.whiteString, toSecondProgFP);
  994. X        break;
  995. X    case MatchPosition:
  996. X        if (firstProgramXID == NULL) {
  997. X            if (appData.readPositionFile == NULL) {
  998. X                DisplayMessage("Select position file first");
  999. X                return;
  1000. X            }
  1001. X            InitChessProgram(appData.firstHost, appData.firstChessProgram,
  1002. X                &firstProgramPID, &toFirstProgFP, &fromFirstProgFP,
  1003. X                &firstProgramXID);
  1004. X            if (!SetupPositionFromFileProc(appData.readPositionFile))
  1005. X                return;
  1006. X        }
  1007. X        InitChessProgram(appData.secondHost, appData.secondChessProgram,
  1008. X            &secondProgramPID, &toSecondProgFP, &fromSecondProgFP,
  1009. X            &secondProgramXID);
  1010. X        SendCurrentBoard(toSecondProgFP);
  1011. X        lastGameMode = gameMode = TwoMachinesPlay;
  1012. X        firstMove = True;
  1013. X        SendToProgram(appData.whiteString, toSecondProgFP);
  1014. X        break;
  1015. X    case MatchInit:
  1016. X        InitPosition();
  1017. X        if (firstProgramXID == NULL)
  1018. X            InitChessProgram(appData.firstHost, appData.firstChessProgram,
  1019. X                &firstProgramPID, &toFirstProgFP, &fromFirstProgFP,
  1020. X                &firstProgramXID);
  1021. X        InitChessProgram(appData.secondHost, appData.secondChessProgram,
  1022. X            &secondProgramPID, &toSecondProgFP, &fromSecondProgFP,
  1023. X            &secondProgramXID);
  1024. X        lastGameMode = gameMode = TwoMachinesPlay;
  1025. X        SendToProgram(appData.whiteString, toSecondProgFP);
  1026. X    default:
  1027. X        break;
  1028. X    }
  1029. }
  1030. X
  1031. void
  1032. PauseProc()
  1033. {
  1034. X    static GameMode previous_mode = PauseGame;
  1035. X
  1036. X    switch (gameMode) {
  1037. X    case ForceMoves:
  1038. X    case EndOfGame:
  1039. X        return;
  1040. X    case PauseGame:
  1041. X        gameMode = previous_mode;
  1042. X        previous_mode = PauseGame;
  1043. X        DisplayClocks(ReStartTimers);
  1044. X        DisplayMessage("");
  1045. X        break;
  1046. X    case PlayFromGameFile:
  1047. X        if (readGameXID == NULL)
  1048. X            readGameXID = XtAppAddTimeOut(appContext,
  1049. X                (int) (1000 * appData.timeDelay), ReadGameFile, NULL);
  1050. X        else {
  1051. X            XtRemoveTimeOut(readGameXID);
  1052. X            readGameXID = NULL;
  1053. X        }
  1054. X        DisplayMessage("Pausing");
  1055. X        break;
  1056. X    case BeginningOfGame:        /* play game from files end here at the end */
  1057. X    case MachinePlaysWhite:
  1058. X    case MachinePlaysBlack:
  1059. X    case TwoMachinesPlay:
  1060. X    case SetupPosition:
  1061. X        if (currentMove == 0)    /* don't pause if no one has moved */
  1062. X            return;
  1063. X        previous_mode = gameMode;
  1064. X        gameMode = PauseGame;
  1065. X        DisplayClocks(StopTimers);
  1066. X        DisplayMessage("Pausing");
  1067. X        break;
  1068. X    }
  1069. }
  1070. X
  1071. void
  1072. GameProc()
  1073. {
  1074. X    if (gameMode != BeginningOfGame)
  1075. X        return;
  1076. X    if (appData.readGameFile == NULL)
  1077. X        FileNamePopUp("Game file name?", VOID_PROC PlayFromGameFileProc);
  1078. X    else
  1079. X        (void) PlayFromGameFileProc(appData.readGameFile);
  1080. }
  1081. X
  1082. void
  1083. Iconify()
  1084. {
  1085. X    Arg args[1];
  1086. X
  1087. X    fromX = fromY = -1;
  1088. X
  1089. X    XtSetArg(args[0], XtNiconic, True);
  1090. X    XtSetValues(shellWidget, args, 1);
  1091. }
  1092. X
  1093. void
  1094. SendToProgram(message, fp)
  1095. X    char *message;
  1096. X    FILE *fp;
  1097. {
  1098. X    if (xboardDebug)
  1099. X        fprintf(stderr, "Sending to %s: %s",
  1100. X            fp == toFirstProgFP ? "first" : "second", message);
  1101. X    fputs(message, fp);
  1102. }
  1103. X
  1104. void
  1105. ReceiveFromProgram(fp)
  1106. X    FILE *fp;
  1107. {
  1108. X    char message[MSG_SIZ], *end_str;
  1109. X
  1110. X    if (fgets(message, MSG_SIZ, fp) == NULL)
  1111. X        return;
  1112. X
  1113. X    if ((end_str = (char *) strchr(message, '\r')) != NULL)
  1114. X        *end_str = '\0';
  1115. X    if ((end_str = (char *) strchr(message, '\n')) != NULL)
  1116. X        *end_str = '\0';
  1117. X
  1118. X    if (xboardDebug)
  1119. X        fprintf(stderr, "Received from %s: %s\n",
  1120. X            fp == fromFirstProgFP ? "first" : "second", message);
  1121. X    HandleMachineMove(message);
  1122. }
  1123. X
  1124. void
  1125. DisplayMessage(message)
  1126. X    char *message;
  1127. {
  1128. X    Arg arg;
  1129. X
  1130. X    XtSetArg(arg, XtNlabel, message);
  1131. X    XtSetValues(messageWidget, &arg, 1);
  1132. }
  1133. X
  1134. /*
  1135. X * DisplayClocks manages the game clocks.
  1136. X *
  1137. X * In tournament play, black starts the clock and then white makes a move.
  1138. X * DisplayClocks starts black's clock when white makes the first move.
  1139. X * Also, DisplayClocks doesn't account for network lag so it could get
  1140. X * out of sync with GNU Chess's clock -- but then, referees are always right.
  1141. X */
  1142. void
  1143. DisplayClocks(clock_mode)
  1144. X    int clock_mode;
  1145. {
  1146. X    switch (clock_mode) {
  1147. X    case ResetTimers:
  1148. X        if (timerXID != NULL) {
  1149. X            XtRemoveTimeOut(timerXID);
  1150. X            timerXID = NULL;
  1151. X        }
  1152. X
  1153. X        whiteTimeRemaining = appData.timeControl * 60;
  1154. X        DisplayTimerLabel(whiteTimerWidget, "White", whiteTimeRemaining);
  1155. X
  1156. X        blackTimeRemaining = appData.timeControl * 60;
  1157. X        DisplayTimerLabel(blackTimerWidget, "Black", blackTimeRemaining);
  1158. X        break;
  1159. X    case DisplayTimers:
  1160. X        if (gameMode == PauseGame)
  1161. X            return;
  1162. X        if (appData.clockMode) {
  1163. X            if (WHITE_ON_MOVE) {
  1164. X                if ((currentMove > 0) || (gameMode == TwoMachinesPlay))
  1165. X                    whiteTimeRemaining--;
  1166. X                if (whiteTimeRemaining <= 0) {
  1167. X                    whiteTimeRemaining = 0;
  1168. X                    DisplayMessage("White's flag dropped");
  1169. X                }
  1170. X            } else {
  1171. X                blackTimeRemaining--;
  1172. X                if (blackTimeRemaining <= 0) {
  1173. X                    blackTimeRemaining = 0;
  1174. X                    DisplayMessage("Black's flag dropped");
  1175. X                }
  1176. X            }
  1177. X        }
  1178. X
  1179. X        DisplayTimerLabel(whiteTimerWidget, "White", whiteTimeRemaining);
  1180. X        DisplayTimerLabel(blackTimerWidget, "Black", blackTimeRemaining);
  1181. X
  1182. X        /*
  1183. X         * reset clocks when time control is acheived
  1184. X         */
  1185. X        if (appData.clockMode && (currentMove != 0)
  1186. X            && ((currentMove % (appData.movesPerSession * 2)) == 0)
  1187. X            && (whiteTimeRemaining > 0) && (blackTimeRemaining > 0)) {
  1188. X            whiteTimeRemaining = appData.timeControl * 60;
  1189. X            blackTimeRemaining = appData.timeControl * 60;
  1190. X        }
  1191. X
  1192. X        if (timerXID != NULL) {
  1193. X            XtRemoveTimeOut(timerXID);
  1194. X            timerXID = NULL;
  1195. X        }
  1196. X        if (appData.clockMode)
  1197. X            timerXID = XtAppAddTimeOut(appContext,
  1198. X                1000, DisplayClocks, DisplayTimers);
  1199. X        break;
  1200. X    case StopTimers:
  1201. X        if (timerXID == NULL)
  1202. X            return;
  1203. X        XtRemoveTimeOut(timerXID);
  1204. X        timerXID = NULL;
  1205. X        break;
  1206. X    case ReStartTimers:
  1207. X        if (timerXID != NULL)
  1208. X            return;
  1209. X
  1210. X        DisplayTimerLabel(whiteTimerWidget, "White", whiteTimeRemaining);
  1211. X        DisplayTimerLabel(blackTimerWidget, "Black", blackTimeRemaining);
  1212. X
  1213. X        if (appData.clockMode)
  1214. X            timerXID = XtAppAddTimeOut(appContext,
  1215. X                1000, DisplayClocks, DisplayTimers);
  1216. X        break;
  1217. X    }
  1218. }
  1219. X
  1220. void
  1221. DisplayTimerLabel(w, color, timer)
  1222. X    Widget w;
  1223. X    char *color;
  1224. X    time_t timer;
  1225. {
  1226. X    char buf[MSG_SIZ];
  1227. X    Arg args[3];
  1228. X
  1229. X    if (appData.clockMode) {
  1230. X        sprintf(buf, "%s: %s", color, TimeString(timer));
  1231. X        XtSetArg(args[0], XtNlabel, buf);
  1232. X    } else
  1233. X        XtSetArg(args[0], XtNlabel, color);
  1234. X
  1235. X    if (((color[0] == 'B') && WHITE_ON_MOVE)
  1236. X        || ((color[0] == 'W') && !WHITE_ON_MOVE)) {
  1237. X        XtSetArg(args[1], XtNbackground, timerForegroundPixel);
  1238. X        XtSetArg(args[2], XtNforeground, timerBackgroundPixel);
  1239. X    } else {
  1240. X        XtSetArg(args[1], XtNbackground, timerBackgroundPixel);
  1241. X        XtSetArg(args[2], XtNforeground, timerForegroundPixel);
  1242. X    }
  1243. X
  1244. X    XtSetValues(w, args, 3);
  1245. }
  1246. X
  1247. char *
  1248. TimeString(tm)
  1249. X    time_t tm;
  1250. {
  1251. X    int second, minute, hour, day;
  1252. X    static char buf[32];
  1253. X
  1254. X    if (tm >= (60 * 60 * 24)) {
  1255. X        day = (int) (tm / (60 * 60 * 24));
  1256. X        tm -= day * 60 * 60 * 24;
  1257. X    } else
  1258. X        day = 0;
  1259. X
  1260. X    if (tm >= (60 * 60)) {
  1261. X        hour = (int) (tm / (60 * 60));
  1262. X        tm -= hour * 60 * 60;
  1263. X    } else
  1264. X        hour = 0;
  1265. X
  1266. X    if (tm >= 60) {
  1267. X        minute = (int) (tm / 60);
  1268. X        tm -= minute * 60;
  1269. X    } else
  1270. X        minute = 0;
  1271. X
  1272. X    second = tm % 60;
  1273. X
  1274. X    if (day > 0)
  1275. X        sprintf(buf, " %d:%02d:%02d:%02d ", day, hour, minute, second);
  1276. X    else if (hour > 0)
  1277. X        sprintf(buf, " %d:%02d:%02d ", hour, minute, second);
  1278. X    else
  1279. X        sprintf(buf, " %2d:%02d ", minute, second);
  1280. X
  1281. X    return buf;
  1282. }
  1283. X
  1284. void
  1285. Usage()
  1286. {
  1287. X    fprintf(stderr, "Usage %s:\n", programName);
  1288. X    fprintf(stderr, "\tstandard Xt options\n");
  1289. X    fprintf(stderr, "\t-wpc or -whitePieceColor color\n");
  1290. X    fprintf(stderr, "\t-bpc or -blackPieceColor color\n");
  1291. X    fprintf(stderr, "\t-lsc or -lightSquareColor color\n");
  1292. X    fprintf(stderr, "\t-dsc or -darkSquareColor color\n");
  1293. X    fprintf(stderr, "\t-mps or -movesPerSession moves\n");
  1294. X    fprintf(stderr, "\t-fcp or -firstChessProgram program_name\n");
  1295. X    fprintf(stderr, "\t-scp or -secondChessProgram program_name\n");
  1296. X    fprintf(stderr, "\t-fh or -firstHost host_name\n");
  1297. X    fprintf(stderr, "\t-sh or -secondHost host_name\n");
  1298. X    fprintf(stderr, "\t-spb or -solidPawnBitmap file_name\n");
  1299. X    fprintf(stderr, "\t-srb or -solidRookBitmap file_name\n");
  1300. X    fprintf(stderr, "\t-sbb or -solidBishopBitmap file_name\n");
  1301. X    fprintf(stderr, "\t-skb or -solidKnightBitmap file_name\n");
  1302. X    fprintf(stderr, "\t-sqb or -solidQueenBitmap file_name\n");
  1303. X    fprintf(stderr, "\t-skb or -solidKingBitmap file_name\n");
  1304. X    fprintf(stderr, "\t-opb or -outlinePawnBitmap file_name\n");
  1305. X    fprintf(stderr, "\t-orb or -outlineRookBitmap file_name\n");
  1306. X    fprintf(stderr, "\t-obb or -outlineBishopBitmap file_name\n");
  1307. X    fprintf(stderr, "\t-okb or -outlineKnightBitmap file_name\n");
  1308. X    fprintf(stderr, "\t-oqb or -outlineQueenBitmap file_name\n");
  1309. X    fprintf(stderr, "\t-okb or -outlineKingBitmap file_name\n");
  1310. X    fprintf(stderr, "\t-rsh or -remoteShell shell_name\n");
  1311. X    fprintf(stderr, "\t-td or -timeDelay seconds\n");
  1312. X    fprintf(stderr, "\t-tc or -timeControl minutes\n");
  1313. X    fprintf(stderr, "\t-rgf or -readGameFile file_name\n");
  1314. X    fprintf(stderr, "\t-rpf or -readPositionFile file_name\n");
  1315. X    fprintf(stderr, "\t-sgf or -saveGameFile file_name\n");
  1316. X    fprintf(stderr, "\t-spf or -savePositionFile file_name\n");
  1317. X    fprintf(stderr, "\t-mm or -matchMode (False | Init | Position | Opening)\n");
  1318. X    fprintf(stderr, "\t-mono or -monoMode (True | False)\n");
  1319. X    fprintf(stderr, "\t-debug or -debugMode (True | False)\n");
  1320. X    fprintf(stderr, "\t-clock or -clockMode (True | False)\n");
  1321. X    fprintf(stderr, "\t-big or -bigSizeMode (True | False)\n");
  1322. X    fprintf(stderr, "\t-st or -searchTime seconds\n");
  1323. X
  1324. X    exit(0);
  1325. }
  1326. X
  1327. /*
  1328. X * This is necessary because some C libraries aren't ANSI C compliant yet.
  1329. X */
  1330. char *
  1331. StrStr(string, match)
  1332. X    char *string, *match;
  1333. {
  1334. X    int i, length;
  1335. X
  1336. X    length = strlen(match);
  1337. X
  1338. X    for (i = strlen(string) - length; i >= 0; i--, string++)
  1339. X        if (!strncmp(match, string, (size_t) length))
  1340. X            return string;
  1341. X
  1342. X    return NULL;
  1343. }
  1344. X
  1345. #if    SYSTEM_FIVE || SYSV
  1346. char *
  1347. PseudoTTY(ptyv)
  1348. X    int *ptyv;
  1349. {
  1350. X    struct stat stb;
  1351. X    int c, i;
  1352. X
  1353. X    for (c = 'p'; c <= 'z'; c++)
  1354. X        for (i = 0; i < 16; i++) {
  1355. #ifdef    HPUX
  1356. X            sprintf(ptyname, "/dev/ptym/pty%c%x", c, i);
  1357. #else
  1358. #ifdef    RTU
  1359. X            sprintf(ptyname, "/dev/pty%x", i);
  1360. #else
  1361. X            sprintf(ptyname, "/dev/pty%c%x", c, i);
  1362. #endif
  1363. #endif
  1364. X
  1365. #ifdef    IRIS
  1366. X            *ptyv = open("/dev/ptc", O_RDWR | O_NDELAY, 0);
  1367. X            if (*ptyv < 0)
  1368. X                return NULL;
  1369. X            if (fstat(*ptyv, &stb) < 0)
  1370. X                return NULL;
  1371. #else
  1372. X            if (stat(ptyname, &stb) < 0)
  1373. X                return NULL;
  1374. X            *ptyv = open(ptyname, O_RDWR | O_NDELAY, 0);
  1375. #endif
  1376. X
  1377. X            if (*ptyv >= 0) {
  1378. #ifdef    HPUX
  1379. X                sprintf(ptyname, "/dev/pty/tty%c%x", c, i);
  1380. #else
  1381. #ifdef    RTU
  1382. X                sprintf(ptyname, "/dev/ttyp%x", i);
  1383. #else
  1384. #ifdef    IRIS
  1385. X                sprintf(ptyname, "/dev/ttyq%d", minor(stb.st_rdev));
  1386. #else
  1387. X                sprintf(ptyname, "/dev/tty%c%x", c, i);
  1388. #endif
  1389. #endif
  1390. #endif
  1391. X
  1392. #ifndef    UNIPLUS
  1393. X                if (access(ptyname, 6) != 0) {
  1394. X                    close(*ptyv);
  1395. #ifdef    IRIS
  1396. X                    return NULL;
  1397. #else
  1398. X                    continue;
  1399. #endif
  1400. X                }
  1401. #endif
  1402. X
  1403. #ifdef    FIONBIO
  1404. X            {
  1405. X                int on = 1;
  1406. X                ioctl(*ptyv, FIONBIO, &on);
  1407. X            }
  1408. #endif
  1409. X
  1410. #ifdef    IBMRTAIX
  1411. X            signal(SIGHUP, SIG_IGN);
  1412. #endif
  1413. X            return ptyname;
  1414. X        }
  1415. X    }
  1416. X
  1417. X    return NULL;
  1418. }
  1419. X
  1420. #else
  1421. X
  1422. void
  1423. CatchPipeSignal()
  1424. {
  1425. X    /*
  1426. X     * If a game is just being played out and there is no reason for
  1427. X     * gnuchessr to be used, so ignore pipe signals.  This allows people
  1428. X     * to use xboard as a chess board without need for gnuchess.
  1429. X     */
  1430. X    switch (gameMode) {
  1431. X    case ForceMoves:
  1432. X    case PlayFromGameFile:
  1433. X    case SetupPosition:
  1434. X    case BeginningOfGame:
  1435. X        break;
  1436. X    default:
  1437. X        fprintf(stderr, "Caught pipe signal\n");
  1438. X        exit(0);
  1439. X    }
  1440. }
  1441. #endif
  1442. SHAR_EOF
  1443. echo 'File xboard/xboard.c is complete' &&
  1444. chmod 0644 xboard/xboard.c ||
  1445. echo 'restore of xboard/xboard.c failed'
  1446. Wc_c="`wc -c < 'xboard/xboard.c'`"
  1447. test 80472 -eq "$Wc_c" ||
  1448.     echo 'xboard/xboard.c: original size 80472, current size' "$Wc_c"
  1449. rm -f _shar_wnt_.tmp
  1450. fi
  1451. # ============= xboard/xboard.h ==============
  1452. if test -f 'xboard/xboard.h' -a X"$1" != X"-c"; then
  1453.     echo 'x - skipping xboard/xboard.h (File already exists)'
  1454.     rm -f _shar_wnt_.tmp
  1455. else
  1456. > _shar_wnt_.tmp
  1457. echo 'x - extracting xboard/xboard.h (Text)'
  1458. sed 's/^X//' << 'SHAR_EOF' > 'xboard/xboard.h' &&
  1459. /*
  1460. X * XBoard -- an Xt/Athena user interface for GNU Chess
  1461. X *
  1462. X * Dan Sears
  1463. X * Chris Sears
  1464. X *
  1465. X * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts.
  1466. X *
  1467. X * All Rights Reserved
  1468. X *
  1469. X * Permission to use, copy, modify, and distribute this software and its
  1470. X * documentation for any purpose and without fee is hereby granted,
  1471. X * provided that the above copyright notice appear in all copies and that
  1472. X * both that copyright notice and this permission notice appear in
  1473. X * supporting documentation, and that the name of Digital not be
  1474. X * used in advertising or publicity pertaining to distribution of the
  1475. X * software without specific, written prior permission.
  1476. X *
  1477. X * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  1478. X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  1479. X * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  1480. X * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  1481. X * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1482. X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  1483. X * SOFTWARE.
  1484. X */
  1485. #define BOARD_SIZE                8                /* rarely changed */
  1486. #define BIG_SQUARE_SIZE            80
  1487. #define SMALL_SQUARE_SIZE        64
  1488. #define LINE_GAP                3
  1489. #define MAX_MOVES                512
  1490. #define MSG_SIZ                    256
  1491. #define DIALOG_SIZE                250
  1492. #define MOVE_LEN                8
  1493. #define TIME_CONTROL            5                /* in minutes */
  1494. #define TIME_DELAY                "1.0"            /* seconds between moves */
  1495. #define TIME_SEARCH                0                /* don't specify search time */
  1496. #define MOVES_PER_SESSION        40                /* moves per TIME_CONTROL */
  1497. #define WHITE_ON_MOVE            ((int) ((currentMove % 2) == 0))
  1498. #define FIRST_CHESS_PROGRAM        "gnuchessr"
  1499. #define SECOND_CHESS_PROGRAM    "gnuchessr"
  1500. #define FIRST_HOST                "localhost"
  1501. #define SECOND_HOST                "localhost"
  1502. #define MATCH_MODE                "False"
  1503. #define INIT_STRING                "new\nbeep\nrandom\n"
  1504. #define WHITE_STRING            "white\ngo\n"
  1505. #define BLACK_STRING            "black\ngo\n"
  1506. #define WHITE_PIECE_COLOR        "#FFFFCC"
  1507. #define BLACK_PIECE_COLOR        "#202020"
  1508. #define LIGHT_SQUARE_COLOR        "#C8C365"
  1509. #define DARK_SQUARE_COLOR        "#77A26D"
  1510. X
  1511. typedef enum {
  1512. X    BeginningOfGame, MachinePlaysWhite, MachinePlaysBlack, TwoMachinesPlay,
  1513. X    ForceMoves, PlayFromGameFile, SetupPosition, PauseGame, EndOfGame
  1514. } GameMode;
  1515. X
  1516. typedef enum {
  1517. X    MatchFalse, MatchInit, MatchPosition, MatchOpening
  1518. } MatchMode;
  1519. X
  1520. typedef enum {
  1521. X    WhitePawn, WhiteRook, WhiteKnight, WhiteBishop, WhiteQueen, WhiteKing,
  1522. X    BlackPawn, BlackRook, BlackKnight, BlackBishop, BlackQueen, BlackKing,
  1523. X    EmptySquare
  1524. } ChessSquare;
  1525. X
  1526. typedef ChessSquare Board[BOARD_SIZE][BOARD_SIZE];
  1527. X
  1528. typedef enum {
  1529. X    WhiteKingSideCastle = 1, WhiteQueenSideCastle,
  1530. X    WhitePromotionKnight, WhitePromotionBishop,
  1531. X    WhitePromotionRook, WhitePromotionQueen,
  1532. X    BlackPromotionKnight, BlackPromotionBishop,
  1533. X    BlackPromotionRook, BlackPromotionQueen,
  1534. X    BlackKingSideCastle, BlackQueenSideCastle,
  1535. X    WhiteCapturesEnPassant, BlackCapturesEnPassant, NormalMove,
  1536. X    WhiteWins, BlackWins, GameIsDrawn, StartGame, BadMove, Comment
  1537. } ChessMove;
  1538. X
  1539. typedef enum {            /* Same order as buttonStrings */
  1540. X    ButtonQuit, ButtonPlayFromFile, ButtonMachinePlaysBlack, ButtonForward,
  1541. X    ButtonReset, ButtonSetupFromFile, ButtonMachinePlaysWhite, ButtonBackward,
  1542. X    ButtonFlip, ButtonSaveGame, ButtonSwitch, ButtonForce,
  1543. X    ButtonHint, ButtonSavePosition, ButtonTwoMachinesPlay, ButtonPause
  1544. } Button;
  1545. X
  1546. typedef enum {
  1547. X    ResetTimers, DisplayTimers, StopTimers, ReStartTimers
  1548. } ClockMode;
  1549. X
  1550. /*
  1551. X * Various compatibility grunge
  1552. X */
  1553. #ifdef __STDC__
  1554. #define    P(args)        args
  1555. #define VOID_PROC    (void(*)(char*))
  1556. #else
  1557. #define P(args)        ()
  1558. #define VOID_PROC
  1559. #endif
  1560. SHAR_EOF
  1561. chmod 0644 xboard/xboard.h ||
  1562. echo 'restore of xboard/xboard.h failed'
  1563. Wc_c="`wc -c < 'xboard/xboard.h'`"
  1564. test 3583 -eq "$Wc_c" ||
  1565.     echo 'xboard/xboard.h: original size 3583, current size' "$Wc_c"
  1566. rm -f _shar_wnt_.tmp
  1567. fi
  1568. # ============= xboard/xboard.man ==============
  1569. if test -f 'xboard/xboard.man' -a X"$1" != X"-c"; then
  1570.     echo 'x - skipping xboard/xboard.man (File already exists)'
  1571.     rm -f _shar_wnt_.tmp
  1572. else
  1573. > _shar_wnt_.tmp
  1574. echo 'x - extracting xboard/xboard.man (Text)'
  1575. sed 's/^X//' << 'SHAR_EOF' > 'xboard/xboard.man' &&
  1576. ..TH XBOARD 1 "June 11, 1991" "X Version 11"
  1577. ..SH NAME
  1578. xboard \- Xt/Athena user interface for GNU Chess, version 1.2
  1579. ..SH SYNOPSIS
  1580. ..B xboard
  1581. [
  1582. ..IR "\-wpc or -whitePieceColor color"
  1583. ]
  1584. [
  1585. ..IR "\-bpc or -blackPieceColor color"
  1586. ]
  1587. [
  1588. ..IR "\-lsc or -lightSquareColor color"
  1589. ]
  1590. [
  1591. ..IR "\-dsc or -darkSquareColor color"
  1592. ]
  1593. [
  1594. ..IR "\-mps or -movesPerSession moves"
  1595. ]
  1596. [
  1597. ..IR "\-fcp or -firstChessProgram program_name"
  1598. ]
  1599. [
  1600. ..IR "\-scp or -secondChessProgram program_name"
  1601. ]
  1602. [
  1603. ..IR "\-fh or -firstHost host_name"
  1604. ]
  1605. [
  1606. ..IR "\-sh or -secondHost host_name"
  1607. ]
  1608. [
  1609. ..IR "\-spb or -solidPawnBitmap file_name"
  1610. ]
  1611. [
  1612. ..IR "\-srb or -solidRookBitmap file_name"
  1613. ]
  1614. [
  1615. ..IR "\-sbb or -solidBishopBitmap file_name"
  1616. ]
  1617. [
  1618. ..IR "\-skb or -solidKnightBitmap file_name"
  1619. ]
  1620. [
  1621. ..IR "\-sqb or -solidQueenBitmap file_name"
  1622. ]
  1623. [
  1624. ..IR "\-skb or -solidKingBitmap file_name"
  1625. ]
  1626. [
  1627. ..IR "\-opb or -outlinePawnBitmap file_name"
  1628. ]
  1629. [
  1630. ..IR "\-orb or -outlineRookBitmap file_name"
  1631. ]
  1632. [
  1633. ..IR "\-obb or -outlineBishopBitmap file_name"
  1634. ]
  1635. [
  1636. ..IR "\-okb or -outlineKnightBitmap file_name"
  1637. ]
  1638. [
  1639. ..IR "\-oqb or -outlineQueenBitmap file_name"
  1640. ]
  1641. [
  1642. ..IR "\-okb or -outlineKingBitmap file_name"
  1643. ]
  1644. [
  1645. ..IR "\-rsh or -remoteShell shell_name"
  1646. ]
  1647. [
  1648. ..IR "\-td or -timeDelay seconds"
  1649. ]
  1650. [
  1651. ..IR "\-tc or -timeControl minutes"
  1652. ]
  1653. [
  1654. ..IR "\-rgf or -readGameFile file_name"
  1655. ]
  1656. [
  1657. ..IR "\-rpf or -readPositionFile file_name"
  1658. ]
  1659. ..IR "\-sgf or -saveGameFile file_name"
  1660. ]
  1661. [
  1662. ..IR "\-spf or -savePositionFile file_name"
  1663. ]
  1664. [
  1665. ..IR "\-mm or -matchMode (False | Init | Position | Opening)"
  1666. ]
  1667. [
  1668. ..IR "\-mono or -monoMode (True | False)"
  1669. ]
  1670. [
  1671. ..IR "\-debug or -debugMode (True | False)"
  1672. ]
  1673. [
  1674. ..IR "\-clock or -clockMode (True | False)"
  1675. ]
  1676. [
  1677. ..IR "\-big or -bigSizeMode (True | False)"
  1678. ]
  1679. [
  1680. ..IR "\-st or -searchTime seconds"
  1681. ]
  1682. ..SH DESCRIPTION
  1683. ..IR xboard
  1684. provides an X11/Xt/Athena Widgets user interface for GNU Chess.
  1685. With
  1686. ..IR xboard
  1687. you can play GNU Chess,
  1688. setup arbitrary positions,
  1689. force variations or watch
  1690. ..IR xboard
  1691. manage a game between two chess programs.
  1692. ..LP
  1693. ..IR xboard
  1694. can also be used as a chessboard to play out games.
  1695. It will read through a game file or allow a player to play (force mode)
  1696. through a variation manually.
  1697. All of the keystroke commands (Backward, Forward, Reset, etc.) work.
  1698. A chess program doesn't even need to be present in the program search path
  1699. in this case.
  1700. This is useful for keeping track of email postal games or browsing games
  1701. off the net.
  1702. ..LP
  1703. After starting
  1704. ..IR xboard
  1705. you can make moves by pressing a mouse button
  1706. while the cursor is over a square with your piece on it
  1707. and dragging the mouse to another square.
  1708. If the move is illegal,
  1709. ..IR gnuchess
  1710. will not allow it.
  1711. ..IR xboard
  1712. will then retract the move.
  1713. ..LP
  1714. Alternate bitmaps for piece icons can be specified
  1715. either by choosing one of two built-in sets or with
  1716. the file name resources described below.
  1717. There are two sets of piece bitmaps available:
  1718. a large set (the default) and a small set.
  1719. It is easiest to select the small set in the .Xdefaults file:
  1720. ..sp 1
  1721. ..br
  1722. XXBoard*bigSizeMode:    false
  1723. ..LP
  1724. The font used for button labels and comments can be changed in the
  1725. ..Xdefaults file:
  1726. ..sp 1
  1727. ..br
  1728. XXBoard*font:    helvetica_oblique14
  1729. ..LP
  1730. If you are using a grayscale monitor, try setting the colors to:
  1731. ..sp 1
  1732. ..br
  1733. XXBoard*whitePieceColor:     gray100
  1734. ..br
  1735. XXBoard*blackPieceColor:     gray0
  1736. ..br
  1737. XXBoard*lightSquareColor:    gray60
  1738. ..br
  1739. XXBoard*darkSquareColor:     gray40
  1740. ..SH OPTIONS
  1741. The following command line options also correspond to X resources
  1742. that you can set in your
  1743. ..IR \&.Xdefaults
  1744. file.
  1745. ..TP 8
  1746. ..B standard Xt options
  1747. ..IR xboard
  1748. accepts standard Xt options like
  1749. ..IR "\-display"
  1750. and
  1751. ..IR "\-geometry" .
  1752. ..TP 8
  1753. ..B -wpc or -whitePieceColor color
  1754. Color specification for white pieces
  1755. suitable for
  1756. ..IR XParseColor (3X11).
  1757. Default: #FFFFCC.
  1758. These colors look good on a DEC workstation.
  1759. If you need different colors, try using the
  1760. ..IR xcolors
  1761. application.  Source for
  1762. ..IR xcolors
  1763. can be found in the X11/R4 contrib directory.
  1764. ..TP 8
  1765. ..B -bpc or -blackPieceColor color
  1766. Same for black pieces.
  1767. Default: #202020.
  1768. ..TP 8
  1769. ..B -lsc or -lightSquareColor color
  1770. Same for light squares.
  1771. Default: #C8C365.
  1772. ..TP 8
  1773. ..B -dsc or -darkSquareColor color
  1774. Same for dark squares.
  1775. Default: #77A26D.
  1776. ..TP 8
  1777. ..B -td or -timeDelay seconds
  1778. Time delay between moves during "Play From File".
  1779. This doesn't have to be round numbers.
  1780. Try -td 0.4.  Default: 1 second.
  1781. ..TP 8
  1782. ..B -clock or -clockMode (True | False)
  1783. Determines whether or not to use the clock.
  1784. Some people aren't interested in having the chess clock be updated.
  1785. This allows it to be turned off.  The side that is on move is still
  1786. highlighted.
  1787. ..TP 8
  1788. ..B -big or -bigSizeMode (True | False)
  1789. Determines which set of bitmaps to use, a built-in 80x80 pixel set
  1790. or a built-in 64-64 set.
  1791. ..TP 8
  1792. ..B -st or -searchTime seconds
  1793. Call GNU Chess with only one argument.
  1794. Determines the program search time in seconds.
  1795. ..TP 8
  1796. ..B -tc or -timeControl minutes
  1797. Amount of time for a set of moves determined by
  1798. ..IR movesPerSession .
  1799. If this number of moves is played within the time control period,
  1800. ..IR xboard
  1801. resets the time clocks.
  1802. Default: 5 minutes.
  1803. ..TP 8
  1804. ..B -mps or -movesPerSession moves
  1805. Number of moves in a playing session.
  1806. Default: 40 moves.
  1807. ..TP 8
  1808. ..B -rgf or -readGameFile file
  1809. Name of file to read a game record from.
  1810. If the first line does not appear to start with a move,
  1811. that is if the first character of the file is not `1',
  1812. then the first line is assumed to be a title and is displayed.
  1813. Comments either start with [ and end with a matching ]
  1814. or they start with a ! and end with the next newline.
  1815. Game files are found in the directory named by the CHESSDIR environment
  1816. variable.  If this variable is not declared then the current directory is used
  1817. unless the file name starts with a /.
  1818. ..TP 8
  1819. ..B -rpf or -readPositionFile file
  1820. Name of file to read a game position from.
  1821. Position files are found in the directory named by the CHESSDIR environment
  1822. variable.  If this variable is not declared then the current directory is used
  1823. unless the file name starts with a /.
  1824. ..TP 8
  1825. ..B -sgf or -saveGameFile file
  1826. Name of file to save a game record to.
  1827. No default.
  1828. ..TP 8
  1829. ..B -spf or -savePositionFile file
  1830. Name of file to save a game position to.
  1831. No default.
  1832. ..TP 8
  1833. ..B -rsh or -remoteShell shell_name
  1834. Some systems do not use rsh as the remote shell.
  1835. This option allows a user to name the remote shell command.
  1836. This should be done in the resource file.
  1837. ..TP 8
  1838. ..B -fcp or -firstChessProgram program
  1839. Name of first chess program that,
  1840. by default,
  1841. plays black.
  1842. Default: "gnuchessr".
  1843. ..TP 8
  1844. ..B -scp or -secondChessProgram program
  1845. Name of second chess program that,
  1846. by default,
  1847. plays white.
  1848. Default: "gnuchessr".
  1849. ..TP 8
  1850. ..B -fh or -firstHost host
  1851. Name of host the white chess program plays on.
  1852. Default: "localhost".
  1853. ..TP 8
  1854. ..B -sh or -secondHost host
  1855. Name of host the black chess program plays on.
  1856. Default: "localhost".
  1857. ..TP 8
  1858. ..B -s*b or -solid*Bitmap file
  1859. Names of the bitmap files for the bitmap piece icons.
  1860. Default: solid_pawn.bitmap, solid_rook.bitmap ...
  1861. ..TP 8
  1862. ..B -o*b or -outline*Bitmap file
  1863. Names of the bitmap files for the outline piece icons.
  1864. Default: outline_pawn.bitmap, outline_rook.bitmap ...
  1865. ..TP 8
  1866. ..B -mm or -matchMode "(False | Init | Position | Opening)"
  1867. Automatically run a game between
  1868. ..IR firstChessProgram
  1869. and
  1870. ..IR secondChessProgram .
  1871. If
  1872. ..IR matchMode
  1873. is set to
  1874. ..IR Init ,
  1875. ..IR xboard
  1876. will start the game with the initial chess position.
  1877. If
  1878. ..IR matchMode
  1879. is set to
  1880. ..IR Position ,
  1881. ..IR xboard
  1882. will start the game with the position specified by the
  1883. ..IR readPositionFile
  1884. resource.
  1885. If
  1886. ..IR matchMode
  1887. is set to
  1888. ..IR Opening ,
  1889. ..IR xboard
  1890. will play out the opening moves specified by the
  1891. ..IR -readGameFile
  1892. resource.
  1893. Default: "False".
  1894. ..TP 8
  1895. ..B -mono or -monoMode (False | True)
  1896. Determines whether
  1897. ..IR xboard
  1898. displays its pieces and squares with two colors or four.
  1899. You shouldn't have to specify monochrome.
  1900. ..IR xboard
  1901. will determine if this is necessary.
  1902. ..SH RESOURCES
  1903. ..TP 8
  1904. ..B initString
  1905. The actual string that is sent to initialize the chess program can be
  1906. set from .Xdefaults.  It can't be set from the command line because of
  1907. syntax problems.
  1908. ..TP 8
  1909. ..B whiteString and blackString
  1910. These resources control what is sent when the Machine White and Machine Black
  1911. buttons are selected.  This is mostly for compatibility with previous versions
  1912. of gnuchess.
  1913. ..TP 8
  1914. ..B XBoard*font
  1915. This is the font that is used by
  1916. ..IR xboard .
  1917. ..SH COMMAND BUTTONS AND KEYS
  1918. ..TP 8
  1919. ..B Quit
  1920. Quits
  1921. ..IR xboard .
  1922. Q or q is a keyboard equivalent.
  1923. ..TP 8
  1924. ..B Reset
  1925. Resets
  1926. ..IR xboard
  1927. to the beginning of a chess game.
  1928. It also deselects any game or position files.
  1929. ..TP 8
  1930. ..B Flip View
  1931. inverts the view of the chess board.
  1932. ..TP 8
  1933. ..B Hint
  1934. displays a move hint from GNU Chess.
  1935. ..TP 8
  1936. ..B Play From File
  1937. plays a game from a record file.
  1938. If no file is specified a popup dialog asks for a filename.
  1939. Game files are found in the directory named by the CHESSDIR environment
  1940. variable.  If this variable is not declared then the current directory is used
  1941. unless the file name starts with a /.
  1942. G or g is a keyboard equivalent.
  1943. ..TP 8
  1944. ..B Setup From File
  1945. sets up a position from a position file.
  1946. If no file is specified a popup dialog asks for a filename.
  1947. Position files are found in the directory named by the CHESSDIR environment
  1948. variable.  If this variable is not declared then the current directory is used
  1949. unless the file name starts with a /.
  1950. ..TP 8
  1951. ..B Save Game
  1952. saves a game to a record file.
  1953. If no file is specified a popup dialog asks for a filename.
  1954. ..TP 8
  1955. ..B Save Position
  1956. saves a position to a position file.
  1957. If no file is specified a popup dialog asks for a filename.
  1958. ..TP 8
  1959. ..B Machine Black
  1960. forces GNU Chess to play black.
  1961. ..TP 8
  1962. ..B Machine White
  1963. forces GNU Chess to play white.
  1964. ..TP 8
  1965. ..B Switch Sides
  1966. forces GNU Chess to switch sides.
  1967. ..TP 8
  1968. ..B Two Machines
  1969. plays a game between two computer programs.
  1970. ..TP 8
  1971. ..B Forward
  1972. moves forward through a series of remembered moves.
  1973. F or f is a keyboard equivalent.
  1974. ..TP 8
  1975. ..B Backward
  1976. moves backward through a series of remembered moves.
  1977. B or b is a keyboard equivalent.
  1978. ..TP 8
  1979. ..B Force Moves
  1980. forces a series of moves.
  1981. ..TP 8
  1982. ..B Pause
  1983. pauses the game clocks or game replay.
  1984. P or p is a keyboard equivalent.
  1985. ..TP 8
  1986. ..B Iconify
  1987. I, i, C or c iconifies
  1988. SHAR_EOF
  1989. true || echo 'restore of xboard/xboard.man failed'
  1990. fi
  1991. echo 'End of  part 2'
  1992. echo 'File xboard/xboard.man is continued in part 3'
  1993. echo 3 > _shar_seq_.tmp
  1994. exit 0
  1995.  
  1996. --
  1997. Dan Heller
  1998. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  1999. Senior Writer                President          comp-sources-x@uunet.uu.net
  2000. argv@ora.com                 argv@zipcode.com
  2001.