aboutsummaryrefslogtreecommitdiff
path: root/src/ctaklm.c
diff options
context:
space:
mode:
authortslil clingman <tslil@posteo.de>2021-01-18 20:33:43 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commit897b759511426de4fbc94defb278e85b3bb3ec40 (patch)
tree3a835318cfc04887168ac7ec5c333f6eb3e9e6f5 /src/ctaklm.c
parent39ec3bc95e6a27e97c3200a558d9cc8712853606 (diff)
Shed dependency of linenoise
Diffstat (limited to 'src/ctaklm.c')
-rw-r--r--src/ctaklm.c26
1 files changed, 16 insertions, 10 deletions
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 <stdio.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
-#include <linenoise.h>
#include <tak.h>
#include <ct1986.h>
@@ -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);