2 * UCI support thru Polyglot
4 * Author: Alessandro Scotti (Jan 2006)
6 * Copyright 2006 Alessandro Scotti
8 * Enhancement Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015,
9 * 2016 Free Software Foundation, Inc.
11 * ------------------------------------------------------------------------
13 * GNU XBoard is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or (at
16 * your option) any later version.
18 * GNU XBoard is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see http://www.gnu.org/licenses/.
26 * ------------------------------------------------------------------------
35 Boolean GetArgValue(char *a);
38 InitEngineUCI (const char *iniDir, ChessProgramState *cps)
39 { // replace engine command line by adapter command with expanded meta-symbols
42 char polyglotCommand[MSG_SIZ];
44 if(cps->isUCI == 2) p = appData.ucciAdapter; else
45 p = appData.adapterCommand;
48 if(*p == '\\') p++; else
49 if(*p == '%') { // substitute marker
50 char argName[MSG_SIZ], buf[MSG_SIZ], *s = buf;
51 if(*++p == '%') { // second %, expand as f or s in option name (e.g. %%cp -> fcp)
52 *s++ = cps == &first ? 'f' : 's';
55 while(isdigit(*p) || isalpha(*p)) *s++ = *p++; // copy option name
57 if(cps == &second) { // change options for first into those for second engine
58 if(strstr(buf, "first") == buf) sprintf(argName, "second%s", buf+5); else
59 if(buf[0] == 'f') sprintf(argName, "s%s", buf+1); else
60 safeStrCpy(argName, buf, sizeof(argName)/sizeof(argName[0]));
61 } else safeStrCpy(argName, buf, sizeof(argName)/sizeof(argName[0]));
62 if(GetArgValue(argName)) { // look up value of option with this name
64 while(*s) *q++ = *s++;
65 } else DisplayFatalError("Bad adapter command", 0, 1);
71 cps->program = StrSave(polyglotCommand);
72 cps->dir = appData.polyglotDir;