From: H.G. Muller Date: Tue, 1 Sep 2009 03:29:49 +0000 (-0700) Subject: workaround for error message for missing pieces used in variants and initstring bugfix X-Git-Tag: v4.4.0.beta2 X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=495294ea0ecf08fae79348f0599b33047936dfc0;p=xboard.git workaround for error message for missing pieces used in variants and initstring bugfix error messages showed for non-existing pieces showed up for old user supplied pixmaps. Loading a pixmap of the king for the missing pieces now. Another bad bug surfaced: the -initString argument does not work in any XBoard version! (Including 4.2.7b) The escape sequences for linefeed in the string are not understood: -initString "new\nrandom\n" actually sends the \ and n to the engine (which then does not recognize the line as a valid command)! So I also added a patch to expand escape sequences in the InitString and ComputerString command-line options. --- diff --git a/xboard.c b/xboard.c index d539705..7b1fe43 100644 --- a/xboard.c +++ b/xboard.c @@ -2320,6 +2320,19 @@ void InitDrawingSizes(BoardSize boardSize, int flags) } #endif +void EscapeExpand(char *p, char *q) +{ // [HGM] initstring: routine to shape up string arguments + while(*p++ = *q++) if(p[-1] == '\\') + switch(*q++) { + case 'n': p[-1] = '\n'; break; + case 'r': p[-1] = '\r'; break; + case 't': p[-1] = '\t'; break; + case '\\': p[-1] = '\\'; break; + case 0: *p = 0; return; + default: p[-1] = q[-1]; break; + } +} + int main(argc, argv) int argc; @@ -2378,7 +2391,6 @@ main(argc, argv) #endif #endif - setbuf(stdout, NULL); setbuf(stderr, NULL); debugFP = stderr; @@ -2419,16 +2431,6 @@ main(argc, argv) exit(2); } - if ((chessDir = (char *) getenv("CHESSDIR")) == NULL) { - chessDir = "."; - } else { - if (chdir(chessDir) != 0) { - fprintf(stderr, _("%s: can't cd to CHESSDIR: "), programName); - perror(chessDir); - exit(1); - } - } - p = getenv("HOME"); if (p == NULL) p = "/tmp"; i = strlen(p) + strlen("/.xboardXXXXXx.pgn") + 1; @@ -2441,6 +2443,28 @@ main(argc, argv) clientResources, XtNumber(clientResources), NULL, 0); + { // [HGM] initstring: kludge to fix bad bug. expand '\n' characters in init string and computer string. + static char buf[MSG_SIZ]; + EscapeExpand(buf, appData.initString); + appData.initString = strdup(buf); + EscapeExpand(buf, appData.secondInitString); + appData.secondInitString = strdup(buf); + EscapeExpand(buf, appData.firstComputerString); + appData.firstComputerString = strdup(buf); + EscapeExpand(buf, appData.secondComputerString); + appData.secondComputerString = strdup(buf); + } + + if ((chessDir = (char *) getenv("CHESSDIR")) == NULL) { + chessDir = "."; + } else { + if (chdir(chessDir) != 0) { + fprintf(stderr, _("%s: can't cd to CHESSDIR: "), programName); + perror(chessDir); + exit(1); + } + } + if (appData.debugMode && appData.nameOfDebugFile && strcmp(appData.nameOfDebugFile, "stderr")) { /* [DM] debug info to file [HGM] make the filename a command-line option, and allow it to remain stderr */ if ((debugFP = fopen(appData.nameOfDebugFile, "w")) == NULL) { @@ -3953,9 +3977,23 @@ void CreateXPMPieces() if ((r=XpmReadFileToPixmap(xDisplay, xBoardWindow, buf, &(xpmPieceBitmap2[kind][piece]), NULL, &attr)) != 0) { - fprintf(stderr, _("Error %d loading XPM file \"%s\"\n"), - r, buf); - exit(1); + if(piece != (int)WhiteKing && piece > (int)WhiteQueen) { + // [HGM] missing: read of unorthodox piece failed; substitute King. + snprintf(buf, sizeof(buf), "%s/k%s%u.xpm", + ExpandPathName(appData.pixmapDirectory), + xpmkind[kind], ss); + if (appData.debugMode) { + fprintf(stderr, _("(Replace by File:%s:) "), buf); + } + r=XpmReadFileToPixmap(xDisplay, xBoardWindow, buf, + &(xpmPieceBitmap2[kind][piece]), + NULL, &attr); + } + if (r != 0) { + fprintf(stderr, _("Error %d loading XPM file \"%s\"\n"), + r, buf); + exit(1); + } } if(piece <= (int) WhiteKing) xpmPieceBitmap[kind][piece] = xpmPieceBitmap2[kind][piece]; @@ -9445,4 +9483,4 @@ SetProgramStats( FrontEndProgramStats * stats ) // [HR] TODO // [HGM] done, but perhaps backend should call this directly? EngineOutputUpdate( stats ); -} +} \ No newline at end of file