X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=uci.c;h=5eeda2b5ebc83639d60a0fa1cbbf052b45abaa76;hb=01f882089a19430bb12ab89d1ba1b56cf7a2cc6b;hp=f02507f1df2b2fc9e999d89b2003ef80b92fae8b;hpb=bb1c4f8ed2489e4891fe044532a35107d33174d2;p=xboard.git diff --git a/uci.c b/uci.c index f02507f..5eeda2b 100644 --- a/uci.c +++ b/uci.c @@ -24,91 +24,49 @@ */ #include #include -#include +#include -#ifdef WIN32 -// [HGM] this was probably a Windows-specific constant. Needs to be defined here now I -// threw out the Windows-specific includes (winboard.h etc.). 100 seems enough. -#include -#define SLASH_CHAR "\\" -#else -#define MAX_PATH 100 -#define SLASH_CHAR "/" +#if HAVE_MALLOC_H + #include #endif #include "common.h" #include "backend.h" - -#define INIFILE_PREFIX "polyglot_" -#define INIFILE_SUFFIX_1ST "1st" -#define INIFILE_SUFFIX_2ND "2nd" -#define INIFILE_EXT ".ini" - - -static const char * GetIniFilename( ChessProgramState * cps ) -{ - return cps == &first ? INIFILE_PREFIX INIFILE_SUFFIX_1ST INIFILE_EXT : INIFILE_PREFIX INIFILE_SUFFIX_2ND INIFILE_EXT; - } +Boolean GetArgValue(char *a); void InitEngineUCI( const char * iniDir, ChessProgramState * cps ) -{ +{ // replace engine command line by adapter command with expanded meta-symbols if( cps->isUCI ) { - const char * iniFileName = GetIniFilename( cps ); - char polyglotIniFile[ MAX_PATH ]; - FILE * f; - - /* Build name of initialization file */ - if( strchr( iniDir, ' ' ) != NULL ) { - char iniDirShort[ MAX_PATH ]; -#ifdef WIN32 - GetShortPathName( iniDir, iniDirShort, sizeof(iniDirShort) ); - - strcpy( polyglotIniFile, iniDirShort ); -#else - // [HGM] UCI: not sure if this works, but GetShortPathName seems Windows pecific - // and names with spaces in it do not work in xboard in many places, so ignore - strcpy( polyglotIniFile, iniDir ); -#endif - } - else { - strcpy( polyglotIniFile, iniDir ); - } - - strcat( polyglotIniFile, SLASH_CHAR ); - strcat( polyglotIniFile, iniFileName ); - - /* Create initialization file */ - f = fopen( polyglotIniFile, "w" ); - - if( f != NULL ) { - fprintf( f, "[Polyglot]\n" ); - - if( cps->dir != 0 && strlen(cps->dir) > 0 ) { - fprintf( f, "EngineDir = %s\n", cps->dir ); + char *p, *q; + char polyglotCommand[MSG_SIZ]; + + p = appData.adapterCommand; + q = polyglotCommand; + while(*p) { + if(*p == '\\') p++; else + if(*p == '%') { // substitute marker + char argName[MSG_SIZ], buf[MSG_SIZ], *s = buf; + if(*++p == '%') { // second %, expand as f or s in option name (e.g. %%cp -> fcp) + *s++ = cps == &first ? 'f' : 's'; + p++; } - - if( cps->program != 0 && strlen(cps->program) > 0 ) { - fprintf( f, "EngineCommand = %s\n", cps->program ); - } - - fprintf( f, "Book = %s\n", appData.usePolyglotBook ? "true" : "false" ); - fprintf( f, "BookFile = %s\n", appData.polyglotBook ); - - fprintf( f, "[Engine]\n" ); - fprintf( f, "Hash = %d\n", appData.defaultHashSize ); - - fprintf( f, "NalimovPath = %s\n", appData.defaultPathEGTB ); - fprintf( f, "NalimovCache = %d\n", appData.defaultCacheSizeEGTB ); - - fprintf( f, "OwnBook = %s\n", cps->hasOwnBookUCI ? "true" : "false" ); - - fclose( f ); - - /* Replace program with properly configured Polyglot */ - cps->dir = appData.polyglotDir; - cps->program = (char *) malloc( strlen(polyglotIniFile) + 32 ); - strcpy( cps->program, "polyglot " ); - strcat( cps->program, polyglotIniFile ); + while(*p >= '0' && *p) *s++ = *p++; // copy option name + *s = NULLCHAR; + if(cps == &second) { // change options for first into those for second engine + if(strstr(buf, "first") == buf) sprintf(argName, "second%s", buf+5); else + if(buf[0] == 'f') sprintf(argName, "s%s", buf+1); else + strcpy(argName, buf); + } else strcpy(argName, buf); + if(GetArgValue(argName)) { // look up value of option with this name + s = argName; + while(*s) *q++ = *s++; + } else DisplayFatalError("Bad adapter command", 0, 1); + continue; + } + if(*p) *q++ = *p++; } + *q = NULLCHAR; + cps->program = StrSave(polyglotCommand); + cps->dir = appData.polyglotDir; } }