guile-user
[Top][All Lists]
Advanced

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

Re: Change every in/out port?


From: Alejandro Forero Cuervo
Subject: Re: Change every in/out port?
Date: Wed, 12 Dec 2001 09:15:20 -0500
User-agent: Mutt/1.2.5i

    I'm sorry that I cannot completely understand Scheme's
    port concept.

Ports are just streams.  Output sent to output ports can go to files
(in the Unix file descriptor sense: this includes sockets, terminals,
files (of course) and a few of other things) or to buffers in memory
(and perhaps to a few other things).  Input ports are just the same
but, obviously, for reading, not for writing.

    I want to change guile's input/output ports to the
    my internal buffers (e.g. char buf[...]).

One part of this is very easy to do.  All you need to do is create a
string output port (this is the kind of output port that stores
writting information in a buffer) and set it as your current
output/error port.

Creating those output ports goes like this:

    (define port-output (open-output-string))
    (define port-error  (open-error-string ))

Now you can set them as your input/output/error ports:

    (set-current-output-port port-output)
    (set-current-error-port  port-error )

After you've done this, whatever Guile writes will be sent to those
ports, rather than to your program's stdout/stderr.

Now to read whatever Guile has written to those ports, you... ack, I
just realized I don't know how to do this from Guile!  From C you
would use scm_strport_to_string, but I can't seem to find the same
function from Guile's side. :(

You'll need to do this from C, I guess.  Or wait for someone else's
reply.  Or you could also use make-soft-port, which I haven't used but
looks very nice. :)

For examples on how to do these things from C, see

    
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/hbuilder/hb/src/hbguile.c?rev=1.6&content-type=text/vnd.viewcvs-markup

and look for scm_set_current_output_port and the code nearby.

Sorry I could not be as helpful as I wanted to.

Good luck.

Alejo.
http://bachue.com/alejo

--
The mere formulation of a problem is far more essential than its solution.
      -- Albert Einstein.

$0='!/sfldbi!yjoV0msfQ!sfiupob!utvK'x44;print map{("\e[7m \e[0m",chr ord
(chop$0)-1)[$_].("\n")[++$i%77]}split//,unpack'B*',pack'H*',($F='F'x19).
"F0F3E0607879CC1E0F0F339F3FF399C666733333CCF87F99E6133999999E67CFFCCF3".
"219CC1CCC033E7E660198CCE4E66798303873CCE60F3387$F"#Don't you love Perl?

Attachment: pgpQa02zuajJC.pgp
Description: PGP signature


reply via email to

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