1 /* input.c -- input management stuff
3 * author: hackbard@hackdaworld.dyndns.org
9 int input_init(t_input *input,int outfd) {
11 dprintf(outfd,"[input] initializing input system ...\n");
19 int input_ios_init(t_input *input) {
24 size=((input->mode&CONTENT_BUFFER)?MAX_CONTENT:1);
26 if((input->content=(char *)malloc(size))==NULL) {
27 perror("[input] malloc call");
31 memset(input->content,0,size);
34 tcgetattr(0,&(input->tios));
37 /* general settings */
38 tios.c_iflag&=ICRNL; /* \r -> \n */
39 tios.c_cc[VTIME]=0; /* no timeout */
40 tios.c_cc[VMIN]=1; /* 1 char for non-can. mode */
42 /* depending on used modes */
43 if(!(input->mode&LINE_BUFFERED)) tios.c_lflag&=(~ICANON);
44 if(!(input->mode&INPUT_ECHO)) tios.c_lflag&=(~ECHO);
46 tcsetattr(0,TCSANOW,&tios);
51 int input_shutdown(t_input *input) {
54 tcsetattr(0,TCSANOW,&(input->tios));
55 dprintf(input->outfd,"[input] shutdown\n");
60 int input_get_event(t_input *input,int (*callback)(t_input *input,void *ptr),
63 char data[MAX_CONTENT];
66 /* delete char counter if not buffered */
67 if(!(input->mode&CONTENT_BUFFER)) input->c_count=0;
69 if((count=read(0,data,MAX_CONTENT))==-1) {
70 perror("[input] read call");
74 if(input->c_count>=MAX_CONTENT) {
75 dprintf(input->outfd,"[input] max input length reached\n");
79 strncpy(&(input->content[input->c_count]),data,count);
80 input->c_count+=count;