mes: read-string: Take optional port argument.

* src/posix.c (read_string): Take optional port argument.
* mes/module/mes/guile.mes (read-string): Remove.
This commit is contained in:
Jan Nieuwenhuizen 2018-10-21 12:00:00 +02:00
parent d6660a5d83
commit 0e1d98963c
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
2 changed files with 5 additions and 11 deletions

View file

@ -31,16 +31,6 @@
(mes-use-module (srfi srfi-16)) (mes-use-module (srfi srfi-16))
(mes-use-module (mes display)) (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 (drain-input port) (read-string))
(define (make-string n . fill) (define (make-string n . fill)

View file

@ -112,8 +112,11 @@ write_char (SCM i) ///((arity . n))
} }
SCM 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 lst = cell_nil;
SCM c = read_char (); SCM c = read_char ();
while (VALUE (c) != -1) while (VALUE (c) != -1)
@ -121,6 +124,7 @@ read_string ()
lst = append2 (lst, cons (c, cell_nil)); lst = append2 (lst, cons (c, cell_nil));
c = read_char (); c = read_char ();
} }
g_stdin = fd;
return MAKE_STRING (lst); return MAKE_STRING (lst);
} }