From 43e068c7ecc89ba411e518ad4f6bdcbed895f4cd Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Wed, 30 Nov 2016 09:22:55 +0100 Subject: [PATCH] Treat EOF same as quit command A EOF during reading from the GUI caused UCI2WB to exit through a different path as a 'quit' command. Now the EOF detection just fakes a 'quit -1' command was received, and then processes that as usual. This means it also causes proper termination of the engine when it occurs during thinking (sending 'stop'). The '-1' appendage to the command allows the 'quit' handling to return an error code. --- UCI2WB.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/UCI2WB.c b/UCI2WB.c index 2971c3f..73a55c6 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -417,7 +417,7 @@ GUI2Engine() nomove: fflush(toE); fflush(stdout); i = 0; while((x = getchar()) != EOF && (line[i] = x) != '\n') i++; - line[++i] = 0; if(x == EOF) { printf("# EOF\n"); EPRINT((f, "# quit\n")) exit(-1); } + line[++i] = 0; if(x == EOF) { printf("# EOF\n"); sprintf(line, "quit -1\n"); } sscanf(line, "%s", command); if(!strcmp(command, "offer")) { drawOffer = 1; goto nomove; } // backlogged anyway, so this can be done instantly if(think) { // command arrived during thinking; order abort for 'instant commands' @@ -545,7 +545,7 @@ GUI2Engine() else if(!strcmp(command, "name")) { if(namOpt) EPRINT((f, "# setoption name UCI_Opponent value none none %s %s", comp ? "computer" : "human", line+5)) } else if(!strcmp(command, "computer")) comp = 1; else if(!strcmp(command, "result")) { if(sc == 's') EPRINT((f, "# gameover %s\n", line[8] == '/' ? "draw" : (line[7] == '0') == mySide ? "win" : "lose")) } - else if(!strcmp(command, "quit")) { EPRINT((f, "# quit\n")) fflush(toE), exit(0); } + else if(!strcmp(command, "quit")) { EPRINT((f, "# quit\n")) fflush(toE), exit(atoi(line+4)); } } } -- 1.7.0.4