X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=46a0df4ac157a68bfd932cf1b1b5f2cdc15c24f3;hb=e70077aab0199817f37aef9ed0bdba1bbca93b45;hp=8d16cf513bb28d16b7a09c89ec10e40924a21f6b;hpb=b595d12f49b98daeed0b9629ab759c16b897bc7a;p=xboard.git diff --git a/backend.c b/backend.c index 8d16cf5..46a0df4 100644 --- a/backend.c +++ b/backend.c @@ -5,7 +5,7 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. + * 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. * * Enhancements Copyright 2005 Alessandro Scotti * @@ -147,12 +147,6 @@ extern int gettimeofday(struct timeval *, struct timezone *); #endif -/* A point in time */ -typedef struct { - long sec; /* Assuming this is >= 32 bits */ - int ms; /* Assuming this is >= 16 bits */ -} TimeMark; - int establish P((void)); void read_from_player P((InputSourceRef isr, VOIDSTAR closure, char *buf, int count, int error)); @@ -210,8 +204,6 @@ void CopyPlayerNameIntoFileName P((char **, char *)); char *SavePart P((char *)); int SaveGameOldStyle P((FILE *)); int SaveGamePGN P((FILE *)); -void GetTimeMark P((TimeMark *)); -long SubtractTimeMarks P((TimeMark *, TimeMark *)); int CheckFlags P((void)); long NextTickLength P((long)); void CheckTimeControl P((void)); @@ -823,7 +815,7 @@ InitEngine(ChessProgramState *cps, int n) len = snprintf(buf, MSG_SIZ, _("protocol version %d not supported"), appData.protocolVersion[n]); - if( (len > MSG_SIZ) && appData.debugMode ) + if( (len >= MSG_SIZ) && appData.debugMode ) fprintf(debugFP, "InitBackEnd1: buffer truncated.\n"); DisplayFatalError(buf, 0, 2); @@ -834,6 +826,7 @@ InitEngine(ChessProgramState *cps, int n) } InitEngineUCI( installDir, cps ); // [HGM] moved here from winboard.c, to make available in xboard + ParseFeatures(appData.featureDefaults, cps); } ChessProgramState *savCps; @@ -1069,7 +1062,7 @@ InitBackEnd1() case VariantKriegspiel: /* need to hide pieces and move details */ /* case VariantFischeRandom: (Fabien: moved below) */ len = snprintf(buf,MSG_SIZ, _("Variant %s supported only in ICS mode"), appData.variant); - if( (len > MSG_SIZ) && appData.debugMode ) + if( (len >= MSG_SIZ) && appData.debugMode ) fprintf(debugFP, "InitBackEnd1: buffer truncated.\n"); DisplayFatalError(buf, 0, 2); @@ -1087,7 +1080,7 @@ InitBackEnd1() case Variant36: default: len = snprintf(buf, MSG_SIZ, _("Unknown variant name %s"), appData.variant); - if( (len > MSG_SIZ) && appData.debugMode ) + if( (len >= MSG_SIZ) && appData.debugMode ) fprintf(debugFP, "InitBackEnd1: buffer truncated.\n"); DisplayFatalError(buf, 0, 2); @@ -1492,7 +1485,7 @@ InitBackEnd3 P((void)) len = snprintf(buf, MSG_SIZ, _("Could not connect to host %s, port %s"), appData.icsHost, appData.icsPort); - if( (len > MSG_SIZ) && appData.debugMode ) + if( (len >= MSG_SIZ) && appData.debugMode ) fprintf(debugFP, "InitBackEnd3: buffer truncated.\n"); DisplayFatalError(buf, err, 1); @@ -1546,7 +1539,7 @@ InitBackEnd3 P((void)) initialMode = Training; } else { len = snprintf(buf, MSG_SIZ, _("Unknown initialMode %s"), appData.initialMode); - if( (len > MSG_SIZ) && appData.debugMode ) + if( (len >= MSG_SIZ) && appData.debugMode ) fprintf(debugFP, "InitBackEnd3: buffer truncated.\n"); DisplayFatalError(buf, 0, 2); @@ -2145,7 +2138,7 @@ StringToVariant(e) break; default: len = snprintf(buf, MSG_SIZ, _("Unknown wild type %d"), wnum); - if( (len > MSG_SIZ) && appData.debugMode ) + if( (len >= MSG_SIZ) && appData.debugMode ) fprintf(debugFP, "StringToVariant: buffer truncated.\n"); DisplayError(buf, 0); @@ -3133,6 +3126,8 @@ read_from_ics(isr, closure, data, count, error) } } // [HGM] kibitz: end of patch + if(looking_at(buf, &i, "* rating adjustment: * --> *\n")) continue; + // [HGM] chat: intercept tells by users for which we have an open chat window channel = -1; if(started == STARTED_NONE && (looking_at(buf, &i, "* tells you:") || looking_at(buf, &i, "* says:") || @@ -3635,7 +3630,7 @@ read_from_ics(isr, closure, data, count, error) flipView = appData.flipView; DrawPosition(TRUE, boards[currentMove]); DisplayBothClocks(); - snprintf(str, MSG_SIZ, "%s vs. %s", + snprintf(str, MSG_SIZ, _("%s vs. %s"), gameInfo.white, gameInfo.black); DisplayTitle(str); gameMode = IcsIdle; @@ -3862,6 +3857,7 @@ read_from_ics(isr, closure, data, count, error) strncmp(why, "Continuing ", 11) == 0) { gs_gamenum = gamenum; safeStrCpy(gs_kind, strchr(why, ' ') + 1,sizeof(gs_kind)/sizeof(gs_kind[0])); + if(ics_gamenum == -1) // [HGM] only if we are not already involved in a game (because gin=1 sends us such messages) VariantSwitch(boards[currentMove], StringToVariant(gs_kind)); // [HGM] variantswitch: even before we get first board #if ZIPPY if (appData.zippyPlay) { @@ -4049,10 +4045,10 @@ read_from_ics(isr, closure, data, count, error) char wh[16], bh[16]; PackHolding(wh, white_holding); PackHolding(bh, black_holding); - snprintf(str, MSG_SIZ,"[%s-%s] %s-%s", wh, bh, + snprintf(str, MSG_SIZ, "[%s-%s] %s-%s", wh, bh, gameInfo.white, gameInfo.black); } else { - snprintf(str, MSG_SIZ, "%s [%s] vs. %s [%s]", + snprintf(str, MSG_SIZ, _("%s [%s] vs. %s [%s]"), gameInfo.white, white_holding, gameInfo.black, black_holding); } @@ -4437,6 +4433,13 @@ ParseBoard12(string) board[k][1] = board[k][BOARD_WIDTH-2] = (ChessSquare) 0;; } } + if(moveNum==0 && gameInfo.variant == VariantSChess) { + board[5][BOARD_RGHT+1] = WhiteAngel; + board[6][BOARD_RGHT+1] = WhiteMarshall; + board[1][0] = BlackMarshall; + board[2][0] = BlackAngel; + board[1][1] = board[2][1] = board[5][BOARD_RGHT] = board[6][BOARD_RGHT] = 1; + } CopyBoard(boards[moveNum], board); boards[moveNum][HOLDINGS_SET] = 0; // [HGM] indicate holdings not set if (moveNum == 0) { @@ -4472,6 +4475,7 @@ ParseBoard12(string) if(board[BOARD_HEIGHT-1][i] == BlackRook) j = i; initialRights[4] = boards[moveNum][CASTLING][4] = (castle_bl == 0 && gameInfo.variant != VariantFischeRandom ? NoRights : j); + boards[moveNum][CASTLING][2] = boards[moveNum][CASTLING][5] = NoRights; if(gameInfo.variant == VariantKnightmate) { wKing = WhiteUnicorn; bKing = BlackUnicorn; } for(k=BOARD_LEFT; k 0) promoSweep = BlackKing; - if(!step) step = 1; + if(!step) step = -1; } while(PieceToChar(promoSweep) == '.' || PieceToChar(promoSweep) == '~' || promoSweep == pawn || appData.testLegality && (promoSweep == king || gameInfo.variant == VariantShogi && promoSweep != PROMOTED last && last != PROMOTED promoSweep && last != promoSweep)); @@ -6023,21 +6033,25 @@ SendBoard(cps, moveNum) } else { ChessSquare *bp; - int i, j; + int i, j, left=0, right=BOARD_WIDTH; /* Kludge to set black to move, avoiding the troublesome and now * deprecated "black" command. */ if (!WhiteOnMove(moveNum)) // [HGM] but better a deprecated command than an illegal move... SendToProgram(boards[0][1][BOARD_LEFT] == WhitePawn ? "a2a3\n" : "black\n", cps); + if(!cps->extendedEdit) left = BOARD_LEFT, right = BOARD_RGHT; // only board proper + SendToProgram("edit\n", cps); SendToProgram("#\n", cps); for (i = BOARD_HEIGHT - 1; i >= 0; i--) { - bp = &boards[moveNum][i][BOARD_LEFT]; - for (j = BOARD_LEFT; j < BOARD_RGHT; j++, bp++) { + bp = &boards[moveNum][i][left]; + for (j = left; j < right; j++, bp++) { + if(j == BOARD_LEFT-1 || j == BOARD_RGHT) continue; if ((int) *bp < (int) BlackPawn) { - snprintf(message, MSG_SIZ, "%c%c%c\n", PieceToChar(*bp), - AAA + j, ONE + i); + if(j == BOARD_RGHT+1) + snprintf(message, MSG_SIZ, "%c@%d\n", PieceToChar(*bp), bp[-1]); + else snprintf(message, MSG_SIZ, "%c%c%c\n", PieceToChar(*bp), AAA + j, ONE + i); if(message[0] == '+' || message[0] == '~') { snprintf(message, MSG_SIZ,"%c%c%c+\n", PieceToChar((ChessSquare)(DEMOTED *bp)), @@ -6054,11 +6068,14 @@ SendBoard(cps, moveNum) SendToProgram("c\n", cps); for (i = BOARD_HEIGHT - 1; i >= 0; i--) { - bp = &boards[moveNum][i][BOARD_LEFT]; - for (j = BOARD_LEFT; j < BOARD_RGHT; j++, bp++) { + bp = &boards[moveNum][i][left]; + for (j = left; j < right; j++, bp++) { + if(j == BOARD_LEFT-1 || j == BOARD_RGHT) continue; if (((int) *bp != (int) EmptySquare) && ((int) *bp >= (int) BlackPawn)) { - snprintf(message,MSG_SIZ, "%c%c%c\n", ToUpper(PieceToChar(*bp)), + if(j == BOARD_LEFT-2) + snprintf(message, MSG_SIZ, "%c@%d\n", ToUpper(PieceToChar(*bp)), bp[1]); + else snprintf(message,MSG_SIZ, "%c%c%c\n", ToUpper(PieceToChar(*bp)), AAA + j, ONE + i); if(message[0] == '+' || message[0] == '~') { snprintf(message, MSG_SIZ,"%c%c%c+\n", @@ -6656,7 +6673,7 @@ FinishMove(moveType, fromX, fromY, toX, toY, promoChar) gameMode = MachinePlaysBlack; StartClocks(); SetGameInfo(); - snprintf(buf, MSG_SIZ, "%s vs. %s", gameInfo.white, gameInfo.black); + snprintf(buf, MSG_SIZ, _("%s vs. %s"), gameInfo.white, gameInfo.black); DisplayTitle(buf); if (first.sendName) { snprintf(buf, MSG_SIZ,"name %s\n", gameInfo.white); @@ -8118,10 +8135,12 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. return; // [HGM] This return was missing, causing option features to be recognized as non-compliant commands! } - if (!appData.testLegality && !strncmp(message, "setup ", 6)) { // [HGM] allow first engine to define opening position + if ((!appData.testLegality || gameInfo.variant == VariantFairy) && + !strncmp(message, "setup ", 6)) { // [HGM] allow first engine to define opening position int dummy, s=6; char buf[MSG_SIZ]; - if(appData.icsActive || forwardMostMove != 0 || cps != &first || startedFromSetupPosition) return; + if(appData.icsActive || forwardMostMove != 0 || cps != &first) return; if(sscanf(message, "setup (%s", buf) == 1) s = 8 + strlen(buf), buf[s-9] = NULLCHAR, SetCharTable(pieceToChar, buf); + if(startedFromSetupPosition) return; ParseFEN(boards[0], &dummy, message+s); DrawPosition(TRUE, boards[0]); startedFromSetupPosition = TRUE; @@ -8350,6 +8369,8 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. parseList[currentMove], _(cps->which)); DisplayMoveError(buf1); DrawPosition(FALSE, boards[currentMove]); + + SetUserThinkingEnables(); return; } if (strncmp(message, "time", 4) == 0 && StrStr(message, "Illegal")) { @@ -8654,7 +8675,7 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. if(f = fopen(buf, "w")) { // export PV to applicable PV file fprintf(f, "%5.2f/%-2d %s", curscore/100., plylev, pv); fclose(f); - } else DisplayError("failed writing PV", 0); + } else DisplayError(_("failed writing PV"), 0); } tempStats.depth = plylev; @@ -9537,6 +9558,7 @@ InitChessProgram(cps, setup) hintRequested = FALSE; bookRequested = FALSE; + ParseFeatures(appData.features[cps == &second], cps); // [HGM] allow user to overrule features /* [HGM] some new WB protocol commands to configure engine are sent now, if engine supports them */ /* moved to before sending initstring in 4.3.15, so Polyglot can delay UCI 'isready' to recepton of 'new' */ if(cps->memSize) { /* [HGM] memory */ @@ -9923,6 +9945,7 @@ void SwapEngines(int n) SWAP(logo, p) SWAP(pgnName, p) SWAP(pvSAN, h) + SWAP(engOptions, p) } void @@ -10469,6 +10492,7 @@ GameEnds(result, resultDetails, whosays) first.matchWins, second.matchWins, appData.matchGames - (first.matchWins + second.matchWins)); if(!appData.tourneyFile[0]) matchGame++, DisplayTwoMachinesTitle(); // [HGM] update result in window title + if(ranking && strcmp(ranking, "busy") && appData.afterTourney && appData.afterTourney[0]) RunCommand(appData.afterTourney); popupRequested++; // [HGM] crash: postpone to after resetting endingGame if (appData.firstPlaysBlack) { // [HGM] match: back to original for next match first.twoMachinesColor = "black\n"; @@ -10636,6 +10660,7 @@ Reset(redraw, init) ModeHighlight(); if(appData.icsActive) gameInfo.variant = VariantNormal; currentMove = forwardMostMove = backwardMostMove = 0; + MarkTargetSquares(1); InitPosition(redraw); for (i = 0; i < MAX_MOVES; i++) { if (commentList[i] != NULL) { @@ -11567,7 +11592,7 @@ LoadGame(f, gameNumber, title, useList) yynewfile(f); if (lg && lg->gameInfo.white && lg->gameInfo.black) { - snprintf(buf, sizeof(buf), "%s vs. %s", lg->gameInfo.white, + snprintf(buf, sizeof(buf), _("%s vs. %s"), lg->gameInfo.white, lg->gameInfo.black); DisplayTitle(buf); } else if (*title != NULLCHAR) { @@ -12195,7 +12220,7 @@ SaveGameToFile(filename, append) DisplayMessage(_("Waiting for access to save file"), ""); flock(fileno(f), LOCK_EX); // [HGM] lock: lock file while we are writing DisplayMessage(_("Saving game"), ""); - if(lseek(fileno(f), 0, SEEK_END) == -1) DisplayError("Bad Seek", errno); // better safe than sorry... + if(lseek(fileno(f), 0, SEEK_END) == -1) DisplayError(_("Bad Seek"), errno); // better safe than sorry... result = SaveGame(f, 0, NULL); DisplayMessage(buf, ""); return result; @@ -13182,7 +13207,7 @@ MachineWhiteEvent() pausing = FALSE; ModeHighlight(); SetGameInfo(); - snprintf(buf, MSG_SIZ, "%s vs. %s", gameInfo.white, gameInfo.black); + snprintf(buf, MSG_SIZ, _("%s vs. %s"), gameInfo.white, gameInfo.black); DisplayTitle(buf); if (first.sendName) { snprintf(buf, MSG_SIZ, "name %s\n", gameInfo.black); @@ -13259,7 +13284,7 @@ MachineBlackEvent() pausing = FALSE; ModeHighlight(); SetGameInfo(); - snprintf(buf, MSG_SIZ, "%s vs. %s", gameInfo.white, gameInfo.black); + snprintf(buf, MSG_SIZ, _("%s vs. %s"), gameInfo.white, gameInfo.black); DisplayTitle(buf); if (first.sendName) { snprintf(buf, MSG_SIZ, "name %s\n", gameInfo.white); @@ -13304,24 +13329,24 @@ DisplayTwoMachinesTitle() char buf[MSG_SIZ]; if (appData.matchGames > 0) { if(appData.tourneyFile[0]) { - snprintf(buf, MSG_SIZ, "%s vs. %s (%d/%d%s)", + snprintf(buf, MSG_SIZ, _("%s vs. %s (%d/%d%s)"), gameInfo.white, gameInfo.black, nextGame+1, appData.matchGames+1, appData.tourneyType>0 ? "gt" : appData.tourneyType<0 ? "sw" : "rr"); } else if (first.twoMachinesColor[0] == 'w') { - snprintf(buf, MSG_SIZ, "%s vs. %s (%d-%d-%d)", + snprintf(buf, MSG_SIZ, _("%s vs. %s (%d-%d-%d)"), gameInfo.white, gameInfo.black, first.matchWins, second.matchWins, matchGame - 1 - (first.matchWins + second.matchWins)); } else { - snprintf(buf, MSG_SIZ, "%s vs. %s (%d-%d-%d)", + snprintf(buf, MSG_SIZ, _("%s vs. %s (%d-%d-%d)"), gameInfo.white, gameInfo.black, second.matchWins, first.matchWins, matchGame - 1 - (first.matchWins + second.matchWins)); } } else { - snprintf(buf, MSG_SIZ, "%s vs. %s", gameInfo.white, gameInfo.black); + snprintf(buf, MSG_SIZ, _("%s vs. %s"), gameInfo.white, gameInfo.black); } DisplayTitle(buf); } @@ -14878,6 +14903,7 @@ if(appData.debugMode) fprintf(debugFP, "Append: in='%s' %d\n", text, addBraces); while (*text == '\n') text++; len = strlen(text); while (len > 0 && text[len - 1] == '\n') len--; + text[len] = NULLCHAR; if (len == 0) return; @@ -15457,6 +15483,7 @@ ParseFeatures(args, cps) if (*p == NULLCHAR) return; if (BoolFeature(&p, "setboard", &cps->useSetboard, cps)) continue; + if (BoolFeature(&p, "xedit", &cps->extendedEdit, cps)) continue; if (BoolFeature(&p, "time", &cps->sendTime, cps)) continue; if (BoolFeature(&p, "draw", &cps->sendDrawOffers, cps)) continue; if (BoolFeature(&p, "sigint", &cps->useSigint, cps)) continue;