home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnuch40.zip / gnuchess-4.0.pl79 / src / util.c < prev    next >
C/C++ Source or Header  |  1998-09-28  |  2KB  |  81 lines

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