X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=424463dad2eca1e8477a821e39fb78ca9b85c765;hb=60876535e02fb87e638a0aa94aa80490093099fc;hp=932e5bb194732c044ac109b34805e68f9b177ddd;hpb=0e642a2b9658ccaef62bf668f9d51598ee3a7deb;p=xboard.git diff --git a/backend.c b/backend.c index 932e5bb..424463d 100644 --- a/backend.c +++ b/backend.c @@ -4816,17 +4816,17 @@ ParseOneMove(move, moveNum, moveType, fromX, fromY, toX, toY, promoChar) void -ParsePV(char *pv) +ParsePV(char *pv, Boolean storeComments) { // Parse a string of PV moves, and append to current game, behind forwardMostMove int fromX, fromY, toX, toY; char promoChar; ChessMove moveType; Boolean valid; - int nr = 0; + int nr = 0, dummy; endPV = forwardMostMove; do { while(*pv == ' ') pv++; - if(*pv == '(') pv++; // first (ponder) move can be in parentheses + if(nr == 0 && *pv == '(') pv++; // first (ponder) move can be in parentheses valid = ParseOneMove(pv, endPV, &moveType, &fromX, &fromY, &toX, &toY, &promoChar); if(appData.debugMode){ fprintf(debugFP,"parsePV: %d %c%c%c%c '%s'\n", valid, fromX+AAA, fromY+ONE, toX+AAA, toY+ONE, pv); @@ -4848,9 +4848,30 @@ fprintf(debugFP,"parsePV: %d %c%c%c%c '%s'\n", valid, fromX+AAA, fromY+ONE, toX+ strcpy(moveList[endPV-2], "_0_0"); // suppress premove highlight on takeback move } } + if(moveType == Comment) { + // [HGM] vari: try to skip comment + int level = 0; char c, *start = pv, wait = NULLCHAR; + do { + if(!wait) { + if(*pv == '(') level++; else + if(*pv == ')' && level) level--; + } + if(*pv == wait) wait = NULLCHAR; else + if(*pv == '{') wait = '}'; else + if(*pv == '[') wait = ']'; + pv++; + } while(*pv && (wait || level)); + if(storeComments) { + c = *pv; *pv = NULLCHAR; + AppendComment(endPV, start, FALSE); + *pv = c; + } + valid++; // allow comments in PV + continue; } + if(sscanf(pv, "%d...", &dummy) == 1 || sscanf(pv, "%d.", &dummy) == 1) + while(*pv && *pv++ != ' '); // skip any move numbers while(*pv && *pv++ != ' '); // skip what we parsed; assume space separators - if(moveType == Comment) { valid++; continue; } // allow comments in PV nr++; if(endPV+1 > framePtr) break; // no space, truncate if(!valid) break; @@ -4861,7 +4882,13 @@ fprintf(debugFP,"parsePV: %d %c%c%c%c '%s'\n", valid, fromX+AAA, fromY+ONE, toX+ moveList[endPV-1][1] = fromY + ONE; moveList[endPV-1][2] = toX + AAA; moveList[endPV-1][3] = toY + ONE; - parseList[endPV-1][0] = NULLCHAR; + if(storeComments) + CoordsToAlgebraic(boards[endPV - 1], + PosFlags(endPV - 1), + fromY, fromX, toY, toX, promoChar, + parseList[endPV - 1]); + else + parseList[endPV-1][0] = NULLCHAR; } while(valid); currentMove = endPV; if(currentMove == forwardMostMove) ClearPremoveHighlights(); else @@ -4885,7 +4912,7 @@ LoadMultiPV(int x, int y, char *buf, int index, int *start, int *end) index = startPV; while(buf[index] && buf[index] != '\n') index++; buf[index] = 0; - ParsePV(buf+startPV); + ParsePV(buf+startPV, FALSE); *start = startPV; *end = index-1; return TRUE; } @@ -4895,7 +4922,7 @@ LoadPV(int x, int y) { // called on right mouse click to load PV int which = gameMode == TwoMachinesPlay && (WhiteOnMove(forwardMostMove) == (second.twoMachinesColor[0] == 'w')); lastX = x; lastY = y; - ParsePV(lastPV[which]); // load the PV of the thinking engine in the boards array. + ParsePV(lastPV[which], FALSE); // load the PV of the thinking engine in the boards array. return TRUE; } @@ -15030,7 +15057,7 @@ PushTail(int firstMove, int lastMove) } storedGames++; - forwardMostMove = currentMove; // truncte game so we can start variation + forwardMostMove = firstMove; // truncate game so we can start variation if(storedGames == 1) GreyRevert(FALSE); } @@ -15042,6 +15069,7 @@ PopTail(Boolean annotate) if(appData.icsActive) return FALSE; // only in local mode if(!storedGames) return FALSE; // sanity + CommentPopDown(); // make sure no stale variation comments to the destroyed line can remain open storedGames--; ToNrEvent(savedFirst[storedGames]); // sets currentMove @@ -15060,7 +15088,7 @@ PopTail(Boolean annotate) } strcat(buf, ")"); } - for(i=1; i 0 && --level == 0 && p-text > index && end == NULL) end = p-1; + } + if(*p == wait) wait = NULLCHAR; // closing ]} found + p++; + } + if(!start || !end) return; // no variation found, or syntax error in PGN: ignore click + if(appData.debugMode) fprintf(debugFP, "at move %d load variation '%s'\n", currentMove, start); + end[1] = NULLCHAR; // clip off comment beyond variation + ToNrEvent(currentMove-1); + PushTail(currentMove, forwardMostMove); // shelve main variation. This truncates game + // kludge: use ParsePV() to append variation to game + move = currentMove; + ParsePV(start, TRUE); + forwardMostMove = endPV; endPV = -1; currentMove = move; // cleanup what ParsePV did + ClearPremoveHighlights(); + CommentPopDown(); + ToNrEvent(currentMove+1); +}