aboutsummaryrefslogtreecommitdiff
path: root/src/calculer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/calculer.c')
-rw-r--r--src/calculer.c34
1 files changed, 9 insertions, 25 deletions
diff --git a/src/calculer.c b/src/calculer.c
index de2dcf8..eab2bde 100644
--- a/src/calculer.c
+++ b/src/calculer.c
@@ -18,6 +18,7 @@
#include "config.h"
#include <assert.h>
+#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -25,7 +26,6 @@
#include <time.h>
#include <unistd.h>
-#include "_readline.h"
#include "disp.h"
static int lower = 0;
@@ -187,43 +187,27 @@ main(int argc, char *argv[])
logfile = fopen(logpath, "a");
assert(logfile); /* TODO: handle non-fatal error properly */
disp = get_disp(disp_name);
+ disp->init();
while (1)
{
- char prompt[32] = {0};
int x, y, res;
- char *input;
- int input_val;
+ int input;
x = calculer_rand();
y = calculer_rand();
res = x+y;
-
- sprintf(prompt, "%d + %d = ", x, y);
+ disp->display_calc(x, y);
void *measure_data = measure_before();
- input = readline(prompt);
-
- if ((!input) || (*input == '\0'))
+ input = disp->read_input();
+ if (input == INT_MAX)
{
- free(input);
+ disp->destroy();
fclose(logfile);
exit(0);
}
-
- input_val = atoi(input);
- if (measure_after(measure_data, input_val == res))
- {
- free(input);
- fclose(logfile);
- exit(1);
- }
-
- if (input_val == res)
- printf("RIGHT\n");
- else
- printf("WRONG\n");
-
- free(input);
+ measure_after(measure_data, input == res);
+ disp->display_res(input == res, 0);
}
fclose(logfile);