X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=uci.c;fp=uci.c;h=0885ee01f2692e34f12abe968bf7935e036c63c8;hb=8f1501373295f172dd1118391c6ee914ecbc4e67;hp=d0f76c4afcd67f30dfedef21bc051733bebf0ad6;hpb=d13479fa8f80542d1fef82b56c87c8f68573bfba;p=xboard.git diff --git a/uci.c b/uci.c index d0f76c4..0885ee0 100644 --- a/uci.c +++ b/uci.c @@ -29,89 +29,38 @@ #include #endif -#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 "/" -#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; - } 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], *s = argName; + 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 != ' ' && *p) *s++ = *p++; // copy option name + *s = NULLCHAR; + 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; } }