X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fivac.git;a=blobdiff_plain;f=src%2Finput.c;fp=src%2Finput.c;h=0000000000000000000000000000000000000000;hp=b29688ce50b90d31243d7a8d1968b065335eebce;hb=21a073b6e9d464f3f11dfb290d27341bb4a203b6;hpb=40031b2d692a7b83e437535045ece6c58f8bf31e diff --git a/src/input.c b/src/input.c deleted file mode 100644 index b29688c..0000000 --- a/src/input.c +++ /dev/null @@ -1,77 +0,0 @@ -/* 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; -}