From 0e1d98963c1f8f28bafd53fd9b10d937fc216cb4 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 21 Oct 2018 12:00:00 +0200 Subject: [PATCH] mes: read-string: Take optional port argument. * src/posix.c (read_string): Take optional port argument. * mes/module/mes/guile.mes (read-string): Remove. --- mes/module/mes/guile.mes | 10 ---------- src/posix.c | 6 +++++- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/mes/module/mes/guile.mes b/mes/module/mes/guile.mes index 65169415..ab1e2455 100644 --- a/mes/module/mes/guile.mes +++ b/mes/module/mes/guile.mes @@ -31,16 +31,6 @@ (mes-use-module (srfi srfi-16)) (mes-use-module (mes display)) -(if #t ;;(not (defined? 'read-string)) - (define (read-string) - (define (read-string c) - (if (eq? c #\*eof*) '() - (cons c (read-string (read-char))))) - (let ((string (list->string (read-string (read-char))))) - (if (and=> (getenv "MES_DEBUG") (compose (lambda (o) (> o 3)) string->number)) - (core:display-error (string-append "drained: `" string "'\n"))) - string))) - (define (drain-input port) (read-string)) (define (make-string n . fill) diff --git a/src/posix.c b/src/posix.c index acd77e48..eba767a4 100644 --- a/src/posix.c +++ b/src/posix.c @@ -112,8 +112,11 @@ write_char (SCM i) ///((arity . n)) } SCM -read_string () +read_string (SCM port) ///((arity . n)) { + int fd = g_stdin; + if (TYPE (port) == TPAIR && TYPE (car (port)) == TNUMBER) + g_stdin = VALUE (CAR (port)); SCM lst = cell_nil; SCM c = read_char (); while (VALUE (c) != -1) @@ -121,6 +124,7 @@ read_string () lst = append2 (lst, cons (c, cell_nil)); c = read_char (); } + g_stdin = fd; return MAKE_STRING (lst); }