home *** CD-ROM | disk | FTP | other *** search
/ Dream 44 / Amiga_Dream_44.iso / RiscPc / jeux / ArcBoard004.arc / !GNUChessX / src / c / util < prev   
Text File  |  1995-07-02  |  2KB  |  79 lines

  1. /*
  2.  * util.c - C source for GNU CHESS
  3.  *
  4.  * Copyright (c) 1988,1989,1990 John Stanback
  5.  * Copyright (c) 1992 Free Software Foundation
  6.  *
  7.  * This file is part of GNU CHESS.
  8.  *
  9.  * GNU Chess is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2, or (at your option)
  12.  * any later version.
  13.  *
  14.  * GNU Chess is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with GNU Chess; see the file COPYING.  If not, write to
  21.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23. #include "gnuchess.h"
  24.  
  25. int
  26. parse (FILE * fd, UTSHORT *mv, SHORT side, CHAR *opening)
  27. {
  28.   register int c, i, r1, r2, c1, c2;
  29.   CHAR s[128];
  30.   CHAR *p;
  31.  
  32.   while ((c = getc (fd)) == ' ' || c == '\n') ;
  33.   i = 0;
  34.   s[0] = (CHAR) c;
  35.   if (c == '!')
  36.     {
  37.       p = opening;
  38.       do
  39.     {
  40.       *p++ = c;
  41.       c = getc (fd);
  42.       if (c == '\n' || c == EOF)
  43.         {
  44.           *p = '\0';
  45.           return 0;
  46.         }
  47.       } while (true);
  48.     }
  49.   while (c != '?' && c != ' ' && c != '\t' && c != '\n' && c != EOF)
  50.     s[++i] = (CHAR) (c = getc (fd));
  51.   s[++i] = '\0';
  52.   if (c == EOF)
  53.     return (-1);
  54.   if (s[0] == '!' || s[0] == ';' || i < 3)
  55.     {
  56.       while (c != '\n' && c != EOF)
  57.     c = getc (fd);
  58.       return (0);
  59.     }
  60.   if (s[4] == 'o')
  61.     *mv = ((side == black) ? LONGBLACKCASTLE : LONGWHITECASTLE);
  62.   else if (s[0] == 'o')
  63.     *mv = ((side == black) ? BLACKCASTLE : WHITECASTLE);
  64.   else
  65.     {
  66.       c1 = s[0] - 'a';
  67.       r1 = s[1] - '1';
  68.       c2 = s[2] - 'a';
  69.       r2 = s[3] - '1';
  70.       *mv = (locn (r1, c1) << 8) | locn (r2, c2);
  71.     }
  72.   if (c == '?')
  73.     {                /* Bad move, not for the program to play */
  74.       *mv |= 0x8000;        /* Flag it ! */
  75.       c = getc (fd);
  76.     }
  77.   return (1);
  78. }
  79.