guile-user
[Top][All Lists]
Advanced

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

Re: Newbie question - How do I get a full transcript?


From: Tim Halliday
Subject: Re: Newbie question - How do I get a full transcript?
Date: Thu, 21 Nov 2002 16:37:16 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.1) Gecko/20020827

Neil,

Thanks. You suggestion pointed me down a fruitful path. I'm not using
readline at the moment, so I can get away with the following.

-tim



(define (fork-out-port stdPort transPort )
  (make-soft-port
    (vector
      (lambda (c)
         ( write c stdPort )
         ( write c transPort )
         ( force-output transPort ) )
      (lambda (s)
         ( display s stdPort )
         ( display s transPort )
         ( force-output transPort ) )
      (lambda ()
         ( force-output stdPort )
         ( force-output transPort ) )
      (lambda () #f )
      (lambda ()
         ( close-port stdPort )
         ( close-port transPort ) )
    )
    "w"
))

(define (fork-in-port stdPort transPort )
  (make-soft-port
    (vector
      (lambda (c) #f)
      (lambda (s) #f)
      (lambda () #f)
      (lambda ()
        (define c (read-char stdPort ) )
        (display c transPort )
        c )
      (lambda ()
         ( close-port stdPort )
         ( close-port transPort ) )
    )
    "rw"
))

(let ((transcript (open-output-file "transcript")))
  (set-current-output-port (fork-out-port (current-output-port) transcript))
  (set-current-error-port (fork-out-port (current-error-port) transcript))
  (set-current-input-port (fork-in-port (current-input-port) transcript)))





Neil Jerram wrote:
"Tim" == Tim Halliday <address@hidden> writes:


    Tim> I've got a C application which I've bound Guile into. I want
    Tim> to generate a complete transcript of everything that the user
    Tim> enters, or Guile displays during the session.

    Tim> I've tried specifying hooks for before-print-hook and
    Tim> before-eval-hook, but that doesn't seem to get me everything
    Tim> like Guile generated error messages.

    Tim> Is there a better way to go about this?

Interesting question.  I don't think there's any simple way.  For a
transcript of output you can create a new output that acts like `tee':

(define (fork-port . ports)
(make-soft-port (vector
      (lambda (c)
        (for-each (lambda (port)
                    (write c port))
                  ports))
      (lambda (s)
        (for-each (lambda (port)
                    (display s port))
                  ports))
      (lambda ()
        (for-each force-output ports))
      #f
      (lambda ()
        (for-each close-port ports)))
    "w"))

(let ((transcript (open-output-file "transcript")))
  (set-current-output-port (fork-port (current-output-port) transcript))
  (set-current-error-port (fork-port (current-error-port) transcript)))

Input is trickier because of readline.

        Neil




--

Tim Halliday
address@hidden
214.480.1399





reply via email to

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