added some comments and formated code
[xboard.git] / winboard / parser.c
index ff36db3..08d0755 100644 (file)
@@ -9,7 +9,7 @@
 #define YY_FLEX_MINOR_VERSION 5
 
 #include <stdio.h>
-#include <errno.h>
+
 
 /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
 #ifdef c_plusplus
@@ -22,9 +22,7 @@
 #ifdef __cplusplus
 
 #include <stdlib.h>
-#ifndef _WIN32
 #include <unistd.h>
-#endif
 
 /* Use prototypes in function declarations. */
 #define YY_USE_PROTOS
@@ -64,7 +62,6 @@
 #define YY_PROTO(proto) ()
 #endif
 
-
 /* Returned upon end-of-file. */
 #define YY_NULL 0
 
@@ -1710,10 +1707,12 @@ char *yytext;
 #define INITIAL 0
 /*
  * parser.l -- lex parser of algebraic chess moves for XBoard
- * $Id: parser.l,v 2.1 2003/10/27 19:21:00 mann Exp $
  *
- * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts.
- * Enhancements Copyright 1992-95 Free Software Foundation, Inc.
+ * Copyright 1991 by Digital Equipment Corporation, Maynard,
+ * Massachusetts.
+ *
+ * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
+ * 2007, 2008, 2009 Free Software Foundation, Inc.
  *
  * The following terms apply to Digital Equipment Corporation's copyright
  * interest in XBoard:
@@ -1737,24 +1736,25 @@ char *yytext;
  * SOFTWARE.
  * ------------------------------------------------------------------------
  *
- * The following terms apply to the enhanced version of XBoard distributed
- * by the Free Software Foundation:
+ * The following terms apply to the enhanced version of XBoard
+ * distributed by the Free Software Foundation:
  * ------------------------------------------------------------------------
- * This program is free software; you can redistribute it and/or modify
+ *
+ * GNU XBoard is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * GNU XBoard is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- * ------------------------------------------------------------------------
- */
+ * along with this program. If not, see http://www.gnu.org/licenses/.  
+ *
+ *------------------------------------------------------------------------
+ ** See the file ChangeLog for a revision history.  */
 
 /* This parser handles all forms of promotion.
  * The parser resolves ambiguous moves by searching and check-testing.
@@ -1974,20 +1974,9 @@ YY_MALLOC_DECL
                        YY_FATAL_ERROR( "input in flex scanner failed" ); \
                result = n; \
                } \
-       else \
-               { \
-               errno=0; \
-               while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
-                       { \
-                       if( errno != EINTR) \
-                               { \
-                               YY_FATAL_ERROR( "input in flex scanner failed" ); \
-                               break; \
-                               } \
-                       errno=0; \
-                       clearerr(yyin); \
-                       } \
-               }
+       else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
+                 && ferror( yyin ) ) \
+               YY_FATAL_ERROR( "input in flex scanner failed" );
 #endif
 
 /* No semi-colon after return; correct usage is to write "yyterminate();" -
@@ -2212,7 +2201,8 @@ YY_RULE_SETUP
       return (int) IllegalMove;
 
     result = LegalityTest(boards[yyboardindex],
-                         PosFlags(yyboardindex), EP_UNKNOWN,
+                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!
+                         EP_UNKNOWN,
                           initialRights, /* [HGM] assume all castlings allowed */
                           currentMoveString[1] - ONE,
                           currentMoveString[0] - AAA,
@@ -2275,7 +2265,8 @@ YY_RULE_SETUP
       return 0;
 
     result = LegalityTest(boards[yyboardindex],
-                         PosFlags(yyboardindex), EP_UNKNOWN,
+                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!
+                         EP_UNKNOWN,
                           initialRights, /* [HGM] assume all castlings allowed */
                           currentMoveString[1] - ONE,
                           currentMoveString[0] - AAA,
@@ -2461,7 +2452,8 @@ YY_RULE_SETUP
     }
 
     result = LegalityTest(boards[yyboardindex],
-                         PosFlags(yyboardindex), EP_UNKNOWN,
+                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!
+                         EP_UNKNOWN,
                           initialRights, /* [HGM] assume all castlings allowed */
                           currentMoveString[1] - ONE,
                           currentMoveString[0] - AAA,
@@ -2501,7 +2493,8 @@ YY_RULE_SETUP
     }
 
     result = LegalityTest(boards[yyboardindex],
-                         PosFlags(yyboardindex), EP_UNKNOWN,
+                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!
+                         EP_UNKNOWN,
                           initialRights, /* [HGM] assume all castlings allowed */
                           currentMoveString[1] - ONE,
                           currentMoveString[0] - AAA,
@@ -2688,7 +2681,8 @@ YY_RULE_SETUP
         fprintf(debugFP, "long castling %d %d\n", ff, ft);
     }
     return (int) LegalityTest(boards[yyboardindex],
-                             PosFlags(yyboardindex), EP_UNKNOWN,
+                             PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: e.p.!
+                             EP_UNKNOWN,
                               castlingRights[yyboardindex], /* [HGM] use true castling rights */
                              rf, ff, rt, ft, NULLCHAR);
 }
@@ -2746,7 +2740,8 @@ YY_RULE_SETUP
     }
 
     return (int) LegalityTest(boards[yyboardindex],
-                              PosFlags(yyboardindex), EP_UNKNOWN,
+                             PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: e.p.!
+                             EP_UNKNOWN,
                               castlingRights[yyboardindex], /* [HGM] use true castling rights */
                              rf, ff, rt, ft, NULLCHAR);
 }
@@ -3549,15 +3544,11 @@ YY_BUFFER_STATE b;
        }
 
 
-#ifndef _WIN32
-#include <unistd.h>
-#else
 #ifndef YY_ALWAYS_INTERACTIVE
 #ifndef YY_NEVER_INTERACTIVE
 extern int isatty YY_PROTO(( int ));
 #endif
 #endif
-#endif
 
 #ifdef YY_USE_PROTOS
 void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )