Add forgotten files 1.4.70b
[polyglot.git] / mainloop.c
index 0d94a5c..ce51459 100644 (file)
-// mainloop.c\r
-\r
-// constants\r
-\r
-#define StringSize ((int)4096)\r
-\r
-// includes\r
-\r
-#include <errno.h>\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-\r
-#include "main.h"\r
-#include "engine.h"\r
-#include "gui.h"\r
-#include "option.h"\r
-#include "xboard2uci.h"\r
-#include "uci2uci.h"\r
-\r
-// prototypes\r
-\r
-static void mainloop_init            ();\r
-static void mainloop_wait_for_event  ();\r
-static void mainloop_engine_step(char * string);\r
-static void mainloop_gui_step(char * string);\r
-\r
-// functions\r
-\r
-// mainloop_init()\r
-    \r
-static void mainloop_init(){\r
-    if(!option_get_bool(Option,"UCI")){\r
-        xboard2uci_init();  // the default\r
-    }\r
-}\r
-\r
-// mainloop_engine_step()\r
-\r
-static void mainloop_engine_step(char * string){\r
-    if(option_get_bool(Option,"UCI")){\r
-        uci2uci_engine_step(string); \r
-    }else{\r
-        xboard2uci_engine_step(string);\r
-    }\r
-}\r
-\r
-// mainloop_gui_step()\r
-\r
-static void mainloop_gui_step(char * string){\r
-    if(option_get_bool(Option,"UCI")){\r
-        uci2uci_gui_step(string); \r
-    }else if(my_string_equal(string,"uci")){ // mode auto detection\r
-        my_log("POLYGLOT *** Switching to UCI mode ***\n");\r
-        option_set(Option,"UCI","true");\r
-        uci2uci_gui_step(string);\r
-    }else{\r
-        xboard2uci_gui_step(string);\r
-    }\r
-}\r
-\r
-// mainloop()\r
-\r
-void mainloop() {\r
-    char string[StringSize];\r
-    mainloop_init();\r
-    while (!engine_eof(Engine)) {\r
-            // process buffered lines\r
-        while(TRUE){\r
-            if(gui_get_non_blocking(GUI,string)){\r
-                mainloop_gui_step(string);\r
-            }else if(!engine_eof(Engine) &&\r
-                     engine_get_non_blocking(Engine,string) ){\r
-                mainloop_engine_step(string);\r
-            }else{\r
-                break;\r
-            }\r
-        }\r
-        mainloop_wait_for_event();\r
-    }\r
-    my_log("POLYGLOT *** Mainloop has ended ***\n");\r
-    // This should be handled better.\r
-    engine_close(Engine);\r
-    my_log("POLYGLOT Calling exit\n");\r
-    exit(EXIT_SUCCESS);\r
-\r
-}\r
-\r
-\r
-\r
-\r
-// mainloop_wait_for_event()\r
-\r
-static void mainloop_wait_for_event(){\r
-    pipex_t *pipex[3];\r
-    pipex[0]=GUI->pipex;\r
-    pipex[1]=Engine->pipex;\r
-    pipex[2]=NULL;\r
-    pipex_wait_event(pipex);\r
-}\r
-\r
-\r
-\r
+// mainloop.c
+
+// includes
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "main.h"
+#include "engine.h"
+#include "gui.h"
+#include "option.h"
+//#include "ini.h"
+#include "xboard2uci.h"
+#include "uci2uci.h"
+
+// prototypes
+
+static void mainloop_init            ();
+static void mainloop_wait_for_event  ();
+static void mainloop_engine_step(char * string);
+static void mainloop_gui_step(char * string);
+
+// functions
+
+// mainloop_init()
+    
+static void mainloop_init(){
+    if(!option_get_bool(Option,"UCI")){
+        xboard2uci_init();  // the default
+    }
+}
+
+// mainloop_engine_step()
+
+static void mainloop_engine_step(char * string){
+    if(option_get_bool(Option,"UCI")){
+        uci2uci_engine_step(string); 
+    }else{
+        xboard2uci_engine_step(string);
+    }
+}
+
+// mainloop_gui_step()
+
+static void mainloop_gui_step(char * string){
+    if(option_get_bool(Option,"UCI")){
+        uci2uci_gui_step(string); 
+    }else if(my_string_equal(string,"uci")){ // mode auto detection
+        my_log("POLYGLOT *** Switching to UCI mode ***\n");
+        option_set(Option,"UCI","true");
+        uci2uci_gui_step(string);
+    }else{
+        xboard2uci_gui_step(string);
+    }
+}
+
+// mainloop()
+
+void mainloop() {
+    char string[StringSize];
+    my_log("POLYGLOT *** Mainloop started ***\n");
+    mainloop_init();
+    while (!engine_eof(Engine)) {
+            // process buffered lines
+        while(TRUE){
+            if(gui_get_non_blocking(GUI,string)){
+                mainloop_gui_step(string);
+            }else if(!engine_eof(Engine) &&
+                     engine_get_non_blocking(Engine,string) ){
+                mainloop_engine_step(string);
+            }else{
+                break;
+            }
+        }
+        mainloop_wait_for_event();
+    }
+    my_log("POLYGLOT *** Mainloop has ended ***\n");
+    // This should be handled better.
+    engine_close(Engine);
+    my_log("POLYGLOT Calling exit\n");
+    exit(EXIT_SUCCESS);
+
+}
+
+
+
+
+// mainloop_wait_for_event()
+
+static void mainloop_wait_for_event(){
+    pipex_t *pipex[3];
+    pipex[0]=GUI->pipex;
+    pipex[1]=Engine->pipex;
+    pipex[2]=NULL;
+    pipex_wait_event(pipex);
+}
+
+
+