From 38ec07c34b5cb57510367ba086b6288260da373d Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 6 Jan 2023 17:55:49 +0200 Subject: [PATCH] use getline on Windows for the REPL --- src/builtins/sysfn.c | 7 +++---- src/main.c | 10 +++++----- src/windows/getline.h | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 047e1e6e..27b1af91 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -9,9 +9,7 @@ #include "../nfns.h" #include -#if !defined(_WIN32) && !defined(_WIN64) - #include -#else +#if defined(_WIN32) || defined(_WIN64) #include "../windows/getline.c" #endif #include @@ -892,11 +890,12 @@ B toUtf8_c1(B t, B x) { extern char** environ; -#if __has_include() && __has_include() && !WASM +#if __has_include() && __has_include() && __has_include() && __has_include() && !WASM #define HAS_SH 1 #include #include #include +#include typedef struct pollfd pollfd; void shClose(int fd) { if (close(fd)) err("bad file descriptor close"); } diff --git a/src/main.c b/src/main.c index 6872c8e5..703ca577 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,10 @@ #include "utils/time.h" #include "utils/interrupt.h" +#if defined(_WIN32) || defined(_WIN64) + #include "windows/getline.h" +#endif + #if __GNUC__ && __i386__ && !__clang__ #warning "CBQN is known to miscompile on GCC for 32-bit x86 builds; using clang instead is suggested" @@ -899,11 +903,7 @@ int main(int argc, char* argv[]) { } char* ln = NULL; size_t gl = 0; - #if defined(_WIN32) || defined(_WIN64) - i64 read = 0; - #else - i64 read = getline(&ln, &gl, stdin); - #endif + i64 read = getline(&ln, &gl, stdin); if (read<=0 || ln[0]==0) { if(!silentREPL) putchar('\n'); break; } if (ln[read-1]==10) ln[--read] = 0; cbqn_runLine(ln, read); diff --git a/src/windows/getline.h b/src/windows/getline.h index 11512b8b..7b121161 100644 --- a/src/windows/getline.h +++ b/src/windows/getline.h @@ -6,6 +6,6 @@ #define MAX_LINE_LENGTH 8192 -//ssize_t processinput (char **lptr, size_t *n, FILE *hIn); +ssize_t getline(char **lptr, size_t *n, FILE *fp); #endif /* GETLINE_H */ \ No newline at end of file