|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
//
// 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);
}
|