X-Git-Url: http://winboard.nl/cgi-bin?p=xboard.git;a=blobdiff_plain;f=parser.c;h=e3250050557709805ea1e299fb1796a936250fd8;hp=471ae94101f769b32d58a12e3cb03228224c4b90;hb=95244a1c40718e9ad8bda9e2df66677e180354d6;hpb=ff23924264802924788f2a15c73a8d058e90432e diff --git a/parser.c b/parser.c index 471ae94..e325005 100644 --- a/parser.c +++ b/parser.c @@ -1,7 +1,7 @@ /* * parser.c -- * - * Copyright 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc. + * Copyright 2011, 2012, 2013, 2014, 2015, 2016 Free Software Foundation, Inc. * ------------------------------------------------------------------------ * * GNU XBoard is free software: you can redistribute it and/or modify @@ -381,6 +381,7 @@ char PromoSuffix (char **p) { char *start = *p; + if(**p == ' ') return NULLCHAR; // common case, test explicitly for speed if(**p == 'e' && (Match("ep", p) || Match("e.p.", p))) { *p = start; return NULLCHAR; } // non-compliant e.p. suffix is no promoChar! if(**p == '+' && IS_SHOGI(gameInfo.variant)) { (*p)++; return '+'; } if(**p == '=' || (gameInfo.variant == VariantSChess) && **p == '/') (*p)++; // optional = (or / for Seirawan gating) @@ -403,7 +404,7 @@ NextUnit (char **p) if(**p == NULLCHAR) { // make sure there is something to parse if(fromString) return 0; // we are parsing string, so the end is really the end - *p = inPtr = inputBuf; + *p = inPtr = parseStart = inputBuf; if(!ReadLine()) return 0; // EOF } else if(inPtr > inputBuf + PARSEBUFSIZE/2) { // buffer fills up with already parsed stuff char *q = *p, *r = inputBuf; @@ -509,19 +510,32 @@ NextUnit (char **p) } if( type[1] != type[2] && // means fromY is of opposite type as ToX, or NOTHING (type[0] == NOTHING || type[0] == type[2]) ) { // well formed - + int suffix = 7; fromX = (currentMoveString[0] = coord[0] + 'a') - AAA; fromY = (currentMoveString[1] = coord[1] + '0') - ONE; currentMoveString[4] = cl.promoCharIn = PromoSuffix(p); currentMoveString[5] = NULLCHAR; + if(**p == 'x' && !cl.promoCharIn) { // other leg follows + char *q = *p; + int x = *++*p, y; + ++*p; y = Number(p); + if(**p == '-' || **p == 'x') { // 3-leg move! + currentMoveString[7] = (kill2X = toX) + AAA; // what we thought was to-square is in fact 1st kill-square of two + currentMoveString[8] = (kill2Y = toY) + ONE; // append it after 2nd kill-square + toX = x - AAA; // kludge alert: this will become 2nd kill square + toY = y + '0' - ONE; + suffix += 2; + } else *p = q; // 2-leg move, rewind to leave reading of 2nd leg to code below + } if(!cl.promoCharIn && (**p == '-' || **p == 'x')) { // Lion-type multi-leg move currentMoveString[5] = (killX = toX) + AAA; // what we thought was to-square is in fact kill-square currentMoveString[6] = (killY = toY) + ONE; // append it as suffix behind long algebraic move currentMoveString[4] = ';'; - currentMoveString[7] = NULLCHAR; + currentMoveString[suffix+1] = NULLCHAR; // read new to-square (VERY non-robust! Assumes correct (non-alpha-rank) syntax, and messes up on errors) toX = cl.ftIn = (currentMoveString[2] = *++*p) - AAA; ++*p; toY = cl.rtIn = (currentMoveString[3] = Number(p) + '0') - ONE; + currentMoveString[suffix] = cl.promoCharIn = PromoSuffix(p); } if(type[0] != NOTHING && type[1] != NOTHING && type[3] != NOTHING) { // fully specified. ChessSquare realPiece = boards[yyboardindex][fromY][fromX];