-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
67 lines (64 loc) · 1.4 KB
/
main.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "header/main.h"
#include "header/output.h"
#include "header/input.h"
//TODO Put Input functions in an own file
//TODO Not very readable
int main(void)
{
char input[IN_SZ];
int retv = 0;
while(1)
{
II_Action action = None;
unsigned int insz = 0;
int rires = 0;
printout("Enter action: ");
rires = readInput(input, IN_SZ, &insz);
if (rires == RI_EOF)
break;
if (rires == RI_INSUFFICIENT_BUFFER_SIZE)
printerr("Insufficient buffer size ignoring remaining characters");
else if (rires)
{
printerr("Error reading input");
break;
}
if (insz > IN_SZ)
{
printerr("Unknwon error reading input");
retv = 1;
break;
}
if(interpretInput(input, insz, &action))
printerr("Could not interpret input");
else
{
rires = executeInput(action, input, insz);
if (rires == EI_EXIT)
break;
//TODO Make pretty after separating retvs
//TODO Put strings somewhere else
if (rires != EXAMPLE_SUCCESS)
{
switch(rires)
{
case EXAMPLE_FAIL:
printerr("Example failed");
break;
case EI_EX_DETER_FAILED:
printerr("Example number could not be determined");
break;
case EE_UNKNOWN_EXNO:
printerr("Example number not found");
break;
case EI_UNKNOWN_ACTION:
printerr("Unrecognised action");
break;
default:
printerr("Unknwon error while trying to execute input");
}
}
}
}
return retv;
}