From: H.G. Muller Date: Thu, 9 Jun 2011 08:12:13 +0000 (+0200) Subject: verson 1.4.54b X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=471c4c42e267be298ce20951d5a352acd6b55190;p=polyglot.git verson 1.4.54b --- diff --git a/ChangeLog b/ChangeLog index 5e3b777..0f13117 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +=========1.4.54b================ +- More graceful handling of engine crashes. +- New EngineCommand is now passed through wordexp on Linux. =========1.4.53b================ - Multipv code by HGM. =========1.4.52b================ diff --git a/Makefile.in b/Makefile.in index d6a4340..e2ab7de 100644 --- a/Makefile.in +++ b/Makefile.in @@ -39,8 +39,7 @@ subdir = . DIST_COMMON = README $(am__configure_deps) $(dist_doc_DATA) \ $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(srcdir)/config.h.in $(top_srcdir)/configure AUTHORS COPYING \ - ChangeLog INSTALL NEWS TODO config.guess config.sub depcomp \ - install-sh missing + ChangeLog INSTALL NEWS TODO depcomp install-sh missing ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ diff --git a/README b/README index 4358d8e..9ab6f15 100644 --- a/README +++ b/README @@ -5,8 +5,8 @@ POLYGLOT(6) POLYGLOT(6) NAME PolyGlot - Winboard protocol to UCI protocol adapter - book engine for Polyglot books - - a collection of utilities for creating and analyzing open- - ing books + - a collection of utilities for creating and analyzing + opening books - a utility for analyzing epd files - a perft counter @@ -16,8 +16,8 @@ SYNOPSIS =]* [-uci =]* polyglot make-book [-pgn inputfile] [-bin outputfile] [-max-ply ply] - [-min-game games] [-min-score score] [-only-white] [-only-black] [-uni- - form] + [-min-game games] [-min-score score] [-only-white] [-only-black] + [-uniform] polyglot merge-book -in1 inputfile1 -in2 inputfile2 [-out outputfile] @@ -32,17 +32,16 @@ SYNOPSIS polyglot perft [-fen fen] [-max-depth depth] DESCRIPTION - PolyGlot as adapter and book engine - + PolyGlot as adapter and book engine PolyGlot is a "UCI adapter". It connects a GUI interface (such as XBoard, Winboard, Arena or Chessbase) to a UCI chess engine. By specifying an opening book (in PolyGlot book format) chess engines can transparently use such books. - PolyGlot understands the two main GUI protocols: UCI and xboard. Nor- - mally the protocol will be auto detected but this can be overridden in - the configuration file. + PolyGlot understands the two main GUI protocols: UCI and xboard. + Normally the protocol will be auto detected but this can be overridden + in the configuration file. In xboard mode PolyGlot fully translates between the xboard and UCI protocols. In addition it tries to solve known problems with other @@ -53,9 +52,9 @@ DESCRIPTION engine and vice versa, except that it will play book moves on behalf of the engine when the occasion arises. - The engine options are exported as UCI options in UCI mode and as "fea- - ture option=" commands in xboard mode. The latter form an extension of - the xboard protocol as defined by H.G. Muller. + The engine options are exported as UCI options in UCI mode and as + "feature option=" commands in xboard mode. The latter form an extension + of the xboard protocol as defined by H.G. Muller. Options which normally appear in the [PolyGlot] section of the config file (see below) are exported as options with their name prefixed by @@ -64,11 +63,10 @@ DESCRIPTION NOTE: Not all options are exported, only those that make sense in the given mode. - Book making utilities - + Book making utilities PolyGlot supports the "PolyGlot opening book format". This is the - defacto standard non-proprietary opening book format. It is fully docu- - mented here + defacto standard non-proprietary opening book format. It is fully + documented here http://alpha.uhasselt.be/Research/Algebra/Toga/book_format.html @@ -81,13 +79,13 @@ DESCRIPTION .abk format are undocumented and proprietary. They can only be used by their own GUIs. - PolyGlot can compile a pgn file into a binary PolyGlot book and fur- - thermore it can merge two such binary books into a third one. + PolyGlot can compile a pgn file into a binary PolyGlot book and + furthermore it can merge two such binary books into a third one. PolyGlot can also extract some useful information from PolyGlot books. The utility "dump-book" dumps the "lines" in a book for a given color. - By definition a line is a sequence of moves (from the starting posi- - tion) in which the given color makes only book moves and the other + By definition a line is a sequence of moves (from the starting + position) in which the given color makes only book moves and the other color makes arbitrary moves (i.e. not necessarily book moves). Since a PolyGlot book is built up from positions and not lines there @@ -111,17 +109,15 @@ DESCRIPTION Due to the possibility of transpositions this is not a fool proof method. - Epd test mode - + Epd test mode In epd test mode, PolyGlot will search positions in an epd file and - record the number of times the right best move was found. The argu- - ments specify when to stop the search in any given position. - - Perft counts + record the number of times the right best move was found. The + arguments specify when to stop the search in any given position. + Perft counts A perft count is the number of legal move sequence in a given position - up to a given depth. PolyGlot can perform such perft counts. It is how- - ever much slower than other more dedicated programs. + up to a given depth. PolyGlot can perform such perft counts. It is + however much slower than other more dedicated programs. OPTIONS When PolyGlot is invoked as an adapter of in epd-test mode it gets its @@ -159,8 +155,7 @@ OPTIONS When invoked as - polyglot make-book - + polyglot make-book PolyGlot supports the following options -pgn (default: "book.pgn") @@ -193,8 +188,7 @@ OPTIONS When invoked as - polyglot merge-book - + polyglot merge-book PolyGlot supports the following options -in1 @@ -212,8 +206,7 @@ OPTIONS When invoked as - polyglot dump-book - + polyglot dump-book PolyGlot supports the following options -bin (default: book.bin) @@ -227,21 +220,19 @@ OPTIONS When invoked as - polyglot info-book - + polyglot info-book PolyGlot supports the following options -bin (default: book.bin) Input file in PolyGlot book format. -exact - Attempt to count the provably unreachable positions among the iso- - lated ones. Note that this takes a very long time. + Attempt to count the provably unreachable positions among the + isolated ones. Note that this takes a very long time. When invoked as - polyglot epd-test - + polyglot epd-test (possibly with a config file as first argument) PolyGlot supports besides the generic options described above the following additional options. @@ -267,8 +258,7 @@ OPTIONS When invoked as - polyglot perft - + polyglot perft PolyGlot supports the following options -fen (default: starting position) @@ -291,13 +281,13 @@ CONFIG FILE FORMAT The characters "#" and ";" serve as comment characters. - By default initial and final white space is stripped from option val- - ues. If you want to avoid this, or if you want use one of the comment - characters # or ; in option values (such as for NalimovPath), enclose - the value in quotes. - - [PolyGlot] section + Initial and final white space is stripped from option names and values. + If you need to use characters which have a special meaning to PolyGlot + (these are ';#[]=\') you should quote them by preceding them with '\'. + "Quoting" other characters in this way has no effect. In particular the + use of '\' as a path separator in windows should normally not affected. + [PolyGlot] section This section is used by PolyGlot only. The engine is unaware of these options. The list of available options is detailed below. @@ -315,7 +305,10 @@ CONFIG FILE FORMAT EngineCommand Put here the name of the engine executable file. You can also add command-line arguments. Path searching is used and the current - directory will be "EngineDir". + directory will be "EngineDir". On Linux the EngineCommand is passed + to wordexp so that shell quoting rules and expansions are applied. + On Windows the EngineCommand is simply passed to CreateProcess + which does its own shell like processing. SettingsDir (default: $HOME/.polyglot on Linux; ".\_PG" on Windows) The directory where ini files are stored for engines that are @@ -350,8 +343,8 @@ CONFIG FILE FORMAT move are ignored. ResignScore (default: 600) - This is the score in centipawns that will trigger resign "count- - ing". + This is the score in centipawns that will trigger resign + "counting". ShowPonder (default: true) Show search information during engine pondering. Turning this off @@ -368,8 +361,8 @@ CONFIG FILE FORMAT move). KibitzCommand (default: "tellall") - xboard command to use for kibitzing, normally "tellall" for kibitz- - ing or "tellothers" for whispering. + xboard command to use for kibitzing, normally "tellall" for + kibitzing or "tellothers" for whispering. KibitzDelay (default: 5) How many seconds to wait before starting kibitzing. This has an @@ -398,8 +391,8 @@ CONFIG FILE FORMAT BookFile (default: book.bin) The name of the (binary) book file. Note that PolyGlot will look for it in the directory it was launched from, not in the engine - directory. Of course, full path can be used in which case the cur- - rent directory does not matter. + directory. Of course, full path can be used in which case the + current directory does not matter. BookRandom (default: true) Select moves according to their weights in the book. If false the @@ -436,15 +429,14 @@ CONFIG FILE FORMAT If true then PolyGlot restricts the options it sends to those that are potentially useful for WinBoard. - Work arounds - + Work arounds Work arounds are identical to options except that they should be used only when necessary. Their purpose is to try to hide problems with various software (not just engines). - IMPORTANT: Any of these work arounds might be removed in future ver- - sions of PolyGlot. You are strongly recommended to contact the author - of faulty software and truly fix the problem. + IMPORTANT: Any of these work arounds might be removed in future + versions of PolyGlot. You are strongly recommended to contact the + author of faulty software and truly fix the problem. PolyGlot supports the following work arounds: @@ -455,16 +447,16 @@ CONFIG FILE FORMAT CanPonder (default: false) PolyGlot now conforms to the documented UCI behaviour: the engine will be allowed to ponder only if it (the engine) declares the - "Ponder" UCI option. However some engines which can actually pon- - der do not declare the option. This work around lets PolyGlot know - that they can ponder. + "Ponder" UCI option. However some engines which can actually + ponder do not declare the option. This work around lets PolyGlot + know that they can ponder. SyncStop (default: false) - When a ponder miss occurs, Polyglot interrupts the engine and IMME- - DIATELY launches a new search. While there should be no problem - with this, some engines seem confused and corrupt their search - board. "SyncStop" forces PolyGlot to wait for the (now useless) - ponder search to finish before launching the new search. + When a ponder miss occurs, Polyglot interrupts the engine and + IMMEDIATELY launches a new search. While there should be no + problem with this, some engines seem confused and corrupt their + search board. "SyncStop" forces PolyGlot to wait for the (now + useless) ponder search to finish before launching the new search. PromoteWorkAround (default: false) Some engines do not specify a promotion piece, e.g. they send @@ -480,15 +472,14 @@ CONFIG FILE FORMAT to the way kibitzing is implemented, KibitzMove is disabled in that case. - [Engine] section - + [Engine] section This section contains engine UCI options. PolyGlot does not understand them, but sends the information to the engine at startup (converted to UCI form). You can add any UCI option that makes sense to the engine (not just the common options about hash-table size and tablebases). - NOTE: use INI syntax, not UCI. For example "OwnBook = true" is cor- - rect. It will be replaced by PolyGlot with "setoption name OwnBook + NOTE: use INI syntax, not UCI. For example "OwnBook = true" is + correct. It will be replaced by PolyGlot with "setoption name OwnBook value true" at engine startup. Standard UCI options are @@ -560,4 +551,4 @@ SEE ALSO - 2009-09-11 POLYGLOT(6) + 2009-11-30 POLYGLOT(6) diff --git a/config.h b/config.h index a06a794..f7c18b8 100644 --- a/config.h +++ b/config.h @@ -115,13 +115,13 @@ #define PACKAGE_NAME "polyglot" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "polyglot 1.4.53b" +#define PACKAGE_STRING "polyglot 1.4.54b" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "polyglot" /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.4.53b" +#define PACKAGE_VERSION "1.4.54b" /* Define as the return type of signal handlers (`int' or `void'). */ #define RETSIGTYPE void @@ -142,7 +142,7 @@ #define TIME_WITH_SYS_TIME 1 /* Version number of package */ -#define VERSION "1.4.53b" +#define VERSION "1.4.54b" /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ diff --git a/configure b/configure index 5cd8837..1b54161 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.63 for polyglot 1.4.53b. +# Generated by GNU Autoconf 2.63 for polyglot 1.4.54b. # # Report bugs to . # @@ -596,8 +596,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='polyglot' PACKAGE_TARNAME='polyglot' -PACKAGE_VERSION='1.4.53b' -PACKAGE_STRING='polyglot 1.4.53b' +PACKAGE_VERSION='1.4.54b' +PACKAGE_STRING='polyglot 1.4.54b' PACKAGE_BUGREPORT='michel.vandenbergh@uhasselt.be' ac_unique_file="mainloop.c" @@ -1284,7 +1284,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures polyglot 1.4.53b to adapt to many kinds of systems. +\`configure' configures polyglot 1.4.54b to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1350,7 +1350,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of polyglot 1.4.53b:";; + short | recursive ) echo "Configuration of polyglot 1.4.54b:";; esac cat <<\_ACEOF @@ -1437,7 +1437,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -polyglot configure 1.4.53b +polyglot configure 1.4.54b generated by GNU Autoconf 2.63 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1451,7 +1451,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by polyglot $as_me 1.4.53b, which was +It was created by polyglot $as_me 1.4.54b, which was generated by GNU Autoconf 2.63. Invocation command line was $ $0 $@ @@ -2167,7 +2167,7 @@ fi # Define the identity of the package. PACKAGE='polyglot' - VERSION='1.4.53b' + VERSION='1.4.54b' cat >>confdefs.h <<_ACEOF @@ -6995,7 +6995,7 @@ exec 6>&1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by polyglot $as_me 1.4.53b, which was +This file was extended by polyglot $as_me 1.4.54b, which was generated by GNU Autoconf 2.63. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -7058,7 +7058,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_version="\\ -polyglot config.status 1.4.53b +polyglot config.status 1.4.54b configured by $0, generated by GNU Autoconf 2.63, with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/configure.ac b/configure.ac index 417ca80..8d0ad47 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) -AC_INIT([polyglot], [1.4.53b], [michel.vandenbergh@uhasselt.be]) +AC_INIT([polyglot], [1.4.54b], [michel.vandenbergh@uhasselt.be]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([mainloop.c]) AC_CONFIG_HEADER([config.h]) diff --git a/ini.c b/ini.c index 5b02ef8..0edb2d3 100644 --- a/ini.c +++ b/ini.c @@ -25,6 +25,10 @@ typedef enum { FINISHED =8, } parse_state_t; +// variables + +const char *ini_specials=";\\#[]="; + // functions // ini_line_parse() @@ -42,30 +46,39 @@ line_type_t ini_line_parse(const char *line, char c; int type=SYNTAX_ERROR; int spaces=0; - bool outer_quote=FALSE; + bool quoted; while(state!=FINISHED){ c=line[index++]; -// printf("STATE=%d c=[%c]\n",state,c); + quoted=FALSE; + if(c=='\\'){ + if(strchr(ini_specials,line[index])){ + quoted=TRUE; + c=line[index++]; + } + } + // printf("STATE=%d quoted=%d c=[%c]\n",state,quoted,c); switch(state){ case START: - if((c==';')||(c=='#')||(c=='\r')||(c=='\n')||(c=='\0')){ + if(!quoted && ((c==';')||(c=='#')||(c=='\r')|| + (c=='\n')||(c=='\0'))){ type=EMPTY_LINE; state=FINISHED; - }else if(c=='['){ + }else if(!quoted && c=='['){ state=SECTION_NAME; - }else if(c!=' '){ + }else if(quoted || c!=' '){ name[name_index++]=c; state=NAME; } goto next; break; case NAME: - if(c=='='){ + if(!quoted && c=='='){ state=START_VALUE; - }else if(c==' '){ + }else if(!quoted && c==' '){ state=NAME_SPACE; spaces=1; - }else if((c==';')||(c=='#')||(c=='\r')||(c=='\n')||(c=='\0')){ + }else if(!quoted && ((c==';')||(c=='#')||(c=='\r') + ||(c=='\n')||(c=='\0'))){ type=SYNTAX_ERROR; state=FINISHED; }else{ @@ -74,11 +87,12 @@ line_type_t ini_line_parse(const char *line, goto next; break; // we don't get here case NAME_SPACE: - if(c==' '){ + if(!quoted && c==' '){ spaces++; - }else if(c=='='){ + }else if(!quoted && c=='='){ state=START_VALUE; - }else if((c==';')||(c=='#')||(c=='\r')||(c=='\n')||(c=='\0')){ + }else if(!quoted && ((c==';')||(c=='#')||(c=='\r')|| + (c=='\n')||(c=='\0'))){ type=SYNTAX_ERROR; state=FINISHED; }else{ @@ -92,28 +106,22 @@ line_type_t ini_line_parse(const char *line, goto next; break; // we don't get here case START_VALUE: - if(c=='"'){ - outer_quote=TRUE; - spaces=0; - state=VALUE_SPACE; - }else if((c==';')||(c=='#')||(c=='\r')||(c=='\n')||(c=='\0')){ + if(!quoted && ((c==';')||(c=='#')||(c=='\r')|| + (c=='\n')||(c=='\0'))){ type=EMPTY_VALUE; state=FINISHED; - }else if(c!=' '){ + }else if(quoted || c!=' '){ value[value_index++]=c; state=VALUE; } goto next; break; // we don't get here case VALUE: - if(c=='"'){ - state=QUOTE_SPACE; - spaces=0; - }else if(c==' '){ + if(!quoted && c==' '){ state=VALUE_SPACE; spaces=1; - }else if((c=='\r' || c=='\n' || c==';' || c=='#'||(c=='\0'))&& - !outer_quote){ + }else if(!quoted && ((c=='\r' || c=='\n' || c==';' || + c=='#'||(c=='\0')))){ type=NAME_VALUE; state=FINISHED; }else{ @@ -122,49 +130,24 @@ line_type_t ini_line_parse(const char *line, goto next; break; // we don't get here case VALUE_SPACE: - if(c==' '){ - spaces++; - }else if((c=='\r' || c=='\n' || c==';' || c=='#'||(c=='\0'))&& - !outer_quote){ - type=NAME_VALUE; - state=FINISHED; - }else{ - for(i=0;isection,"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(); @@ -445,6 +440,7 @@ int main(int argc, char * argv[]) { // start engine engine_open(Engine); + if(!engine_active(Engine)){ my_fatal("Could not start \"%s\"\n",option_get(Option,"EngineCommand")); } @@ -458,6 +454,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); @@ -568,7 +565,7 @@ int main(int argc, char * argv[]) { } } - gui_init(GUI); + // gui_init(GUI); mainloop(); return EXIT_SUCCESS; } @@ -579,7 +576,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){ @@ -635,9 +632,10 @@ 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); diff --git a/mainloop.c b/mainloop.c index 84a0ac0..4f23279 100644 --- a/mainloop.c +++ b/mainloop.c @@ -64,6 +64,7 @@ static void mainloop_gui_step(char * string){ void mainloop() { char string[StringSize]; + my_log("POLYGLOT *** Mainloop started ***\n"); mainloop_init(); while (!engine_eof(Engine)) { // process buffered lines diff --git a/pipex.h b/pipex.h index e1a3618..8a51652 100644 --- a/pipex.h +++ b/pipex.h @@ -39,6 +39,8 @@ typedef struct { char szWriteBuffer[LINE_INPUT_MAX_CHAR]; DWORD dwWriteIndex; const char *name; + const char *command; + BOOL quit_pending; } pipex_t; @@ -68,6 +70,8 @@ typedef struct { io_t io[1]; pid_t pid; int state; + bool quit_pending; + const char *command; } pipex_t; #endif diff --git a/pipex_posix.c b/pipex_posix.c index 9df6f38..737f9ce 100644 --- a/pipex_posix.c +++ b/pipex_posix.c @@ -4,6 +4,8 @@ #include #include +#include +#include #include "pipex.h" // constants @@ -28,9 +30,13 @@ void pipex_open(pipex_t *pipex, char * ptr; char * argv[256]; int from_child[2], to_child[2]; + wordexp_t p; + int i,ret; pipex->pid=-1; pipex->io->name=name; + pipex->quit_pending=FALSE; + pipex->command=command; if(command==NULL){ pipex->io->in_fd = STDIN_FILENO; @@ -43,7 +49,7 @@ void pipex_open(pipex_t *pipex, }else{ // parse the command line and create the argument list - +#if 0 if (strlen(command) >= StringSize) my_fatal("pipex_open(): buffer overflow\n"); strcpy(string,command); argc = 0; @@ -53,7 +59,27 @@ void pipex_open(pipex_t *pipex, } argv[argc] = NULL; - +#else + //printf("command=[%s]\n",command); + //Buffer overflow alert + ret=wordexp(command, &p, 0); + if(ret!=0){ + my_fatal("pipex_open(): %s: Unable to parse command.\n",command); + } + argc = p.we_wordc; + if(argc>=256-2){ + my_fatal("pipex_open(): %s: Too many arguments.\n",command); + } + for(i=0;i 0 @@ -203,7 +229,26 @@ void pipex_send_eof(pipex_t *pipex){ // pipex_exit() void pipex_exit(pipex_t *pipex){ - // NOOP for now + int status; + my_log("POLYGLOT Waiting for child process to exit.\n"); + waitpid(pipex->pid,&status,0); + if(WIFEXITED(status)){ + if(pipex->quit_pending){ + my_log("POLYGLOT Child exited with status %d.\n",WEXITSTATUS(status)); + }else{ + // Suppress further messages. + pipex->quit_pending=TRUE; + my_fatal("pipex_exit(): %s: child exited with status %d.\n",pipex->command,WEXITSTATUS(status)); + } + }else if(WIFSIGNALED(status)){ + if(pipex->quit_pending){ + my_log("POLYGLOT pipex_exit(): %s: child terminated with signal %d.\n",pipex->command,WTERMSIG(status)); + }else{ + // Suppress further messages. + pipex->quit_pending=TRUE; + my_fatal("pipex_exit(): %s: child terminated with signal %d.\n",pipex->command,WTERMSIG(status)); + } + } return; } diff --git a/pipex_win32.c b/pipex_win32.c index 5b18b06..0bbf990 100644 --- a/pipex_win32.c +++ b/pipex_win32.c @@ -72,6 +72,8 @@ void pipex_open(pipex_t *pipex, char *szCurrentDir; pipex->state=0; pipex->name=szName; + pipex->command=szProcFile; + pipex->quit_pending=FALSE; pipex->hProcess=NULL; if (szProcFile == NULL) { pipex->hInput = GetStdHandle(STD_INPUT_HANDLE); @@ -99,7 +101,7 @@ void pipex_open(pipex_t *pipex, my_fatal("pipex_open(): cannot change directory: %s\n", strerror(errno)); } - if(CreateProcess(NULL, + if(CreateProcess(NULL, (LPSTR) szProcFile, NULL, NULL, @@ -194,7 +196,11 @@ void pipex_exit(pipex_t *pipex) { DWORD lpexit; CloseHandle(pipex->hInput); CloseHandle(pipex->hOutput); - + if(!pipex->quit_pending){ + // suppress further errors + pipex->quit_pending=TRUE; + my_fatal("pipex_exit(): %s: child exited unexpectedly.\n",pipex->command); + } if(GetExitCodeProcess(pipex->hProcess,&lpexit)){ if(lpexit==STILL_ACTIVE) //must be java,hammer it down! diff --git a/polyglot.man b/polyglot.man index 12f1611..51c2dc7 100644 --- a/polyglot.man +++ b/polyglot.man @@ -1,15 +1,7 @@ -.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 +.\" Automatically generated by Pod::Man 2.1801 (Pod::Simple 3.05) .\" .\" Standard preamble: .\" ======================================================================== -.de Sh \" Subsection heading -.br -.if t .Sp -.ne 5 -.PP -\fB\\$1\fR -.PP -.. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp @@ -48,22 +40,25 @@ . ds R" '' 'br\} .\" +.\" Escape single quotes in literal strings from groff's Unicode transform. +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.\" .\" If the F register is turned on, we'll generate index entries on stderr for -.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index +.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. -.if \nF \{\ +.ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} -.\" -.\" For nroff, turn off justification. Always turn off hyphenation; it makes -.\" way too many mistakes in technical documents. -.hy 0 -.if n .na +.el \{\ +. de IX +.. +.\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. @@ -129,7 +124,11 @@ .\" ======================================================================== .\" .IX Title "POLYGLOT 6" -.TH POLYGLOT 6 "2009-09-11" "" "" +.TH POLYGLOT 6 "2009-11-30" "" "" +.\" For nroff, turn off justification. Always turn off hyphenation; it makes +.\" way too many mistakes in technical documents. +.if n .ad l +.nh .SH "NAME" PolyGlot \- Winboard protocol to UCI protocol adapter \- book engine for Polyglot books @@ -148,12 +147,12 @@ polyglot info-book [\-bin inputfile] [\-exact] .PP polyglot dump-book [\-bin inputfile] \-color color [\-out outputfile] .PP -polyglot [configfile] epd-test [engineoptions] [\-epd inputfile] [\-min\-depth depth] [\-max\-depth depth] [\-max\-time time] [\-depth\-delta delta] +polyglot [configfile] epd-test [engineoptions] [\-epd inputfile] [\-min\-depth depth] [\-max\-depth depth] [\-max\-time time] [\-depth\-delta delta] .PP polyglot perft [\-fen fen] [\-max\-depth depth] .SH "DESCRIPTION" .IX Header "DESCRIPTION" -.Sh "PolyGlot as adapter and book engine" +.SS "PolyGlot as adapter and book engine" .IX Subsection "PolyGlot as adapter and book engine" PolyGlot is a \*(L"\s-1UCI\s0 adapter\*(R". It connects a \s-1GUI\s0 interface (such as XBoard, Winboard, Arena or Chessbase) to a \s-1UCI\s0 chess engine. @@ -184,7 +183,7 @@ by \*(L"Polyglot\*(R". This makes it easy to filter them in the \s-1GUI\s0. .PP \&\s-1NOTE:\s0 Not all options are exported, only those that make sense in the given mode. -.Sh "Book making utilities" +.SS "Book making utilities" .IX Subsection "Book making utilities" PolyGlot supports the \*(L"PolyGlot opening book format\*(R". This is the defacto standard non-proprietary opening book format. It is fully documented @@ -195,17 +194,17 @@ http://alpha.uhasselt.be/Research/Algebra/Toga/book_format.html Roughly speaking a PolyGlot opening book is a collection of triples (position, move, weight). A \*(L"position\*(R" is represented by a 64\-bit Zobrist hash key. The weight is proportional to the probability the move should -be played. +be played. .PP Other opening book formats such as ChessBase's .ctg format and Arena's \&.abk format are undocumented and proprietary. They can only be used -by their own GUIs. +by their own GUIs. .PP PolyGlot can compile a pgn file into a binary PolyGlot book and furthermore it can merge two such binary books into a third one. .PP PolyGlot can also extract some useful information from PolyGlot books. The utility -\&\*(L"dump\-book\*(R" dumps the \*(L"lines\*(R" in a book for a given color. By definition +\&\*(L"dump-book\*(R" dumps the \*(L"lines\*(R" in a book for a given color. By definition a line is a sequence of moves (from the starting position) in which the given color makes only book moves and the other color makes arbitrary moves (i.e. not necessarily book moves). @@ -213,7 +212,7 @@ arbitrary moves (i.e. not necessarily book moves). Since a PolyGlot book is built up from positions and not lines there may be (and there usually are) many positions in the book that are not on a \*(L"line\*(R" as defined in the previous paragraph. It is convenient -to call such positions \*(L"isolated\*(R" positions. The utility \*(L"info\-book\*(R" +to call such positions \*(L"isolated\*(R" positions. The utility \*(L"info-book\*(R" counts such isolated positions. .PP Some of the isolated positions are provably unreachable and they @@ -229,12 +228,12 @@ it is difficult to identify the latter. If invoked with \*(L"\-exact\*(R" the utility info-book will attempt to count the isolated positions which require a player to make a non-book move when a book move is available. Due to the possibility of transpositions this is not a fool proof method. -.Sh "Epd test mode" +.SS "Epd test mode" .IX Subsection "Epd test mode" In epd test mode, PolyGlot will search positions in an epd file and record the number of times the right best move was found. The arguments specify when to stop the search in any given position. -.Sh "Perft counts" +.SS "Perft counts" .IX Subsection "Perft counts" A perft count is the number of legal move sequence in a given position up to a given depth. PolyGlot can perform such perft counts. It @@ -254,11 +253,11 @@ Do not use a config file, even if one was specified on the command line. .IP "\fB\-pg\fR" 4 .IX Item "-pg" The argument is a string of the form =. This option will -set the Polyglot option to . +set the Polyglot option to . .IP "\fB\-uci\fR" 4 .IX Item "-uci" The argument is a string of the form =. This option will -set the engine option to . +set the engine option to . .IP "\fB\-ec\fR" 4 .IX Item "-ec" This is an alias for \-pg \*(L"EngineCommand=\*(R" @@ -281,17 +280,17 @@ This is an alias for \-pg \*(L"LogFile=\*(R". This is an alias for \-pg \*(L"OnlyWbOptions=\*(R". .PP When invoked as -.Sh "polyglot make-book" +.SS "polyglot make-book" .IX Subsection "polyglot make-book" PolyGlot supports the following options .ie n .IP "\fB\-pgn\fR (default: ""book.pgn"")" 4 .el .IP "\fB\-pgn\fR (default: ``book.pgn'')" 4 .IX Item "-pgn (default: book.pgn)" -Input file in pgn format. +Input file in pgn format. .ie n .IP "\fB\-bin\fR (default: ""book.bin"")" 4 .el .IP "\fB\-bin\fR (default: ``book.bin'')" 4 .IX Item "-bin (default: book.bin)" -Output file in PolyGlot format. +Output file in PolyGlot format. .IP "\fB\-max\-ply\fR (default: 1024)" 4 .IX Item "-max-ply (default: 1024)" Specifies the maximum ply-depth of lines included in the book. @@ -302,7 +301,7 @@ Specifies the minimum number of games that have to contain this move for it to b .IX Item "-min-score (default: 0.0)" Specifies the minimum score (or weight) this move should have received for it to be included in the book. The score is 2*(wins)+(draws), globally scaled -to fit into 16 bits. +to fit into 16 bits. .IP "\fB\-only\-white\fR" 4 .IX Item "-only-white" Include only moves for white in the book. @@ -312,11 +311,11 @@ Include only moves for black in the book. .IP "\fB\-uniform\fR" 4 .IX Item "-uniform" Set all weights to 1. In other words, all moves will be selected with -equal probability. +equal probability. .PP When invoked as -.Sh "polyglot merge-book" +.SS "polyglot merge-book" .IX Subsection "polyglot merge-book" PolyGlot supports the following options .IP "\fB\-in1\fR" 4 @@ -335,7 +334,7 @@ moves and weights from \*(L"in1\*(R" will be retained in \*(L"out\*(R". .PP When invoked as -.Sh "polyglot dump-book" +.SS "polyglot dump-book" .IX Subsection "polyglot dump-book" PolyGlot supports the following options .IP "\fB\-bin\fR (default: book.bin)" 4 @@ -350,7 +349,7 @@ The name of the output file. .PP When invoked as -.Sh "polyglot info-book" +.SS "polyglot info-book" .IX Subsection "polyglot info-book" PolyGlot supports the following options .IP "\fB\-bin\fR (default: book.bin)" 4 @@ -359,10 +358,10 @@ Input file in PolyGlot book format. .IP "\fB\-exact\fR" 4 .IX Item "-exact" Attempt to count the provably unreachable positions among the isolated ones. -Note that this takes a very long time. +Note that this takes a very long time. .PP When invoked as -.Sh "polyglot epd-test" +.SS "polyglot epd-test" .IX Subsection "polyglot epd-test" (possibly with a config file as first argument) PolyGlot supports besides the generic options described above the following additional @@ -387,7 +386,7 @@ Minimal search depth when the search is stopped using \*(L"\-depth\-delta\*(R". Minimal search time when the search is stopped using \*(L"\-depth\-delta\*(R". .PP When invoked as -.Sh "polyglot perft" +.SS "polyglot perft" .IX Subsection "polyglot perft" PolyGlot supports the following options @@ -399,9 +398,9 @@ Fen at which to start searching. Maximum depth to search. .SH "CONFIG FILE FORMAT" .IX Header "CONFIG FILE FORMAT" -There should be a different config file for each engine. +There should be a different config file for each engine. .PP -The config file is in the traditional \s-1INI\s0 format. +The config file is in the traditional \s-1INI\s0 format. .PP .Vb 6 \& [PolyGLot] @@ -412,13 +411,15 @@ The config file is in the traditional \s-1INI\s0 format. \& ... .Ve .PP -The characters \*(L"#\*(R" and \*(L";\*(R" serve as comment characters. +The characters \*(L"#\*(R" and \*(L";\*(R" serve as comment characters. .PP -By default initial and final white space is stripped from option -values. If you want to avoid this, or if you want use one of -the comment characters # or ; in option values (such as for NalimovPath), -enclose the value in quotes. -.Sh "[PolyGlot] section" +Initial and final white space is stripped from option names and +values. If you need to use characters which have a special meaning to +PolyGlot (these are ';#[]=\e') you should quote them by preceding them +with '\e'. \*(L"Quoting\*(R" other characters in this way has no effect. In +particular the use of '\e' as a path separator in windows should +normally not affected. +.SS "[PolyGlot] section" .IX Subsection "[PolyGlot] section" This section is used by PolyGlot only. The engine is unaware of these options. The list of available options is detailed below. @@ -438,7 +439,10 @@ any data file. .IX Item "EngineCommand" Put here the name of the engine executable file. You can also add command-line arguments. Path searching is used and the current -directory will be \*(L"EngineDir\*(R". +directory will be \*(L"EngineDir\*(R". On Linux the EngineCommand is passed +to wordexp so that shell quoting rules and expansions are applied. +On Windows the EngineCommand is simply passed to CreateProcess which +does its own shell like processing. .ie n .IP "\fBSettingsDir\fR (default: $HOME/.polyglot on Linux; "".\e_PG"" on Windows)" 4 .el .IP "\fBSettingsDir\fR (default: \f(CW$HOME\fR/.polyglot on Linux; ``.\e_PG'' on Windows)" 4 .IX Item "SettingsDir (default: $HOME/.polyglot on Linux; ._PG on Windows)" @@ -501,10 +505,10 @@ regardless of the delay. .IP "\fBKibitzInterval\fR (default: 0)" 4 .IX Item "KibitzInterval (default: 0)" This is another form of throttling. PolyGlot will usually wait this -many seconds before doing the next kibitz. +many seconds before doing the next kibitz. .IP "\fB\s-1UCI\s0\fR (default: false)" 4 .IX Item "UCI (default: false)" -If true PolyGlot will not understand xboard commands. +If true PolyGlot will not understand xboard commands. .IP "\fBMateScore\fR (default: 10000)" 4 .IX Item "MateScore (default: 10000)" Mate score reported to \s-1GUI\s0 when in xboard mode. @@ -526,17 +530,17 @@ does not matter. .IP "\fBBookRandom\fR (default: true)" 4 .IX Item "BookRandom (default: true)" Select moves according to their weights in the book. If false the move -with the highest weight is selected. +with the highest weight is selected. .IP "\fBBookLearn\fR (default: false)" 4 .IX Item "BookLearn (default: false)" Store learning information in the book (which must be writable). Currently -no engine actually uses this information. +no engine actually uses this information. .IP "\fBBookDepth\fR (default: 256)" 4 .IX Item "BookDepth (default: 256)" -Stop using the book after this number of moves. +Stop using the book after this number of moves. .IP "\fBBookTreshold\fR (default: 5)" 4 .IX Item "BookTreshold (default: 5)" -Do not play moves with a weight (probability) lower than this (in per mil). +Do not play moves with a weight (probability) lower than this (in per mil). .IP "\fBUseNice\fR (default: false)" 4 .IX Item "UseNice (default: false)" Run the engine at nice level 5, or \*(L"NiceValue\*(R" if it set. On some @@ -551,16 +555,16 @@ Win32 priority levels are mapped in a sensible way to Unix nice levels. .IP "\fBAffinity\fR (default: \-1)" 4 .IX Item "Affinity (default: -1)" This a bit vector in which each bit represents the processors that a -process is allowed to run on. This option works only on Windows. +process is allowed to run on. This option works only on Windows. .IP "\fBOnlyWbOptions\fR (default: true)" 4 .IX Item "OnlyWbOptions (default: true)" If true then PolyGlot restricts the options it sends to those that -are potentially useful for WinBoard. -.Sh "Work arounds" +are potentially useful for WinBoard. +.SS "Work arounds" .IX Subsection "Work arounds" Work arounds are identical to options except that they should be used only when necessary. Their purpose is to try to hide problems with -various software (not just engines). +various software (not just engines). .PP \&\s-1IMPORTANT:\s0 Any of these work arounds might be removed in future versions of PolyGlot. You are strongly recommended to contact the @@ -596,8 +600,8 @@ score,depth and time usage) it got from the engine. Some engines however do not send a new pv string just before sending the move. In that case the output of PolyGlot would be inconsistent. When RepeatPV is false PolyGlot does not repeat the last pv string. -Due to the way kibitzing is implemented, KibitzMove is disabled in that case. -.Sh "[Engine] section" +Due to the way kibitzing is implemented, KibitzMove is disabled in that case. +.SS "[Engine] section" .IX Subsection "[Engine] section" This section contains engine \s-1UCI\s0 options. PolyGlot does not understand them, but sends the information to the engine at startup @@ -609,7 +613,7 @@ tablebases). correct. It will be replaced by PolyGlot with \*(L"setoption name OwnBook value true\*(R" at engine startup. .PP -Standard \s-1UCI\s0 options are +Standard \s-1UCI\s0 options are .PP .Vb 4 \& Hash @@ -621,7 +625,7 @@ Standard \s-1UCI\s0 options are Hidden options like \*(L"Ponder\*(R" or \*(L"UCI_xxx\*(R" are automatic and should not be put in an \s-1INI\s0 file. .PP -The other options are engine\-specific. Check their name using a \s-1UCI\s0 +The other options are engine-specific. Check their name using a \s-1UCI\s0 \&\s-1GUI\s0 or launch the engine in a console and type \*(L"uci\*(R". .SH "EXAMPLES" .IX Header "EXAMPLES" @@ -673,7 +677,7 @@ Test epd file \*(L"test.epd\*(R" with a (maximum) search time of 7 minutes per p .Ve .SH "EXIT STATUS" .IX Header "EXIT STATUS" -PolyGlot always returns 0 on exit. +PolyGlot always returns 0 on exit. .SH "AUTHORS" .IX Header "AUTHORS" Main author: Fabien Letouzey diff --git a/polyglot.pod b/polyglot.pod index 7d3a15d..415902f 100644 --- a/polyglot.pod +++ b/polyglot.pod @@ -351,10 +351,12 @@ The config file is in the traditional INI format. The characters "#" and ";" serve as comment characters. -By default initial and final white space is stripped from option -values. If you want to avoid this, or if you want use one of -the comment characters # or ; in option values (such as for NalimovPath), -enclose the value in quotes. +Initial and final white space is stripped from option names and +values. If you need to use characters which have a special meaning to +PolyGlot (these are ';#[]=\') you should quote them by preceding them +with '\'. "Quoting" other characters in this way has no effect. In +particular the use of '\' as a path separator in windows should +normally not affected. =head2 [PolyGlot] section @@ -380,7 +382,10 @@ any data file. Put here the name of the engine executable file. You can also add command-line arguments. Path searching is used and the current -directory will be "EngineDir". +directory will be "EngineDir". On Linux the EngineCommand is passed +to wordexp so that shell quoting rules and expansions are applied. +On Windows the EngineCommand is simply passed to CreateProcess which +does its own shell like processing. =item B (default: $HOME/.polyglot on Linux; ".\_PG" on Windows) diff --git a/polyglot.spec b/polyglot.spec index a0b30e7..15b1bd1 100644 --- a/polyglot.spec +++ b/polyglot.spec @@ -1,6 +1,6 @@ Summary: A Winboard protocol to UCI protocol adapter Name: polyglot -Version: 1.4.53b +Version: 1.4.54b Release: 1 License: GPL Group: Amusement/Games diff --git a/uci.c b/uci.c index dd13713..65d4d2a 100644 --- a/uci.c +++ b/uci.c @@ -153,7 +153,7 @@ void uci_open(uci_t * uci, engine_t * engine) { // 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"); + my_fatal("uci_open(): Not an UCI engine.\n"); } event = uci_parse(uci,string); } while (!engine_eof(Engine) && (event & EVENT_UCI) == 0); diff --git a/util.c b/util.c index 28e56b5..a3fb3ba 100644 --- a/util.c +++ b/util.c @@ -24,6 +24,7 @@ #include "main.h" #include "util.h" +#include "gui.h" // macros @@ -197,16 +198,19 @@ void my_fatal(const char format[], ...) { CONSTRUCT_ARG_STRING(format,string); - fprintf(stderr,"%s",string); my_log("POLYGLOT %s",string); + // This should be gui_send but this does not work. + // Why? + + fprintf(stderr,"tellusererror POLYGLOT: %s",string); if (Error) { // recursive error my_log("POLYGLOT *** RECURSIVE ERROR ***\n"); exit(EXIT_FAILURE); // abort(); } else { - Error = TRUE; - quit(); + Error = TRUE; + quit(); } } @@ -474,4 +478,39 @@ double my_timer_elapsed_real(const my_timer_t * timer) { } +void my_dequote(char *out, const char *in, const char *special){ + const char *p; + char *q; + char c; + p=in; + q=out; + while((c=*(p++))){ + if(c=='\\' && strchr(special,*p)){ + *(q++)=*(p++); + }else{ + *(q++)=c; + } + } + *q='\0'; +} + +void my_quote(char *out, const char *in, const char *special){ + const char *p; + char *q; + char c; + p=in; + q=out; + while(q-out< StringSize-2 && (c=*(p++))){ + if(c=='\\'){ + if(*p!=0 && strchr(special,*p)){ + *(q++)='\\'; + } + }else if(strchr(special,c)){ + *(q++)='\\'; + } + *(q++)=c; + } + *q='\0'; +} + diff --git a/util.h b/util.h index 50eec99..269310d 100644 --- a/util.h +++ b/util.h @@ -178,6 +178,13 @@ extern double my_timer_elapsed_real (const my_timer_t * timer); extern char * my_error(); +extern void my_dequote (char *out, + const char *in, + const char *special); +extern void my_quote (char *out, + const char *in, + const char *special); + #endif // !defined UTIL_H // end of util.h