From 0bcc18ddfe1e849b345a565850e2a14cdab30d1a Mon Sep 17 00:00:00 2001
From: H.G.Muller <hgm@hgm-xboard.(none)>
Date: Fri, 7 Dec 2018 23:02:48 +0100
Subject: [PATCH] Pass command to DoCommand through global command queue

Rather than passing the command to process as a parameter to DoCommand,
we now append it to a global 'command queue', from which DoCommand() then
reads the first line. This in preparation for letting the engine thread
handle the difficult commands.
---
 UCI2WB.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/UCI2WB.c b/UCI2WB.c
index 4cbf5a8..0e7f34f 100644
--- a/UCI2WB.c
+++ b/UCI2WB.c
@@ -436,8 +436,9 @@ Move4Engine(char *m)
     }
 }
 
-int DoCommand (char *line);
+int DoCommand ();
 char mySide;
+char queue[10000], *qStart, *qEnd;
 
 void
 GUI2Engine()
@@ -532,16 +533,19 @@ GUI2Engine()
 	       !strcmp(command, "force") || !strcmp(command, "result")) { EPRINT((f, "# stop\n")); fflush(toE); }
 	    Sync(PAUSE); Release(); // block processing of difficult commands during thinking; send backlog left because of race
 	}
-	if(DoCommand(line)) goto nomove;
+	if(qStart == qEnd) qStart = qEnd = queue;
+	p = line; while(qEnd < queue+10000 && (*qEnd++ = *p++) != '\n') {}
+	if(DoCommand()) goto nomove;
     }
 }
 
 int
-DoCommand (char *line)
+DoCommand ()
 {
-    char command[256], *p, *q, *r, type[99];
+    char line[1024], command[256], *p, *q, *r, type[99];
     int i;
 
+    p=line; while(qStart < qEnd && (*p++ = *qStart++) != '\n') {} *p = 0;
     sscanf(line, "%s", command);
 
 	if(!strcmp(command, "new")) {
-- 
1.7.0.4