X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=gui.c;fp=gui.c;h=9dbe6f5867f4f136c8a16d499adc552ad3076a44;hb=e15efca6667b2673b4c1a5879a6917eab6800e58;hp=0000000000000000000000000000000000000000;hpb=0d182b4efac85dce968068bfe4509e52e9a30051;p=polyglot.git diff --git a/gui.c b/gui.c new file mode 100644 index 0000000..9dbe6f5 --- /dev/null +++ b/gui.c @@ -0,0 +1,104 @@ +// gui.c + +// includes + +#include +#include + +#include "gui.h" +#include "main.h" + +// constants + +static const int StringSize = 4096; + +// variables + +gui_t GUI[1]; + +// functions + +// sig_int() + +static void sig_int(int dummy){ + my_log("POLYGLOT *** SIGINT Received ***\n"); + quit(); +} + +// sig_pipe() + +static void sig_pipe(int dummy){ + my_log("POLYGLOT *** SIGPIPE Received ***\n"); + quit(); +} + +// sig_term() + +static void sig_term(int dummy){ + my_log("POLYGLOT *** SIGTERM Received ***\n"); + quit(); +} + + +// gui_init() + +void gui_init(gui_t *gui){ + +// the following is nice if the "GUI" is a console! + signal(SIGINT,sig_int); +#ifdef SIGTERM + signal(SIGTERM,sig_term); +#endif +#ifdef SIGPIPE + signal(SIGPIPE,sig_pipe); +#endif + pipex_open(gui->pipex,"GUI",NULL); +} + + +// gui_get_non_blocking() + +bool gui_get_non_blocking(gui_t * gui, char *string) { + + ASSERT(gui!=NULL); + ASSERT(string!=NULL); + + if(pipex_eof(gui->pipex)){ + quit(); + return TRUE; // we never get here + } + return pipex_readln_nb(gui->pipex,string); +} + +// gui_get() + +void gui_get(gui_t * gui, char *string) { + if(pipex_eof(gui->pipex)){ + quit(); + } + pipex_readln(gui->pipex,string); +} + + +// gui_send() + +void gui_send(gui_t * gui, const char format[], ...) { + + va_list arg_list; + char string[StringSize]; + + ASSERT(gui!=NULL); + ASSERT(format!=NULL); + + // format + + va_start(arg_list,format); + vsprintf(string,format,arg_list); + va_end(arg_list); + + // send + + pipex_writeln(gui->pipex,string); + +} +