From: proton
Subject: Unicode DRIBBLE file in CLISP
Date: 
Message-ID: <e4bae419-224c-4c66-b612-e517d5c06a5e@l32g2000hse.googlegroups.com>
Hi all, I am trying to use DRIBBLE to get some Unicode output, but so
far without success.
If I don't use Dribble and instead write directly to a file, it works:

(setf *terminal-encoding* (make-encoding :charset charset:utf-8))
(setf out (open "out.txt"))
(format out "~a" <unicode output>)
(close out)

But if use dribble instead of (open) and (format), the output is in
another encoding (probably ISO-8859-1), and I can't read (properly)
the resulting file no matter what I try.

(setf *terminal-encoding* (make-encoding :charset charset:utf-8))
(dribble "out.txt")

I have tried to set
(setf *default-file-encoding* (make-encoding :charset charset:utf-8))

but it doesn't work either and, worst of all, my other files are not
readable anymore.

What am I missing? I am using CLISP 2.43 with Unicode.
Thanks a lot for any help.
From: Pascal Bourguignon
Subject: Re: Unicode DRIBBLE file in CLISP
Date: 
Message-ID: <87abmstvj2.fsf@thalassa.informatimago.com>
proton <··········@gmail.com> writes:

> Hi all, I am trying to use DRIBBLE to get some Unicode output, but so
> far without success.
> If I don't use Dribble and instead write directly to a file, it works:
>
> (setf *terminal-encoding* (make-encoding :charset charset:utf-8))
> (setf out (open "out.txt"))
> (format out "~a" <unicode output>)
> (close out)
>
> But if use dribble instead of (open) and (format), the output is in
> another encoding (probably ISO-8859-1), and I can't read (properly)
> the resulting file no matter what I try.
>
> (setf *terminal-encoding* (make-encoding :charset charset:utf-8))
> (dribble "out.txt")
>
> I have tried to set
> (setf *default-file-encoding* (make-encoding :charset charset:utf-8))
>
> but it doesn't work either and, worst of all, my other files are not
> readable anymore.
>
> What am I missing? I am using CLISP 2.43 with Unicode.
> Thanks a lot for any help.

In clisp, dribble is implemented by rebinding *terminal-io* to a
broadcast-stream.  One consequence, is that each basic stream gathered
in the broadcast-stream can use its own encoding.  The other
consequence is that you can only output characters in the intersection
of the encodings.  

Of course, when opening the dribble file,
custom:*default-file-encoding* is used.  But it would be better if it
was bound to (stream-external-format *terminal-io*).

(stream-external-format *terminal-io*) cannot be changed on the fly,
you have to set the environment or pass the right options before
launching clisp, normally according to the actual terminal you use.



[···@thalassa ~]$ LC_CTYPE=en_US.UTF-8 clisp -norc -q -ansi
[1]> (ext:letf ((custom:*default-file-encoding* 
                   (stream-external-format *terminal-io*))) 
         (dribble "/tmp/my.dribble"))
#<OUTPUT BUFFERED FILE-STREAM CHARACTER #P"/tmp/my.dribble">
[2]> (mapcar (function stream-external-format) 
             (broadcast-stream-streams (two-way-stream-output-stream *terminal-io*)))
(#<ENCODING CHARSET:UTF-8 :UNIX> #<ENCODING CHARSET:UTF-8 :UNIX>)
[3]> 


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

CONSUMER NOTICE: Because of the "uncertainty principle," it is
impossible for the consumer to simultaneously know both the precise
location and velocity of this product.