+++ /dev/null
-/* input.c -- input management stuff
- *
- * author: hackbard@hackdaworld.dyndns.org
- *
- */
-
-#include "input.h"
-
-int input_init(t_input *input) {
-
- struct termios tios;
- int size;
-
- puts("[input] initializing input system ...");
-
- size=((input->mode&CONTENT_BUFFER)?MAX_CONTENT:1);
-
- if((input->content=(char *)malloc(size))==NULL) {
- perror("[input] malloc call");
- return I_ERROR;
- }
-
- memset(input->content,0,size);
- input->c_count=0;
-
- tcgetattr(0,&(input->tios));
- tios=input->tios;
-
- /* general settings */
- tios.c_iflag&=ICRNL; /* \r -> \n */
- tios.c_cc[VTIME]=0; /* no timeout */
- tios.c_cc[VMIN]=1; /* 1 char for non-can. mode */
-
- /* depending on used modes */
- if(!(input->mode&LINE_BUFFERED)) tios.c_lflag&=(~ICANON);
- if(!(input->mode&INPUT_ECHO)) tios.c_lflag&=(~ECHO);
-
- tcsetattr(0,TCSANOW,&tios);
-
- return I_SUCCESS;
-}
-
-int input_shutdown(t_input *input) {
-
- free(input->content);
- tcsetattr(0,TCSANOW,&(input->tios));
- puts("[input] shutdown");
-
- return I_SUCCESS;
-}
-
-int input_get_event(t_input *input,int (*callback)(t_input *input,void *ptr),
- void *ptr) {
-
- char data[MAX_CONTENT];
- int count;
-
- /* delete char counter if not buffered */
- if(!(input->mode&CONTENT_BUFFER)) input->c_count=0;
-
- if((count=read(0,data,MAX_CONTENT))==-1) {
- perror("[input] read call");
- return I_ERROR;
- }
-
- if(input->c_count>=MAX_CONTENT) {
- puts("[input] max input length reached");
- return I_ERROR;
- }
-
- strncpy(&(input->content[input->c_count]),data,count);
- input->c_count+=count;
-
- callback(input,ptr);
-
- return I_SUCCESS;
-}