X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=uci.c;h=5eff8cce7f54ad93044d84addc39dabf3ed52e9b;hb=c6505b9bddf0ed2f461a473d4be40c98608d9866;hp=f8537e295bd0b492c6617586d5cd0d612f112609;hpb=a0f731f21d6aa26dbf7246039a1c66c2ade0533f;p=polyglot.git diff --git a/uci.c b/uci.c index f8537e2..5eff8cc 100644 --- a/uci.c +++ b/uci.c @@ -10,6 +10,7 @@ #include "board.h" #include "engine.h" +#include "gui.h" #include "move.h" #include "move_do.h" #include "move_legal.h" @@ -18,11 +19,12 @@ #include "line.h" #include "uci.h" + // constants static const bool UseDebug = FALSE; -static const int StringSize = 4096; +#define StringSize ((int)4096) // variables @@ -58,11 +60,34 @@ static int mate_score (int dist); // functions + +// uci_adapt_UCI3() + +static void apply_UCI3_heuristics(option_t *opt){ + if(option_get_int(Option,"UCIVersion")>2){ + return; + } + if(!my_string_equal(opt->type,"string")){ + return; + } + if(!strncmp(opt->name,"UCI_",4)){ + return; + } + if(my_string_case_contains(opt->name,"file")){ + my_string_set(&opt->type,"file"); + return; + } + if(my_string_case_contains(opt->name,"path")){ + my_string_set(&opt->type,"path"); + return; + } +} + // uci_set_threads() void uci_set_threads(uci_t * uci, int n) { - ASSERT(n>=1); const char *thread_option=uci_thread_option(uci); + ASSERT(n>=1); if(thread_option){ uci_send_option(uci,thread_option,"%d",n); } @@ -125,6 +150,11 @@ void uci_open(uci_t * uci, engine_t * engine) { do { engine_get(uci->engine,string); + // Handle the case that the engine is really a WB engine somewhat gracefully. + if((strstr(string,"Illegal") || strstr(string,"Error")) + &&strstr(string,"uci")){ + my_fatal("uci_open(): Not an UCI engine (not found).\n"); + } event = uci_parse(uci,string); } while (!engine_eof(Engine) && (event & EVENT_UCI) == 0); } @@ -162,8 +192,8 @@ void uci_clear(uci_t * uci) { uci->best_depth = 0; uci->best_sel_depth = 0; line_clear(uci->best_pv); - - uci->node_nb = 0; +// make the default 1 instead of 0 so that info lines can be recognized by their node number 0 + uci->node_nb = 1; uci->time = 0.0; uci->speed = 0.0; uci->cpu = 0.0; @@ -271,7 +301,7 @@ bool uci_send_option(uci_t * uci, const char option[], const char format[], ...) opt=option_find(uci->option,option); if(opt){ found=TRUE; - if(!my_string_case_equal(opt->type,"button")){ + if(!IS_BUTTON(opt->type)){ if(!my_string_equal(opt->value,value)){ engine_send(uci->engine,"setoption name %s value %s", opt->name,value); @@ -308,7 +338,7 @@ int uci_parse(uci_t * uci, const char string[]) { parse_open(parse,string); if (parse_get_word(parse,command,StringSize)) { - + parse_get_string(parse,argument,StringSize); if (UseDebug) my_log("POLYGLOT COMMAND \"%s\" ARGUMENT \"%s\"\n",command,argument); @@ -666,7 +696,8 @@ static int parse_info(uci_t * uci, const char string[]) { }else if(my_string_case_equal(argument,"Resign")){ event |= EVENT_RESIGN; }else{ - strcpy(uci->info,argument); + snprintf(uci->info,sizeof(uci->info),"%s",argument); + uci->info[sizeof(uci->info)-1]='\0'; event|=EVENT_INFO; } // TODO: argument to EOS @@ -692,11 +723,10 @@ static int parse_info(uci_t * uci, const char string[]) { } else { my_log("POLYGLOT unknown option \"%s\" for command \"%s\"\n",option,command); - // this is for buggy engines; it should probably be protected + // This should probably be protected // by a "WorkAround" option. - strcpy(uci->info,option); - strcat(uci->info," "); - strcat(uci->info,argument); + snprintf(uci->info,sizeof(uci->info),"%s %s",option,argument); + uci->info[sizeof(uci->info)-1]='\0'; event|=EVENT_INFO; } } @@ -805,6 +835,8 @@ static void parse_option(uci_t * uci, const char string[]) { } parse_close(parse); + + apply_UCI3_heuristics(opt); option_insert(uci->option,opt); option_free(opt);