1 /* input.c -- input management stuff
3 * author: hackbard@hackdaworld.dyndns.org
9 int input_init(t_input *input) {
13 puts("[input] initializing input system ...");
15 if((input->content=(char *)malloc(MAX_CONTENT))==NULL) {
16 perror("[input] malloc call");
21 tcgetattr(0,&(input->tios));
24 if(!(input->mode&LINE_BUFFERED)) {
25 tios.c_lflag&=(~ICANON);
26 tios.c_lflag&=(~ECHO);
29 tcsetattr(0,TCSANOW,&tios);
35 int input_shutdown(t_input *input) {
38 tcsetattr(0,TCSANOW,&(input->tios));
39 puts("[input] shutdown");
44 int input_get_event(t_input *input,int (*callback)(t_input *input,void *ptr),
47 char data[MAX_CONTENT];
50 /* delete char counter if not buffered */
51 if(!(input->mode&CONTENT_BUFFER)) input->c_count=0;
53 if((count=read(0,data,MAX_CONTENT))==-1) {
54 perror("[input] read call");
58 if(input->c_count>=MAX_CONTENT) {
59 puts("[input] max input length reached");
63 strncpy(&(input->content[input->c_count]),data,count);
64 input->c_count+=count;