PageRenderTime 65ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/xboard-4.5.2a/xboard.c

#
C | 9144 lines | 7958 code | 806 blank | 380 comment | 1103 complexity | 3223cfc3085b0c66253d8eceeb9a6be2 MD5 | raw file
Possible License(s): GPL-3.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * xboard.c -- X front end for XBoard
  3. *
  4. * Copyright 1991 by Digital Equipment Corporation, Maynard,
  5. * Massachusetts.
  6. *
  7. * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
  8. * 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
  9. *
  10. * The following terms apply to Digital Equipment Corporation's copyright
  11. * interest in XBoard:
  12. * ------------------------------------------------------------------------
  13. * All Rights Reserved
  14. *
  15. * Permission to use, copy, modify, and distribute this software and its
  16. * documentation for any purpose and without fee is hereby granted,
  17. * provided that the above copyright notice appear in all copies and that
  18. * both that copyright notice and this permission notice appear in
  19. * supporting documentation, and that the name of Digital not be
  20. * used in advertising or publicity pertaining to distribution of the
  21. * software without specific, written prior permission.
  22. *
  23. * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  24. * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  25. * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  26. * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  27. * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  28. * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  29. * SOFTWARE.
  30. * ------------------------------------------------------------------------
  31. *
  32. * The following terms apply to the enhanced version of XBoard
  33. * distributed by the Free Software Foundation:
  34. * ------------------------------------------------------------------------
  35. *
  36. * GNU XBoard is free software: you can redistribute it and/or modify
  37. * it under the terms of the GNU General Public License as published by
  38. * the Free Software Foundation, either version 3 of the License, or (at
  39. * your option) any later version.
  40. *
  41. * GNU XBoard is distributed in the hope that it will be useful, but
  42. * WITHOUT ANY WARRANTY; without even the implied warranty of
  43. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  44. * General Public License for more details.
  45. *
  46. * You should have received a copy of the GNU General Public License
  47. * along with this program. If not, see http://www.gnu.org/licenses/. *
  48. *
  49. *------------------------------------------------------------------------
  50. ** See the file ChangeLog for a revision history. */
  51. #define HIGHDRAG 1
  52. #include "config.h"
  53. #include <stdio.h>
  54. #include <ctype.h>
  55. #include <signal.h>
  56. #include <errno.h>
  57. #include <sys/types.h>
  58. #include <sys/stat.h>
  59. #include <pwd.h>
  60. #include <math.h>
  61. #if !OMIT_SOCKETS
  62. # if HAVE_SYS_SOCKET_H
  63. # include <sys/socket.h>
  64. # include <netinet/in.h>
  65. # include <netdb.h>
  66. # else /* not HAVE_SYS_SOCKET_H */
  67. # if HAVE_LAN_SOCKET_H
  68. # include <lan/socket.h>
  69. # include <lan/in.h>
  70. # include <lan/netdb.h>
  71. # else /* not HAVE_LAN_SOCKET_H */
  72. # define OMIT_SOCKETS 1
  73. # endif /* not HAVE_LAN_SOCKET_H */
  74. # endif /* not HAVE_SYS_SOCKET_H */
  75. #endif /* !OMIT_SOCKETS */
  76. #if STDC_HEADERS
  77. # include <stdlib.h>
  78. # include <string.h>
  79. #else /* not STDC_HEADERS */
  80. extern char *getenv();
  81. # if HAVE_STRING_H
  82. # include <string.h>
  83. # else /* not HAVE_STRING_H */
  84. # include <strings.h>
  85. # endif /* not HAVE_STRING_H */
  86. #endif /* not STDC_HEADERS */
  87. #if HAVE_SYS_FCNTL_H
  88. # include <sys/fcntl.h>
  89. #else /* not HAVE_SYS_FCNTL_H */
  90. # if HAVE_FCNTL_H
  91. # include <fcntl.h>
  92. # endif /* HAVE_FCNTL_H */
  93. #endif /* not HAVE_SYS_FCNTL_H */
  94. #if HAVE_SYS_SYSTEMINFO_H
  95. # include <sys/systeminfo.h>
  96. #endif /* HAVE_SYS_SYSTEMINFO_H */
  97. #if TIME_WITH_SYS_TIME
  98. # include <sys/time.h>
  99. # include <time.h>
  100. #else
  101. # if HAVE_SYS_TIME_H
  102. # include <sys/time.h>
  103. # else
  104. # include <time.h>
  105. # endif
  106. #endif
  107. #if HAVE_UNISTD_H
  108. # include <unistd.h>
  109. #endif
  110. #if HAVE_SYS_WAIT_H
  111. # include <sys/wait.h>
  112. #endif
  113. #if HAVE_DIRENT_H
  114. # include <dirent.h>
  115. # define NAMLEN(dirent) strlen((dirent)->d_name)
  116. # define HAVE_DIR_STRUCT
  117. #else
  118. # define dirent direct
  119. # define NAMLEN(dirent) (dirent)->d_namlen
  120. # if HAVE_SYS_NDIR_H
  121. # include <sys/ndir.h>
  122. # define HAVE_DIR_STRUCT
  123. # endif
  124. # if HAVE_SYS_DIR_H
  125. # include <sys/dir.h>
  126. # define HAVE_DIR_STRUCT
  127. # endif
  128. # if HAVE_NDIR_H
  129. # include <ndir.h>
  130. # define HAVE_DIR_STRUCT
  131. # endif
  132. #endif
  133. #include <X11/Intrinsic.h>
  134. #include <X11/StringDefs.h>
  135. #include <X11/Shell.h>
  136. #include <X11/cursorfont.h>
  137. #include <X11/Xatom.h>
  138. #include <X11/Xmu/Atoms.h>
  139. #if USE_XAW3D
  140. #include <X11/Xaw3d/Dialog.h>
  141. #include <X11/Xaw3d/Form.h>
  142. #include <X11/Xaw3d/List.h>
  143. #include <X11/Xaw3d/Label.h>
  144. #include <X11/Xaw3d/SimpleMenu.h>
  145. #include <X11/Xaw3d/SmeBSB.h>
  146. #include <X11/Xaw3d/SmeLine.h>
  147. #include <X11/Xaw3d/Box.h>
  148. #include <X11/Xaw3d/MenuButton.h>
  149. #include <X11/Xaw3d/Text.h>
  150. #include <X11/Xaw3d/AsciiText.h>
  151. #else
  152. #include <X11/Xaw/Dialog.h>
  153. #include <X11/Xaw/Form.h>
  154. #include <X11/Xaw/List.h>
  155. #include <X11/Xaw/Label.h>
  156. #include <X11/Xaw/SimpleMenu.h>
  157. #include <X11/Xaw/SmeBSB.h>
  158. #include <X11/Xaw/SmeLine.h>
  159. #include <X11/Xaw/Box.h>
  160. #include <X11/Xaw/MenuButton.h>
  161. #include <X11/Xaw/Text.h>
  162. #include <X11/Xaw/AsciiText.h>
  163. #endif
  164. // [HGM] bitmaps: put before incuding the bitmaps / pixmaps, to know how many piece types there are.
  165. #include "common.h"
  166. #if HAVE_LIBXPM
  167. #include <X11/xpm.h>
  168. #include "pixmaps/pixmaps.h"
  169. #define IMAGE_EXT "xpm"
  170. #else
  171. #define IMAGE_EXT "xim"
  172. #include "bitmaps/bitmaps.h"
  173. #endif
  174. #include "bitmaps/icon_white.bm"
  175. #include "bitmaps/icon_black.bm"
  176. #include "bitmaps/checkmark.bm"
  177. #include "frontend.h"
  178. #include "backend.h"
  179. #include "backendz.h"
  180. #include "moves.h"
  181. #include "xboard.h"
  182. #include "childio.h"
  183. #include "xgamelist.h"
  184. #include "xhistory.h"
  185. #include "xedittags.h"
  186. #include "gettext.h"
  187. // must be moved to xengineoutput.h
  188. void EngineOutputProc P((Widget w, XEvent *event,
  189. String *prms, Cardinal *nprms));
  190. void EvalGraphProc P((Widget w, XEvent *event,
  191. String *prms, Cardinal *nprms));
  192. #ifdef __EMX__
  193. #ifndef HAVE_USLEEP
  194. #define HAVE_USLEEP
  195. #endif
  196. #define usleep(t) _sleep2(((t)+500)/1000)
  197. #endif
  198. #ifdef ENABLE_NLS
  199. # define _(s) gettext (s)
  200. # define N_(s) gettext_noop (s)
  201. #else
  202. # define _(s) (s)
  203. # define N_(s) s
  204. #endif
  205. typedef struct {
  206. String string;
  207. String ref;
  208. XtActionProc proc;
  209. } MenuItem;
  210. typedef struct {
  211. String name;
  212. String ref;
  213. MenuItem *mi;
  214. } Menu;
  215. int main P((int argc, char **argv));
  216. FILE * XsraSelFile P((Widget w, char *prompt, char *ok, char *cancel, char *failed,
  217. char *init_path, char *filter, char *mode, int (*show_entry)(), char **name_return));
  218. RETSIGTYPE CmailSigHandler P((int sig));
  219. RETSIGTYPE IntSigHandler P((int sig));
  220. RETSIGTYPE TermSizeSigHandler P((int sig));
  221. void CreateGCs P((int redo));
  222. void CreateAnyPieces P((void));
  223. void CreateXIMPieces P((void));
  224. void CreateXPMPieces P((void));
  225. void CreateXPMBoard P((char *s, int n));
  226. void CreatePieces P((void));
  227. void CreatePieceMenus P((void));
  228. Widget CreateMenuBar P((Menu *mb));
  229. Widget CreateButtonBar P ((MenuItem *mi));
  230. char *FindFont P((char *pattern, int targetPxlSize));
  231. void PieceMenuPopup P((Widget w, XEvent *event,
  232. String *params, Cardinal *num_params));
  233. static void PieceMenuSelect P((Widget w, ChessSquare piece, caddr_t junk));
  234. static void DropMenuSelect P((Widget w, ChessSquare piece, caddr_t junk));
  235. void ReadBitmap P((Pixmap *pm, String name, unsigned char bits[],
  236. u_int wreq, u_int hreq));
  237. void CreateGrid P((void));
  238. int EventToSquare P((int x, int limit));
  239. void DrawSquare P((int row, int column, ChessSquare piece, int do_flash));
  240. void EventProc P((Widget widget, caddr_t unused, XEvent *event));
  241. void HandleUserMove P((Widget w, XEvent *event,
  242. String *prms, Cardinal *nprms));
  243. void AnimateUserMove P((Widget w, XEvent * event,
  244. String * params, Cardinal * nParams));
  245. void HandlePV P((Widget w, XEvent * event,
  246. String * params, Cardinal * nParams));
  247. void SelectPV P((Widget w, XEvent * event,
  248. String * params, Cardinal * nParams));
  249. void StopPV P((Widget w, XEvent * event,
  250. String * params, Cardinal * nParams));
  251. void WhiteClock P((Widget w, XEvent *event,
  252. String *prms, Cardinal *nprms));
  253. void BlackClock P((Widget w, XEvent *event,
  254. String *prms, Cardinal *nprms));
  255. void DrawPositionProc P((Widget w, XEvent *event,
  256. String *prms, Cardinal *nprms));
  257. void XDrawPosition P((Widget w, /*Boolean*/int repaint,
  258. Board board));
  259. void CommentClick P((Widget w, XEvent * event,
  260. String * params, Cardinal * nParams));
  261. void CommentPopUp P((char *title, char *label));
  262. void CommentPopDown P((void));
  263. void CommentCallback P((Widget w, XtPointer client_data,
  264. XtPointer call_data));
  265. void ICSInputBoxPopUp P((void));
  266. void ICSInputBoxPopDown P((void));
  267. void FileNamePopUp P((char *label, char *def, char *filter,
  268. FileProc proc, char *openMode));
  269. void FileNamePopDown P((void));
  270. void FileNameCallback P((Widget w, XtPointer client_data,
  271. XtPointer call_data));
  272. void FileNameAction P((Widget w, XEvent *event,
  273. String *prms, Cardinal *nprms));
  274. void AskQuestionReplyAction P((Widget w, XEvent *event,
  275. String *prms, Cardinal *nprms));
  276. void AskQuestionProc P((Widget w, XEvent *event,
  277. String *prms, Cardinal *nprms));
  278. void AskQuestionPopDown P((void));
  279. void PromotionPopDown P((void));
  280. void PromotionCallback P((Widget w, XtPointer client_data,
  281. XtPointer call_data));
  282. void EditCommentPopDown P((void));
  283. void EditCommentCallback P((Widget w, XtPointer client_data,
  284. XtPointer call_data));
  285. void SelectCommand P((Widget w, XtPointer client_data, XtPointer call_data));
  286. void ResetProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  287. void LoadGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  288. void LoadNextGameProc P((Widget w, XEvent *event, String *prms,
  289. Cardinal *nprms));
  290. void LoadPrevGameProc P((Widget w, XEvent *event, String *prms,
  291. Cardinal *nprms));
  292. void ReloadGameProc P((Widget w, XEvent *event, String *prms,
  293. Cardinal *nprms));
  294. void LoadPositionProc P((Widget w, XEvent *event,
  295. String *prms, Cardinal *nprms));
  296. void LoadNextPositionProc P((Widget w, XEvent *event, String *prms,
  297. Cardinal *nprms));
  298. void LoadPrevPositionProc P((Widget w, XEvent *event, String *prms,
  299. Cardinal *nprms));
  300. void ReloadPositionProc P((Widget w, XEvent *event, String *prms,
  301. Cardinal *nprms));
  302. void CopyPositionProc P((Widget w, XEvent *event, String *prms,
  303. Cardinal *nprms));
  304. void PastePositionProc P((Widget w, XEvent *event, String *prms,
  305. Cardinal *nprms));
  306. void CopyGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  307. void PasteGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  308. void SaveGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  309. void SavePositionProc P((Widget w, XEvent *event,
  310. String *prms, Cardinal *nprms));
  311. void MailMoveProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  312. void ReloadCmailMsgProc P((Widget w, XEvent *event, String *prms,
  313. Cardinal *nprms));
  314. void QuitProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  315. void PauseProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  316. void MachineBlackProc P((Widget w, XEvent *event, String *prms,
  317. Cardinal *nprms));
  318. void MachineWhiteProc P((Widget w, XEvent *event,
  319. String *prms, Cardinal *nprms));
  320. void AnalyzeModeProc P((Widget w, XEvent *event,
  321. String *prms, Cardinal *nprms));
  322. void AnalyzeFileProc P((Widget w, XEvent *event,
  323. String *prms, Cardinal *nprms));
  324. void TwoMachinesProc P((Widget w, XEvent *event, String *prms,
  325. Cardinal *nprms));
  326. void MatchProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  327. void MatchOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  328. void IcsClientProc P((Widget w, XEvent *event, String *prms,
  329. Cardinal *nprms));
  330. void EditGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  331. void EditPositionProc P((Widget w, XEvent *event,
  332. String *prms, Cardinal *nprms));
  333. void TrainingProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  334. void EditCommentProc P((Widget w, XEvent *event,
  335. String *prms, Cardinal *nprms));
  336. void IcsInputBoxProc P((Widget w, XEvent *event,
  337. String *prms, Cardinal *nprms));
  338. void AcceptProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  339. void DeclineProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  340. void RematchProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  341. void CallFlagProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  342. void DrawProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  343. void AbortProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  344. void AdjournProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  345. void ResignProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  346. void AdjuWhiteProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  347. void AdjuBlackProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  348. void AdjuDrawProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  349. void EnterKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  350. void UpKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  351. void DownKeyProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  352. void StopObservingProc P((Widget w, XEvent *event, String *prms,
  353. Cardinal *nprms));
  354. void StopExaminingProc P((Widget w, XEvent *event, String *prms,
  355. Cardinal *nprms));
  356. void UploadProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  357. void BackwardProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  358. void ForwardProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  359. void ToStartProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  360. void ToEndProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  361. void RevertProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  362. void AnnotateProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  363. void TruncateGameProc P((Widget w, XEvent *event, String *prms,
  364. Cardinal *nprms));
  365. void RetractMoveProc P((Widget w, XEvent *event, String *prms,
  366. Cardinal *nprms));
  367. void MoveNowProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  368. void AlwaysQueenProc P((Widget w, XEvent *event, String *prms,
  369. Cardinal *nprms));
  370. void AnimateDraggingProc P((Widget w, XEvent *event, String *prms,
  371. Cardinal *nprms));
  372. void AnimateMovingProc P((Widget w, XEvent *event, String *prms,
  373. Cardinal *nprms));
  374. void AutoflagProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  375. void AutoflipProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  376. void BlindfoldProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  377. void FlashMovesProc P((Widget w, XEvent *event, String *prms,
  378. Cardinal *nprms));
  379. void FlipViewProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  380. void HighlightDraggingProc P((Widget w, XEvent *event, String *prms,
  381. Cardinal *nprms));
  382. void HighlightLastMoveProc P((Widget w, XEvent *event, String *prms,
  383. Cardinal *nprms));
  384. void HighlightArrowProc P((Widget w, XEvent *event, String *prms,
  385. Cardinal *nprms));
  386. void MoveSoundProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  387. //void IcsAlarmProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  388. void OneClickProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  389. void PeriodicUpdatesProc P((Widget w, XEvent *event, String *prms,
  390. Cardinal *nprms));
  391. void PonderNextMoveProc P((Widget w, XEvent *event, String *prms,
  392. Cardinal *nprms));
  393. void PopupMoveErrorsProc P((Widget w, XEvent *event, String *prms,
  394. Cardinal *nprms));
  395. void PopupExitMessageProc P((Widget w, XEvent *event, String *prms,
  396. Cardinal *nprms));
  397. //void PremoveProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  398. void ShowCoordsProc P((Widget w, XEvent *event, String *prms,
  399. Cardinal *nprms));
  400. void ShowThinkingProc P((Widget w, XEvent *event, String *prms,
  401. Cardinal *nprms));
  402. void HideThinkingProc P((Widget w, XEvent *event, String *prms,
  403. Cardinal *nprms));
  404. void TestLegalityProc P((Widget w, XEvent *event, String *prms,
  405. Cardinal *nprms));
  406. void SaveSettingsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  407. void SaveOnExitProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  408. void InfoProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  409. void ManProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  410. void HintProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  411. void BookProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  412. void AboutGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  413. void AboutProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  414. void DebugProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  415. void NothingProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  416. void Iconify P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  417. void DisplayMove P((int moveNumber));
  418. void DisplayTitle P((char *title));
  419. void ICSInitScript P((void));
  420. int LoadGamePopUp P((FILE *f, int gameNumber, char *title));
  421. void ErrorPopUp P((char *title, char *text, int modal));
  422. void ErrorPopDown P((void));
  423. static char *ExpandPathName P((char *path));
  424. static void CreateAnimVars P((void));
  425. static void DragPieceMove P((int x, int y));
  426. static void DrawDragPiece P((void));
  427. char *ModeToWidgetName P((GameMode mode));
  428. void ShuffleMenuProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  429. void EngineMenuProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  430. void UciMenuProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  431. void TimeControlProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  432. void OptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  433. void NewVariantProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  434. void IcsTextProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  435. void FirstSettingsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  436. void SecondSettingsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  437. void GameListOptionsPopUp P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  438. void IcsOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  439. void SoundOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  440. void BoardOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  441. void LoadOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  442. void SaveOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
  443. void GameListOptionsPopDown P(());
  444. void ShufflePopDown P(());
  445. void TimeControlPopDown P(());
  446. void GenericPopDown P(());
  447. void update_ics_width P(());
  448. int get_term_width P(());
  449. int CopyMemoProc P(());
  450. void DrawArrowHighlight P((int fromX, int fromY, int toX,int toY));
  451. Boolean IsDrawArrowEnabled P(());
  452. /*
  453. * XBoard depends on Xt R4 or higher
  454. */
  455. int xtVersion = XtSpecificationRelease;
  456. int xScreen;
  457. Display *xDisplay;
  458. Window xBoardWindow;
  459. Pixel lightSquareColor, darkSquareColor, whitePieceColor, blackPieceColor,
  460. jailSquareColor, highlightSquareColor, premoveHighlightColor;
  461. Pixel lowTimeWarningColor;
  462. GC lightSquareGC, darkSquareGC, jailSquareGC, lineGC, wdPieceGC, wlPieceGC,
  463. bdPieceGC, blPieceGC, wbPieceGC, bwPieceGC, coordGC, highlineGC,
  464. wjPieceGC, bjPieceGC, prelineGC, countGC;
  465. Pixmap iconPixmap, wIconPixmap, bIconPixmap, xMarkPixmap;
  466. Widget shellWidget, layoutWidget, formWidget, boardWidget, messageWidget,
  467. whiteTimerWidget, blackTimerWidget, titleWidget, widgetList[16],
  468. commentShell, promotionShell, whitePieceMenu, blackPieceMenu, dropMenu,
  469. menuBarWidget, buttonBarWidget, editShell, errorShell, analysisShell,
  470. ICSInputShell, fileNameShell, askQuestionShell;
  471. Widget historyShell, evalGraphShell, gameListShell;
  472. int hOffset; // [HGM] dual
  473. XSegment secondSegments[BOARD_RANKS + BOARD_FILES + 2];
  474. XSegment gridSegments[BOARD_RANKS + BOARD_FILES + 2];
  475. XSegment jailGridSegments[BOARD_RANKS + BOARD_FILES + 6];
  476. Font clockFontID, coordFontID, countFontID;
  477. XFontStruct *clockFontStruct, *coordFontStruct, *countFontStruct;
  478. XtAppContext appContext;
  479. char *layoutName;
  480. char *oldICSInteractionTitle;
  481. FileProc fileProc;
  482. char *fileOpenMode;
  483. char installDir[] = "."; // [HGM] UCI: needed for UCI; probably needs run-time initializtion
  484. Position commentX = -1, commentY = -1;
  485. Dimension commentW, commentH;
  486. typedef unsigned int BoardSize;
  487. BoardSize boardSize;
  488. Boolean chessProgram;
  489. int minX, minY; // [HGM] placement: volatile limits on upper-left corner
  490. int squareSize, smallLayout = 0, tinyLayout = 0,
  491. marginW, marginH, // [HGM] for run-time resizing
  492. fromX = -1, fromY = -1, toX, toY, commentUp = False, analysisUp = False,
  493. ICSInputBoxUp = False, askQuestionUp = False,
  494. filenameUp = False, promotionUp = False, pmFromX = -1, pmFromY = -1,
  495. editUp = False, errorUp = False, errorExitStatus = -1, lineGap, defaultLineGap;
  496. Pixel timerForegroundPixel, timerBackgroundPixel;
  497. Pixel buttonForegroundPixel, buttonBackgroundPixel;
  498. char *chessDir, *programName, *programVersion,
  499. *gameCopyFilename, *gamePasteFilename;
  500. Boolean alwaysOnTop = False;
  501. Boolean saveSettingsOnExit;
  502. char *settingsFileName;
  503. char *icsTextMenuString;
  504. char *icsNames;
  505. char *firstChessProgramNames;
  506. char *secondChessProgramNames;
  507. WindowPlacement wpMain;
  508. WindowPlacement wpConsole;
  509. WindowPlacement wpComment;
  510. WindowPlacement wpMoveHistory;
  511. WindowPlacement wpEvalGraph;
  512. WindowPlacement wpEngineOutput;
  513. WindowPlacement wpGameList;
  514. WindowPlacement wpTags;
  515. #define SOLID 0
  516. #define OUTLINE 1
  517. Pixmap pieceBitmap[2][(int)BlackPawn];
  518. Pixmap pieceBitmap2[2][(int)BlackPawn+4]; /* [HGM] pieces */
  519. Pixmap xpmPieceBitmap[4][(int)BlackPawn]; /* LL, LD, DL, DD actually used*/
  520. Pixmap xpmPieceBitmap2[4][(int)BlackPawn+4]; /* LL, LD, DL, DD set to select from */
  521. Pixmap xpmLightSquare, xpmDarkSquare, xpmJailSquare;
  522. Pixmap xpmBoardBitmap[2];
  523. int useImages, useImageSqs, useTexture, textureW[2], textureH[2];
  524. XImage *ximPieceBitmap[4][(int)BlackPawn+4]; /* LL, LD, DL, DD */
  525. Pixmap ximMaskPm[(int)BlackPawn]; /* clipmasks, used for XIM pieces */
  526. Pixmap ximMaskPm2[(int)BlackPawn+4]; /* clipmasks, used for XIM pieces */
  527. XImage *ximLightSquare, *ximDarkSquare;
  528. XImage *xim_Cross;
  529. #define pieceToSolid(piece) &pieceBitmap[SOLID][(piece) % (int)BlackPawn]
  530. #define pieceToOutline(piece) &pieceBitmap[OUTLINE][(piece) % (int)BlackPawn]
  531. #define White(piece) ((int)(piece) < (int)BlackPawn)
  532. /* Variables for doing smooth animation. This whole thing
  533. would be much easier if the board was double-buffered,
  534. but that would require a fairly major rewrite. */
  535. typedef struct {
  536. Pixmap saveBuf;
  537. Pixmap newBuf;
  538. GC blitGC, pieceGC, outlineGC;
  539. XPoint startSquare, prevFrame, mouseDelta;
  540. int startColor;
  541. int dragPiece;
  542. Boolean dragActive;
  543. int startBoardX, startBoardY;
  544. } AnimState;
  545. /* There can be two pieces being animated at once: a player
  546. can begin dragging a piece before the remote opponent has moved. */
  547. static AnimState game, player;
  548. /* Bitmaps for use as masks when drawing XPM pieces.
  549. Need one for each black and white piece. */
  550. static Pixmap xpmMask[BlackKing + 1];
  551. /* This magic number is the number of intermediate frames used
  552. in each half of the animation. For short moves it's reduced
  553. by 1. The total number of frames will be factor * 2 + 1. */
  554. #define kFactor 4
  555. SizeDefaults sizeDefaults[] = SIZE_DEFAULTS;
  556. MenuItem fileMenu[] = {
  557. {N_("New Game Ctrl+N"), "New Game", ResetProc},
  558. {N_("New Shuffle Game ..."), "New Shuffle Game", ShuffleMenuProc},
  559. {N_("New Variant ... Alt+Shift+V"), "New Variant", NewVariantProc}, // [HGM] variant: not functional yet
  560. {"----", NULL, NothingProc},
  561. {N_("Load Game Ctrl+O"), "Load Game", LoadGameProc},
  562. {N_("Load Position Ctrl+Shift+O"), "Load Position", LoadPositionProc},
  563. // {N_("Load Next Game"), "Load Next Game", LoadNextGameProc},
  564. // {N_("Load Previous Game"), "Load Previous Game", LoadPrevGameProc},
  565. // {N_("Reload Same Game"), "Reload Same Game", ReloadGameProc},
  566. {N_("Next Position Shift+PgDn"), "Load Next Position", LoadNextPositionProc},
  567. {N_("Prev Position Shift+PgUp"), "Load Previous Position", LoadPrevPositionProc},
  568. {"----", NULL, NothingProc},
  569. // {N_("Reload Same Position"), "Reload Same Position", ReloadPositionProc},
  570. {N_("Save Game Ctrl+S"), "Save Game", SaveGameProc},
  571. {N_("Save Position Ctrl+Shift+S"), "Save Position", SavePositionProc},
  572. {"----", NULL, NothingProc},
  573. {N_("Mail Move"), "Mail Move", MailMoveProc},
  574. {N_("Reload CMail Message"), "Reload CMail Message", ReloadCmailMsgProc},
  575. {"----", NULL, NothingProc},
  576. {N_("Quit Ctr+Q"), "Exit", QuitProc},
  577. {NULL, NULL, NULL}
  578. };
  579. MenuItem editMenu[] = {
  580. {N_("Copy Game Ctrl+C"), "Copy Game", CopyGameProc},
  581. {N_("Copy Position Ctrl+Shift+C"), "Copy Position", CopyPositionProc},
  582. {"----", NULL, NothingProc},
  583. {N_("Paste Game Ctrl+V"), "Paste Game", PasteGameProc},
  584. {N_("Paste Position Ctrl+Shift+V"), "Paste Position", PastePositionProc},
  585. {"----", NULL, NothingProc},
  586. {N_("Edit Game Ctrl+E"), "Edit Game", EditGameProc},
  587. {N_("Edit Position Ctrl+Shift+E"), "Edit Position", EditPositionProc},
  588. {N_("Edit Tags"), "Edit Tags", EditTagsProc},
  589. {N_("Edit Comment"), "Edit Comment", EditCommentProc},
  590. {"----", NULL, NothingProc},
  591. {N_("Revert Home"), "Revert", RevertProc},
  592. {N_("Annotate"), "Annotate", AnnotateProc},
  593. {N_("Truncate Game End"), "Truncate Game", TruncateGameProc},
  594. {"----", NULL, NothingProc},
  595. {N_("Backward Alt+Left"), "Backward", BackwardProc},
  596. {N_("Forward Alt+Right"), "Forward", ForwardProc},
  597. {N_("Back to Start Alt+Home"), "Back to Start", ToStartProc},
  598. {N_("Forward to End Alt+End"), "Forward to End", ToEndProc},
  599. {NULL, NULL, NULL}
  600. };
  601. MenuItem viewMenu[] = {
  602. {N_("Flip View F2"), "Flip View", FlipViewProc},
  603. {"----", NULL, NothingProc},
  604. {N_("Engine Output Alt+Shift+O"), "Show Engine Output", EngineOutputProc},
  605. {N_("Move History Alt+Shift+H"), "Show Move History", HistoryShowProc}, // [HGM] hist: activate 4.2.7 code
  606. {N_("Evaluation Graph Alt+Shift+E"), "Show Evaluation Graph", EvalGraphProc},
  607. {N_("Game List Alt+Shift+G"), "Show Game List", ShowGameListProc},
  608. {N_("ICS text menu"), "ICStex", IcsTextProc},
  609. {"----", NULL, NothingProc},
  610. {N_("Tags"), "Show Tags", EditTagsProc},
  611. {N_("Comments"), "Show Comments", EditCommentProc},
  612. {N_("ICS Input Box"), "ICS Input Box", IcsInputBoxProc},
  613. {"----", NULL, NothingProc},
  614. {N_("Board..."), "Board Options", BoardOptionsProc},
  615. {N_("Game List Tags..."), "Game List", GameListOptionsPopUp},
  616. {NULL, NULL, NULL}
  617. };
  618. MenuItem modeMenu[] = {
  619. {N_("Machine White Ctrl+W"), "Machine White", MachineWhiteProc},
  620. {N_("Machine Black Ctrl+B"), "Machine Black", MachineBlackProc},
  621. {N_("Two Machines Ctrl+T"), "Two Machines", TwoMachinesProc},
  622. {N_("Analysis Mode Ctrl+A"), "Analysis Mode", AnalyzeModeProc},
  623. {N_("Analyze File Ctrl+F"), "Analyze File", AnalyzeFileProc },
  624. {N_("Edit Game Ctrl+E"), "Edit Game", EditGameProc},
  625. {N_("Edit Position Ctrl+Shift+E"), "Edit Position", EditPositionProc},
  626. {N_("Training"), "Training", TrainingProc},
  627. {N_("ICS Client"), "ICS Client", IcsClientProc},
  628. {"----", NULL, NothingProc},
  629. {N_("Machine Match"), "Machine Match", MatchProc},
  630. {N_("Pause Pause"), "Pause", PauseProc},
  631. {NULL, NULL, NULL}
  632. };
  633. MenuItem actionMenu[] = {
  634. {N_("Accept F3"), "Accept", AcceptProc},
  635. {N_("Decline F4"), "Decline", DeclineProc},
  636. {N_("Rematch F12"), "Rematch", RematchProc},
  637. {"----", NULL, NothingProc},
  638. {N_("Call Flag F5"), "Call Flag", CallFlagProc},
  639. {N_("Draw F6"), "Draw", DrawProc},
  640. {N_("Adjourn F7"), "Adjourn", AdjournProc},
  641. {N_("Abort F8"),"Abort", AbortProc},
  642. {N_("Resign F9"), "Resign", ResignProc},
  643. {"----", NULL, NothingProc},
  644. {N_("Stop Observing F10"), "Stop Observing", StopObservingProc},
  645. {N_("Stop Examining F11"), "Stop Examining", StopExaminingProc},
  646. {N_("Upload to Examine"), "Upload to Examine", UploadProc},
  647. {"----", NULL, NothingProc},
  648. {N_("Adjudicate to White"), "Adjudicate to White", AdjuWhiteProc},
  649. {N_("Adjudicate to Black"), "Adjudicate to Black", AdjuBlackProc},
  650. {N_("Adjudicate Draw"), "Adjudicate Draw", AdjuDrawProc},
  651. {NULL, NULL, NULL}
  652. };
  653. MenuItem engineMenu[] = {
  654. {N_("Engine #1 Settings ..."), "Engine #1 Settings", FirstSettingsProc},
  655. {N_("Engine #2 Settings ..."), "Engine #2 Settings", SecondSettingsProc},
  656. {"----", NULL, NothingProc},
  657. {N_("Hint"), "Hint", HintProc},
  658. {N_("Book"), "Book", BookProc},
  659. {"----", NULL, NothingProc},
  660. {N_("Move Now Ctrl+M"), "Move Now", MoveNowProc},
  661. {N_("Retract Move Ctrl+X"), "Retract Move", RetractMoveProc},
  662. {NULL, NULL, NULL}
  663. };
  664. MenuItem optionsMenu[] = {
  665. #define OPTIONSDIALOG
  666. #ifdef OPTIONSDIALOG
  667. {N_("General ..."), "General", OptionsProc},
  668. #endif
  669. {N_("Time Control ... Alt+Shift+T"), "Time Control", TimeControlProc},
  670. {N_("Common Engine ... Alt+Shift+U"), "Common Engine", UciMenuProc},
  671. {N_("Adjudications ... Alt+Shift+J"), "Adjudications", EngineMenuProc},
  672. {N_("ICS ..."), "ICS", IcsOptionsProc},
  673. {N_("Match ..."), "Match", MatchOptionsProc},
  674. {N_("Load Game ..."), "Load Game", LoadOptionsProc},
  675. {N_("Save Game ..."), "Save Game", SaveOptionsProc},
  676. // {N_(" ..."), "", OptionsProc},
  677. {N_("Game List ..."), "Game List", GameListOptionsPopUp},
  678. {N_("Sounds ..."), "Sounds", SoundOptionsProc},
  679. {"----", NULL, NothingProc},
  680. #ifndef OPTIONSDIALOG
  681. {N_("Always Queen Ctrl+Shift+Q"), "Always Queen", AlwaysQueenProc},
  682. {N_("Animate Dragging"), "Animate Dragging", AnimateDraggingProc},
  683. {N_("Animate Moving Ctrl+Shift+A"), "Animate Moving", AnimateMovingProc},
  684. {N_("Auto Flag Ctrl+Shift+F"), "Auto Flag", AutoflagProc},
  685. {N_("Auto Flip View"), "Auto Flip View", AutoflipProc},
  686. {N_("Blindfold"), "Blindfold", BlindfoldProc},
  687. {N_("Flash Moves"), "Flash Moves", FlashMovesProc},
  688. #if HIGHDRAG
  689. {N_("Highlight Dragging"), "Highlight Dragging", HighlightDraggingProc},
  690. #endif
  691. {N_("Highlight Last Move"), "Highlight Last Move", HighlightLastMoveProc},
  692. {N_("Highlight With Arrow"), "Arrow", HighlightArrowProc},
  693. {N_("Move Sound"), "Move Sound", MoveSoundProc},
  694. // {N_("ICS Alarm"), "ICS Alarm", IcsAlarmProc},
  695. {N_("One-Click Moving"), "OneClick", OneClickProc},
  696. {N_("Periodic Updates"), "Periodic Updates", PeriodicUpdatesProc},
  697. {N_("Ponder Next Move Ctrl+Shift+P"), "Ponder Next Move", PonderNextMoveProc},
  698. {N_("Popup Exit Message"), "Popup Exit Message", PopupExitMessageProc},
  699. {N_("Popup Move Errors"), "Popup Move Errors", PopupMoveErrorsProc},
  700. // {N_("Premove"), "Premove", PremoveProc},
  701. {N_("Show Coords"), "Show Coords", ShowCoordsProc},
  702. {N_("Hide Thinking Ctrl+Shift+H"), "Hide Thinking", HideThinkingProc},
  703. {N_("Test Legality Ctrl+Shift+L"), "Test Legality", TestLegalityProc},
  704. {"----", NULL, NothingProc},
  705. #endif
  706. {N_("Save Settings Now"), "Save Settings Now", SaveSettingsProc},
  707. {N_("Save Settings on Exit"), "Save Settings on Exit", SaveOnExitProc},
  708. {NULL, NULL, NULL}
  709. };
  710. MenuItem helpMenu[] = {
  711. {N_("Info XBoard"), "Info XBoard", InfoProc},
  712. {N_("Man XBoard F1"), "Man XBoard", ManProc},
  713. {"----", NULL, NothingProc},
  714. {N_("About XBoard"), "About XBoard", AboutProc},
  715. {NULL, NULL, NULL}
  716. };
  717. Menu menuBar[] = {
  718. {N_("File"), "File", fileMenu},
  719. {N_("Edit"), "Edit", editMenu},
  720. {N_("View"), "View", viewMenu},
  721. {N_("Mode"), "Mode", modeMenu},
  722. {N_("Action"), "Action", actionMenu},
  723. {N_("Engine"), "Engine", engineMenu},
  724. {N_("Options"), "Options", optionsMenu},
  725. {N_("Help"), "Help", helpMenu},
  726. {NULL, NULL, NULL}
  727. };
  728. #define PAUSE_BUTTON "P"
  729. MenuItem buttonBar[] = {
  730. {"<<", "<<", ToStartProc},
  731. {"<", "<", BackwardProc},
  732. {PAUSE_BUTTON, PAUSE_BUTTON, PauseProc},
  733. {">", ">", ForwardProc},
  734. {">>", ">>", ToEndProc},
  735. {NULL, NULL, NULL}
  736. };
  737. #define PIECE_MENU_SIZE 18
  738. String pieceMenuStrings[2][PIECE_MENU_SIZE] = {
  739. { N_("White"), "----", N_("Pawn"), N_("Knight"), N_("Bishop"), N_("Rook"),
  740. N_("Queen"), N_("King"), "----", N_("Elephant"), N_("Cannon"),
  741. N_("Archbishop"), N_("Chancellor"), "----", N_("Promote"), N_("Demote"),
  742. N_("Empty square"), N_("Clear board") },
  743. { N_("Black"), "----", N_("Pawn"), N_("Knight"), N_("Bishop"), N_("Rook"),
  744. N_("Queen"), N_("King"), "----", N_("Elephant"), N_("Cannon"),
  745. N_("Archbishop"), N_("Chancellor"), "----", N_("Promote"), N_("Demote"),
  746. N_("Empty square"), N_("Clear board") }
  747. };
  748. /* must be in same order as PieceMenuStrings! */
  749. ChessSquare pieceMenuTranslation[2][PIECE_MENU_SIZE] = {
  750. { WhitePlay, (ChessSquare) 0, WhitePawn, WhiteKnight, WhiteBishop,
  751. WhiteRook, WhiteQueen, WhiteKing, (ChessSquare) 0, WhiteAlfil,
  752. WhiteCannon, WhiteAngel, WhiteMarshall, (ChessSquare) 0,
  753. PromotePiece, DemotePiece, EmptySquare, ClearBoard },
  754. { BlackPlay, (ChessSquare) 0, BlackPawn, BlackKnight, BlackBishop,
  755. BlackRook, BlackQueen, BlackKing, (ChessSquare) 0, BlackAlfil,
  756. BlackCannon, BlackAngel, BlackMarshall, (ChessSquare) 0,
  757. PromotePiece, DemotePiece, EmptySquare, ClearBoard },
  758. };
  759. #define DROP_MENU_SIZE 6
  760. String dropMenuStrings[DROP_MENU_SIZE] = {
  761. "----", N_("Pawn"), N_("Knight"), N_("Bishop"), N_("Rook"), N_("Queen")
  762. };
  763. /* must be in same order as PieceMenuStrings! */
  764. ChessSquare dropMenuTranslation[DROP_MENU_SIZE] = {
  765. (ChessSquare) 0, WhitePawn, WhiteKnight, WhiteBishop,
  766. WhiteRook, WhiteQueen
  767. };
  768. typedef struct {
  769. char piece;
  770. char* widget;
  771. } DropMenuEnables;
  772. DropMenuEnables dmEnables[] = {
  773. { 'P', "Pawn" },
  774. { 'N', "Knight" },
  775. { 'B', "Bishop" },
  776. { 'R', "Rook" },
  777. { 'Q', "Queen" }
  778. };
  779. Arg shellArgs[] = {
  780. { XtNwidth, 0 },
  781. { XtNheight, 0 },
  782. { XtNminWidth, 0 },
  783. { XtNminHeight, 0 },
  784. { XtNmaxWidth, 0 },
  785. { XtNmaxHeight, 0 }
  786. };
  787. Arg layoutArgs[] = {
  788. { XtNborderWidth, 0 },
  789. { XtNdefaultDistance, 0 },
  790. };
  791. Arg formArgs[] = {
  792. { XtNborderWidth, 0 },
  793. { XtNresizable, (XtArgVal) True },
  794. };
  795. Arg boardArgs[] = {
  796. { XtNborderWidth, 0 },
  797. { XtNwidth, 0 },
  798. { XtNheight, 0 }
  799. };
  800. Arg titleArgs[] = {
  801. { XtNjustify, (XtArgVal) XtJustifyRight },
  802. { XtNlabel, (XtArgVal) "..." },
  803. { XtNresizable, (XtArgVal) True },
  804. { XtNresize, (XtArgVal) False }
  805. };
  806. Arg messageArgs[] = {
  807. { XtNjustify, (XtArgVal) XtJustifyLeft },
  808. { XtNlabel, (XtArgVal) "..." },
  809. { XtNresizable, (XtArgVal) True },
  810. { XtNresize, (XtArgVal) False }
  811. };
  812. Arg timerArgs[] = {
  813. { XtNborderWidth, 0 },
  814. { XtNjustify, (XtArgVal) XtJustifyLeft }
  815. };
  816. XtResource clientResources[] = {
  817. { "flashCount", "flashCount", XtRInt, sizeof(int),
  818. XtOffset(AppDataPtr, flashCount), XtRImmediate,
  819. (XtPointer) FLASH_COUNT },
  820. };
  821. XrmOptionDescRec shellOptions[] = {
  822. { "-flashCount", "flashCount", XrmoptionSepArg, NULL },
  823. { "-flash", "flashCount", XrmoptionNoArg, "3" },
  824. { "-xflash", "flashCount", XrmoptionNoArg, "0" },
  825. };
  826. XtActionsRec boardActions[] = {
  827. { "DrawPosition", DrawPositionProc },
  828. { "HandleUserMove", HandleUserMove },
  829. { "AnimateUserMove", AnimateUserMove },
  830. { "HandlePV", HandlePV },
  831. { "SelectPV", SelectPV },
  832. { "StopPV", StopPV },
  833. { "FileNameAction", FileNameAction },
  834. { "AskQuestionProc", AskQuestionProc },
  835. { "AskQuestionReplyAction", AskQuestionReplyAction },
  836. { "PieceMenuPopup", PieceMenuPopup },
  837. { "WhiteClock", WhiteClock },
  838. { "BlackClock", BlackClock },
  839. { "Iconify", Iconify },
  840. { "ResetProc", ResetProc },
  841. { "NewVariantProc", NewVariantProc },
  842. { "LoadGameProc", LoadGameProc },
  843. { "LoadNextGameProc", LoadNextGameProc },
  844. { "LoadPrevGameProc", LoadPrevGameProc },
  845. { "LoadSelectedProc", LoadSelectedProc },
  846. { "SetFilterProc", SetFilterProc },
  847. { "ReloadGameProc", ReloadGameProc },
  848. { "LoadPositionProc", LoadPositionProc },
  849. { "LoadNextPositionProc", LoadNextPositionProc },
  850. { "LoadPrevPositionProc", LoadPrevPositionProc },
  851. { "ReloadPositionProc", ReloadPositionProc },
  852. { "CopyPositionProc", CopyPositionProc },
  853. { "PastePositionProc", PastePositionProc },
  854. { "CopyGameProc", CopyGameProc },
  855. { "PasteGameProc", PasteGameProc },
  856. { "SaveGameProc", SaveGameProc },
  857. { "SavePositionProc", SavePositionProc },
  858. { "MailMoveProc", MailMoveProc },
  859. { "ReloadCmailMsgProc", ReloadCmailMsgProc },
  860. { "QuitProc", QuitProc },
  861. { "MachineWhiteProc", MachineWhiteProc },
  862. { "MachineBlackProc", MachineBlackProc },
  863. { "AnalysisModeProc", AnalyzeModeProc },
  864. { "AnalyzeFileProc", AnalyzeFileProc },
  865. { "TwoMachinesProc", TwoMachinesProc },
  866. { "IcsClientProc", IcsClientProc },
  867. { "EditGameProc", EditGameProc },
  868. { "EditPositionProc", EditPositionProc },
  869. { "TrainingProc", EditPositionProc },
  870. { "EngineOutputProc", EngineOutputProc}, // [HGM] Winboard_x engine-output window
  871. { "EvalGraphProc", EvalGraphProc}, // [HGM] Winboard_x avaluation graph window
  872. { "ShowGameListProc", ShowGameListProc },
  873. { "ShowMoveListProc", HistoryShowProc},
  874. { "EditTagsProc", EditCommentProc },
  875. { "EditCommentProc", EditCommentProc },
  876. { "IcsInputBoxProc", IcsInputBoxProc },
  877. { "PauseProc", PauseProc },
  878. { "AcceptProc", AcceptProc },
  879. { "DeclineProc", DeclineProc },
  880. { "RematchProc", RematchProc },
  881. { "CallFlagProc", CallFlagProc },
  882. { "DrawProc", DrawProc },
  883. { "AdjournProc", AdjournProc },
  884. { "AbortProc", AbortProc },
  885. { "ResignProc", ResignProc },
  886. { "AdjuWhiteProc", AdjuWhiteProc },
  887. { "AdjuBlackProc", AdjuBlackProc },
  888. { "AdjuDrawProc", AdjuDrawProc },
  889. { "EnterKeyProc", EnterKeyProc },
  890. { "UpKeyProc", UpKeyProc },
  891. { "DownKeyProc", DownKeyProc },
  892. { "StopObservingProc", StopObservingProc },
  893. { "StopExaminingProc", StopExaminingProc },
  894. { "UploadProc", UploadProc },
  895. { "BackwardProc", BackwardProc },
  896. { "ForwardProc", ForwardProc },
  897. { "ToStartProc", ToStartProc },
  898. { "ToEndProc", ToEndProc },
  899. { "RevertProc", RevertProc },
  900. { "AnnotateProc", AnnotateProc },
  901. { "TruncateGameProc", TruncateGameProc },
  902. { "MoveNowProc", MoveNowProc },
  903. { "RetractMoveProc", RetractMoveProc },
  904. { "EngineMenuProc", (XtActionProc) EngineMenuProc },
  905. { "UciMenuProc", (XtActionProc) UciMenuProc },
  906. { "TimeControlProc", (XtActionProc) TimeControlProc },
  907. { "FlipViewProc", FlipViewProc },
  908. { "PonderNextMoveProc", PonderNextMoveProc },
  909. #ifndef OPTIONSDIALOG
  910. { "AlwaysQueenProc", AlwaysQueenProc },
  911. { "AnimateDraggingProc", AnimateDraggingProc },
  912. { "AnimateMovingProc", AnimateMovingProc },
  913. { "AutoflagProc", AutoflagProc },
  914. { "AutoflipProc", AutoflipProc },
  915. { "BlindfoldProc", BlindfoldProc },
  916. { "FlashMovesProc", FlashMovesProc },
  917. #if HIGHDRAG
  918. { "HighlightDraggingProc", HighlightDraggingProc },
  919. #endif
  920. { "HighlightLastMoveProc", HighlightLastMoveProc },
  921. // { "IcsAlarmProc", IcsAlarmProc },
  922. { "MoveSoundProc", MoveSoundProc },
  923. { "PeriodicUpdatesProc", PeriodicUpdatesProc },
  924. { "PopupExitMessageProc", PopupExitMessageProc },
  925. { "PopupMoveErrorsProc", PopupMoveErrorsProc },
  926. // { "PremoveProc", PremoveProc },
  927. { "ShowCoordsProc", ShowCoordsProc },
  928. { "ShowThinkingProc", ShowThinkingProc },
  929. { "HideThinkingProc", HideThinkingProc },
  930. { "TestLegalityProc", TestLegalityProc },
  931. #endif
  932. { "SaveSettingsProc", SaveSettingsProc },
  933. { "SaveOnExitProc", SaveOnExitProc },
  934. { "InfoProc", InfoProc },
  935. { "ManProc", ManProc },
  936. { "HintProc", HintProc },
  937. { "BookProc", BookProc },
  938. { "AboutGameProc", AboutGameProc },
  939. { "AboutProc", AboutProc },
  940. { "DebugProc", DebugProc },
  941. { "NothingProc", NothingProc },
  942. { "CommentClick", (XtActionProc) CommentClick },
  943. { "CommentPopDown", (XtActionProc) CommentPopDown },
  944. { "EditCommentPopDown", (XtActionProc) EditCommentPopDown },
  945. { "TagsPopDown", (XtActionProc) TagsPopDown },
  946. { "ErrorPopDown", (XtActionProc) ErrorPopDown },
  947. { "ICSInputBoxPopDown", (XtActionProc) ICSInputBoxPopDown },
  948. { "FileNamePopDown", (XtActionProc) FileNamePopDown },
  949. { "AskQuestionPopDown", (XtActionProc) AskQuestionPopDown },
  950. { "GameListPopDown", (XtActionProc) GameListPopDown },
  951. { "GameListOptionsPopDown", (XtActionProc) GameListOptionsPopDown },
  952. { "PromotionPopDown", (XtActionProc) PromotionPopDown },
  953. { "HistoryPopDown", (XtActionProc) HistoryPopDown },
  954. { "EngineOutputPopDown", (XtActionProc) EngineOutputPopDown },
  955. { "EvalGraphPopDown", (XtActionProc) EvalGraphPopDown },
  956. { "ShufflePopDown", (XtActionProc) ShufflePopDown },
  957. { "TimeControlPopDown", (XtActionProc) TimeControlPopDown },
  958. { "GenericPopDown", (XtActionProc) GenericPopDown },
  959. { "CopyMemoProc", (XtActionProc) CopyMemoProc },
  960. };
  961. char globalTranslations[] =
  962. ":<Key>F9: ResignProc() \n \
  963. :Ctrl<Key>n: ResetProc() \n \
  964. :Meta<Key>V: NewVariantProc() \n \
  965. :Ctrl<Key>o: LoadGameProc() \n \
  966. :Meta<Key>Next: LoadNextGameProc() \n \
  967. :Meta<Key>Prior: LoadPrevGameProc() \n \
  968. :Ctrl<Key>s: SaveGameProc() \n \
  969. :Ctrl<Key>c: CopyGameProc() \n \
  970. :Ctrl<Key>v: PasteGameProc() \n \
  971. :Ctrl<Key>O: LoadPositionProc() \n \
  972. :Shift<Key>Next: LoadNextPositionProc() \n \
  973. :Shift<Key>Prior: LoadPrevPositionProc() \n \
  974. :Ctrl<Key>S: SavePositionProc() \n \
  975. :Ctrl<Key>C: CopyPositionProc() \n \
  976. :Ctrl<Key>V: PastePositionProc() \n \
  977. :Ctrl<Key>q: QuitProc() \n \
  978. :Ctrl<Key>w: MachineWhiteProc() \n \
  979. :Ctrl<Key>b: MachineBlackProc() \n \
  980. :Ctrl<Key>t: TwoMachinesProc() \n \
  981. :Ctrl<Key>a: AnalysisModeProc() \n \
  982. :Ctrl<Key>f: AnalyzeFileProc() \n \
  983. :Ctrl<Key>e: EditGameProc() \n \
  984. :Ctrl<Key>E: EditPositionProc() \n \
  985. :Meta<Key>O: EngineOutputProc() \n \
  986. :Meta<Key>E: EvalGraphProc() \n \
  987. :Meta<Key>G: ShowGameListProc() \n \
  988. :Meta<Key>H: ShowMoveListProc() \n \
  989. :<Key>Pause: PauseProc() \n \
  990. :<Key>F3: AcceptProc() \n \
  991. :<Key>F4: DeclineProc() \n \
  992. :<Key>F12: RematchProc() \n \
  993. :<Key>F5: CallFlagProc() \n \
  994. :<Key>F6: DrawProc() \n \
  995. :<Key>F7: AdjournProc() \n \
  996. :<Key>F8: AbortProc() \n \
  997. :<Key>F10: StopObservingProc() \n \
  998. :<Key>F11: StopExaminingProc() \n \
  999. :Meta Ctrl<Key>F12: DebugProc() \n \
  1000. :Meta<Key>End: ToEndProc() \n \
  1001. :Meta<Key>Right: ForwardProc() \n \
  1002. :Meta<Key>Home: ToStartProc() \n \
  1003. :Meta<Key>Left: BackwardProc() \n \
  1004. :<Key>Home: RevertProc() \n \
  1005. :<Key>End: TruncateGameProc() \n \
  1006. :Ctrl<Key>m: MoveNowProc() \n \
  1007. :Ctrl<Key>x: RetractMoveProc() \n \
  1008. :Meta<Key>J: EngineMenuProc() \n \
  1009. :Meta<Key>U: UciMenuProc() \n \
  1010. :Meta<Key>T: TimeControlProc() \n \
  1011. :Ctrl<Key>P: PonderNextMoveProc() \n "
  1012. #ifndef OPTIONSDIALOG
  1013. "\
  1014. :Ctrl<Key>Q: AlwaysQueenProc() \n \
  1015. :Ctrl<Key>F: AutoflagProc() \n \
  1016. :Ctrl<Key>A: AnimateMovingProc() \n \
  1017. :Ctrl<Key>L: TestLegalityProc() \n \
  1018. :Ctrl<Key>H: HideThinkingProc() \n "
  1019. #endif
  1020. "\
  1021. :<Key>-: Iconify() \n \
  1022. :<Key>F1: ManProc() \n \
  1023. :<Key>F2: FlipViewProc() \n \
  1024. <KeyDown>.: BackwardProc() \n \
  1025. <KeyUp>.: ForwardProc() \n \
  1026. Shift<Key>1: AskQuestionProc(\"Direct command\",\
  1027. \"Send to chess program:\",,1) \n \
  1028. Shift<Key>2: AskQuestionProc(\"Direct command\",\
  1029. \"Send to second chess program:\",,2) \n";
  1030. char boardTranslations[] =
  1031. "<Btn1Down>: HandleUserMove(0) \n \
  1032. Shift<Btn1Up>: HandleUserMove(1) \n \
  1033. <Btn1Up>: HandleUserMove(0) \n \
  1034. <Btn1Motion>: AnimateUserMove() \n \
  1035. <Btn3Motion>: HandlePV() \n \
  1036. <Btn3Up>: PieceMenuPopup(menuB) \n \
  1037. Shift<Btn2Down>: XawPositionSimpleMenu(menuB) XawPositionSimpleMenu(menuD)\
  1038. PieceMenuPopup(menuB) \n \
  1039. Any<Btn2Down>: XawPositionSimpleMenu(menuW) XawPositionSimpleMenu(menuD) \
  1040. PieceMenuPopup(menuW) \n \
  1041. Shift<Btn3Down>: XawPositionSimpleMenu(menuW) XawPositionSimpleMenu(menuD)\
  1042. PieceMenuPopup(menuW) \n \
  1043. Any<Btn3Down>: XawPositionSimpleMenu(menuB) XawPositionSimpleMenu(menuD) \
  1044. PieceMenuPopup(menuB) \n";
  1045. char whiteTranslations[] = "<BtnDown>: WhiteClock()\n";
  1046. char blackTranslations[] = "<BtnDown>: BlackClock()\n";
  1047. char ICSInputTranslations[] =
  1048. "<Key>Up: UpKeyProc() \n "
  1049. "<Key>Down: DownKeyProc() \n "
  1050. "<Key>Return: EnterKeyProc() \n";
  1051. // [HGM] vari: another hideous kludge: call extend-end first so we can be sure select-start works,
  1052. // as the widget is destroyed before the up-click can call extend-end
  1053. char commentTranslations[] = "<Btn3Down>: extend-end() select-start() CommentClick() \n";
  1054. String xboardResources[] = {
  1055. "*fileName*value.translations: #override\\n <Key>Return: FileNameAction()",
  1056. "*question*value.translations: #override\\n <Key>Return: AskQuestionReplyAction()",
  1057. "*errorpopup*translations: #override\\n <Key>Return: ErrorPopDown()",
  1058. NULL
  1059. };
  1060. /* Max possible square size */
  1061. #define MAXSQSIZE 256
  1062. static int xpm_avail[MAXSQSIZE];
  1063. #ifdef HAVE_DIR_STRUCT
  1064. /* Extract piece size from filename */
  1065. static int
  1066. xpm_getsize(name, len, ext)
  1067. char *name;
  1068. int len;
  1069. char *ext;
  1070. {
  1071. char *p, *d;
  1072. char buf[10];
  1073. if (len < 4)
  1074. return 0;
  1075. if ((p=strchr(name, '.')) == NULL ||
  1076. StrCaseCmp(p+1, ext) != 0)
  1077. return 0;
  1078. p = name + 3;
  1079. d = buf;
  1080. while (*p && isdigit(*p))
  1081. *(d++) = *(p++);
  1082. *d = 0;
  1083. return atoi(buf);
  1084. }
  1085. /* Setup xpm_avail */
  1086. static int
  1087. xpm_getavail(dirname, ext)
  1088. char *dirname;
  1089. char *ext;
  1090. {
  1091. DIR *dir;
  1092. struct dirent *ent;
  1093. int i;
  1094. for (i=0; i<MAXSQSIZE; ++i)
  1095. xpm_avail[i] = 0;
  1096. if (appData.debugMode)
  1097. fprintf(stderr, "XPM dir:%s:ext:%s:\n", dirname, ext);
  1098. dir = opendir(dirname);
  1099. if (!dir)
  1100. {
  1101. fprintf(stderr, _("%s: Can't access XPM directory %s\n"),
  1102. programName, dirname);
  1103. exit(1);
  1104. }
  1105. while ((ent=readdir(dir)) != NULL) {
  1106. i = xpm_getsize(ent->d_name, NAMLEN(ent), ext);
  1107. if (i > 0 && i < MAXSQSIZE)
  1108. xpm_avail[i] = 1;
  1109. }
  1110. closedir(dir);
  1111. return 0;
  1112. }
  1113. void
  1114. xpm_print_avail(fp, ext)
  1115. FILE *fp;
  1116. char *ext;
  1117. {
  1118. int i;
  1119. fprintf(fp, _("Available `%s' sizes:\n"), ext);
  1120. for (i=1; i<MAXSQSIZE; ++i) {
  1121. if (xpm_avail[i])
  1122. printf("%d\n", i);
  1123. }
  1124. }
  1125. /* Return XPM piecesize closest to size */
  1126. int
  1127. xpm_closest_to(dirname, size, ext)
  1128. char *dirname;
  1129. int size;
  1130. char *ext;
  1131. {
  1132. int i;
  1133. int sm_diff = MAXSQSIZE;
  1134. int sm_index = 0;
  1135. int diff;
  1136. xpm_getavail(dirname, ext);
  1137. if (appData.debugMode)
  1138. xpm_print_avail(stderr, ext);
  1139. for (i=1; i<MAXSQSIZE; ++i) {
  1140. if (xpm_avail[i]) {
  1141. diff = size - i;
  1142. diff = (diff<0) ? -diff : diff;
  1143. if (diff < sm_diff) {
  1144. sm_diff = diff;
  1145. sm_index = i;
  1146. }
  1147. }
  1148. }
  1149. if (!sm_index) {
  1150. fprintf(stderr, _("Error: No `%s' files!\n"), ext);
  1151. exit(1);
  1152. }
  1153. return sm_index;
  1154. }
  1155. #else /* !HAVE_DIR_STRUCT */
  1156. /* If we are on a system without a DIR struct, we can't
  1157. read the directory, so we can't collect a list of
  1158. filenames, etc., so we can't do any size-fitting. */
  1159. int
  1160. xpm_closest_to(dirname, size, ext)
  1161. char *dirname;
  1162. int size;
  1163. char *ext;
  1164. {
  1165. fprintf(stderr, _("\
  1166. Warning: No DIR structure found on this system --\n\
  1167. Unable to autosize for XPM/XIM pieces.\n\
  1168. Please report this error to frankm@hiwaay.net.\n\
  1169. Include system type & operating system in message.\n"));
  1170. return size;
  1171. }
  1172. #endif /* HAVE_DIR_STRUCT */
  1173. static char *cnames[9] = { "black", "red", "green", "yellow", "blue",
  1174. "magenta", "cyan", "white" };
  1175. typedef struct {
  1176. int attr, bg, fg;
  1177. } TextColors;
  1178. TextColors textColors[(int)NColorClasses];
  1179. /* String is: "fg, bg, attr". Which is 0, 1, 2 */
  1180. static int
  1181. parse_color(str, which)
  1182. char *str;
  1183. int which;
  1184. {
  1185. char *p, buf[100], *d;
  1186. int i;
  1187. if (strlen(str) > 99) /* watch bounds on buf */
  1188. return -1;
  1189. p = str;
  1190. d = buf;
  1191. for (i=0; i<which; ++i) {
  1192. p = strchr(p, ',');
  1193. if (!p)
  1194. return -1;
  1195. ++p;
  1196. }
  1197. /* Could be looking at something like:
  1198. black, , 1
  1199. .. in which case we want to stop on a comma also */
  1200. while (*p && *p != ',' && !isalpha(*p) && !isdigit(*p))
  1201. ++p;
  1202. if (*p == ',') {
  1203. return -1; /* Use default for empty field */
  1204. }
  1205. if (which == 2 || isdigit(*p))
  1206. return atoi(p);
  1207. while (*p && isalpha(*p))
  1208. *(d++) = *(p++);
  1209. *d = 0;
  1210. for (i=0; i<8; ++i) {
  1211. if (!StrCaseCmp(buf, cnames[i]))
  1212. return which? (i+40) : (i+30);
  1213. }
  1214. if (!StrCaseCmp(buf, "default")) return -1;
  1215. fprintf(stderr, _("%s: unrecognized color %s\n"), programName, buf);
  1216. return -2;
  1217. }
  1218. static int
  1219. parse_cpair(cc, str)
  1220. ColorClass cc;
  1221. char *str;
  1222. {
  1223. if ((textColors[(int)cc].fg=parse_color(str, 0)) == -2) {
  1224. fprintf(stderr, _("%s: can't parse foreground color in `%s'\n"),
  1225. programName, str);
  1226. return -1;
  1227. }
  1228. /* bg and attr are optional */
  1229. textColors[(int)cc].b

Large files files are truncated, but you can click here to view the full file