forked from ulthiel/polyglot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.c
97 lines (63 loc) · 1.41 KB
/
gui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// gui.c
// includes
#include <stdarg.h>
#include <signal.h>
#include "gui.h"
#include "main.h"
// 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,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[], ...) {
char string[FormatBufferSize];
ASSERT(gui!=NULL);
ASSERT(format!=NULL);
// format
CONSTRUCT_ARG_STRING(format,string);
// send
pipex_writeln(gui->pipex,string);
}