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