}\r
\r
int\r
-GetChar()\r
+ReadLine (FILE *f, char *line)\r
{\r
- int c;\r
- if(fromF) {\r
- if((c = fgetc(fromF)) != EOF) return c;\r
- fclose(fromF); fromF = 0; printf("# end fake\n");\r
- }\r
- return fgetc(fromE);\r
+ int x, i = 0;\r
+ while((x = fgetc(f)) != EOF && (line[i] = x) != '\n') i++; line[++i] = 0;\r
+ return (x != EOF);\r
}\r
\r
void *\r
int i=0, x; char *p, dummy, len;\r
\r
fflush(stdout); fflush(toE);\r
- while((line[i] = x = GetChar()) != EOF && line[i] != '\n') i++;\r
- line[++i] = 0;\r
- if(x == EOF) printf("tellusererror UCI2WB: %s died on me\n", binary), exit(0);\r
+ if(fromF && !ReadLine(fromF, line)) fromF = 0, printf("# end fake\n");\r
+ if(!fromF && !ReadLine(fromE, line)) printf("tellusererror UCI2WB: %s died on me\n", binary), exit(0);\r
DPRINT("# engine said: %s", line), fflush(stdout);\r
if(sscanf(line, "%s", command) != 1) continue;\r
if(!strcmp(command, "bestmove")) {\r
char line[256], command[256], *p, *q, *r, mySide, type[99];\r
\r
while(1) {\r
- int i, x, difficult, think=0;\r
+ int i, difficult, think=0;\r
\r
if((computer == stm || computer == ANALYZE && !searching) && !suspended) {\r
DPRINT("# start search\n");\r
nomove:\r
for(difficult=0; !difficult; ) { // read and handle commands that can (or must) be handled during thinking\r
fflush(toE); fflush(stdout);\r
- i = 0; while((x = getchar()) != EOF && (line[i] = x) != '\n') i++;\r
- line[++i] = 0; if(x == EOF) { printf("# EOF\n"); sprintf(line, "quit -1\n"); }\r
+ if(!ReadLine(stdin, line)) printf("# EOF\n"), sprintf(line, "quit -1\n");\r
if(think && !pause) Sync(PAUSE), think = 0, Release(); // if no longer thinking, take dummy pause\r
sscanf(line, "%s", command); DPRINT("# '%s' think=%d pause=%d log=%d sent=%d\n", command, think, pause, logLen, sentLen);\r
if(!strcmp(command, "usermove")) { difficult--; break; } // for efficiency during game play, moves, time & otim are tried first\r