From 897b759511426de4fbc94defb278e85b3bb3ec40 Mon Sep 17 00:00:00 2001 From: tslil clingman Date: Mon, 18 Jan 2021 20:33:43 -0500 Subject: Shed dependency of linenoise --- src/ctaklm.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ctaklm.c b/src/ctaklm.c index 080da01..ff5b8b0 100644 --- a/src/ctaklm.c +++ b/src/ctaklm.c @@ -1,8 +1,7 @@ -#include #include +#include #include -#include #include #include @@ -424,18 +423,25 @@ main(int argc, char **argv) { search_depth = 3; new_game(5); - char *line; + char *line = NULL; + ssize_t read; + size_t alloc_size; + for (int playing = 1; playing;) { - while((human == 0) && (line = linenoise("ctaklm> ")) != NULL) { - if (input_is_not_turn(line)) { - int r = handle_turn(line); - if (r == EXIT_SUCCESS && won == 0xFF) { - human = 1; + fputs("ctaklm> ", stdout); + fflush(stdout); + while ((human == 0) && (read = getline(&line, &alloc_size, stdin)) != -1) { + if (read) { + line[read - 1] = 0; + if (input_is_not_turn(line)) { + int r = handle_turn(line); + if (r == EXIT_SUCCESS && won == 0xFF) { + human = 1; + } } } - free(line); } - if ((human == 0) && line == NULL) { + if ((human == 0) && (read == -1)) { playing = 0; } else { ct1986_turn(search_depth); -- cgit v1.3.1