home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume28 / notation / part01 < prev    next >
Encoding:
Text File  |  1992-02-13  |  57.5 KB  |  2,253 lines

  1. Newsgroups: comp.sources.misc
  2. From: hthomas@ph.tn.tudelft.nl (Henry Thomas)
  3. Subject:  v28i036:  notation - chess preprocessor v3.9, Part01/04
  4. Message-ID: <csm-v28i036=notation.144616@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 3472b8a36c3064f13281bf047492679d
  6. Date: Tue, 11 Feb 1992 20:46:48 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: hthomas@ph.tn.tudelft.nl (Henry Thomas)
  10. Posting-number: Volume 28, Issue 36
  11. Archive-name: notation/part01
  12. Environment: UNIX
  13. Supersedes: notation: Volume20, Issue 52-55
  14.  
  15. This program is is chess preprocessor. It reads chess games, either
  16. in full algebraic or shortened notation (ie Nf1-g3 or f1g3 or Ng3) and
  17. is able to output the games and/or the board af any move, in ascii,
  18. postscript, TeX, or nroff. It also can generate output for the gnuan
  19. and xboard programs. It is multi-lingual (european) for piece
  20. identification. The program understands french, english, german,
  21. spanish dutch, italian, polish etc. The program also handles variations
  22. and symbolized comments.
  23.  
  24. This program is ok on UNIX (Sun Sparc Station and Sun-3). It uses
  25. standard C, and function declarations are done in both K&R-C and
  26. ANSI-C.  It won't difficult to compile on a IBM-PC with MSC (I 
  27. easily got an older version to work with TURBO-C).
  28.  
  29. I hope the program is clear enough to be easily modified. Anyway,
  30. I would like to centralize modifications, in order to manage an
  31. up-to-date version. So send me any modifications, in forms of diff
  32. files, if possible, along with the version number of the program.
  33. ---------------------
  34. #! /bin/sh
  35. # This is a shell archive.  Remove anything before this line, then feed it
  36. # into a shell via "sh file" or similar.  To overwrite existing files,
  37. # type "sh file -c".
  38. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  39. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  40. # Contents:  README chesssymb.def notation.c
  41. # Wrapped by kent@sparky on Tue Feb 11 14:22:45 1992
  42. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  43. echo If this archive is complete, you will see the following message:
  44. echo '          "shar: End of archive 1 (of 4)."'
  45. if test -f 'README' -a "${1}" != "-c" ; then 
  46.   echo shar: Will not clobber existing file \"'README'\"
  47. else
  48.   echo shar: Extracting \"'README'\" \(5243 characters\)
  49.   sed "s/^X//" >'README' <<'END_OF_FILE'
  50. X** DESCRIPTION
  51. X  This program is is chess preprocessor. It reads chess games, either
  52. Xin full algebraic or shortened notation (ie Nf1-g3 or f1g3 or Ng3) and
  53. Xis able to output the games and/or the board af any move, in ascii,
  54. Xpostscript, TeX, or nroff. It also can generate output for the gnuan
  55. Xand xboard programs. It is multi-lingual (european) for piece
  56. Xidentification. The program understand french, english, german,
  57. Xspanish dutch, italian, polish etc. The program also handle variations
  58. Xand symbolized comments.
  59. X
  60. XThis is a freeware program. You have the right to modify it, give it,
  61. Xprovided you don't modify the copyright notice and my name still
  62. Xremains.  The distribution has 4 shar-type files.
  63. X
  64. X** COMPATIBILITY
  65. X  This program is ok on UNIX (Sun Sparc Station and Sun-3). It uses
  66. Xstandard C, and fonctions declarations are done in both K&R-C and
  67. XANSI-C.  It won't difficult to compile on a IBM-PC with
  68. XMSC (I easily get to work an older function with TURBO-C).
  69. X
  70. X** QUICK USE
  71. X  Anyway, you want to try quickly the program, issue the command
  72. X"make" in this directory, and then type "notation algebric.txt" to
  73. Xtest the programm on Kasparov/Karpov game 13 (Lyon, November 1990).
  74. XIf you want to install it completely ( TeX, helpfile etc), edit the
  75. XMakefile and type "make install".  Read and modify the makefile for
  76. Xcustomizing notation to your national language and library path.  If
  77. Xyou want a complete manual, read notation.doc.  To print a postscript
  78. Xfile, merge the ps font definition and the output of the Notation
  79. Xprogram (say foo.ps) and send it to the printer (for instance "cat
  80. XCheq foo.ps | lpr").
  81. X
  82. X** SOURCES
  83. X  NOTA: <version number> is currently 3.9
  84. X
  85. X  They are posted to "comp.sources.misc". You can then get them from
  86. Xany site archiving "comp.sources.misc".
  87. X
  88. X  They are available by anonymous ftp on wuarchive.wustl.edu,
  89. X(user:anonymous, password:<your address>). The path is
  90. X"pub/Notation.tar.Z" ou "pub/Notation<version number>.tar.Z"
  91. XThe patch are also available as "Notation-patch<version number>.shar.Z".
  92. X
  93. X ** I expect the source to show up soon on garbo.uwasa.fi.
  94. XIf you're in Europe, you can get notation from the server
  95. Xgarbo.uwasa.fi:
  96. X-- by anonymous ftp with path /unix/util/notation.tar.Z
  97. X-- by e-mail by sending the message
  98. X
  99. X        mail mailserv@garbo.uwasa.fi
  100. X        Subject:garbo-request
  101. X        send unix/util/notation.tar.Z
  102. X
  103. X        (or  send unix/util/notation<version number>.tar.Z)
  104. X
  105. X   You will receive the uuencoded-split program within hours.
  106. X
  107. X  You can also get them by mail, from "hthomas@ph.tn.tudelft.nl". But
  108. XI prefer you try the others before.
  109. X
  110. X
  111. X** IMPORTANT
  112. X  If you want to use PostScript or LaTeX, you need two packages not
  113. Xprovided here. However, here is a way to get them:
  114. X
  115. X**** Postscript: 
  116. X  You need the font "Cheq", freely distributed by Adobe.  Send a mail
  117. Xto "ps-file-server@adobe.com" with the body "send Programs
  118. Xchessfont.ps". For use with "notation", rename the file "Cheq".
  119. X
  120. X------------------------------------------------------------------
  121. Xchessfont.ps              58548 Jun 22 1989
  122. X    This is the Adobe chess font "Cheq", created by John Renner. It 
  123. X    is an ASCII downloadable version of the font that is not in any 
  124. X    particular font format for a specific platform. See also
  125. X    "chessfontUNIX.shar" and "chessfontMAC.shar" for the font bundled 
  126. X    with other useful files like screen fonts and AFM files. If you 
  127. X    just want the font, it is available in this file separately for 
  128. X    convenience.
  129. X------------------------------------------------------------------
  130. X
  131. X**** LaTeX: 
  132. X  You need the chess fonts designed by Piet Tutalaers
  133. X"rcpt@urc.tue.nl". YOU NEED VERSION 1.2 (released 10/02/91). The
  134. Xcomplete distribution is available
  135. X
  136. X-- by ftp : on sol.cs.ruu.nl (131.211.80.5) with path TEX/chess.tar.Z
  137. X(please restrict access to weekends or evening/night (i.e.  between
  138. Xabout 2000 and 0.900 UTC)).
  139. X
  140. X------------------------------------------------------------------
  141. X-rw-r--r--  1 piet     staff        2984 Dec  3 10:11 chess.README
  142. X-rwxr--r--  1 piet     staff      129679 Dec  3 15:57 chess.tar.Z
  143. X------------------------------------------------------------------
  144. X
  145. X-- by e-mail : send the following message to 
  146. Xmail-server@cs..ruu.nl (or uunet!mcsun!hp4nl!ruuinf):
  147. X
  148. Xbegin
  149. Xpath john@highbrown.edu
  150. Xsend TEX/chess.tar.Z
  151. Xend
  152. X
  153. XThe path command can be deleted if we receive a valid from address in
  154. Xyour message. If this is the first time you use the mail server, we
  155. Xsuggest you first issue the request:
  156. Xsend help
  157. X
  158. X
  159. X** DOCUMENTATION
  160. X  See the file notation.doc for any info
  161. X
  162. X** COPYRIGHT
  163. X
  164. X  This is a freeware program. Commercial use is prohibited. It is free
  165. Xfor non-commercial use.  You have the right to modify it, give it,
  166. Xprovided you don't modify the copyright notice and my name still
  167. Xremains clearly indicated. For the others packages (Cheq and chess
  168. Xfont) refer to the original copyright notice.
  169. X
  170. X** USER FEEDBACK
  171. X
  172. X  If you're happy with this program, let me know :-) Thanks.
  173. X
  174. X
  175. X** MODIFICATIONS
  176. X
  177. X  I hope the program to be clear enough to be easily modified. Anyway,
  178. XI would like to centralize modification, in order to manage an
  179. Xup-to-date version. So send me the modification, in forms of diff
  180. Xfiles, if possible, along with the version number of the program.
  181. END_OF_FILE
  182.   if test 5243 -ne `wc -c <'README'`; then
  183.     echo shar: \"'README'\" unpacked with wrong size!
  184.   fi
  185.   # end of 'README'
  186. fi
  187. if test -f 'chesssymb.def' -a "${1}" != "-c" ; then 
  188.   echo shar: Will not clobber existing file \"'chesssymb.def'\"
  189. else
  190.   echo shar: Extracting \"'chesssymb.def'\" \(5043 characters\)
  191.   sed "s/^X//" >'chesssymb.def' <<'END_OF_FILE'
  192. X/*
  193. X  chess symbols : arguments (all are strings)
  194. X  0: ident
  195. X  1: ascii name
  196. X  2: ascii abbrev
  197. X  3: TeX name
  198. X  4: Postscript name (Mr. Walker font)
  199. X  5: english text
  200. X  6: french text
  201. X  */
  202. X
  203. XCHESSSYMB ( COM_CHK, "+", "+" ,  "+", "",
  204. X       "check",
  205. X       "echec" )
  206. XCHESSSYMB ( COM_DCK, "++", "++" ,  "++", "",
  207. X       "double check",
  208. X       "echec double" )
  209. XCHESSSYMB ( COM_WSB, "$wsb", "+=", "\\wbetter", "",
  210. X       "white stands lightly better",
  211. X       "les blancs ont un jeu un peu meilleur" )
  212. XCHESSSYMB ( COM_BSB, "$bsb", "=+", "\\bbetter", "",
  213. X       "black stands lightly better",
  214. X       "les noirs ont un jeu un peu meilleur" )
  215. XCHESSSYMB ( COM_WBE, "$wbe", "+_", "\\wupperhand", "",
  216. X       "white has the upper hand",
  217. X       "les blancs ont le meilleur jeu" )
  218. XCHESSSYMB ( COM_BBE, "$bbe", "_+", "\\bupperhand", "",
  219. X       "black has the upper hand",
  220. X       "les noirs ont le meilleur jeu" )
  221. XCHESSSYMB ( COM_WDA, "$wda", "+-", "\\wdecisive", "",
  222. X       "white has a decisive advantage",
  223. X       "les blancs ont un avantage de'cisif" )
  224. XCHESSSYMB ( COM_BDA, "$bda", "-+", "\\bdecisive", "",
  225. X       "black has a decisive advantage",
  226. X       "les noirs ont un avantage de'cisif" )
  227. XCHESSSYMB ( COM_EQA, "="  , "=",  "\\equal", "",
  228. X       "even",
  229. X       "e'gal" )
  230. XCHESSSYMB ( COM_UCR, "$ucr", "~" ,  "\\unclear", "",
  231. X       "unclear",
  232. X       "incertain" )
  233. XCHESSSYMB ( COM_WCO, "$wco", "=~" ,  "\\compensation", "",
  234. X       "with compensation for the material",
  235. X       "avec compensation pour le mate'riel" )
  236. XCHESSSYMB ( COM_DAD, "$dad", "(^)" ,  "\\devadvantage", "",
  237. X       "development advantage",
  238. X       "avance de de'veloppement" )
  239. XCHESSSYMB ( COM_SPA, "$spa", "()" ,  "\\moreroom", "",
  240. X       "greater space advantage",
  241. X       "grand avantage d'espace" )
  242. XCHESSSYMB ( COM_WTA, "$wta", "->" ,  "\\withattack", "",
  243. X       "with attack",
  244. X       "avec attaque" )
  245. XCHESSSYMB ( COM_WIN, "$win", "|^" ,  "\\withinit", "",
  246. X       "with initiative",
  247. X       "avec initiative" )
  248. XCHESSSYMB ( COM_WCP, "$wcp", "<->" ,  "\\counterplay", "",
  249. X       "with counter-play",
  250. X       "avec contre-attaque" )
  251. XCHESSSYMB ( COM_ZUG, "$zug", "(.)" ,  "\\zugzwang", "",
  252. X       "zugzwang",
  253. X       "zug zwang" )
  254. XCHESSSYMB ( COM_MAT, "#", "#" ,  "\\mate", "",
  255. X       "mate",
  256. X       "mat" )
  257. XCHESSSYMB ( COM_VGM, "!", "!" ,  "!", "",
  258. X       "very good move",
  259. X       "un tre`s bon coup" )
  260. XCHESSSYMB ( COM_VBM, "?", "?" ,  "?", "",
  261. X       "very bad move",
  262. X       "un tre`s mauvais coup" )
  263. XCHESSSYMB ( COM_EXM, "!!", "!!" ,  "!!", "",
  264. X       "excellent move",
  265. X       "un excellent coup" )
  266. XCHESSSYMB ( COM_MIS, "??", "??" ,  "??", "",
  267. X       "a mistake",
  268. X       "un coup faible" )
  269. XCHESSSYMB ( COM_MDA, "!?", "!?" ,  "!?", "",
  270. X       "a move deserving attention",
  271. X       "un coup qui me'rite l'attention" )
  272. XCHESSSYMB ( COM_DUM, "?!", "?!" ,  "?!", "",
  273. X       "a dubious move",
  274. X       "un coup d'une valeur douteuse" )
  275. XCHESSSYMB ( COM_WTI, "$wti", "/\\" ,  "\\withidea", "",
  276. X       "with the idea...",
  277. X       "avec l'ide'e..." )
  278. XCHESSSYMB ( COM_OLM, "$olm", "[]" ,  "\\onlymove", "",
  279. X       "only move",
  280. X       "seul coup possible" )
  281. XCHESSSYMB ( COM_BEI, "$bei", "^_" ,  "\\betteris", "",
  282. X       "better is",
  283. X       "est meilleur" )
  284. XCHESSSYMB ( COM_FIL, "$fil", "<=>" ,  "\\file", "",
  285. X       "file",
  286. X       "colonne" )
  287. XCHESSSYMB ( COM_DIA, "$dia", "/^" ,  "\\diagonal", "",
  288. X       "diagonal",
  289. X       "diagonale" )
  290. XCHESSSYMB ( COM_CNT, "$cnt", "[+]" ,  "\\centre", "",
  291. X       "center",
  292. X       "centre" )
  293. XCHESSSYMB ( COM_KGS, "$kgs", ">>" ,  "\\kside", "",
  294. X       "king's side",
  295. X       "aile roi" )
  296. XCHESSSYMB ( COM_QNS, "$qns", "<<" ,  "\\qside", "",
  297. X       "queen's side",
  298. X       "aile reine" )
  299. XCHESSSYMB ( COM_WKP, "$wkp", "><" ,  "\\weakpt", "",
  300. X       "weak point",
  301. X       "point faigle" )
  302. XCHESSSYMB ( COM_END, "$end", "_|_" ,  "\\ending", "",
  303. X       "ending",
  304. X       "finale" )
  305. XCHESSSYMB ( COM_POB, "$pob", "==" ,  "\\bishoppair", "",
  306. X       "pair of bishops",
  307. X       "paire de fous" )
  308. XCHESSSYMB ( COM_OPC, "$opc", "=#" ,  "\\opposbishops", "",
  309. X       "bishops of opposite colors",
  310. X       "fous de couleurs oppose'es" )
  311. XCHESSSYMB ( COM_SCB, "$scb", "##" ,  "\\samebishops", "",
  312. X       "same coloured bishops",
  313. X       "fous de me^me couleur" )
  314. XCHESSSYMB ( COM_UNP, "$unp", "oo" ,  "\\unitedpawns", "",
  315. X       "united pawns",
  316. X       "pions unis" )
  317. XCHESSSYMB ( COM_SEP, "$sep", "o..o" ,  "\\seppawns", "",
  318. X       "separated pawns",
  319. X       "pions se'pare's" )
  320. XCHESSSYMB ( COM_DOP, "$dop", "o/o" ,  "\\doublepawns", "",
  321. X       "doubled pawns",
  322. X       "pions double's" )
  323. XCHESSSYMB ( COM_TIM, "$tim", "(+)" ,  "\\timelimit", "",
  324. X       "time",
  325. X       "temps" )
  326. XCHESSSYMB ( COM_NOV, "$nov", "N" ,  "\\novelty", "",
  327. X       "novelty",
  328. X       "nouveaute'" )
  329. XCHESSSYMB ( COM_COM, "$com", "RR" ,  "\\comment", "",
  330. X       "editorial comment",
  331. X       "commentaire e'ditorial" )
  332. XCHESSSYMB ( COM_VAR, "$var", "R" ,  "\\various", "",
  333. X       "various moves",
  334. X       "coups divers" )
  335. XCHESSSYMB ( COM_WTO, "$wto", "_|" ,  "\\without", "",
  336. X       "without",
  337. X       "sans" )
  338. XCHESSSYMB ( COM_ETC, "etc", "etc" ,  "{etc}", "",
  339. X       "etc",
  340. X       "etc" )
  341. XCHESSSYMB ( COM_ETD, "||", "||" ,  "\\etc", "",
  342. X       "etc",
  343. X       "etc" )
  344. XCHESSSYMB ( COM_SEE, "$see", "" ,  "\\see", "",
  345. X       "see",
  346. X       "voir" )
  347. XCHESSSYMB ( COM_ENP, "ep", "ep" ,  "{ep}", "",
  348. X       "en passant",
  349. X       "en passant" )
  350. END_OF_FILE
  351.   if test 5043 -ne `wc -c <'chesssymb.def'`; then
  352.     echo shar: \"'chesssymb.def'\" unpacked with wrong size!
  353.   fi
  354.   # end of 'chesssymb.def'
  355. fi
  356. if test -f 'notation.c' -a "${1}" != "-c" ; then 
  357.   echo shar: Will not clobber existing file \"'notation.c'\"
  358. else
  359.   echo shar: Extracting \"'notation.c'\" \(42748 characters\)
  360.   sed "s/^X//" >'notation.c' <<'END_OF_FILE'
  361. X/*
  362. X  Notation program
  363. X  @(#)notation.c    3.9 (C) Henry Thomas   Release 3     Dated 12/10/91
  364. X */
  365. X/* Programme d'analyse de notation echiquienne
  366. X   Copyright (C) 1990 Henry Thomas
  367. X   Nom: notation
  368. X   Auteur: Henry Thomas
  369. X   Date: 27/11/90
  370. X/*
  371. XThis file is part of NOTATION program.
  372. X
  373. XNOTATION is free software; you can redistribute it and/or modify
  374. Xit under the terms of the GNU General Public License as published by
  375. Xthe Free Software Foundation; either version 1, or (at your option)
  376. Xany later version.
  377. X
  378. XNOTATION is distributed in the hope that it will be useful,
  379. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  380. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  381. XGNU General Public License for more details.
  382. X
  383. XYou should have received a copy of the GNU General Public License
  384. Xalong with NOTATION; see the file COPYING.  If not, write to
  385. Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  386. X
  387. X/* --------------------- data part ---------------------- */
  388. X
  389. X/* les tableaux suivants sont les tables de transcription de notation
  390. X   selon les langages
  391. X   */
  392. X#ifdef __STDC__
  393. X#include <stdlib.h>
  394. X#endif
  395. X#include <stdio.h>
  396. X#include <string.h>
  397. X#include <ctype.h>
  398. X
  399. X#include "chesstype.h"
  400. X#include "notation.h"
  401. X#include "drivers.h"
  402. X#include "lexer.h"
  403. X
  404. Xextern void close_files();
  405. X
  406. Xchar * version_string =
  407. X  "@(#)notation.c    3.9 (C) Henry Thomas.   Release 3     Dated 12/10/91";
  408. X
  409. Xstatic char * keywords[]= {
  410. X  "@startplay" , "@clearboard" , "@showboard" ,
  411. X  "@whitesmove", "@blacksmove", "@configwhite", "@configblack" ,
  412. X  "@default" , 
  413. X  /* these are keywords with arguments */
  414. X  "@title", "@subtitle", "@score", "@language",
  415. X  /* "special" keyword */
  416. X  "@special", 
  417. X  /* null and final keyword */
  418. X  "@null"
  419. X  };
  420. X
  421. Xint configuring = FALSE ;
  422. Xint configside = 0 ;
  423. X
  424. X
  425. Xstatic char * t_language[] = {
  426. X  "french", "english", "italian", "spanish", "german", "dutch",
  427. X  "czech",  "hungarian","polish", "romanian", "FIDE"
  428. X};
  429. X
  430. Xstatic int in_language = DEFAULT_INPUT_LANGUAGE ;
  431. Xstatic int out_language = DEFAULT_OUTPUT_LANGUAGE ;
  432. X
  433. Xstatic char c_language[NBLANGUAGES][7] = {
  434. X/* french    */  { '@' ,'R' , 'D' , 'T' , 'F' , 'C' , 'P' },
  435. X/* english   */  { '@' ,'K' , 'Q' , 'R' , 'B' , 'N' , 'P' },
  436. X/* italian   */  { '@' ,'R' , 'D' , 'T' , 'A' , 'C' , 'P' },
  437. X/* spanish   */  { '@' ,'R' , 'D' , 'T' , 'A' , 'C' , 'P' },
  438. X/* german    */  { '@' ,'K' , 'D' , 'T' , 'L' , 'S' , 'B' },
  439. X/* dutch     */  { '@' ,'K' , 'D' , 'T' , 'L' , 'P' , 'O' },
  440. X/* czech     */  { '@' ,'K' , 'D' , 'V' , 'S' , 'J' , 'P' },
  441. X/* hungarian */  { '@' ,'K' , 'V' , 'B' , 'F' , 'H' , 'G' },
  442. X/* polish    */  { '@' ,'K' , 'H' , 'W' , 'G' , 'S' , 'P' },
  443. X/* romanian  */  { '@' ,'R' , 'D' , 'T' , 'N' , 'C' , 'P' },
  444. X/* FIDE      */  { '@' ,'K' , 'D' , 'T' , 'S' , 'N' , 'P' }
  445. X/* UNIMPLEMENTED ... */
  446. X/* user_def  *//*{ '@' ,'X' , 'X' , 'X' , 'X' , 'X' , 'X' }*/
  447. X/* russian not implemented : ASCII russian is an oxymoron */
  448. X/* russian   *//*{ '@' ,'K' , 'F' , 'D' , 'C' , 'K' , 'P' }*/
  449. X           };
  450. X
  451. X/* input translation table */
  452. Xchar *in_table;
  453. X
  454. Xchar *  c_roque[] = { "O-O" , "O-O-O" , "o-o" , "o-o-o" , "0-0" , "0-0-0" };
  455. X
  456. X/* various notations for en passant */
  457. X#define N_EP 2
  458. Xchar * c_en_passant[] = { "ep" , "e.p." } ;
  459. X
  460. X
  461. X/* notation for catch */
  462. Xchar c_prise ='x';
  463. X
  464. X/* various comments */
  465. Xchar * c_comments[] = { "+" , "++" , 
  466. X              "?" , "??", "!", "!!", "!?", "?!",
  467. X              "mate", "draw" };
  468. X
  469. X/* movement tables */
  470. X/* move only */
  471. X/* white pawn, move */
  472. X#define NB_M_PAWN_MOVE_WD 2
  473. Xstatic int m_pawn_move_wd [][2] = {
  474. X  { 1, 0}, {2, 0}
  475. X};
  476. X
  477. X/* black pawn, move */
  478. X#define NB_M_PAWN_MOVE_BD 2
  479. Xstatic int m_pawn_move_bd [][2] = {
  480. X  {-1, 0}, {-2, 0}
  481. X};
  482. X
  483. X/* TRICK = we have added the catching move at the end of
  484. X   the non catching ones; so in check_depl, we try first 
  485. X   the non catching one and then the catching one.
  486. X   So, even if catching (x) is non indicated in the input, 
  487. X   we succeed in guessing the move
  488. X   */
  489. X/* white pawn, move */
  490. X/*#define NB_M_PAWN_WD 2*/
  491. X#define NB_M_PAWN_WD 4
  492. Xstatic int m_pawn_wd [][2] = {
  493. X  { 1, 0}, {2, 0},
  494. X/* catch... */
  495. X  { 1, 1}, { 1,-1}
  496. X};
  497. X
  498. X/* white pawn, catch */
  499. X#define NB_M_PAWN_WX 2
  500. Xstatic int m_pawn_wx [][2] = {
  501. X  { 1, 1}, { 1,-1}
  502. X};
  503. X
  504. X/* black pawn, move */
  505. X/*#define NB_M_PAWN_BD 2*/
  506. X#define NB_M_PAWN_BD 4
  507. Xstatic int m_pawn_bd [][2] = {
  508. X  {-1, 0}, {-2, 0},
  509. X/* catch... */
  510. X  {-1, 1}, {-1,-1} 
  511. X};
  512. X
  513. X/* black pawn, catch */
  514. X#define NB_M_PAWN_BX 2
  515. Xstatic int m_pawn_bx [][2] = {
  516. X  {-1, 1}, {-1,-1} 
  517. X};
  518. X
  519. X
  520. X#define NB_M_KNIGHT  8
  521. Xstatic int m_knight[][2] = { 
  522. X  { 2, 1}, { 2,-1}, {-2, 1}, {-2,-1},
  523. X  { 1, 2}, { 1,-2}, {-1, 2}, {-1,-2}
  524. X};
  525. X
  526. X#define NB_M_BISHOP 28
  527. Xstatic int m_bishop[][2] = {
  528. X  { 7, 7},  {6, 6}, { 5, 5}, { 4, 4}, { 3, 3}, { 2, 2}, { 1, 1},
  529. X  { 7,-7}, { 6,-6}, { 5,-5}, { 4,-4}, { 3,-3}, { 2,-2}, { 1,-1},
  530. X  {-7,-7}, {-6,-6}, {-5,-5}, {-4,-4}, {-3,-3}, {-2,-2}, {-1,-1},
  531. X  {-7, 7}, {-6, 6}, {-5, 5}, {-4, 4}, {-3, 3}, {-2, 2}, {-1, 1}
  532. X};
  533. X
  534. X#define NB_M_ROOK 28
  535. Xstatic int m_rook[][2] = {
  536. X  { 7, 0}, { 6, 0}, { 5, 0}, { 4, 0}, { 3, 0}, { 2, 0}, { 1, 0},
  537. X  {-7, 0}, {-6, 0}, {-5, 0}, {-4, 0}, {-3, 0}, {-2, 0}, {-1, 0},
  538. X  { 0, 7}, { 0, 6}, { 0, 5}, { 0, 4}, { 0, 3}, { 0, 2}, { 0, 1},
  539. X  { 0,-7}, { 0,-6}, { 0,-5}, { 0,-4}, { 0,-3}, { 0,-2}, { 0,-1}
  540. X};
  541. X
  542. X#define NB_M_QUEEN 56
  543. Xstatic int m_queen[][2] = {
  544. X  { 7, 7},  {6, 6}, { 5, 5}, { 4, 4}, { 3, 3}, { 2, 2}, { 1, 1},
  545. X  { 7,-7}, { 6,-6}, { 5,-5}, { 4,-4}, { 3,-3}, { 2,-2}, { 1,-1},
  546. X  {-7,-7}, {-6,-6}, {-5,-5}, {-4,-4}, {-3,-3}, {-2,-2}, {-1,-1},
  547. X  {-7, 7}, {-6, 6}, {-5, 5}, {-4, 4}, {-3, 3}, {-2, 2}, {-1, 1},
  548. X  { 7, 0}, { 6, 0}, { 5, 0}, { 4, 0}, { 3, 0}, { 2, 0}, { 1, 0},
  549. X  {-7, 0}, {-6, 0}, {-5, 0}, {-4, 0}, {-3, 0}, {-2, 0}, {-1, 0},
  550. X  { 0, 7}, { 0, 6}, { 0, 5}, { 0, 4}, { 0, 3}, { 0, 2}, { 0, 1},
  551. X  { 0,-7}, { 0,-6}, { 0,-5}, { 0,-4}, { 0,-3}, { 0,-2}, { 0,-1}
  552. X};
  553. X
  554. X#define NB_M_KING 8
  555. Xstatic int m_king[][2] = {
  556. X  { 1, 1}, { 1, 0}, { 1,-1},
  557. X  {-1, 1}, {-1, 0}, {-1,-1},
  558. X  { 0, 1}, { 0, -1}
  559. X};
  560. X
  561. X
  562. X/* I/O */
  563. XFILE * infile ;
  564. XFILE * fhelp;
  565. X
  566. Xstatic char * t_output[] = 
  567. X{ "ascii", "postscript", "tex", "roff", "xchess", "gnu" };
  568. X
  569. X/* stack -- used for variation */
  570. X
  571. X/* stack element */
  572. Xtypedef struct {
  573. X  depl * d;
  574. X  game * b;
  575. X  
  576. X  /* we don't stack drivers, but only to variables */
  577. X  int d1,d2; /* iswhiteturn and interrupt */
  578. X} stack_elt ;
  579. X
  580. X/* size of the stack
  581. X   0 = ordinary play
  582. X   1 = level 1 variation
  583. X   2 = level 2 variation
  584. X   3 = level 3 variation
  585. X*/
  586. X#define VARIATION_MAX 3
  587. X
  588. X/* the stack itself */
  589. Xstatic stack_elt stack[VARIATION_MAX];
  590. X
  591. X/* top of the stack */
  592. X/* --> explicit in dr->variation */
  593. X
  594. X
  595. X/* ---------- automata definitions --------- */
  596. X/* table for syntaxic analysis of move */
  597. X
  598. X#define FINAL    10
  599. X#define TML     FINAL   /* terminal state */
  600. X#define NBETAT     11
  601. X#define NBCLAS     8
  602. X
  603. X/* successor of state */
  604. Xstatic int transit[NBETAT][NBCLAS] = { 
  605. X/*   P a-h 1-8   -   x   =  \0   ? */ 
  606. X/*(  0   1   2   3   4   5   6   7)*/
  607. X  {  1,  2, -1, -1, -1, -1, -1, -1 }, /* etat  0 */
  608. X  { -1,  2, -1, -1,  4, -1, -1, -1 }, /* etat  1 */
  609. X  { -1,  6,  3,  4,  4,  8,TML,TML }, /* etat  2 */
  610. X  { -1,  6, -1,  4,  4,  8,TML,TML }, /* etat  3 */
  611. X  {  5,  6, -1, -1, -1, -1, -1, -1 }, /* etat  4 */
  612. X  { -1,  6, -1, -1, -1, -1, -1, -1 }, /* etat  5 */
  613. X  { -1, -1,  7, -1, -1, -1, -1, -1 }, /* etat  6 */
  614. X  { -1, -1, -1, -1, -1,  8,TML,TML }, /* etat  7 */
  615. X  {  9, -1, -1, -1, -1, -1,TML, -1 }, /* etat  8 */
  616. X  { -1, -1, -1, -1, -1, -1,TML,TML }, /* etat  9 */
  617. X  { -1, -1, -1, -1, -1, -1, -1, -1 }  /* etat 10 == terminal */
  618. X};
  619. X
  620. X/* actions to do */
  621. Xstatic int action[NBETAT][NBCLAS] = {
  622. X/*   P a-h 1-8   -   x   =  \0   ? */ 
  623. X  {  1,  2, -1, -1, -1, -1, -1, -1 }, /* etat  0 */
  624. X  { -1,  2, -1, -1, 10, -1, -1, -1 }, /* etat  1 */
  625. X  { -1, 13,  3,  4,  5, 14,  6,  7 }, /* etat  2 */
  626. X  { -1, 13, -1,  4,  5, 14,  6,  7 }, /* etat  3 */
  627. X  {  1,  2, -1, -1, -1, -1, -1, -1 }, /* etat  4 */
  628. X  { -1,  2, -1, -1, -1, -1, -1, -1 }, /* etat  5 */
  629. X  { -1, -1,  3, -1, -1, -1, -1, -1 }, /* etat  6 */
  630. X  { -1, -1, -1, -1, -1, 14,  8,  9 }, /* etat  7 */
  631. X  { 15, -1, -1, -1, -1, -1, 17, -1 }, /* etat  8 */
  632. X  { -1, -1, -1, -1, -1, -1, 17, 17 }, /* etat  9 */
  633. X  { -1, -1, -1, -1, -1, -1, -1, -1 }  /* etat 10 */
  634. X};
  635. X
  636. X
  637. X/* the complete play */
  638. Xplay * theplay ;
  639. X
  640. X/* current game
  641. X   the name "tos" means "top of stack"
  642. X   */
  643. Xstatic game * tos = GULL ;
  644. X
  645. X/* variable holding current move */
  646. Xstatic depl * m = MULL ;
  647. X
  648. X
  649. Xint alternate_moves[10][2]; /* table of alternate moves, guessed by
  650. X                   the "move generator": guess depl
  651. X                   */
  652. X
  653. X
  654. X/* the output driver */
  655. Xstatic format * dr;
  656. X
  657. Xstatic int driver; /* driver type, ie gnu, ascii ... */
  658. X
  659. Xstatic int movecount;
  660. X
  661. X/* current move, used by the parser */
  662. Xstatic int curpiece,  curcol,  curlig ;
  663. Xstatic int curdigit, curmove;
  664. X
  665. X/* booleen d'erreur */
  666. Xint error_flag = FALSE;
  667. X
  668. X/* move to display board */
  669. Xstatic int count = 0 ;
  670. X
  671. Xstatic int move_to_display[NB_MOVE_TO_DISP] ;
  672. Xstatic int nb_move_to_dsp = 0;
  673. Xstatic int stop_at_display = FALSE;
  674. X
  675. X/* short and long form comment table */
  676. Xchar * com_short[] = {
  677. X#define CHESSSYMB(LET,LASC,SASC,TEX,PS,ENG,FRA) SASC,
  678. X#include "chesssymb.def"
  679. X ""
  680. X };
  681. X#undef CHESSSYMB
  682. X
  683. Xchar * com_long[] = {
  684. X#define CHESSSYMB(LET,LASC,SASC,TEX,PS,ENG,FRA) LASC,
  685. X#include "chesssymb.def"
  686. X ""
  687. X };
  688. X#undef CHESSSYMB
  689. X
  690. X
  691. X
  692. X#define setboard(A,I,J,P,C)  { (A)->board[(I)][(J)] = (P) ; \
  693. X                 (A)->color[(I)][(J)] = (C); }
  694. X#define clsboard(A,I,J)   { (A)->board[(I)][(J)] = VOID ; \
  695. X                (A)->color[(I)][(J)] = VOID ;}
  696. X
  697. X/* --------------------------- code part --------------------- */
  698. X
  699. X
  700. X#ifdef __STDC__
  701. Xstatic int ispiece(char c)
  702. X#else
  703. Xstatic int ispiece(c)
  704. X     char c;
  705. X#endif
  706. X{
  707. X  register int i;
  708. X  
  709. X  for ( i = 0 ; (i < NUMPIECES) && (c != in_table[i]) ; i++ ) ;
  710. X  /*(void) fprintf(stdout, "piece %d %c\n" , i , c);*/
  711. X  return(i<NUMPIECES);
  712. X}
  713. X
  714. X
  715. X#ifdef __STDC__
  716. Xstatic int piece(char c)
  717. X#else
  718. Xstatic int piece(c)
  719. X     char c ;
  720. X#endif
  721. X{
  722. X  register int i;
  723. X  
  724. X  for ( i = 0 ; (i < NUMPIECES) && (c != in_table[i]) ; i++ ) ;
  725. X  if ( i== NUMPIECES)
  726. X    i = PAWN ;
  727. X  return(i);
  728. X}
  729. X
  730. X/* this function returns the rank of a keyword in a given table.
  731. X   if key is not present, it returns the default value
  732. X   */
  733. X#ifdef __STDC__
  734. Xstatic int find_keyword(char *tab[], int nbentry,int defaut,
  735. X            char *key,int warning)
  736. X#else
  737. Xstatic int find_keyword(tab, nbentry,defaut,key,warning)
  738. X     char * tab[]; /* the table to look in */
  739. X     int nbentry;  /* number of entries */
  740. X     int defaut;  /* the default value to return if search failed */
  741. X     char *key;    /* the key to find */
  742. X     int warning;  /* do we display a warning ? */
  743. X#endif
  744. X{
  745. X  int i ;
  746. X
  747. X  for(i=0; (i< nbentry) ;i++)
  748. X    if (strcmp(tab[i],key)==0)
  749. X      return(i);
  750. X
  751. X  /* we failed to find the keyword */
  752. X  if (warning)
  753. X    (void) fprintf (stderr, "unknow keyword %s in this context\n",key);
  754. X  return(defaut);
  755. X}
  756. X
  757. X/* ---------- board management function ------------- */
  758. X
  759. X#ifdef __STDC__
  760. Xvoid clear_board(game *g)
  761. X#else
  762. Xvoid clear_board(g)
  763. X     game *g;
  764. X#endif
  765. X{
  766. X  register int i,j;
  767. X
  768. X  for (i=0; i < 10; i++ )
  769. X    for (j=0 ; j< 10 ; j++) {
  770. X      g->board[i][j] = VOID;
  771. X      g->color[i][j] = VOID;
  772. X    }
  773. X}
  774. X
  775. X#ifdef __STDC__
  776. Xgame * new_board(void)
  777. X#else
  778. Xgame * new_board()
  779. X#endif
  780. X{
  781. X  game * tmp;
  782. X  int i; 
  783. X
  784. X  tmp = (game *) malloc (sizeof(game));
  785. X  ALLOCP(tmp);
  786. X  for (i=0; i < ((sizeof (game))/ sizeof (int)) ; i++)
  787. X    ((int *) tmp)[i] = 0;
  788. X  return(tmp);
  789. X}
  790. X
  791. X#ifdef __STDC__
  792. Xgame * copy_board(game *from, game *to)
  793. X#else
  794. Xgame * copy_board(from, to)
  795. X     game * from;
  796. X     game * to;
  797. X#endif
  798. X{
  799. X  int i; 
  800. X
  801. X  for (i=0; i < ((sizeof (game))/ sizeof (int)) ; i++)
  802. X    ((int *) to)[i] =  ((int *) from)[i] ;
  803. X  return(to);
  804. X}
  805. X
  806. X#ifdef __STDC__
  807. Xvoid init_board(game *tgm)
  808. X#else
  809. Xvoid init_board(tgm)
  810. X  game * tgm;
  811. X#endif
  812. X{
  813. X  register int i,j;
  814. X
  815. X  clear_board(tgm);
  816. X
  817. X  for (i=1; i< 9 ; i=i+7) {
  818. X    tgm->board[i][1]= tgm->board[i][8] = ROOK ;
  819. X    tgm->board[i][2]= tgm->board[i][7] = KNIGHT ;
  820. X    tgm->board[i][3]= tgm->board[i][6] = BISHOP ;
  821. X    tgm->board[i][4]= QUEEN;
  822. X    tgm->board[i][5]= KING;
  823. X  }
  824. X  for (i=2; i< 8 ; i=i+5) 
  825. X    for (j=1; j <=8 ; j++)
  826. X      tgm->board[i][j] = PAWN;
  827. X
  828. X  for (i=1; i <=2; i++)
  829. X    for (j=1; j <=8 ; j++) {
  830. X      tgm->color[i][j] = WHITE;
  831. X      tgm->color[i+6][j] = BLACK ;
  832. X    }
  833. X}
  834. X
  835. X#ifdef __STDC__
  836. Xdepl * new_move(void)
  837. X#else
  838. Xdepl * new_move()
  839. X#endif
  840. X{
  841. X  depl * tmp;
  842. X  int i; 
  843. X  static int counter = 0;
  844. X
  845. X  tmp = (depl *) malloc (sizeof(depl));
  846. X  ALLOCP(tmp);
  847. X  for (i=0; i < ((sizeof (depl))/ sizeof (int)) ; i++)
  848. X    ((int *) tmp)[i] = 0;
  849. X  tmp->uid = ++counter;
  850. X  tmp->whiteturn = FALSE;
  851. X  tmp->move = 0;
  852. X  return(tmp);
  853. X}
  854. X
  855. X
  856. X#ifdef __STDC__
  857. Xvoid init_move(depl *m)
  858. X#else
  859. Xvoid init_move(m)
  860. X     depl *m;
  861. X#endif
  862. X{
  863. X  m->move= 1 ;
  864. X  m->whiteturn = TRUE ;
  865. X}
  866. X
  867. X#ifdef __STDC__
  868. Xdepl * copy_move(depl *from,depl *to)
  869. X#else
  870. Xdepl * copy_move(from,to)
  871. X     depl * from;
  872. X     depl * to ;
  873. X#endif
  874. X{
  875. X  int i; 
  876. X
  877. X  for (i=0; i < ((sizeof (depl))/ sizeof (int)) ; i++)
  878. X    ((int *) to)[i] = ((int *) from)[i];
  879. X
  880. X  return(to);
  881. X}
  882. X
  883. X/* add a new move as successor to the move m */
  884. X#ifdef __STDC__
  885. Xdepl * add_trailing_move(depl *mo)
  886. X#else
  887. Xdepl * add_trailing_move(mo)
  888. X     depl * mo;
  889. X#endif
  890. X{
  891. X  mo->next = new_move();
  892. X
  893. X  mo->next->prev = mo;
  894. X  mo->next->next = (depl *) NULL;
  895. X  mo->next->sub  = (depl *) NULL;
  896. X
  897. X  mo->next->whiteturn = !( m->whiteturn ) ;
  898. X  mo->next->move = mo->move;
  899. X  if ( mo->next->whiteturn) {
  900. X    mo->next->move++;
  901. X  }
  902. X
  903. X  return(mo->next);
  904. X}
  905. X
  906. X#ifdef __STDC__
  907. Xstatic depl * add_variation(depl *mo)
  908. X#else
  909. Xstatic depl * add_variation(mo)
  910. X     depl * mo;
  911. X#endif
  912. X{
  913. X  depl *ip ; /* insertion point */
  914. X
  915. X  ip = mo ;
  916. X  while (ip->sub != (depl *) NULL )
  917. X    ip = ip->sub ;
  918. X  
  919. X  ip->sub = new_move();
  920. X
  921. X  ip->sub->prev = mo;
  922. X  ip->sub->next = (depl *) NULL;
  923. X  ip->sub->sub  = (depl *) NULL;
  924. X  
  925. X  /* as we have a fictif element heading our list, 
  926. X     ( generated by add_trailing_move() )
  927. X     we have to go back in the numbering */
  928. X  ip->sub->whiteturn =  mo->prev->whiteturn  ;
  929. X  ip->sub->move = mo->prev->move ;
  930. X
  931. X  return(ip->sub);
  932. X}
  933. X
  934. X
  935. X#ifdef __STDC__
  936. Xstatic void free_move_list(depl *d)
  937. X#else
  938. Xstatic void free_move_list(d)
  939. X     depl * d;
  940. X#endif
  941. X{  
  942. X
  943. X  if (d->next != (depl *) NULL) {
  944. X    free_move_list(d->next);
  945. X    free(d->next);
  946. X    d->next = (depl *) NULL;
  947. X  }
  948. X  if (d->sub != (depl *) NULL) {
  949. X    free_move_list(d->sub);
  950. X    free(d->sub);
  951. X    d->sub = (depl *) NULL;
  952. X  }
  953. X}
  954. X  
  955. X/* procedure upadate borad g with move m */
  956. X#ifdef __STDC__
  957. Xvoid do_move(game *g,depl *m)
  958. X#else
  959. Xvoid do_move(g,m)
  960. X     game *g;
  961. X     depl *m;
  962. X#endif
  963. X{
  964. X  switch (m->type) {
  965. X  case MOVE:
  966. X    setboard(g,m->tolig,m->tocol,m->piece,CURCOLOR(m)) ;
  967. X    clsboard(g,m->fromlig,m->fromcol) ;
  968. X    break;
  969. X  case PRISE:
  970. X    setboard(g,m->tolig,m->tocol,m->piece,CURCOLOR(m)) ;
  971. X    clsboard(g,m->fromlig,m->fromcol);
  972. X    break;
  973. X  case GRANDROQUE:
  974. X    if (m->whiteturn)
  975. X      m->fromlig = 1;
  976. X    else 
  977. X      m->fromlig = 8;
  978. X    setboard(g,m->fromlig,3,KING,CURCOLOR(m)) ;
  979. X    setboard(g,m->fromlig,4,ROOK,CURCOLOR(m)) ;
  980. X    clsboard(g,m->fromlig,1) ;
  981. X    clsboard(g,m->fromlig,5) ;
  982. X    break;
  983. X  case PETITROQUE:
  984. X    if (m->whiteturn)
  985. X      m->fromlig = 1;
  986. X    else 
  987. X      m->fromlig = 8;
  988. X    setboard(g,m->fromlig,7,KING,CURCOLOR(m)) ;
  989. X    setboard(g,m->fromlig,6,ROOK,CURCOLOR(m)) ;
  990. X    clsboard(g,m->fromlig,5) ;
  991. X    clsboard(g,m->fromlig,8) ;
  992. X    break;
  993. X  case EN_PASSANT:
  994. X    setboard(g,m->tolig,m->tocol,m->piece,CURCOLOR(m)) ;
  995. X    clsboard(g,m->tolig,m->fromcol) ;
  996. X    clsboard(g,m->fromlig,m->fromcol) ;
  997. X    break;
  998. X  case PROMOTION:
  999. X    setboard(g,m->tolig,m->tocol,m->piece,CURCOLOR(m)) ;
  1000. X    clsboard(g,m->fromlig,m->fromcol);
  1001. X    break;
  1002. X  case PROM_ET_PRISE:
  1003. X    setboard(g,m->tolig,m->tocol,m->piece,CURCOLOR(m)) ;
  1004. X    clsboard(g,m->fromlig,m->fromcol);
  1005. X    break;
  1006. X  default:
  1007. X    fprintf(stderr,"\nUnable to do move: unknown move type\n");
  1008. X    break;
  1009. X  }
  1010. X}
  1011. X
  1012. X
  1013. X
  1014. X/* this procedure undo the effect of move m on the board g */
  1015. X#ifdef __STDC__
  1016. Xvoid undo_move(game *g,depl *m)
  1017. X#else
  1018. Xvoid undo_move(g,m)
  1019. X     game *g;
  1020. X     depl *m;
  1021. X#endif
  1022. X{
  1023. X  switch (m->type) {
  1024. X  case MOVE:
  1025. X    clsboard(g,m->tolig,m->tocol) ;
  1026. X    setboard(g,m->fromlig,m->fromcol,m->piece,CURCOLOR(m)) ;
  1027. X    break;
  1028. X  case PRISE:
  1029. X    setboard(g,m->tolig,m->tocol,m->prise,OPPCOLOR(m)) ;
  1030. X    setboard(g,m->fromlig,m->fromcol,m->piece,CURCOLOR(m)) ;
  1031. X    break;
  1032. X  case GRANDROQUE:
  1033. X    if (m->whiteturn)
  1034. X      m->fromlig = 1;
  1035. X    else 
  1036. X      m->fromlig = 8;
  1037. X    clsboard(g,m->fromlig,3) ;
  1038. X    clsboard(g,m->fromlig,4) ;
  1039. X    setboard(g,m->fromlig,5,KING,CURCOLOR(m)) ;
  1040. X    setboard(g,m->fromlig,1,ROOK,CURCOLOR(m)) ;
  1041. X    break;
  1042. X  case PETITROQUE:
  1043. X    if (m->whiteturn)
  1044. X      m->fromlig = 1;
  1045. X    else 
  1046. X      m->fromlig = 8;
  1047. X    clsboard(g,m->fromlig,6) ;
  1048. X    clsboard(g,m->fromlig,7) ;
  1049. X    setboard(g,m->fromlig,5,KING,CURCOLOR(m)) ;
  1050. X    setboard(g,m->fromlig,8,ROOK,CURCOLOR(m)) ;
  1051. X    break;
  1052. X  case EN_PASSANT:
  1053. X    clsboard(g,m->tolig,m->tocol) ;
  1054. X    setboard(g,m->tolig,m->fromcol,PAWN,OPPCOLOR(m)) ;
  1055. X    setboard(g,m->fromlig,m->fromcol,m->piece,CURCOLOR(m)) ;
  1056. X    break;
  1057. X  case PROMOTION:
  1058. X    clsboard(g,m->tolig,m->tocol);
  1059. X    setboard(g,m->fromlig,m->fromcol,PAWN,CURCOLOR(m)) ;
  1060. X    break;
  1061. X  case PROM_ET_PRISE:
  1062. X    setboard(g,m->tolig,m->tocol,m->prise,OPPCOLOR(m)) ;
  1063. X    setboard(g,m->fromlig,m->fromcol,PAWN,CURCOLOR(m)) ;
  1064. X    break;
  1065. X  default:
  1066. X    fprintf(stderr,"\nUnable to undo move: unknown move type\n");
  1067. X    break;
  1068. X  }
  1069. X}
  1070. X
  1071. X/* variation procedures == stack manipulation */
  1072. X
  1073. X#ifdef __STDC__
  1074. Xvoid enter_variation(void)
  1075. X#else
  1076. Xvoid enter_variation()
  1077. X#endif
  1078. X{
  1079. X  int l;
  1080. X
  1081. X  l = dr->variation ;
  1082. X  
  1083. X  if (l >= VARIATION_MAX) {
  1084. X    error((stderr,"\nMaximum imbricated variation is %d\n",VARIATION_MAX));
  1085. X  } else {
  1086. X    /* save current line/variation */
  1087. X    stack[l].d = m;
  1088. X    stack[l].b = tos;
  1089. X    stack[l].d1 = dr->iswhiteturn;
  1090. X    stack[l].d2 = dr->interrupt = TRUE ;    
  1091. X    /* create new */
  1092. X    tos = new_board();
  1093. X    (void) copy_board(stack[l].b, tos);
  1094. X
  1095. X    /* A variation FOLLOWS the main line 
  1096. X       so we need to backtrack one move
  1097. X       */
  1098. X    m = add_variation(stack[l].d);
  1099. X    undo_move(tos,stack[l].d);
  1100. X
  1101. X    /* set variables */
  1102. X    l++;
  1103. X    dr->variation = l;
  1104. X
  1105. X    output_variation(dr,VARIATION_IN);
  1106. X  }
  1107. X}
  1108. X
  1109. X#ifdef __STDC__
  1110. Xvoid exit_variation(void)
  1111. X#else
  1112. Xvoid exit_variation()
  1113. X#endif
  1114. X{
  1115. X  int l ;
  1116. X
  1117. X  l = dr->variation ;
  1118. X  
  1119. X  if (l == 0) {
  1120. X    error((stderr,"\nYou cannot exit from the main line (a variation level error?)\n"));
  1121. X  } else {
  1122. X    output_variation(dr,VARIATION_OUT);
  1123. X
  1124. X    l--;
  1125. X    free(tos);
  1126. X    free(m);
  1127. X    m = stack[l].d ;
  1128. X    tos = stack[l].b ;
  1129. X
  1130. X    dr->iswhiteturn = stack[l].d1 ;
  1131. X    dr->interrupt = stack[l].d2 ;
  1132. X    dr->variation = l;
  1133. X  }
  1134. X}
  1135. X
  1136. X/* ----------- semantic evaluation of move ----------- */
  1137. X/* check if  position lies within the board
  1138. X   */
  1139. X#ifdef __STDC__
  1140. Xint in_board(int l,int c)
  1141. X#else
  1142. Xint in_board(l,c)
  1143. X     int l,c;
  1144. X#endif
  1145. X{
  1146. X  return ((c >= 1) && (c <= 8) && (l >= 1) && (l <= 8));
  1147. X}
  1148. X
  1149. X/* check that the path from pos1 to pos2 is free
  1150. X   */
  1151. X#ifdef __STDC__
  1152. Xint path_free(int l1,int c1,int l2,int c2)
  1153. X#else
  1154. Xint path_free(l1, c1, l2, c2)
  1155. Xint l1,c1, l2, c2;
  1156. X#endif
  1157. X{
  1158. X  int li = 1 ;
  1159. X  int ci = 1 ;
  1160. X  int lig, col;
  1161. X
  1162. X
  1163. X  li = SIGN(l2-l1);
  1164. X  ci = SIGN(c2-c1);
  1165. X
  1166. X
  1167. X  if ( c1 == c2 ) {    
  1168. X    col = c1;
  1169. X    for (lig = l1 +li; lig != l2 ; lig +=li)
  1170. X      if (tos->board[lig][col] != VOID)
  1171. X    return (FALSE);
  1172. X    return(TRUE);
  1173. X  }
  1174. X
  1175. X  if ( l1 == l2) {
  1176. X    lig = l1 ;
  1177. X    for (col = c1 + ci; col != c2 ; col +=ci)
  1178. X      if (tos->board[lig][col] != VOID)
  1179. X    return (FALSE);
  1180. X    return(TRUE);
  1181. X  }
  1182. X
  1183. X  for (lig = l1+li,col =c1+ci; (lig!=l2) && (col!=c2); lig+=li, col+= ci)
  1184. X    if (tos->board[lig][col] != VOID) {
  1185. X      return (FALSE);
  1186. X    }
  1187. X  return(TRUE);
  1188. X}
  1189. X
  1190. X/* check roque is possible */
  1191. X#ifdef __STDC__
  1192. Xint check_roque(void)
  1193. X#else
  1194. Xint check_roque()
  1195. X#endif
  1196. X{
  1197. X  int lig, col ;
  1198. X
  1199. X  if (m->whiteturn)
  1200. X    lig = 1 ;
  1201. X  else
  1202. X    lig =8;
  1203. X  if (m->type == GRANDROQUE)
  1204. X    for (col = 2; col < 5 ; col++)
  1205. X      if (tos->board[lig][col] != VOID)
  1206. X    return(FALSE);
  1207. X  if (m->type == PETITROQUE)
  1208. X    for (col = 6; col < 7 ; col++)
  1209. X      if (tos->board[lig][col] != VOID)
  1210. X    return(FALSE);
  1211. X  return(TRUE);
  1212. X}
  1213. X  
  1214. X/* check -- or guess -- where a given piece come */
  1215. X#ifdef __STDC__
  1216. Xint guess_piece(void) 
  1217. X#else
  1218. Xint guess_piece() 
  1219. X#endif
  1220. X{
  1221. X  return(tos->board[m->fromlig][m->fromcol]); 
  1222. X}
  1223. X
  1224. X/* try to guess the move -- low-level function 
  1225. X   it returns -- in the parms -- the coordinates of a possible move
  1226. X   it returns -- as value -- the number of possible move
  1227. X */
  1228. X#ifdef __STDC__
  1229. Xint guess_depl(int nb, int tab[][2],
  1230. X           int * pl1, int * pc1, int l2, int c2, int path)
  1231. X#else
  1232. Xint guess_depl(nb, tab, pl1, pc1, l2,c2,path)
  1233. X     int nb;
  1234. X     int tab[10][2];
  1235. X     int *pl1, *pc1;
  1236. X     int l2,c2;
  1237. X     int path; /* tell if we have to check for a free path 
  1238. X          used for en passant */
  1239. X#endif
  1240. X{
  1241. X  int i, c, l;
  1242. X  int count = 0;
  1243. X
  1244. X  for (i=0; i< nb; i++ ) {
  1245. X    l = l2 - tab[i][0];
  1246. X    c = c2 - tab[i][1];
  1247. X    if (in_board(l,c))
  1248. X      if ((tos->board[l][c] == m->piece) &&
  1249. X      (tos->color[l][c] == CURCOLOR(m)) &&
  1250. X      ( !path || (path && path_free(l,c, l2, c2))) &&
  1251. X      ( ((*pl1) == 0) || ((*pl1) == l) ) &&
  1252. X      ( ((*pc1) == 0) || ((*pc1) == c) ) )
  1253. X    {
  1254. X      alternate_moves[count][0] = l;
  1255. X      alternate_moves[count][1] = c;
  1256. X      count++;
  1257. X    }
  1258. X  }
  1259. X  alternate_moves[count][0] = alternate_moves[count][1] = 0;
  1260. X  if (count > 0) {
  1261. X    /* we return the first entry because the last entry, in the case of pawn,
  1262. X       movement, might be a catching move, even it a non-catching, more 
  1263. X       probable, is present
  1264. X       */
  1265. X    *pl1 = alternate_moves[0][0];
  1266. X    *pc1 = alternate_moves[0][1];
  1267. X  }
  1268. X  return(count);
  1269. X}
  1270. X
  1271. X/* check for ambiguity in a move
  1272. X   used in output function: the piece had been already moved and
  1273. X   if we guess another move, there is an ambiguity
  1274. X   */
  1275. X#ifdef __STDC__
  1276. Xint ambiguity(depl *d, int *amline, int *amcols)
  1277. X#else
  1278. Xint ambiguity(d, amline, amcols )
  1279. X     depl *d ;
  1280. X     int * amline;
  1281. X     int *amcols;
  1282. X#endif
  1283. X{
  1284. X  int l1 = 0 ;
  1285. X  int c1 = 0 ;
  1286. X  int r = 0;
  1287. X  int frompiece = d->piece;
  1288. X  int l2 = d->tolig;
  1289. X  int c2 = d->tocol ;
  1290. X  int i;
  1291. X
  1292. X  undo_move(tos,m);
  1293. X
  1294. X
  1295. X  switch(frompiece) {
  1296. X  case PAWN:
  1297. X    if (m->type == PRISE) {
  1298. X      if (m->whiteturn)
  1299. X    r = guess_depl(NB_M_PAWN_WX, m_pawn_wx, &l1,&c1, l2,c2, FALSE);
  1300. X      else
  1301. X    r = guess_depl(NB_M_PAWN_BX, m_pawn_bx, &l1,&c1, l2,c2, FALSE);
  1302. X    } else {
  1303. X      if (m->whiteturn)
  1304. X    r = guess_depl(NB_M_PAWN_MOVE_WD,m_pawn_move_wd,&l1,&c1, l2,c2, FALSE);
  1305. X      else
  1306. X    r = guess_depl(NB_M_PAWN_MOVE_BD,m_pawn_move_bd,&l1,&c1,l2,c2, FALSE);
  1307. X    }
  1308. X    break;
  1309. X  case KNIGHT:
  1310. X    r = guess_depl(NB_M_KNIGHT, m_knight, &l1,&c1, l2,c2, FALSE);
  1311. X    break;
  1312. X  case BISHOP:
  1313. X    r = guess_depl(NB_M_BISHOP, m_bishop, &l1,&c1, l2,c2, TRUE);
  1314. X    break;
  1315. X  case ROOK:
  1316. X    r = guess_depl(NB_M_ROOK,   m_rook,   &l1,&c1, l2,c2, TRUE);
  1317. X    break;
  1318. X  case QUEEN:
  1319. X    r = guess_depl(NB_M_QUEEN,  m_queen,  &l1,&c1, l2,c2, TRUE);
  1320. X    break;
  1321. X  case KING:
  1322. X    r = guess_depl(NB_M_KING,   m_king,   &l1,&c1, l2,c2, TRUE);
  1323. X    break;
  1324. X  default:
  1325. X    break;
  1326. X  }
  1327. X  do_move(tos,m);
  1328. X
  1329. X  if (r > 1) {
  1330. X    /* we have an ambiguity, we use alternate_moves to resolve it:
  1331. X       we look through that table to find identical lines: if so, 
  1332. X       we signal that the column determines move; 
  1333. X       we then do the same with columns
  1334. X       */
  1335. X    *amline = TRUE ;
  1336. X    *amcols = TRUE ;
  1337. X    for (i= 1; i < r ; i++) {
  1338. X      if (alternate_moves[i][0] != alternate_moves[0][0])
  1339. X    *amline = FALSE;
  1340. X      if (alternate_moves[i][1] != alternate_moves[0][1])
  1341. X    *amcols = FALSE;
  1342. X    }
  1343. X  }
  1344. X  return( (r > 1) );
  1345. X}
  1346. X
  1347. X#ifdef __STDC__
  1348. Xint check_move(depl *m)
  1349. X#else
  1350. Xint check_move(m)
  1351. X     depl * m;
  1352. X#endif
  1353. X{
  1354. X  int l1,c1,l2,c2;
  1355. X  int tmp; /* tmp boolean */
  1356. X  l1 = m->fromlig;
  1357. X  c1 = m->fromcol;
  1358. X  l2 = m->tolig;
  1359. X  c2 = m->tocol;
  1360. X
  1361. X  if ((m->type == GRANDROQUE) || (m->type == PETITROQUE))
  1362. X    return(check_roque());
  1363. X
  1364. X  if ((tos->board[l1][c1] != m->piece)||
  1365. X      (tos->color[l1][c1] != CURCOLOR(m))){
  1366. X    fprintf(stderr,"Problem: piece should be %c\n",in_table[tos->board[l1][c1]]);
  1367. X    if (m->whiteturn)
  1368. X      error ((stderr,"\nOriginating position and piece not coherent for White move %d\n",m->move));
  1369. X    else
  1370. X      error ((stderr,"\nOriginating position and piece not coherent for Black move %d\n",m->move));
  1371. X    return(FALSE);
  1372. X  }
  1373. X
  1374. X  /* if prise === FALSE, we must not take a piece */
  1375. X  if (tos->board[l2][c2] != VOID 
  1376. X      && (m->type != PRISE) && (m->type != PROM_ET_PRISE)) {
  1377. X    (void) fprintf(stderr,"catching not indicated at move %d.\n",m->move);
  1378. X    return(FALSE);
  1379. X  }
  1380. X
  1381. X  /* prendre une de ses propres pieces */
  1382. X  if (tos->color[l2][c2] == tos->color[l1][c1] && m->prise) {
  1383. X    (void) fprintf(stderr,"attempt to catch same color piece at move %d.\n",
  1384. X           m->move);
  1385. X    return(FALSE);
  1386. X  }
  1387. X
  1388. X  /* we check if the move is a possible one for the piece
  1389. X     */
  1390. X
  1391. X  switch(m->piece) {
  1392. X  case PAWN:
  1393. X    if (m->prise) {
  1394. X      if (m->whiteturn)
  1395. X    tmp = guess_depl(NB_M_PAWN_WX, m_pawn_wx, &l1,&c1, l2,c2, FALSE);
  1396. X      else
  1397. X    tmp = guess_depl(NB_M_PAWN_BX, m_pawn_bx, &l1,&c1, l2,c2, FALSE);
  1398. X    } else {
  1399. X      if (m->whiteturn)
  1400. X    tmp = guess_depl(NB_M_PAWN_WD, m_pawn_wd, &l1,&c1, l2,c2, FALSE);
  1401. X      else
  1402. X    tmp = guess_depl(NB_M_PAWN_BD, m_pawn_bd, &l1,&c1, l2,c2, FALSE);
  1403. X    }
  1404. X    /* is it a "prise en passant " */
  1405. X    if ((c1 != c2) && (tos->board[l2][c2] == VOID)
  1406. X    && (tos->board[l1][c2] == PAWN)) {
  1407. X      m->type = EN_PASSANT ;
  1408. X      /* we must perform here the "en passant" test */
  1409. X      tos->board[l1][c2] = VOID ;
  1410. X      tos->color[l1][c2] = VOID ;
  1411. X      tmp = TRUE;
  1412. X    }
  1413. X    return(tmp);
  1414. X    break;
  1415. X  case KNIGHT:
  1416. X    return(guess_depl(NB_M_KNIGHT, m_knight, &l1,&c1, l2,c2, FALSE));
  1417. X    break;
  1418. X  case BISHOP:
  1419. X    return(guess_depl(NB_M_BISHOP, m_bishop, &l1,&c1, l2,c2, TRUE));
  1420. X    break;
  1421. X  case ROOK:
  1422. X    return(guess_depl(NB_M_ROOK,   m_rook,   &l1,&c1, l2,c2, TRUE));
  1423. X    break;
  1424. X  case QUEEN:
  1425. X    return(guess_depl(NB_M_QUEEN,  m_queen,  &l1,&c1, l2,c2, TRUE));
  1426. X    break;
  1427. X  case KING:
  1428. X    return(guess_depl(NB_M_KING,   m_king,   &l1,&c1, l2,c2, TRUE));
  1429. X    break;
  1430. X  default:
  1431. X    break;
  1432. X  }
  1433. X
  1434. X  return(TRUE);
  1435. X}
  1436. X
  1437. X/* try to guess the move -- used for shortened notation
  1438. X   */
  1439. X#ifdef __STDC__
  1440. Xint guess_move(void)
  1441. X#else
  1442. Xint guess_move()
  1443. X#endif
  1444. X{
  1445. X  int l1,c1,l2,c2;
  1446. X
  1447. X  if ((m->type == GRANDROQUE) || (m->type == PETITROQUE))
  1448. X    return(TRUE);
  1449. X
  1450. X  l1 = m->fromlig ;
  1451. X  c1 = m->fromcol ;
  1452. X  l2 = m->tolig;
  1453. X  c2 = m->tocol;
  1454. X
  1455. X  switch(m->piece) {
  1456. X  case PAWN:
  1457. X    if (m->prise) {
  1458. X      if (m->whiteturn)
  1459. X    (void) guess_depl(NB_M_PAWN_WX, m_pawn_wx, &l1,&c1, l2,c2, FALSE);
  1460. X      else
  1461. X    (void) guess_depl(NB_M_PAWN_BX, m_pawn_bx, &l1,&c1, l2,c2, FALSE);
  1462. X    } else {
  1463. X      if (m->whiteturn)
  1464. X    (void) guess_depl(NB_M_PAWN_WD, m_pawn_wd, &l1,&c1, l2,c2, FALSE); 
  1465. X      else
  1466. X    (void) guess_depl(NB_M_PAWN_BD, m_pawn_bd, &l1,&c1, l2,c2, FALSE); 
  1467. X    }
  1468. X    break;
  1469. X  case KNIGHT:
  1470. X    (void) guess_depl(NB_M_KNIGHT, m_knight, &l1,&c1, l2,c2, FALSE);
  1471. X    break;
  1472. X  case BISHOP:
  1473. X    (void) guess_depl(NB_M_BISHOP, m_bishop, &l1,&c1, l2,c2, TRUE);
  1474. X    break;
  1475. X  case ROOK:
  1476. X    (void) guess_depl(NB_M_ROOK, m_rook, &l1,&c1, l2,c2, TRUE);
  1477. X    break;
  1478. X  case QUEEN:
  1479. X    (void) guess_depl(NB_M_QUEEN, m_queen, &l1,&c1, l2,c2, TRUE);
  1480. X    break;
  1481. X  case KING:
  1482. X    (void) guess_depl(NB_M_KING, m_king, &l1,&c1, l2,c2, TRUE);
  1483. X    break;
  1484. X  default:
  1485. X    break;
  1486. X  }
  1487. X
  1488. X  if ((l1 == 0) || (c1 == 0)) {
  1489. X    if (m->whiteturn)
  1490. X      error((stderr,"\nUnable to guess white move %d, with piece %c\n",
  1491. X         m->move,in_table[m->piece]));
  1492. X    else
  1493. X      error((stderr,"\nUnable to guess black move %d, with piece %c\n",
  1494. X         m->move,in_table[m->piece]));
  1495. X    return(FALSE);
  1496. X  } else {
  1497. X    m->fromcol = c1;
  1498. X    m->fromlig = l1;
  1499. X    return(TRUE);
  1500. X  }
  1501. X}
  1502. X
  1503. X/* --------------- execution of move ----------------- */
  1504. X
  1505. X/* clear a position */
  1506. X#ifdef __STDC__
  1507. Xint clear_pos(int lig, int col)
  1508. X#else
  1509. Xint clear_pos(lig,col)
  1510. X     int lig;
  1511. X     int col;
  1512. X#endif
  1513. X{
  1514. X  tos->board[lig][col] = VOID ;
  1515. X  tos->color[lig][col] = VOID ;
  1516. X  return(TRUE);
  1517. X}
  1518. X
  1519. X/* configure the board */
  1520. X#ifdef __STDC__
  1521. Xint configure(void)
  1522. X#else
  1523. Xint configure()
  1524. X#endif
  1525. X{
  1526. X  if (configuring) {
  1527. X    if (m->piece == VOID)
  1528. X      m->piece = PAWN ;
  1529. X    tos->board[m->tolig][m->tocol] = m->piece ;
  1530. X    tos->color[m->tolig][m->tocol] = configside ;
  1531. X  }
  1532. X  return(TRUE);
  1533. X}
  1534. X
  1535. X/* execute a move, no checking */
  1536. X#ifdef __STDC__
  1537. Xint execute_move(void)
  1538. X#else
  1539. Xint execute_move()
  1540. X#endif
  1541. X{
  1542. X  register int i;
  1543. X
  1544. X  if (m->piece == VOID )
  1545. X    m->piece = PAWN;
  1546. X
  1547. X  if ((m->fromlig == 0) || (m->fromcol == 0))
  1548. X    (void) guess_move();
  1549. X  
  1550. X  /* supply to the -- maybe -- deficiency of input notation
  1551. X     */
  1552. X  if ((m->fromlig !=0) || (m->fromcol != 0))
  1553. X    m->piece = tos->board[m->fromlig][m->fromcol];
  1554. X
  1555. X  if (tos->board[m->tolig][m->tocol] != VOID) {
  1556. X    m->type = PRISE;
  1557. X    m->prise = tos->board[m->tolig][m->tocol] ;
  1558. X  }
  1559. X
  1560. X  if (!check_move(m)) {
  1561. X    if (m->whiteturn)
  1562. X      error((stderr,"\nWhite move %d illegal\n",m->move));
  1563. X    else
  1564. X      error((stderr,"\nBlack move %d illegal\n",m->move));
  1565. X  }
  1566. X
  1567. X  do_move(tos, m);
  1568. X
  1569. X  output_move(dr,m);
  1570. X
  1571. X  if (error_flag) {
  1572. X    (void) fprintf(dr->outfile, "\nLast position encountered:\n");
  1573. X    output_board(dr,tos);
  1574. X    close_files();
  1575. X    exit(0);
  1576. X  }
  1577. X
  1578. X  /* do we need to display the move ? */
  1579. X  if (nb_move_to_dsp > 0) {
  1580. X    for (i=0; i < nb_move_to_dsp; i++)
  1581. X      if (m->move == (move_to_display[i] ) && !m->whiteturn ) {
  1582. X    output_board(dr,tos);
  1583. X    if (stop_at_display) {
  1584. X      output_end(dr);
  1585. X      close_files();
  1586. X      exit(0);
  1587. X    }
  1588. X      }
  1589. X  }
  1590. X
  1591. X  return(TRUE);
  1592. X}
  1593. X
  1594. X/* ------------------ automata ----------------------- */
  1595. X
  1596. X/* categorise the input for the automata */
  1597. X#ifdef __STDC__
  1598. Xint typechar(char c)
  1599. X#else
  1600. Xint typechar(c)
  1601. X     char c;
  1602. X#endif
  1603. X{
  1604. X  if (ispiece(c))
  1605. X    return(0);
  1606. X  if ((c >=  'a') && ( c <= 'h'))
  1607. X    return(1);
  1608. X  if ((c >=  '1') && ( c <= '8'))
  1609. X    return(2);
  1610. X  if ( c== '-' )
  1611. X    return(3);
  1612. X  if ((c == 'x') || (c == 'X' ))
  1613. X    return(4);
  1614. X  if (c == '=' )
  1615. X    return(5);
  1616. X  if (c == '\0' )
  1617. X    return(6);
  1618. X  return(7);
  1619. X}
  1620. X
  1621. X
  1622. X/* execute the actions decided by the automata */
  1623. X#ifdef __STDC__
  1624. Xint execute(int num,char c)
  1625. X#else
  1626. Xint execute(num,c)
  1627. X     int num;
  1628. X     char c;
  1629. X#endif
  1630. X{
  1631. X  switch (num) {
  1632. X  case 1: /* set cur piece */
  1633. X    curpiece = piece(c);
  1634. X    break;
  1635. X  case 2: /* set cur col */
  1636. X    curcol = lettertocol(c);
  1637. X    break;
  1638. X  case 3: /* set cur lig */
  1639. X    curlig = lettertolig(c);
  1640. X    break;
  1641. X  case 4: /* from = cur ; prise = false */
  1642. X    m->piece = curpiece ;
  1643. X    m->fromcol = curcol ;
  1644. X    m->fromlig = curlig;
  1645. X    /*m->topiece = curpiece;*/
  1646. X    break;
  1647. X  case 5: /* from = cur ; prise = true */
  1648. X    m->piece = curpiece ;
  1649. X    m->fromcol = curcol ;
  1650. X    m->fromlig = curlig;
  1651. X    m->type = PRISE ;
  1652. X    m->prise = curpiece;
  1653. X    break;
  1654. X  case 6: /* to = cur ; guess from */
  1655. X  case 7: /* to = cur ; guess from ; parse remaining token */
  1656. X    m->piece = curpiece ;
  1657. X    m->tocol = curcol;
  1658. X    m->tolig = curlig ;
  1659. X
  1660. X    /*m->topiece = curpiece ; /* ? */
  1661. X
  1662. X    if (configuring)
  1663. X      (void) configure();
  1664. X    else {
  1665. X      (void) execute_move();
  1666. X    }
  1667. X    break;
  1668. X  case 8: /* to = cur */
  1669. X  case 9: /* to = cur */
  1670. X    m->tocol = curcol;
  1671. X    m->tolig = curlig ;
  1672. X
  1673. X    if (configuring)
  1674. X      (void) configure();
  1675. X    else {
  1676. X      (void) execute_move();
  1677. X    }
  1678. X    break;
  1679. X  case 10: /* piece = cur piece ; prise = true */
  1680. X    /* later : guess from position */
  1681. X    m->piece = curpiece ;
  1682. X    m->type = PRISE ;
  1683. X    break;
  1684. X  case 11: /* grand roque */
  1685. X  case 12: /* petit roque */
  1686. X    (void) execute_move();
  1687. X    break;
  1688. X  case 13: /* case of simpliest algebraic notation ;
  1689. X          only e2e4 : this is the transition from e2 to e4
  1690. X          also the case of move such as Nge2
  1691. X          from =cur; prise = FALSE;
  1692. X          also:
  1693. X          curcol = ...
  1694. X          */
  1695. X    m->piece = curpiece ;
  1696. X    m->fromcol = curcol ;
  1697. X    m->fromlig = curlig;
  1698. X
  1699. X    m->type = MOVE;
  1700. X    curcol = lettertocol(c);
  1701. X    break;
  1702. X  case 14: /* promotion, the "=" */
  1703. X    /* NB: actions need some clean up here */
  1704. X    /* to = cur */
  1705. X
  1706. X    m->tocol = curcol;
  1707. X    m->tolig = curlig ;
  1708. X    /*m->topiece = curpiece ;*/
  1709. X
  1710. X    if (m->type == PRISE )
  1711. X      m->type = PROM_ET_PRISE ;
  1712. X    else
  1713. X      m->type = PROMOTION ;
  1714. X    /* by default, we promote to queen 
  1715. X       this can be overwritten by explicit naming
  1716. X       */
  1717. X    m->promotion = curpiece = QUEEN ;
  1718. X    break;
  1719. X  case 15: /* promotion, the piece name */
  1720. X    m->promotion = curpiece = piece(c) ;
  1721. X    break;
  1722. X  case 16: /* not used */ 
  1723. X    break;
  1724. X  case 17: /* execute move for promotion */
  1725. X    (void) execute_move();
  1726. X    break;
  1727. X  case -1:
  1728. X    break;
  1729. X  default:
  1730. X    break;
  1731. X  }
  1732. X  return(TRUE);
  1733. X}
  1734. X
  1735. X#ifdef __STDC__
  1736. Xint parse_number(char *token)
  1737. X#else
  1738. Xint parse_number(token)
  1739. X     char *token;
  1740. X#endif
  1741. X{
  1742. X  int curmove = 0 ;
  1743. X  int i;
  1744. X
  1745. X  /* check coherency with internal numbering */
  1746. X  i = 0;
  1747. X  while (isdigit(token[i])) {
  1748. X   curmove = curmove * 10 +  ((int) token[i++] - (int) '0' );
  1749. X  }
  1750. X  movecount = curmove ;
  1751. X  return(TRUE);
  1752. X}
  1753. X
  1754. X#ifdef __STDC__
  1755. Xint parse_text(char *text)
  1756. X#else
  1757. Xint parse_text(text)
  1758. X     char *text;
  1759. X#endif
  1760. X{
  1761. X  output_text(dr,T_TEXT, text, 0);
  1762. X  return(TRUE);
  1763. X}
  1764. X
  1765. X#ifdef __STDC__
  1766. Xint parse_comment(char *com)
  1767. X#else
  1768. Xint parse_comment(com)
  1769. X     char *com;
  1770. X#endif
  1771. X{
  1772. X  int t;
  1773. X
  1774. X  if (com[0] == '$')
  1775. X    /* we look in the long ascii table */
  1776. X    t = find_keyword(com_long, NUM_COM_CODE, NUM_COM_CODE, com, TRUE);
  1777. X  else {
  1778. X    /* we look for the comment in the short ascii table */
  1779. X    t = find_keyword(com_short, NUM_COM_CODE, NUM_COM_CODE, com,FALSE);
  1780. X    if (t == NUM_COM_CODE)
  1781. X      fprintf (stderr,"\nWhat is \"%s\" ?\n",com);   
  1782. X  }
  1783. X  if (t != NUM_COM_CODE)
  1784. X    output_text(dr,T_COMMENT, com, t);
  1785. X  return(TRUE);
  1786. X}
  1787. X
  1788. X#ifdef __STDC__
  1789. Xint parse_keyword(char *token, char *text)
  1790. X#else
  1791. Xint parse_keyword(token,text)
  1792. X     char *token;
  1793. X     char *text;
  1794. X#endif
  1795. X{
  1796. X  char c;
  1797. X
  1798. X  switch (find_keyword(keywords, NBKEYWORD, KNULL, token, TRUE)) {
  1799. X  case START:
  1800. X    /* don't forget we are configuring the previous move */
  1801. X    /* -> move 0, black */
  1802. X    configuring = FALSE;
  1803. X    m->move = 0;
  1804. X    m->whiteturn = FALSE;
  1805. X    break;
  1806. X  case CLEAR:
  1807. X    clear_board(tos);
  1808. X    m= theplay->chain;
  1809. X    free_move_list(m);
  1810. X    break;
  1811. X  case SHOWBOARD:
  1812. X    output_board(dr,tos);
  1813. X    break;
  1814. X  case TOWHITE:
  1815. X    /* don't forget we are configuring the previous move */
  1816. X    /* reset to 0,black --> 1,white */
  1817. X    m->move = 0;
  1818. X    m->whiteturn = FALSE;
  1819. X    break;
  1820. X  case TOBLACK:
  1821. X    /* reset to 1,white -> 1 black */
  1822. X    m->move = 1;
  1823. X    m->whiteturn = TRUE;
  1824. X    break;
  1825. X  case CONFIGWH:
  1826. X    configuring = TRUE ;
  1827. X    configside = WHITE;
  1828. X    m= theplay->chain;
  1829. X    free_move_list(m);
  1830. X    break;
  1831. X  case CONFIGBL:
  1832. X    configuring = TRUE ;
  1833. X    configside = BLACK;
  1834. X    m= theplay->chain;
  1835. X    free_move_list(m);
  1836. X    break;
  1837. X  case DEFAULTP:
  1838. X    init_board(tos);
  1839. X    m= theplay->chain;
  1840. X    free_move_list(m);
  1841. X    break;
  1842. X  case TITLE:
  1843. X    output_text(dr, T_TITLE, text, NULL);
  1844. X    break;
  1845. X  case SUBTITLE:
  1846. X    output_text(dr, T_SUBTITLE, text, NULL);
  1847. X    break;
  1848. X  case SCORE:
  1849. X    output_text(dr, T_SCORE, text, NULL);
  1850. X    break;
  1851. X  case LANGUE:
  1852. X    in_language = find_keyword (t_language, NBLANGUAGES, in_language,
  1853. X                   text,TRUE);
  1854. X    associe_traduction( &in_table, in_language);           
  1855. X    break;
  1856. X  case SPECIAL: /* all input, up to \n is copied to output */
  1857. X    while ((( c = getc(infile)) != EOF) && (c != '\n'))
  1858. X      (void) putc (c,dr->outfile);
  1859. X    putc ('\n', dr->outfile);
  1860. X    break;
  1861. X  case KNULL:
  1862. X  default:
  1863. X    fprintf(stderr,"unknown keyword %s\n",token);
  1864. X    break;
  1865. X  }
  1866. X  return(TRUE);
  1867. X}
  1868. X
  1869. X#ifdef __STDC__
  1870. Xint parse_roque(char *token)
  1871. X#else
  1872. Xint parse_roque(token)
  1873. X     char * token;
  1874. X#endif
  1875. X{ 
  1876. X  int i;
  1877. X
  1878. X  for (i=0; i < NBROQUE && (strcmp(c_roque[i],token)!=0); i++) ;
  1879. X  if ( i < NBROQUE ) {
  1880. X    
  1881. X    m = add_trailing_move(m);
  1882. X    init_parse(m);
  1883. X
  1884. X    if (strlen(token) == 3) {
  1885. X      m->type = PETITROQUE ;
  1886. X      (void) execute(12,DUMMYCHAR);
  1887. X    } else {
  1888. X      m->type = GRANDROQUE ;
  1889. X      (void) execute(11,DUMMYCHAR);
  1890. X    }
  1891. X    /*(void) fprintf(stderr,"ROQUE\n");*/
  1892. X    return(TRUE);
  1893. X  }
  1894. X
  1895. X  return(FALSE);
  1896. X}
  1897. X
  1898. X#ifdef __STDC__
  1899. Xint  parse_move(char *token)
  1900. X#else
  1901. Xint  parse_move(token)
  1902. X     char *token;
  1903. X#endif
  1904. X{
  1905. X  register int i;
  1906. X  int correcte = FALSE ;
  1907. X  int erreursyntaxe = FALSE ;
  1908. X  int etat =0;
  1909. X  int code;
  1910. X  
  1911. X  m = add_trailing_move(m);
  1912. X  init_parse(m);
  1913. X  m->type = MOVE;
  1914. X
  1915. X  i=0;
  1916. X  while ( !correcte && !erreursyntaxe ) {
  1917. X    code = typechar(token[i]);
  1918. X    (void) execute(action[etat][code],token[i]);
  1919. X    etat = transit[etat][code] ;
  1920. X    if (etat == -1) 
  1921. X      erreursyntaxe = TRUE;
  1922. X    if (etat == FINAL)
  1923. X      correcte = TRUE ;
  1924. X    i++;
  1925. X  }
  1926. X  if (erreursyntaxe) {
  1927. X    (void) fprintf(stderr, "no comprende, senor: %s\n",token);
  1928. X    return(FALSE);
  1929. X  }
  1930. X  if (correcte) {
  1931. X    /*(void) fprintf(stderr, "ia panimaiou, davai\n");*/
  1932. X  }
  1933. X  /*init_parse(m);*/
  1934. X  return(TRUE);
  1935. X}
  1936. X
  1937. X#ifdef __STDC__
  1938. Xvoid init_parse(depl *m)
  1939. X#else
  1940. Xvoid init_parse(m)
  1941. X     depl * m ;
  1942. X#endif
  1943. X{
  1944. X
  1945. X  /* global position and piece variable initialised to 0
  1946. X     */
  1947. X  /* move and whiteturn unchanged */ 
  1948. X
  1949. X  m->type = MOVE ;
  1950. X
  1951. X  curpiece = m->piece = VOID ;
  1952. X  curcol = m->tocol = m->fromcol = 0;
  1953. X  curlig = m->tolig = m->fromlig = 0;
  1954. X
  1955. X  m->promotion = VOID;
  1956. X  m->prise = VOID;
  1957. X  m->is_check = FALSE ;
  1958. X
  1959. X  curdigit = curmove = 0;
  1960. X
  1961. X  /*if (movecount != m->move)
  1962. X    (void) fprintf(stderr,"problem in move numbering: %d vs %d\n",
  1963. X           m->move, movecount);*/
  1964. X
  1965. X}
  1966. X
  1967. X/* ------------------- top routines -------------------- */
  1968. X
  1969. X/* cette fonction analyse les arguments de la ligne de commande
  1970. X   */
  1971. X#ifdef __STDC__
  1972. Xint parse_options(int argc,char *argv[])
  1973. X#else
  1974. Xint parse_options(argc,argv)
  1975. X     int argc;
  1976. X     char * argv[];
  1977. X#endif
  1978. X{
  1979. X  int narg =1 ;
  1980. X  int i;
  1981. X  register int c;
  1982. X  char cp[132];
  1983. X  char chaine[MAXTOKLEN];
  1984. X
  1985. X  infile = stdin;
  1986. X  dr->outfile = stdout;
  1987. X  nb_move_to_dsp = 0;
  1988. X
  1989. X  while (narg < argc ) {
  1990. X    (void) strcpy (cp,argv[narg]);
  1991. X    switch (cp[0]) {
  1992. X    case '-' :
  1993. X      switch (cp[1]) {
  1994. X      case 'f' : /* from langage */
  1995. X    if  ((narg+1) >= argc )
  1996. X      fatal((stderr,"missing argument to %s option",cp));
  1997. X    narg++ ;
  1998. X    in_language = find_keyword (t_language, NBLANGUAGES,
  1999. X                    DEFAULT_INPUT_LANGUAGE,
  2000. X                    argv[narg],TRUE);
  2001. X    break;
  2002. X      case 't' : /* to langage */
  2003. X    if  ((narg+1) >= argc )
  2004. X      fatal((stderr,"missing argument to %s option",cp));
  2005. X    narg++ ;
  2006. X    out_language = find_keyword (t_language, NBLANGUAGES,
  2007. X                     DEFAULT_OUTPUT_LANGUAGE,
  2008. X                     argv[narg],TRUE);
  2009. X    break;
  2010. X      case 'o' : /* next arg is output file */
  2011. X    narg++ ;
  2012. X    if ((dr->outfile = fopen (argv[narg],"w+")) == NULL) {
  2013. X      (void) fprintf (stderr,"can't open %s output file\n",argv[narg]);
  2014. X      (void) fprintf (stderr,"assume stdout for output\n");
  2015. X    }
  2016. X    break;
  2017. X      case 'e':
  2018. X    if  ((narg+1) >= argc )
  2019. X      fatal((stderr,"missing argument to %s option",cp));
  2020. X    narg++ ;
  2021. X
  2022. X    i=0;
  2023. X    nb_move_to_dsp = 0;
  2024. X    move_to_display[nb_move_to_dsp] = 0;
  2025. X    while (isdigit(argv[narg][i])) {
  2026. X      move_to_display[nb_move_to_dsp] =
  2027. X        ((int) argv[narg][i] - (int) '0')
  2028. X          + move_to_display[nb_move_to_dsp] * 10;
  2029. X      i++;
  2030. X    }
  2031. X    nb_move_to_dsp++;
  2032. X    stop_at_display = TRUE;
  2033. X    break;
  2034. X      case 'c':
  2035. X    if  ((narg+1) >= argc )
  2036. X      fatal((stderr,"missing argument to %s option",cp));
  2037. X    narg++ ;
  2038. X
  2039. X    i=0;
  2040. X    while (isdigit(argv[narg][i])) {
  2041. X      move_to_display[nb_move_to_dsp] = 0;
  2042. X      while (isdigit(argv[narg][i])) {
  2043. X        move_to_display[nb_move_to_dsp] =
  2044. X          ((int) argv[narg][i] - (int) '0')
  2045. X          + move_to_display[nb_move_to_dsp] * 10;
  2046. X        i++;
  2047. X      }
  2048. X      nb_move_to_dsp++;
  2049. X
  2050. X      if (nb_move_to_dsp > NB_MOVE_TO_DISP)
  2051. X        fatal((stderr,"max. number of move to display exceeded"));
  2052. X
  2053. X      /* process next number */
  2054. X      if (argv[narg][i] == ',')
  2055. X        i++;
  2056. X    }
  2057. X    break;
  2058. X      case 'a': /* algebraic output */
  2059. X    dr->output_move_format = ALGEBRAIC;
  2060. X    break;
  2061. X      case 's':  /* shortened output */
  2062. X    dr->output_move_format = SHORTENED;
  2063. X    break;
  2064. X      case 'b': /* display only the board, no move */
  2065. X    dr->only_board = TRUE;
  2066. X    break;
  2067. X      case 'd': /* output driver */
  2068. X    if  ((narg+1) >= argc )
  2069. X      fatal((stderr,"missing argument to %s option",cp));
  2070. X    narg++ ;
  2071. X    driver = find_keyword(t_output, NB_DRIVER, DEFAULT_DRIVER,
  2072. X                  argv[narg],TRUE);
  2073. X    break;
  2074. X      case 'i': /* no headers */
  2075. X    dr->print_headers = FALSE;
  2076. X    break;
  2077. X      case 'v': /* print version */
  2078. X    /* this already done, so exit() */
  2079. X    exit(0);
  2080. X    break;
  2081. X      case 'h': /* help file */
  2082. X    (void) strcpy(chaine,LIB_DIR);
  2083. X        if ((fhelp = fopen(strcat(chaine,HELP_FILE),"r")) == NULL)
  2084. X          fatal((stderr,"Can't find help file.\n"));
  2085. X        else {
  2086. X          while ((c = getc(fhelp)) != EOF)
  2087. X            (void) fputc(c,stderr);
  2088. X          (void) fclose(fhelp);
  2089. X      exit(0);
  2090. X        }
  2091. X         break;
  2092. X      default:
  2093. X    error((stderr,"\nUnknown command line options %s\n",cp));
  2094. X    break;
  2095. X      }
  2096. X      break;
  2097. X    default: /* assume this is the input file */
  2098. X      if ((infile = fopen (cp,"r")) == NULL)
  2099. X    fatal((stderr,"can't open %s input file\n",cp));
  2100. X    }
  2101. X    narg++;
  2102. X  } /* process next arg */
  2103. X  return(argc);
  2104. X}
  2105. X
  2106. X#ifdef __STDC__
  2107. Xvoid close_files(void)
  2108. X#else
  2109. Xvoid close_files()
  2110. X#endif
  2111. X{
  2112. X  if (!((infile == stdin)||(infile == NULL)))
  2113. X    (void) fclose(infile);
  2114. X  if (dr->outfile != stdout )
  2115. X    (void) fclose(dr->outfile);
  2116. X}
  2117. X
  2118. X#ifdef __STDC__
  2119. Xint associe_traduction (char **table, int language)
  2120. X#else
  2121. Xint associe_traduction (table, language)
  2122. Xchar ** table;
  2123. Xint language ;
  2124. X#endif
  2125. X{
  2126. X  if (language < 0 || (language >= NBLANGUAGES))
  2127. X    error((stderr,"\nUnknown language\n"));
  2128. X  else
  2129. X    *table = c_language[language];
  2130. X  return(language);
  2131. X}
  2132. X
  2133. X#ifdef __STDC__
  2134. Xstatic void print_all_play(play *p)
  2135. X#else
  2136. Xstatic void print_all_play(p)
  2137. Xplay *p;
  2138. X#endif
  2139. X{ 
  2140. X  depl *d;
  2141. X  d = p->chain;
  2142. X  while (d->next != NULL){
  2143. X    d = d->next;
  2144. X    output_move(dr,d);
  2145. X  }
  2146. X}
  2147. X
  2148. X/* ------------- main --------------------- */
  2149. X
  2150. X#ifdef __STDC__
  2151. Xvoid main(int argc,char *argv[])
  2152. X#else
  2153. Xint main(argc,argv)
  2154. X     int argc;
  2155. X     char * argv[];
  2156. X#endif
  2157. X{
  2158. X  (void) fprintf(stderr,"%s\n",version_string);
  2159. X  
  2160. X  /* allocation of driver descriptor */
  2161. X  dr = new_driver();
  2162. X
  2163. X  /* default configuration */
  2164. X  init_driver(dr,DEFAULT_DRIVER);
  2165. X  (void) associe_traduction(&in_table,  DEFAULT_INPUT_LANGUAGE );
  2166. X  (void) associe_traduction(&(dr->out_table), DEFAULT_OUTPUT_LANGUAGE);
  2167. X
  2168. X  (void) parse_options(argc,argv);
  2169. X
  2170. X  (void) associe_traduction (&in_table, in_language);
  2171. X  (void) associe_traduction (&(dr->out_table), out_language);
  2172. X
  2173. X  /* assoc driver */
  2174. X  init_driver(dr,driver);
  2175. X
  2176. X  configuring = FALSE;
  2177. X  configside = VOID;
  2178. X
  2179. X  /* initialise output file */
  2180. X  output_init(dr);
  2181. X
  2182. X  if (error_flag)
  2183. X    fatal((stderr,"\nToo many errors"));
  2184. X
  2185. X  /* allocation of board descriptor */
  2186. X  tos = new_board();
  2187. X  init_board(tos);
  2188. X
  2189. X  /* allocation of move descriptor */
  2190. X  m = new_move();
  2191. X  m->type = VOID ;
  2192. X  /*init_move(m);*/
  2193. X  
  2194. X  /* allocation of the play descriptor */
  2195. X  theplay = (play *) malloc (sizeof(play)) ;
  2196. X  theplay->initial = tos ;
  2197. X  theplay->chain   = m ;
  2198. X  movecount = 1;
  2199. X
  2200. X  /* main analysis routine */
  2201. X  yyin = infile ;
  2202. X  yyout = stderr ;
  2203. X
  2204. X  /*init_parse(m); */
  2205. X  yylex();
  2206. X
  2207. X  if ((count == 0) && !error_flag)
  2208. X    output_board(dr,tos);
  2209. X
  2210. X  if (error_flag) {
  2211. X    error((stderr,"\nLast valid position:\n"));
  2212. X    output_board(dr,tos);
  2213. X    fatal((stderr,"\nToo many errors"));
  2214. X  }
  2215. X      
  2216. X  /* terminates output files */
  2217. X  output_end(dr);
  2218. X
  2219. X  /* close files */
  2220. X  close_files();
  2221. X
  2222. X  /* exit properly */
  2223. X#ifdef __STDC__
  2224. X#else
  2225. X  exit(0);
  2226. X#endif
  2227. X}
  2228. END_OF_FILE
  2229.   if test 42748 -ne `wc -c <'notation.c'`; then
  2230.     echo shar: \"'notation.c'\" unpacked with wrong size!
  2231.   fi
  2232.   # end of 'notation.c'
  2233. fi
  2234. echo shar: End of archive 1 \(of 4\).
  2235. cp /dev/null ark1isdone
  2236. MISSING=""
  2237. for I in 1 2 3 4 ; do
  2238.     if test ! -f ark${I}isdone ; then
  2239.     MISSING="${MISSING} ${I}"
  2240.     fi
  2241. done
  2242. if test "${MISSING}" = "" ; then
  2243.     echo You have unpacked all 4 archives.
  2244.     rm -f ark[1-9]isdone
  2245. else
  2246.     echo You still must unpack the following archives:
  2247.     echo "        " ${MISSING}
  2248. fi
  2249. exit 0
  2250. exit 0 # Just in case...
  2251.