mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
bugfixes and simplifications to ice-9 buffered-input.
* module/ice-9/buffered-input.scm (make-buffered-input-port): Simplify, and fix one case in which we would buffer the EOF object.
This commit is contained in:
parent
62651cb317
commit
fe78af419c
1 changed files with 20 additions and 26 deletions
|
@ -1,6 +1,6 @@
|
||||||
;;;; buffered-input.scm --- construct a port from a buffered input reader
|
;;;; buffered-input.scm --- construct a port from a buffered input reader
|
||||||
;;;;
|
;;;;
|
||||||
;;;; Copyright (C) 2001, 2006 Free Software Foundation, Inc.
|
;;;; Copyright (C) 2001, 2006, 2010 Free Software Foundation, Inc.
|
||||||
;;;;
|
;;;;
|
||||||
;;;; This library is free software; you can redistribute it and/or
|
;;;; This library is free software; you can redistribute it and/or
|
||||||
;;;; modify it under the terms of the GNU Lesser General Public
|
;;;; modify it under the terms of the GNU Lesser General Public
|
||||||
|
@ -59,35 +59,29 @@ port when a new read operation starts, this data will be read before
|
||||||
the first call to @var{reader}, and so @var{reader} will be called
|
the first call to @var{reader}, and so @var{reader} will be called
|
||||||
with @var{continuation?} set to @code{#t}."
|
with @var{continuation?} set to @code{#t}."
|
||||||
(let ((read-string "")
|
(let ((read-string "")
|
||||||
(string-index -1))
|
(string-index 0))
|
||||||
(letrec ((get-character
|
(letrec ((get-character
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(cond
|
(if (< string-index (string-length read-string))
|
||||||
((eof-object? read-string)
|
;; Read a char.
|
||||||
(let ((eof read-string))
|
(let ((res (string-ref read-string string-index)))
|
||||||
(set! read-string "")
|
(set! string-index (+ 1 string-index))
|
||||||
(set! string-index -1)
|
(if (not (char-whitespace? res))
|
||||||
eof))
|
(set! (buffered-input-continuation? port) #t))
|
||||||
((>= string-index (string-length read-string))
|
res)
|
||||||
(set! string-index -1)
|
;; Fill the buffer.
|
||||||
(get-character))
|
(let ((x (reader (buffered-input-continuation? port))))
|
||||||
((= string-index -1)
|
(cond
|
||||||
(set! read-string (reader (buffered-input-continuation? port)))
|
((eof-object? x)
|
||||||
(set! string-index 0)
|
;; Don't buffer the EOF object.
|
||||||
(if (not (eof-object? read-string))
|
x)
|
||||||
(get-character)
|
(else
|
||||||
read-string))
|
(set! read-string x)
|
||||||
(else
|
(set! string-index 0)
|
||||||
(let ((res (string-ref read-string string-index)))
|
(get-character)))))))
|
||||||
(set! string-index (+ 1 string-index))
|
|
||||||
(if (not (char-whitespace? res))
|
|
||||||
(set! (buffered-input-continuation? port) #t))
|
|
||||||
res)))))
|
|
||||||
(input-waiting
|
(input-waiting
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(if (eof-object? read-string)
|
(- (string-length read-string) string-index)))
|
||||||
1
|
|
||||||
(- (string-length read-string) string-index))))
|
|
||||||
(port #f))
|
(port #f))
|
||||||
(set! port (make-soft-port (vector #f #f #f get-character #f input-waiting) "r"))
|
(set! port (make-soft-port (vector #f #f #f get-character #f input-waiting) "r"))
|
||||||
(set! (buffered-input-continuation? port) #f)
|
(set! (buffered-input-continuation? port) #f)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue