// constants\r
\r
\r
-static const char * const Version = "1.4.41b";\r
+static const char * const Version = "1.4.42b";\r
static const char * const HelpMessage = "\\r
SYNTAX\n\\r
* polyglot [configfile] [-noini] [-ec engine] [-ed enginedirectory] [-en enginename] [-log] [-lf logfile] [-hash value] [-bk book] [-pg <name>=<value>]* [-uci <name>=<value>]*\n\\r
\r
// arg_shift_left()\r
\r
-void arg_shift_left(char **argv, int index){\r
+static void arg_shift_left(char **argv, int index){\r
int i;\r
for(i=index; argv[i]!=NULL; i++){\r
argv[i]=argv[i+1];\r
}\r
}\r
\r
+// write_ini()\r
\r
-void write_ini(const char *filename,\r
- option_list_t *pg_options,\r
- option_list_t *uci_options){\r
+static void write_ini(const char *filename,\r
+ option_list_t *pg_options,\r
+ option_list_t *uci_options){\r
option_t *opt;\r
char tmp[StringSize];\r
FILE *f;\r
fprintf(f,"[PolyGlot]\n");\r
option_start_iter(pg_options);\r
while((opt=option_next(pg_options))){\r
- if(!my_string_case_equal(opt->type,"button") && (opt->mode & XBOARD)){\r
+ if(!my_string_equal(opt->value,opt->default_)&&\r
+ !my_string_case_equal(opt->type,"button") &&\r
+ (opt->mode & XBOARD)){\r
snprintf(tmp,sizeof(tmp),"%s=%s\n",opt->name,opt->value);\r
tmp[sizeof(tmp)-1]='\0';\r
fprintf(f,"%s",tmp);\r
fprintf(f,"[Engine]\n");\r
option_start_iter(uci_options);\r
while((opt=option_next(uci_options))){\r
- if(!my_string_case_equal(opt->type,"button")){\r
+ if(!my_string_equal(opt->value,opt->default_)&&\r
+ !my_string_case_equal(opt->type,"button")){\r
snprintf(tmp,sizeof(tmp),"%s=%s\n",opt->name,opt->value);\r
tmp[sizeof(tmp)-1]='\0';\r
fprintf(f,"%s",tmp);\r
// main()\r
\r
int main(int argc, char * argv[]) {\r
- ini_t ini[1];\r
+ ini_t ini[1],ini_save[1];\r
ini_entry_t *entry;\r
char *arg;\r
int arg_index;\r
\r
my_random_init();\r
\r
+ ini_init(ini);\r
+ ini_init(ini_save);\r
+\r
// book utilities\r
\r
if (argc >= 2 && my_string_equal(argv[1],"make-book")) {\r
return EXIT_SUCCESS;\r
}\r
\r
- // what is the config file? This is very hacky right now?\r
+ // TODO: If logging is enabled on the command line turn it on NOW\r
+ // and do not allow it to be overridden later. \r
+ \r
+ // What is the config file? This is very hacky right now.\r
\r
// Do we want a config file at all?\r
\r
arg_shift_left(argv,1);\r
}else{\r
// Config file is the default.\r
- // This has already been set above or in "option_init_pg"\r
+ // This has already been set above or in "option_init_pg()"\r
}\r
\r
- ini_init(ini);\r
\r
// if we use a config file: load it!\r
\r
strerror(errno));\r
}\r
}\r
+ // remind the reader of what options are in effect\r
+\r
+ my_log("POLYGLOG Options from ini file\n");\r
+ ini_disp(ini);\r
+\r
+ // extract PG options\r
+ \r
+ ini_start_iter(ini);\r
+ while((entry=ini_next(ini))){\r
+ if(my_string_case_equal(entry->section,"polyglot")){\r
+ option_set(Option,entry->name,entry->value);\r
+ option_set_default(Option,entry->name,entry->value);\r
+ }\r
+ }\r
+\r
+ // start logging if required\r
+ \r
+ if (option_get_bool(Option,"Log")) {\r
+ my_log_open(option_get_string(Option,"LogFile"));\r
+ }\r
\r
- // parse the command line and merge options\r
+ // log welcome stuff\r
+ \r
+ if(!DEBUG){\r
+ my_log("PolyGlot %s by Fabien Letouzey\n",Version);\r
+ }else{\r
+ my_log("PolyGlot %s by Fabien Letouzey (debug build)\n",Version);\r
+ } \r
+ my_log("POLYGLOT *** START ***\n");\r
+ my_log("POLYGLOT INI file \"%s\"\n",option_get_string(Option,"OptionFile"));\r
+\r
+ // open book (presumably this should go else where)\r
+ \r
+ init_book();\r
\r
+ // scavenge command line for options necessary to start the engine\r
+ \r
arg_index=1;\r
while((arg=argv[arg_index])){\r
-// int i=1;\r
-// char *arg1;\r
-// printf("arg_index=%d\n",arg_index);\r
-// while((arg1=argv[i++])){\r
-// printf("arg=%s ",arg1);\r
-// }\r
-// printf("\n");\r
if(my_string_equal(arg,"-ec") && argv[arg_index+1]){\r
- ini_insert_ex(ini,"PolyGlot","EngineCommand",argv[arg_index+1]);\r
+ option_set(Option,"EngineCommand",argv[arg_index+1]);\r
arg_shift_left(argv,arg_index);\r
arg_shift_left(argv,arg_index);\r
continue;\r
}\r
if(my_string_equal(arg,"-ed") && argv[arg_index+1]){\r
- ini_insert_ex(ini,"PolyGlot","EngineDir",argv[arg_index+1]);\r
+ option_set(Option,"EngineDir",argv[arg_index+1]);\r
arg_shift_left(argv,arg_index);\r
arg_shift_left(argv,arg_index);\r
continue;\r
}\r
if(my_string_equal(arg,"-en") && argv[arg_index+1]){\r
- ini_insert_ex(ini,"PolyGlot","EngineName",argv[arg_index+1]);\r
+ option_set(Option,"EngineName",argv[arg_index+1]);\r
arg_shift_left(argv,arg_index);\r
arg_shift_left(argv,arg_index);\r
continue;\r
}\r
+ arg_index++;\r
+ }\r
+\r
+ // start engine\r
+ \r
+ engine_open(Engine);\r
+ if(!engine_active(Engine)){\r
+ my_fatal("Could not start \"%s\"\n",option_get(Option,"EngineCommand"));\r
+ }\r
+\r
+ // switch to UCI mode if necessary\r
+ \r
+ if (option_get_bool(Option,"UCI")) {\r
+ my_log("POLYGLOT *** Switching to UCI mode ***\n");\r
+ }\r
+\r
+ // initialize uci parsing and send uci command. Parse options and wait\r
+ // for uciok\r
+ \r
+ uci_open(Uci,Engine);\r
+\r
+ // get engine name from engine if not supplied in config file\r
+ \r
+ if (my_string_equal(option_get_string(Option,"EngineName"),"<empty>")) {\r
+ option_set(Option,"EngineName",Uci->name);\r
+ }\r
+\r
+ // what is the name of the persist file?\r
+\r
+ if(my_string_equal(option_get_string(Option,"PersistFile"),"<empty>")){\r
+ char tmp[StringSize];\r
+ snprintf(tmp,sizeof(tmp),"PG_%s.ini",\r
+ option_get_string(Option,"EngineName"));\r
+ tmp[sizeof(tmp)-1]='\0';\r
+ option_set(Option,"PersistFile",tmp);\r
+ }\r
+\r
+ // if "Persist" is true, load the persist file!\r
+ \r
+ if(option_get_bool(Option,"Persist")){\r
+ my_log("POLYGLOT PersistFile=%s\n",option_get_string(Option,"PersistFile"));\r
+ if(ini_parse(ini_save,option_get_string(Option,"PersistFile"))){\r
+ my_log("POLYGLOT Unable to open PersistFile\n"); \r
+ }\r
+ }\r
+ \r
+ // parse the command line and merge remaining options\r
+\r
+ arg_index=1;\r
+ while((arg=argv[arg_index])){\r
if(my_string_equal(arg,"-log")){\r
- ini_insert_ex(ini,"PolyGlot","Log","true");\r
+ ini_insert_ex(ini_save,"PolyGlot","Log","true");\r
arg_shift_left(argv,arg_index);\r
continue;\r
}\r
if(my_string_equal(arg,"-lf") && argv[arg_index+1]){\r
- ini_insert_ex(ini,"PolyGlot","LogFile",argv[arg_index+1]);\r
+ ini_insert_ex(ini_save,"PolyGlot","LogFile",argv[arg_index+1]);\r
arg_shift_left(argv,arg_index);\r
arg_shift_left(argv,arg_index);\r
continue;\r
}\r
if(my_string_equal(arg,"-hash") && argv[arg_index+1]){\r
- ini_insert_ex(ini,"Engine","Hash",argv[arg_index+1]);\r
+ ini_insert_ex(ini_save,"Engine","Hash",argv[arg_index+1]);\r
arg_shift_left(argv,arg_index);\r
arg_shift_left(argv,arg_index);\r
continue;\r
}\r
if(my_string_equal(arg,"-bk") && argv[arg_index+1]){\r
- ini_insert_ex(ini,"PolyGlot","Book","true");\r
- ini_insert_ex(ini,"PolyGlot","BookFile",argv[arg_index+1]);\r
+ ini_insert_ex(ini_save,"PolyGlot","Book","true");\r
+ ini_insert_ex(ini_save,"PolyGlot","BookFile",argv[arg_index+1]);\r
arg_shift_left(argv,arg_index);\r
arg_shift_left(argv,arg_index);\r
continue;\r
ret=ini_line_parse(argv[arg_index++],section,name,value);\r
if(ret==NAME_VALUE){\r
if(my_string_equal(arg,"-pg")){\r
- ini_insert_ex(ini,"PolyGlot",name,value);\r
+ ini_insert_ex(ini_save,"PolyGlot",name,value);\r
}else{\r
- ini_insert_ex(ini,"Engine",name,value);\r
+ ini_insert_ex(ini_save,"Engine",name,value);\r
}\r
}\r
arg_shift_left(argv,arg_index);\r
arg_index++;\r
}\r
\r
- // extract PG options\r
- // this sets both the default and the value\r
- \r
- option_from_ini(Option,ini,"polyglot");\r
- \r
- // start logging if required\r
- \r
- if (option_get_bool(Option,"Log")) {\r
- my_log_open(option_get_string(Option,"LogFile"));\r
- }\r
-\r
- // log welcome stuff\r
- \r
- if(!DEBUG){\r
- my_log("PolyGlot %s by Fabien Letouzey\n",Version);\r
- }else{\r
- my_log("PolyGlot %s by Fabien Letouzey (debug build)\n",Version);\r
- } \r
- my_log("POLYGLOT *** START ***\n");\r
- my_log("POLYGLOT INI file \"%s\"\n",option_get_string(Option,"OptionFile"));\r
+ // remind the reader once again about options\r
\r
- // start engine\r
- \r
- engine_open(Engine);\r
- if(!engine_active(Engine)){\r
- my_fatal("Could not start \"%s\"\n",option_get(Option,"EngineCommand"));\r
- }\r
+ my_log("POLYGLOG Options from save file and command line\n");\r
+ ini_disp(ini_save);\r
\r
- // switch to UCI mode if necessary\r
+ // extract PG options; this time do not set the default\r
+ // polyglot_set_option() performs the necessary actions such\r
+ // as opening the log file/opening book etcetera.\r
\r
- if (option_get_bool(Option,"UCI")) {\r
- my_log("POLYGLOT *** Switching to UCI mode ***\n");\r
- }\r
-\r
- // initialize uci parsing and send uci command. Parse options and wait\r
- // for uciok\r
- \r
- uci_open(Uci,Engine);\r
-\r
- // get engine name from engine if not supplied in config file\r
- \r
- if (my_string_equal(option_get_string(Option,"EngineName"),"<empty>")) {\r
- option_set(Option,"EngineName",Uci->name);\r
- }\r
-\r
- // if there is a save file: load it!\r
-\r
- if(my_string_equal(option_get_string(Option,"SaveFile"),"<empty>")){\r
- char tmp[StringSize];\r
- snprintf(tmp,sizeof(tmp),"PG_%s.ini",\r
- option_get_string(Option,"EngineName"));\r
- tmp[sizeof(tmp)-1]='\0';\r
- option_set(Option,"SaveFile",tmp);\r
- }\r
- if(option_get_bool(Option,"SaveSettingsOnExit")){\r
- my_log("POLYGLOT SaveFile=%s\n",option_get_string(Option,"SaveFile"));\r
- if(ini_parse(ini,option_get_string(Option,"SaveFile"))){\r
- my_log("POLYGLOT Unable to open SaveFile\n"); \r
+ ini_start_iter(ini_save);\r
+ while((entry=ini_next(ini_save))){\r
+ if(my_string_case_equal(entry->section,"polyglot")){\r
+ polyglot_set_option(entry->name,entry->value);\r
}\r
}\r
- // start if it was enabled in the SaveFile\r
- \r
- my_log_close();\r
- if (option_get_bool(Option,"Log")) {\r
- my_log_open(option_get_string(Option,"LogFile"));\r
- }\r
- // remind the user of the options that are now in effect\r
- \r
- ini_disp(ini);\r
-\r
-\r
\r
// done initializing\r
\r
uci_send_option(Uci,entry->name,"%s",entry->value);\r
// since this comes from the ini file, also update default\r
option_set_default(Uci->option,entry->name,entry->value);\r
- //to get a decent display in winboard_x we need to now if an engine really is doing multipv analysis\r
- // "multipv 1" in the pv is meaningless,f.i. toga sends that all the time\r
- //therefore check if MultiPV is set to a decent value in the polyglot ini file\r
+ // this is inherited, it probably does not work correctly\r
if(my_string_case_equal(entry->name,"MultiPV") &&\r
atoi(entry->value)>1){\r
Uci->multipv_mode=TRUE;\r
}\r
}\r
}\r
+ ini_start_iter(ini_save);\r
+ while((entry=ini_next(ini_save))){\r
+ if(my_string_case_equal(entry->section,"engine")){\r
+ // also updates value in Uci->option\r
+ uci_send_option(Uci,entry->name,"%s",entry->value);\r
+ // this is inherited, it probably does not work correctly\r
+ if(my_string_case_equal(entry->name,"MultiPV") &&\r
+ atoi(entry->value)>1){\r
+ Uci->multipv_mode=TRUE;\r
+ }\r
+ }\r
+ }\r
\r
\r
// EPD test\r
}\r
\r
\r
- init_book();\r
gui_init(GUI);\r
mainloop();\r
return EXIT_SUCCESS; \r
}\r
\r
-// polyglot_set_option\r
+// polyglot_set_option()\r
\r
-void polyglot_set_option(char *name, char *value){ // this must be cleaned up!\r
+void polyglot_set_option(const char *name, const char *value){ // this must be cleaned up!\r
+ my_log("POLYGLOT Setting PolyGlot option %s=\"%s\"\n",name,value);\r
option_set(Option,name,value);\r
if(option_get_bool(Option,"Book")&&(my_string_case_equal(name,"BookFile")||my_string_case_equal(name,"Book"))){\r
my_log("POLYGLOT *** SETTING BOOK ***\n");\r
engine_close(Engine);\r
\r
}\r
- if(option_get_bool(Option,"SaveSettingsOnExit")){\r
- write_ini(option_get_string(Option,"SaveFile"),Option,Uci->option);\r
+ if(option_get_bool(Option,"Persist")){\r
+ write_ini(option_get_string(Option,"PersistFile"),\r
+ Option,Uci->option);\r
}\r
my_log("POLYGLOT Calling exit\n");\r
exit(EXIT_SUCCESS);\r