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); <- ???
19 if((input->content=(char *)malloc(size))==NULL) {
20 perror("[input] malloc call");
24 memset(input->content,0,size);
27 tcgetattr(0,&(input->tios));
30 /* general settings */
31 tios.c_iflag&=ICRNL; /* \r -> \n */
32 tios.c_cc[VTIME]=0; /* no timeout */
33 tios.c_cc[VMIN]=1; /* 1 char for non-can. mode */
35 /* depending on used modes */
36 if(!(input->mode&LINE_BUFFERED)) tios.c_lflag&=(~ICANON);
37 if(!(input->mode&INPUT_ECHO)) tios.c_lflag&=(~ECHO);
39 tcsetattr(0,TCSANOW,&tios);
44 int input_shutdown(t_input *input) {
47 tcsetattr(0,TCSANOW,&(input->tios));
48 puts("[input] shutdown");
53 int input_get_event(t_input *input,int (*callback)(t_input *input,void *ptr),
56 char data[MAX_CONTENT];
59 /* delete char counter if not buffered */
60 if(!(input->mode&CONTENT_BUFFER)) input->c_count=0;
62 if((count=read(0,data,MAX_CONTENT))==-1) {
63 perror("[input] read call");
67 if(input->c_count>=MAX_CONTENT) {
68 puts("[input] max input length reached");
72 strncpy(&(input->content[input->c_count]),data,count);
73 input->c_count+=count;