X-Git-Url: http://winboard.nl/cgi-bin?p=polyglot.git;a=blobdiff_plain;f=main.c;h=21bbe17ec97a1b31a499774a25bce1e811a30fe3;hp=60b1c5d7fed9c99e694aa7bab75cb6fdba1b95dc;hb=de010509fa0e57ba955da6512c714fbff8606af3;hpb=a522b5e3c945c6b03810a870bc7016b0b6023c64 diff --git a/main.c b/main.c index 60b1c5d..21bbe17 100644 --- a/main.c +++ b/main.c @@ -39,10 +39,10 @@ // constants -static const char * const Version = "1.4.51b"; +static const char * const Version = "1.4.58b"; static const char * const HelpMessage = "\ SYNTAX\n\ -* polyglot [configfile] [-noini] [-ec engine] [-ed enginedirectory] [-en enginename] [-log] [-lf logfile] [-hash value] [-bk book] [-pg =]* [-uci =]*\n\ +* polyglot [configfile] [-noini] [-ec engine] [-ed enginedirectory] [-en enginename] [-log true/false] [-lf logfile] [-pg =]* [-uci =]*\n\ * polyglot make-book [-pgn inputfile] [-bin outputfile] [-max-ply ply] [-min-game games] [-min-score score] [-only-white] [-only-black] [-uniform]\n\ * polyglot merge-book -in1 inputfile1 -in2 inputfile2 [-out outputfile]\n\ * polyglot info-book [-bin inputfile] [-exact]\n\ @@ -185,9 +185,12 @@ static void make_ini(ini_t *ini){ static void write_ini(const char *filename, ini_t *ini){ + // TODO Quote, dequote const char *quote; ini_entry_t *entry; char tmp[StringSize]; + char tmp1[StringSize]; + char tmp2[StringSize]; FILE *f; time_t t=time(NULL); f=fopen(filename,"w"); @@ -201,16 +204,11 @@ static void write_ini(const char *filename, ini_start_iter(ini); while((entry=ini_next(ini))){ if(my_string_case_equal(entry->section,"polyglot")){ - if(strchr(entry->value,';')|| strchr(entry->value,'#')|| strchr(entry->value,'"')){ - quote="\""; - }else{ - quote=""; - } - snprintf(tmp,sizeof(tmp),"%s=%s%s%s\n", - entry->name, - quote, - entry->value, - quote); + my_quote(tmp1,entry->name,ini_specials); + my_quote(tmp2,entry->value,ini_specials); + snprintf(tmp,sizeof(tmp),"%s=%s\n", + tmp1, + tmp2); tmp[sizeof(tmp)-1]='\0'; fprintf(f,"%s",tmp); } @@ -218,17 +216,12 @@ static void write_ini(const char *filename, fprintf(f,"[Engine]\n"); ini_start_iter(ini); while((entry=ini_next(ini))){ - if(my_string_case_equal(entry->section,"engine")){ - if(strchr(entry->value,';')|| strchr(entry->value,'#')|| strchr(entry->value,'"')){ - quote="\""; - }else{ - quote=""; - } - snprintf(tmp,sizeof(tmp),"%s=%s%s%s\n", - entry->name, - quote, - entry->value, - quote); + if(my_string_case_equal(entry->section,"engine")){ + my_quote(tmp1,entry->name,ini_specials); + my_quote(tmp2,entry->value,ini_specials); + snprintf(tmp,sizeof(tmp),"%s=%s\n", + tmp1, + tmp2); tmp[sizeof(tmp)-1]='\0'; fprintf(f,"%s",tmp); } @@ -287,6 +280,8 @@ int main(int argc, char * argv[]) { Init = FALSE; + gui_init(GUI); + util_init(); option_init_pg(); @@ -369,7 +364,7 @@ int main(int argc, char * argv[]) { if(!my_string_equal(option_get_string(Option,"SettingsFile"),"")){ if(ini_parse(ini,option_get_string(Option,"SettingsFile"))){ - my_fatal("main(): Can't open file \"%s\": %s\n", + my_fatal("main(): Can't open config file \"%s\": %s\n", option_get_string(Option,"SettingsFile"), strerror(errno)); } @@ -442,11 +437,17 @@ int main(int argc, char * argv[]) { option_set(Option,entry->name,entry->value); } + // Make sure that EngineCommand has been set + if(my_string_case_equal(option_get(Option,"EngineCommand"),"")){ + my_fatal("main(): EngineCommand not set\n"); + } + // start engine engine_open(Engine); + if(!engine_active(Engine)){ - my_fatal("Could not start \"%s\"\n",option_get(Option,"EngineCommand")); + my_fatal("main(): Could not start \"%s\"\n",option_get(Option,"EngineCommand")); } // switch to UCI mode if necessary @@ -458,6 +459,7 @@ int main(int argc, char * argv[]) { // initialize uci parsing and send uci command. // Parse options and wait for uciok + // XXX uci_open(Uci,Engine); option_set_default(Option,"EngineName",Uci->name); @@ -543,11 +545,6 @@ int main(int argc, char * argv[]) { if(my_string_case_equal(entry->section,"engine")){ // also updates value in Uci->option uci_send_option(Uci,entry->name,"%s",entry->value); - // this is inherited, it probably does not work correctly - if(my_string_case_equal(entry->name,"MultiPV") && - atoi(entry->value)>1){ - Uci->multipv_mode=TRUE; - } } } @@ -569,11 +566,11 @@ int main(int argc, char * argv[]) { argc=1; while((arg=argv[argc++])){ if(!my_string_equal(arg,"")){ - my_fatal("main(): Option: \"%s\" not found\n",argv[argc-1]); + my_fatal("main(): Incorrect use of option: \"%s\"\n",argv[argc-1]); } } - gui_init(GUI); + // gui_init(GUI); mainloop(); return EXIT_SUCCESS; } @@ -584,7 +581,7 @@ void polyglot_set_option(const char *name, const char *value){ // this must be c ini_t ini[1]; int ret; ini_init(ini); - my_log("POLYGLOT Setting PolyGlot option %s=\"%s\"\n",name,value); + my_log("POLYGLOT Setting PolyGlot option \"%s=%s\"\n",name,value); if(my_string_case_equal(name,"Save")){ ret=my_mkdir(option_get(Option,"SettingsDir")); if(ret){ @@ -637,18 +634,16 @@ void polyglot_set_option(const char *name, const char *value){ // this must be c // quit() void quit() { - my_log("POLYGLOT *** QUIT ***\n"); - - if (Init) { - + if (Init && !Engine->pipex->quit_pending) { stop_search(); + Engine->pipex->quit_pending=TRUE; engine_send(Engine,"quit"); - my_log("POLYGLOT Closing engine\n"); engine_close(Engine); } - my_log("POLYGLOT Calling exit\n"); + my_sleep(200); + my_log("POLYGLOT Calling exit\n"); exit(EXIT_SUCCESS); }