guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: drain-input


From: Neil Jerram
Subject: Re: drain-input
Date: 27 Aug 2001 10:24:21 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

>>>>> "Gary" == Gary Houston <address@hidden> writes:

    >> From: Alex Shinn <address@hidden> Date: 24 Aug 2001
    >> 11:11:05 -0400
    >> 
    >> Could someone explain the purpose of drain-input?  My first
    >> impression was that it would read all remaining input from an
    >> input port, so that you could do the following:

    Gary> It's returning the contents of the port input buffers.  It's
    Gary> possibly useful for syncing buffered input for operations
    Gary> that act directly on the file descriptor.

Here's a procedure that does what I expected `drain-input' to be.  I
use it often in connection with `open-input-pipe':

(define (drain-output port)
  (let loop ((chars '())
             (next (read-char port)))
    (if (eof-object? next)
        (list->string (reverse! chars))
        (loop (cons next chars)
              (read-char port)))))

For example...

(define (texinfo->info str)
  (let* ((tmp (mkstemp! (string-copy "/tmp/guile-makeinfo-XXXXXX")))
         (tmpfn (port-filename tmp)))
    (display str tmp)
    (force-output tmp)
    (close-port tmp)
    (let* ((pipe (open-input-pipe (string-append "makeinfo"
                                                 " --no-headers"
                                                 " --force"
                                                 " -o - "
                                                 tmpfn)))
           (infostr (drain-output pipe)))
      (close-pipe pipe)
      (delete-file tmpfn)
      infostr)))

Perhaps it would be worth adding `drain-output' to (ice-9 popen) ?

        Neil




reply via email to

[Prev in Thread] Current Thread [Next in Thread]