X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=parser.l;h=53b568f29b2a8930df326612e3c62607345016b5;hb=c551a728b8fa7649b043fffb32b7f1d11c67b38a;hp=7e42f8a3b1056350cab4bad63f5e3b066c9a607a;hpb=c56cf062ff40624fad3b09223b527fc3a12c7b01;p=xboard.git diff --git a/parser.l b/parser.l old mode 100755 new mode 100644 index 7e42f8a..53b568f --- a/parser.l +++ b/parser.l @@ -232,7 +232,7 @@ extern void CopyBoard P((Board to, Board from)); currentMoveString[2] - AAA >= BOARD_RGHT || currentMoveString[0] - AAA < BOARD_LEFT || currentMoveString[2] - AAA < BOARD_LEFT ) - return 0; + return ImpossibleMove; piece = boards[yyboardindex] [currentMoveString[1] - ONE][currentMoveString[0] - AAA]; @@ -244,8 +244,6 @@ extern void CopyBoard P((Board to, Board from)); result = LegalityTest(boards[yyboardindex], 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, currentMoveString[3] - ONE, @@ -302,12 +300,10 @@ extern void CopyBoard P((Board to, Board from)); currentMoveString[2] - AAA >= BOARD_RGHT || currentMoveString[0] - AAA < BOARD_LEFT || currentMoveString[2] - AAA < BOARD_LEFT ) - return 0; + return ImpossibleMove; result = LegalityTest(boards[yyboardindex], 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, currentMoveString[3] - ONE, @@ -317,7 +313,7 @@ extern void CopyBoard P((Board to, Board from)); if (currentMoveString[4] == NULLCHAR && (result == WhitePromotionKnight || result == BlackPromotionKnight || result == WhitePromotionQueen || result == BlackPromotionQueen)) { - if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier) + if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk) currentMoveString[4] = PieceToChar(BlackFerz); else if(gameInfo.variant == VariantGreat) currentMoveString[4] = PieceToChar(BlackMan); @@ -329,7 +325,7 @@ extern void CopyBoard P((Board to, Board from)); return (int) result; } -[a-l][0-9]((=?\(?[A-Z]\)?)|=)? { +[a-l][0-9]((=?\(?[A-Za-z]\)?)|=)? { /* * Pawn move, possibly with promotion */ @@ -347,21 +343,20 @@ extern void CopyBoard P((Board to, Board from)); cl.ffIn = yytext[0] - AAA; cl.rtIn = yytext[1] - ONE; cl.ftIn = yytext[0] - AAA; - c = cl.promoCharIn = yytext[2+skip]; + c = cl.promoCharIn = ToLower(yytext[2+skip]); /* [HGM] do not allow values beyond board size */ if(cl.rtIn >= BOARD_HEIGHT || cl.rtIn < 0 || cl.ffIn >= BOARD_RGHT || cl.ftIn < BOARD_LEFT ) - return 0; + return ImpossibleMove; if(c != '=' && c != '+' && c != NULLCHAR && CharToPiece(c) == EmptySquare) return IllegalMove; - Disambiguate(boards[yyboardindex], - PosFlags(yyboardindex), EP_UNKNOWN, &cl); + Disambiguate(boards[yyboardindex], PosFlags(yyboardindex), &cl); currentMoveString[0] = cl.ff + AAA; currentMoveString[1] = cl.rf + ONE; @@ -410,13 +405,12 @@ extern void CopyBoard P((Board to, Board from)); cl.ffIn < BOARD_LEFT || cl.ftIn >= BOARD_RGHT || cl.ftIn < BOARD_LEFT ) - return 0; + return ImpossibleMove; if(c != '=' && c != '+' && c != NULLCHAR && CharToPiece(c) == EmptySquare) return IllegalMove; - Disambiguate(boards[yyboardindex], - PosFlags(yyboardindex), EP_UNKNOWN, &cl); + Disambiguate(boards[yyboardindex], PosFlags(yyboardindex), &cl); currentMoveString[0] = cl.ff + AAA; currentMoveString[1] = cl.rf + ONE; @@ -461,7 +455,7 @@ extern void CopyBoard P((Board to, Board from)); currentMoveString[2] - AAA >= BOARD_RGHT || currentMoveString[0] - AAA < BOARD_LEFT || currentMoveString[2] - AAA < BOARD_LEFT ) - return 0; + return ImpossibleMove; if (gameInfo.variant == VariantXiangqi && /* [HGM] In Xiangqi rank stays same */ currentMoveString[0] != currentMoveString[2] ) { @@ -492,8 +486,6 @@ extern void CopyBoard P((Board to, Board from)); result = LegalityTest(boards[yyboardindex], 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, currentMoveString[3] - ONE, @@ -505,7 +497,7 @@ extern void CopyBoard P((Board to, Board from)); result == WhitePromotionKnight || result == BlackPromotionKnight)) { currentMoveString[4] = PieceToChar(BlackQueen); // [HGM] shatranj: take care of variants without Queen - if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier) + if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk) currentMoveString[4] = PieceToChar(BlackFerz); if(gameInfo.variant == VariantGreat) currentMoveString[4] = PieceToChar(BlackMan); @@ -533,8 +525,6 @@ extern void CopyBoard P((Board to, Board from)); result = LegalityTest(boards[yyboardindex], 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, currentMoveString[3] - ONE, @@ -589,10 +579,9 @@ extern void CopyBoard P((Board to, Board from)); cl.rtIn < 0 || cl.ftIn >= BOARD_RGHT || cl.ftIn < BOARD_LEFT ) - return 0; + return ImpossibleMove; - Disambiguate(boards[yyboardindex], - PosFlags(yyboardindex), EP_UNKNOWN, &cl); + Disambiguate(boards[yyboardindex], PosFlags(yyboardindex), &cl); currentMoveString[0] = cl.ff + AAA; currentMoveString[1] = cl.rf + ONE; @@ -650,10 +639,9 @@ extern void CopyBoard P((Board to, Board from)); cl.rtIn < 0 || cl.ftIn >= BOARD_RGHT || cl.ftIn < BOARD_LEFT ) - return 0; + return ImpossibleMove; - Disambiguate(boards[yyboardindex], - PosFlags(yyboardindex), EP_UNKNOWN, &cl); + Disambiguate(boards[yyboardindex], PosFlags(yyboardindex), &cl); currentMoveString[0] = cl.ff + AAA; currentMoveString[1] = cl.rf + ONE; @@ -698,7 +686,7 @@ extern void CopyBoard P((Board to, Board from)); ft = BOARD_LEFT+2; } } - if(gameInfo.variant == VariantFischeRandom) { + if(PosFlags(0) & F_FRC_TYPE_CASTLING) { if (WhiteOnMove(yyboardindex)) { ff = initialRights[2]; ft = initialRights[1]; @@ -706,7 +694,10 @@ extern void CopyBoard P((Board to, Board from)); ff = initialRights[5]; ft = initialRights[4]; } - fprintf(debugFP, "Parser FRC long %d %d\n", ff, ft); + if (appData.debugMode) + { + fprintf(debugFP, "Parser FRC long %d %d\n", ff, ft); + }; if(ff < 0 || ft < 0) return 0; } sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE); @@ -715,8 +706,6 @@ extern void CopyBoard P((Board to, Board from)); } return (int) LegalityTest(boards[yyboardindex], PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: e.p.! - EP_UNKNOWN, - castlingRights[yyboardindex], /* [HGM] use true castling rights */ rf, ff, rt, ft, NULLCHAR); } @@ -752,7 +741,7 @@ extern void CopyBoard P((Board to, Board from)); ft = BOARD_RGHT-2; } } - if(gameInfo.variant == VariantFischeRandom) { + if(PosFlags(0) & F_FRC_TYPE_CASTLING) { if (WhiteOnMove(yyboardindex)) { ff = initialRights[2]; ft = initialRights[0]; @@ -772,8 +761,6 @@ extern void CopyBoard P((Board to, Board from)); return (int) LegalityTest(boards[yyboardindex], PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: e.p.! - EP_UNKNOWN, - castlingRights[yyboardindex], /* [HGM] use true castling rights */ rf, ff, rt, ft, NULLCHAR); } @@ -790,7 +777,7 @@ extern void CopyBoard P((Board to, Board from)); /* [HGM] do not allow values beyond board size */ if(currentMoveString[3] - ONE >= BOARD_HEIGHT || currentMoveString[2] - AAA >= BOARD_WIDTH ) - return 0; + return ImpossibleMove; if (WhiteOnMove(yyboardindex)) { currentMoveString[0] = ToUpper(yytext[0]); @@ -846,11 +833,11 @@ extern void CopyBoard P((Board to, Board from)); return (int) GameIsDrawn; } -(([Ww](hite)?)|([Bb](lack)?))" "([Mm]ate(s|ed)?)|([Ww][io]n(s)?.*) { +(([Ww](hite)?)|([Bb](lack)?))" "(([Mm]ates)|([Ww][io]n(s)?)) { return (int) (ToUpper(yytext[0]) == 'W' ? WhiteWins : BlackWins); } -(([Ww](hite)?)|([Bb](lack)?))" "([Mm]ate(s|ed)?)|([Ll]os[tes]+.*) { +(([Ww](hite)?)|([Bb](lack)?))" "(([Mm]ated)|([Ll]os[tes]+)) { return (int) (ToUpper(yytext[0]) == 'W' ? BlackWins : WhiteWins); } @@ -985,7 +972,7 @@ int yyoffset() static void output(ch) int ch; { - fprintf(stderr, "PARSER BUG: unmatched character '%c' (0%o)\n", + if(appData.debugMode) fprintf(debugFP, "PARSER BUG: unmatched character '%c' (0%o)\n", ch, ch); } @@ -997,7 +984,7 @@ static void unput(ch) StringToLex--; } else { if (unputCount >= UNPUT_BUF_SIZE) - fprintf(stderr, "PARSER BUG: unput buffer overflow '%c' (0%o)\n", + if(appData.debugMode) fprintf(debugFP, "PARSER BUG: unput buffer overflow '%c' (0%o)\n", ch, ch); unputBuffer[unputCount++] = ch; } @@ -1098,10 +1085,10 @@ int yywrap() /* Parse a move from the given string s */ /* ^ at start of pattern WON'T work here unless using flex */ -ChessMove yylexstr(boardIndex, s) - int boardIndex; - char *s; -{ +ChessMove yylexstr(boardIndex, s, text, len) + int boardIndex, len; + char *s, *text; +{ ChessMove ret; char *oldStringToLex; #ifdef FLEX_SCANNER @@ -1117,7 +1104,9 @@ ChessMove yylexstr(boardIndex, s) yy_switch_to_buffer(buffer); #endif /*FLEX_SCANNER*/ - ret = (ChessMove) yylex(); + ret = (ChessMove) yylex(); + strncpy(text, yy_text, len-1); // [HGM] vari: yy_text is not available to caller after buffer switch ?!? + text[len-1] = NULLCHAR; #ifdef FLEX_SCANNER if (oldBuffer != NULL)