This is the mail archive of the
guile@cygnus.com
mailing list for the Guile project.
a simple problem
- To: guile@sourceware.cygnus.com
- Subject: a simple problem
- From: "<Brad Knotwell" <knotwell@f5.com>
- Date: Mon, 16 Aug 1999 16:50:26 -0700 (PDT)
- Reply-To: knotwell@f5.com
This is probably a frequent problem, so I apologize in advance.
I wrote a small program (guile 1.3) to illustrate my problem. I'm
trying to copy from one port to another. I'd hoped to use
read-line/write-line to do so, but it appears that for binary data
there's a problem. However, I thought the 'split option to read-line
could help me work around it.
Interestingly enough, the split flag leads me to copy the correct
number of bytes, but the data is different than I expect. Am I
completely misunderstanding the usage of the split flag and the
difference between display and write-line?
Thanks in advance.
--Brad
#!/usr/local/bin/guile -s
!#
(define in (open-input-file "/var/lib/locatedb"))
(define out (open-output-file "/tmp/b"))
;this works but it __dirt__ slow and doesn't fit the interface I'd
;like
;
;(define (cp-port in-port out-port)
; (let ((data (read-char in-port)))
; (if (eof-object? data)
; #t
; (begin
; (write-char data out-port)
; (cp-port in-port out-port)))))
;this should work and does copy the correct number of bytes,
;but the bytes written to the output port appear wrong
(define (cp-port in-port out-port)
(let ((data (read-line in-port 'split)))
(if (eof-object? (cdr data))
(begin
(display (car data) out-port)
#t)
(begin
(write-line (car data) out-port)
(cp-port in-port out-port)))))
(cp-port in out)