From 82b1cce1bc5c91c0b56501f5dab912390206ace5 Mon Sep 17 00:00:00 2001 From: Tristan Riehs Date: Thu, 20 Jun 2024 20:39:08 +0900 Subject: Use cli and gui as shared libraries --- src/calculer.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) (limited to 'src/calculer.c') 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 +#include #include #include #include @@ -25,7 +26,6 @@ #include #include -#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); -- cgit v1.2.3