Fixing make-generated-input-port for real.

This commit is contained in:
Alex Shinn 2015-01-22 12:10:11 +09:00
parent 7156ce08b2
commit ed467add6a

View file

@ -354,13 +354,16 @@
(let ((n (- end start))) (let ((n (- end start)))
(cond (cond
((>= (- len offset) n) ((>= (- len offset) n)
;; buf contains enough to fill str
(let* ((offset2 (let* ((offset2
(string-cursor-copy! str start buf offset (+ offset n))) (string-cursor-copy! str start buf offset (+ offset n)))
(end2 (+ (- offset2 offset) start))) (end2 (+ (- offset2 offset) start)))
(set! offset offset2) (set! offset offset2)
end2)) end2))
(else (else
;; copy the rest of buf into str
(string-cursor-copy! str start buf offset len) (string-cursor-copy! str start buf offset len)
;; i is the position to copy into str, from start to end
(let lp ((i (+ start (- len offset)))) (let lp ((i (+ start (- len offset))))
(set! buf (generator)) (set! buf (generator))
(cond (cond
@ -371,16 +374,15 @@
(+ i start)) (+ i start))
(else (else
(set! len (string-size buf)) (set! len (string-size buf))
(set! offset 0)
(cond (cond
((>= (- len offset) (- n i)) ((>= len (- n i))
(let* ((offset2 (string-cursor-copy! str i buf 0 (- n i))) (let* ((offset2 (string-cursor-copy! str i buf 0 (- n i)))
(end2 (+ (- offset2 offset) start))) (end2 (+ i offset2)))
(set! offset offset2) (set! offset offset2)
end2)) end2))
(else (else
(let ((offset2 (string-cursor-copy! str i buf offset len))) (let ((offset2 (string-cursor-copy! str i buf 0 len)))
(lp (+ i (- offset2 offset)))))))))))))))) (lp (+ i offset2)))))))))))))))
;;> An input port which runs all input (in arbitrary string chunks) ;;> An input port which runs all input (in arbitrary string chunks)
;;> through the \var{filter} procedure. ;;> through the \var{filter} procedure.