X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=parser.c;h=d60b833cf997b6f87795147b16b94739dd3dca47;hb=3536ccf4ea73a0157ef01ae42c72e5448543eb39;hp=bd1a38aef0251d8d60c9abf0f347662a63be690e;hpb=9b57df9ec247e8a2b70640bc6d3787f9c7204595;p=xboard.git diff --git a/parser.c b/parser.c index bd1a38a..d60b833 100644 --- a/parser.c +++ b/parser.c @@ -1,7 +1,7 @@ /* * parser.c -- * - * Copyright 2011, 2012, 2013 Free Software Foundation, Inc. + * Copyright 2011, 2012, 2013, 2014 Free Software Foundation, Inc. * ------------------------------------------------------------------------ * * GNU XBoard is free software: you can redistribute it and/or modify @@ -87,7 +87,7 @@ SkipWhite (char **p) return *p != start; } -inline int +static inline int Match (char *pattern, char **ptr) { char *p = pattern, *s = *ptr; @@ -99,7 +99,7 @@ Match (char *pattern, char **ptr) return 0; // no match, no ptr update } -inline int +static inline int Word (char *pattern, char **p) { if(Match(pattern, p)) return 1; @@ -155,7 +155,7 @@ PromoSuffix (char **p) if(**p == '=' || (gameInfo.variant == VariantSChess) && **p == '/') (*p)++; // optional = (or / for Seirawan gating) if(**p == '(' && (*p)[2] == ')' && isalpha( (*p)[1] )) { (*p) += 3; return ToLower((*p)[-2]); } if(isalpha(**p) && **p != 'x') return ToLower(*(*p)++); // reserve 'x' for multi-leg captures? - if(*p != start) return '='; // must be the optional = + if(*p != start) return **p == '+' ? *(*p)++ : '='; // must be the optional = (or =+) return NULLCHAR; // no suffix detected } @@ -174,6 +174,10 @@ NextUnit (char **p) if(fromString) return 0; // we are parsing string, so the end is really the end *p = inPtr = inputBuf; if(!ReadLine()) return 0; // EOF + } else if(inPtr > inputBuf + PARSEBUFSIZE/2) { // buffer fills up with already parsed stuff + char *q = *p, *r = inputBuf; + while(*r++ = *q++); + *p = inputBuf; inPtr = r - 1; } parseStart = oldp = *p; // remember where we begin @@ -263,6 +267,7 @@ NextUnit (char **p) fromY = DROP_RANK; fromX = cl.pieceIn; currentMoveString[0] = piece; currentMoveString[1] = '@'; + currentMoveString[4] = NULLCHAR; return LegalityTest(boards[yyboardindex], PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, fromY, fromX, toY, toX, NULLCHAR); } if(type[1] == NOTHING && type[0] != NOTHING) { // there is a disambiguator @@ -285,12 +290,15 @@ NextUnit (char **p) toY = cl.rtIn = (currentMoveString[3] = Number(p) + '0') - ONE; } if(type[0] != NOTHING && type[1] != NOTHING && type[3] != NOTHING) { // fully specified. + ChessSquare realPiece = boards[yyboardindex][fromY][fromX]; // Note that Disambiguate does not work for illegal moves, but flags them as impossible if(piece) { // check if correct piece indicated - ChessSquare realPiece = boards[yyboardindex][fromY][fromX]; if(PieceToChar(realPiece) == '~') realPiece = (ChessSquare) (DEMOTED realPiece); if(!(appData.icsActive && PieceToChar(realPiece) == '+') && // trust ICS if it moves promoted pieces piece && realPiece != cl.pieceIn) return ImpossibleMove; + } else if(!separator && **p == '+') { // could be a protocol move, where bare '+' suffix means shogi-style promotion + if(realPiece < (wom ? WhiteCannon : BlackCannon) && PieceToChar(PROMOTED realPiece) == '+') // seems to be that + currentMoveString[4] = cl.promoCharIn = *(*p)++; // append promochar after all } result = LegalityTest(boards[yyboardindex], PosFlags(yyboardindex), fromY, fromX, toY, toX, cl.promoCharIn); if (currentMoveString[4] == NULLCHAR) { // suppy missing mandatory promotion character