use getline on Windows for the REPL

This commit is contained in:
dzaima 2023-01-06 17:55:49 +02:00
parent 833c90b334
commit 38ec07c34b
3 changed files with 9 additions and 10 deletions

View File

@ -9,9 +9,7 @@
#include "../nfns.h"
#include <unistd.h>
#if !defined(_WIN32) && !defined(_WIN64)
#include <poll.h>
#else
#if defined(_WIN32) || defined(_WIN64)
#include "../windows/getline.c"
#endif
#include <errno.h>
@ -892,11 +890,12 @@ B toUtf8_c1(B t, B x) {
extern char** environ;
#if __has_include(<spawn.h>) && __has_include(<sys/wait.h>) && !WASM
#if __has_include(<spawn.h>) && __has_include(<fcntl.h>) && __has_include(<sys/wait.h>) && __has_include(<sys/poll.h>) && !WASM
#define HAS_SH 1
#include <spawn.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <poll.h>
typedef struct pollfd pollfd;
void shClose(int fd) { if (close(fd)) err("bad file descriptor close"); }

View File

@ -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);

View File

@ -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 */