GNU bug report logs -
#21829
guix import hackage failures
Previous Next
Full log
Message #29 received at 21829 <at> debbugs.gnu.org (full text, mbox):
On Thu, Nov 12, 2015 at 9:21 PM, Ludovic Courtès <ludo <at> gnu.org> wrote:
> If we go for the CRLF conversion port, we should avoid the pipe and
> extra thread. Instead, I would suggest something like:
>
> (define (canonical-newline-port port)
> "Return an input port that wraps PORT such that all newlines consist
> of a single carriage return."
> (make-custom-binary-input-port …))
I like this suggestion :-)
I never used custom ports. Is something like this OK? (Seems to work
in the REPL.)
---------------------------------------------------------------
(define (canonical-newline-port port)
"Return an input port that wraps PORT such that all newlines consist
of a single carriage return."
(define (get-position)
(if (port-has-port-position? port) (port-position port) #f))
(define (set-position! position)
(if (port-has-set-port-position!? port)
(set-port-position! position port)
#f))
(define (close) (close-port port))
(define (read! bv start n)
(let loop ((count 0)
(byte (get-u8 port)))
(cond ((or (eof-object? byte) (= count n)) count)
((eqv? byte (char->integer #\return)) (loop count (get-u8 port)))
(else
(bytevector-u8-set! bv (+ start count) byte)
(loop (+ count 1) (get-u8 port))))))
(make-custom-binary-input-port "canonical-newline-port"
read!
get-position
set-position!
close))
---------------------------------------------------------------
IMO this is general enough that it could go into "guix/utils.scm". Are
you OK with this?
Regards,
Fede
This bug report was last modified 9 years and 239 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.