1 /* input.c -- input management stuff
3 * author: hackbard@hackdaworld.dyndns.org
9 int input_init(t_input *input) {
14 puts("[input] initializing input system ...");
16 size=((input->mode&CONTENT_BUFFER)?MAX_CONTENT:1);
18 if((input->content=(char *)malloc(size))==NULL) {
19 perror("[input] malloc call");
23 memset(input->content,0,size);
26 tcgetattr(0,&(input->tios));
29 /* general settings */
30 tios.c_iflag&=ICRNL; /* \r -> \n */
31 tios.c_cc[VTIME]=0; /* no timeout */
32 tios.c_cc[VMIN]=1; /* 1 char for non-can. mode */
34 /* depending on used modes */
35 if(!(input->mode&LINE_BUFFERED)) tios.c_lflag&=(~ICANON);
36 if(!(input->mode&INPUT_ECHO)) tios.c_lflag&=(~ECHO);
38 tcsetattr(0,TCSANOW,&tios);
43 int input_shutdown(t_input *input) {
46 tcsetattr(0,TCSANOW,&(input->tios));
47 puts("[input] shutdown");
52 int input_get_event(t_input *input,int (*callback)(t_input *input,void *ptr),
55 char data[MAX_CONTENT];
58 /* delete char counter if not buffered */
59 if(!(input->mode&CONTENT_BUFFER)) input->c_count=0;
61 if((count=read(0,data,MAX_CONTENT))==-1) {
62 perror("[input] read call");
66 if(input->c_count>=MAX_CONTENT) {
67 puts("[input] max input length reached");
71 strncpy(&(input->content[input->c_count]),data,count);
72 input->c_count+=count;