Allow debug output to go to child process (WB)
authorH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 27 Nov 2015 20:01:22 +0000 (21:01 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 27 Nov 2015 20:01:22 +0000 (21:01 +0100)
A -debugfile name starting with tree slashes will not be interpreted
as a file to write on, but (after stripping the slashes) as an executable
to run, and send the output to. This could be used by an external
broadcasting agaent.

winboard/winboard.c

index 5b57ba3..ba6933f 100644 (file)
@@ -1106,6 +1106,8 @@ InitGeometry()
   screenGeometry.bottom = screenGeometry.top + screenHeight;\r
 }\r
 \r
   screenGeometry.bottom = screenGeometry.top + screenHeight;\r
 }\r
 \r
+ChessProgramState broadcast;\r
+\r
 BOOL\r
 InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine)\r
 {\r
 BOOL\r
 InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine)\r
 {\r
@@ -1138,7 +1140,18 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine)
     appData.ringBellAfterMoves = TRUE;\r
   }\r
   if (appData.debugMode) {\r
     appData.ringBellAfterMoves = TRUE;\r
   }\r
   if (appData.debugMode) {\r
-    debugFP = fopen(appData.nameOfDebugFile, "w");\r
+    char *c = appData.nameOfDebugFile;\r
+    if(strstr(c, "///") == c) {\r
+      broadcast.which = "broadcaster";\r
+      broadcast.pr   = NoProc;\r
+      broadcast.isr  = NULL;\r
+      broadcast.prog = c + 3;\r
+      broadcast.dir  = ".";\r
+      broadcast.host = "localhost";\r
+      StartChessProgram(&broadcast);\r
+      debugFP = (FILE*) _fdopen(_open_osfhandle((long)(((ChildProc*)(broadcast.pr))->hTo), _O_WRONLY), "w");\r
+    } else\r
+    debugFP = fopen(c, "w");\r
     setbuf(debugFP, NULL);\r
   }\r
 \r
     setbuf(debugFP, NULL);\r
   }\r
 \r