From f530eb180414210cb3af4c297abbaccc8bac57c1 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 30 Jul 2015 22:55:46 -0400 Subject: [PATCH] Added read-line --- runtime.c | 7 +++++-- scheme/base.sld | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime.c b/runtime.c index 87e52b8e..1f7a8ad7 100644 --- a/runtime.c +++ b/runtime.c @@ -1381,8 +1381,11 @@ object Cyc_io_read_line(object cont, object port) { if (c == EOF && i == 0) { return_funcall1(cont, Cyc_EOF); } else if (c == EOF || i == 1023 || c == '\n') { - make_string(s, buf); - return_funcall1(cont, &s); + buf[i] = '\0'; + { + make_string(s, buf); + return_funcall1(cont, &s); + } } buf[i++] = c; diff --git a/scheme/base.sld b/scheme/base.sld index 5523e056..db33df76 100644 --- a/scheme/base.sld +++ b/scheme/base.sld @@ -78,6 +78,7 @@ newline write-char flush-output-port + read-line features ) (begin @@ -139,6 +140,10 @@ (if (null? lst) end (func (car lst) (foldr func end (cdr lst))))) + (define (read-line . port) + (if (null? port) + (Cyc-read-line (current-output-port)) + (Cyc-read-line (car port)))) (define (flush-output-port . port) (if (null? port) (Cyc-flush-output-port (current-output-port))