// // Created by imanol on 12/27/16. // #include "input.h" unsigned int input_buffer_length = 0; unsigned int input_buffer_pos = 0; char input_buffer[MAX_INT]; unsigned int stdin_length() { unsigned int length = 0; ioctl(0, I_NREAD, &length); return length; } void read_input() { strncpy(input_buffer,input_buffer+input_buffer_pos,input_buffer_size()); input_buffer_pos = input_buffer_size(); unsigned int old_buffer_length = input_buffer_length; input_buffer_length = stdin_length(); if(!input_buffer_length) { input_buffer_length = 64; //arbitrary } fgets(input_buffer+input_buffer_pos,input_buffer_length,stdin); //TODO: Improve this... Get a way to know how many bytes read input_buffer_length = (unsigned int)strlen(input_buffer); //input_buffer_length += old_buffer_length; } char get_input() { char c = input_buffer[input_buffer_pos++]; return c; } unsigned int input_buffer_size() { return input_buffer_length - (input_buffer_pos); }