X-Git-Url: http://winboard.nl/cgi-bin?p=polyglot.git;a=blobdiff_plain;f=gui.cpp;h=71d0cc07dd45c1140c70b80ee22f6f310c20b87f;hp=9905800e34f63da2fd9bd1be4e04bf54a5b91682;hb=HEAD;hpb=e7a2abd9bd4fce9ebbd70793b00d9d5f99886348 diff --git a/gui.cpp b/gui.cpp index 9905800..71d0cc0 100644 --- a/gui.cpp +++ b/gui.cpp @@ -3,6 +3,7 @@ // includes #include +#include #include "gui.h" #include "main.h" @@ -17,18 +18,35 @@ gui_t GUI[1]; // functions +// sig_quit() + +static void sig_quit(int dummy){ + my_log("POLYGLOT *** SIGINT Received ***\n"); + quit(); +} + // gui_init() void gui_init(gui_t *gui){ - #ifdef _WIN32 - (gui->pipeStdin).Open(); + +// the following is nice if the "GUI" is a console! + signal(SIGINT,sig_quit); +#ifdef _WIN32 + signal(SIGTERM,SIG_IGN); +#ifdef SIGPIPE + signal(SIGPIPE,SIG_IGN); +#endif +#endif + +#ifdef _WIN32 + (gui->io).Open(); #else gui->io->in_fd = STDIN_FILENO; gui->io->out_fd = STDOUT_FILENO; gui->io->name = "GUI"; - + io_init(gui->io); #endif } @@ -36,28 +54,31 @@ void gui_init(gui_t *gui){ // gui_get_non_blocking() -// this is only non_blocking on windows! - bool gui_get_non_blocking(gui_t * gui, char string[], int size) { ASSERT(gui!=NULL); ASSERT(string!=NULL); ASSERT(size>=256); #ifndef _WIN32 - if (!io_get_line(gui->io,string,size)) { // EOF - my_log("POLYGLOT *** EOF from GUI ***\n"); - quit(); + if(io_line_ready(gui->io)){ + gui_get(GUI,string,StringSize); + return true; + }else{ + string[0]='\0'; + return false; } - return true; #else - if ((gui->pipeStdin).LineInput(string)) { + if((gui->io).EOF_()){ + my_log("POLYGLOT *** EOF from GUI ***\n"); + quit(); + return true; // we never get here + }else if ((gui->io).GetBuffer(string)) { my_log("GUI->Adapter: %s\n", string); return true; } else { string[0]='\0'; return false; } - #endif } @@ -65,14 +86,19 @@ bool gui_get_non_blocking(gui_t * gui, char string[], int size) { void gui_get(gui_t * gui, char string[], int size) { bool data_available; - while(true){ - data_available=gui_get_non_blocking(gui, string, size); - if(!data_available){ - Idle(); - }else{ - break; - } +#ifdef _WIN32 + if((gui->io).EOF_()){ + my_log("POLYGLOT *** EOF from GUI ***\n"); + quit(); } + (gui->io).LineInput(string); + my_log("GUI->Adapter: %s\n", string); +#else + if (!io_get_line(gui->io,string,size)) { // EOF + my_log("POLYGLOT *** EOF from GUI ***\n"); + quit(); + } +#endif } @@ -97,8 +123,7 @@ void gui_send(gui_t * gui, const char format[], ...) { #ifndef _WIN32 io_send(gui->io,"%s",string); #else - printf("%s\n",string); - fflush(stdout); + gui->io.LineOutput(string); my_log("Adapter->GUI: %s\n",string); #endif }