diff options
author | Alex AUVOLAT <alexis211@gmail.com> | 2013-06-08 23:09:52 +0200 |
---|---|---|
committer | Alex AUVOLAT <alexis211@gmail.com> | 2013-06-08 23:09:52 +0200 |
commit | 4d65fcb9a8b6c7c6fd5a3390c46a96d11b6a80d4 (patch) | |
tree | c193acf64ff2db985f6664f161cf586c3caeb684 /src/user/lib/libc/std/readline.c | |
parent | eae9997d3c2dbaef53022ddabe61c1800a619499 (diff) | |
download | TCE-4d65fcb9a8b6c7c6fd5a3390c46a96d11b6a80d4.tar.gz TCE-4d65fcb9a8b6c7c6fd5a3390c46a96d11b6a80d4.zip |
All FWIK is deleted. YOSH is now pure C. Not-working KBASIC included.
Diffstat (limited to 'src/user/lib/libc/std/readline.c')
-rw-r--r-- | src/user/lib/libc/std/readline.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/user/lib/libc/std/readline.c b/src/user/lib/libc/std/readline.c index 50e4f0d..4177bf6 100644 --- a/src/user/lib/libc/std/readline.c +++ b/src/user/lib/libc/std/readline.c @@ -1,15 +1,14 @@ #include <readline.h> #include <stdlib.h> -char* freadln(FILE f) { - fprint(f, "\x1b[e"); // enable keyboard echo +char* freadln(FILE *f) { int i; char *p = (char*)malloc(256); char *b = p; while (1) { - int l = read(f, 0, 255, b); + int l = fread(b, 255, 1, f); if (l < 0) { free(b); return 0; @@ -36,15 +35,14 @@ char* freadln(FILE f) { } char* readln() { - return freadln(term); + return freadln(&term); } // ** READLINE -char *freadline(FILE f, readline_history *h) { +char *freadline(FILE *f, readline_history *h) { int i; - fprint(f, "\x1b[h"); // disable keyboard echo if (h->str == 0) { h->str = (char**)malloc(h->max * sizeof(char*)); @@ -78,12 +76,15 @@ char *freadline(FILE f, readline_history *h) { int te = cur - str; char buf[16]; - int l = read(f, 0, 16, buf); + int l = fread(buf, 16, 1, f); if (l < 0) return 0; char *in = buf; while (in < buf + l) { - if (*in == 27) { + if (*in == 4) { // eot + fprintf(f, "^D\n"); + return 0; + } else if (*in == 27) { in++; if (*in == '[') { in++; @@ -142,7 +143,7 @@ char *freadline(FILE f, readline_history *h) { if (finished) { - fprintf(f, "\n"); + fprint(f, "\n"); if (h->str[h->n-1] != str) h->n--; |