-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuci.c
73 lines (70 loc) · 2.7 KB
/
uci.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* UCI support thru Polyglot
*
* Author: Alessandro Scotti (Jan 2006)
*
* Copyright 2006 Alessandro Scotti
*
* Enhancement Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc.
*
* ------------------------------------------------------------------------
*
* GNU XBoard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* GNU XBoard is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
* ------------------------------------------------------------------------
*/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "backend.h"
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 ) {
char *p, *q;
char polyglotCommand[MSG_SIZ];
if(cps->isUCI == 2) p = appData.ucciAdapter; else
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++;
}
while(isdigit(*p) || isalpha(*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
safeStrCpy(argName, buf, sizeof(argName)/sizeof(argName[0]));
} else safeStrCpy(argName, buf, sizeof(argName)/sizeof(argName[0]));
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;
}
}