Re: utf-8 output in a terminal

GrĂ©gory Vanuxem <[email protected]> Mon, 29 Jul 2024 10:51:38 +0200
Newsgroups gmane.lisp.openmcl.devel
Message-ID <CAHnU2dY+iZxjz_vpszOKXyMwEMa0kggNBmODg8AZUhH8rroApQ@mail.gmail.com>
--000000000000ca5a6a061e5ef8c1
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Oh, many thanks, I prefer your solution ;)

Greg


Le lun. 29 juil. 2024 =C3=A0 04:14, R. Matthew Emerson <[email protected]> a =
=C3=A9crit
:
>
>
>
> > On Jul 28, 2024, at 6:31=E2=80=AFPM, Gr=C3=A9gory Vanuxem <g.vanuxem@gm=
ail.com>
wrote:
> >
> > Found!
> >
> > In level-0/l0-misc.lisp there is exactly what i was looking for.
> > (ccl::%get-utf-8-cstring ..) It's a pity I think it is not documented
> > since now UTF-8 is relatively widely used.
> >
> > All is right now!
>
>
> The exported functionality is ccl:get-encoded-string.
>
> (get-encoded-string :utf-8 cname (#_strlen cname))
>
> https://ccl.clozure.com/docs/ccl.html#f_get-encoded-string
>
> The manual also contains examples of using both ccl:with-encoded-cstrs
and ccl:get-encoded-string:
>
> https://ccl.clozure.com/docs/ccl.html#brief-examples
>
>
>
> >
> > Thanks
> >
> > Greg
> >
> > Le lun. 29 juil. 2024 =C3=A0 01:34, Gr=C3=A9gory Vanuxem <g.vanuxem@gma=
il.com> a
=C3=A9crit :
> >>
> >> Hello Matthew,
> >>
> >> Le dim. 28 juil. 2024 =C3=A0 07:31, R. Matthew Emerson <[email protected]=
m> a
=C3=A9crit :
> >>>
> >>>
> >>>
> >>>> On Jul 27, 2024, at 8:23=E2=80=AFPM, Gr=C3=A9gory Vanuxem <g.vanuxem=
@gmail.com>
wrote:
> >>>>
> >>>> In FriCAS  built on top of Clozure CL I obtain this output in a
terminal (WSL2)
> >>>>
> >>>> (gamma(x) =C3=83=C3=82=C2=A2=C3=83=C3=82=C3=83=C3=82 reals && Re(x) =
> 0) || (x =C3=83=C3=82=C2=A2=C3=83=C3=82=C3=83=C3=82 integers &&
> >>>> gamma(x) =C3=83=C3=82=C2=A2=C3=83=C3=82=C3=83=C3=82 reals)
> >>>>
> >>>> instead of (SBCL)
> >>>>
> >>>> (gamma(x) =E2=88=88 reals && Re(x) > 0) || (x =E2=88=89 integers && =
gamma(x) =E2=88=88 reals)
> >>>>
> >>>> if I (print ...) a string with, for example, =E2=88=88, in a pure Cl=
ozure CL
> >>>> (recently git cloned) this is correctly printed, no problem.
> >>>>
> >>>> So I wonder if I have to modify the output stream character encoding
> >>>> or the output routine.
> >>>
> >>> Check that the external format of the FriCAS output stream is what
you expect. In other words, if you pass an explicit :external-format
argument to cl:open, make sure it matches what your terminal requires.
> >>
> >> I don't think it is at this stage in fact, I was wrong. Better
> >> checking what is going on, since the string comes from C (sorry I
> >> forgot to mention that) I tend to think my problem comes from
> >> ccl::%get-cstring. Tracing it seems to show it's not "decoding" it and
> >> considers it as a 8859-1 string. But to test this i.e. force CCL to
> >> use :utf8 format to "read it" I have not found. There is no option
> >> from what I know to get-cstring like :external-format and using
> >> with-encoded-cstrs does not seem to work.
> >>
> >> Right now I am using some FFI macros from FriCAS to simplify my code,
> >> I will try to revert to pure CCL code first to check my claims,
> >> TIMTOWTDI.
> >>
> >>> Doing (describe *terminal-io*) might show something interesting.
Here=E2=80=99s what it shows for me:
> >>>
> >>> ? (describe *terminal-io*)
> >>> #<ECHOING-TWO-WAY-STREAM input #<BASIC-CHARACTER-INPUT-STREAM UTF-8
(TTY/0) #x1824C7D6>, output #<BASIC-CHARACTER-OUTPUT-STREAM UTF-8 (TTY/1)
#x1824C2A6> #x1825FBE6>
> >>> Class: #<STANDARD-CLASS ECHOING-TWO-WAY-STREAM>
> >>> Wrapper: #<CLASS-WRAPPER ECHOING-TWO-WAY-STREAM #x18039A16>
> >>> Instance slots
> >>> SHARED-RESOURCE: NIL
> >>> OPEN-P: T
> >>> INPUT-STREAM: #<BASIC-CHARACTER-INPUT-STREAM UTF-8 (TTY/0) #x1824C7D6=
>
> >>> OUTPUT-STREAM: #<BASIC-CHARACTER-OUTPUT-STREAM UTF-8 (TTY/1)
#x1824C2A6>
> >>>
> >>> The default external format has been #<EXTERNAL-FORMAT :UTF-8/:UNIX
#x18249C6E> for quite a long time now.
> >>>
> >>> https://ccl.clozure.com/docs/ccl.html#characters-and-external-formats
> >>
> >> This is exactly what I have when I use this function in FriCAS. I have
> >> read the documentation and the internal utf32 representation but here
> >> I am stuck. This is not the most important thing I need to do but it
> >> will be imperative for some next stuff.
> >>
> >> In anyway, thanks!
> >>
> >> Greg
> >>
> >>>
> >>>>
> >>>> And more importantly, how can I achieve that?
> >>>>
> >>>> - Greg
> >>>>
> >>>> PS:
> >>>> (1) -> )lisp CCL:*DEFAULT-EXTERNAL-FORMAT*
> >>>> Value =3D :UNIX
> >>>
>

--000000000000ca5a6a061e5ef8c1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div>Oh, many thanks, I prefer your solution ;)<br>
<br>
Greg</div><div><br>
<br>
Le lun. 29 juil. 2024 =C3=A0 04:14, R. Matthew Emerson &lt;<a href=3D"mailt=
o:[email protected]" target=3D"_blank">[email protected]</a>&gt; a =C3=A9crit :=
<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; &gt; On Jul 28, 2024, at 6:31=E2=80=AFPM, Gr=C3=A9gory Vanuxem &lt;<a =
href=3D"mailto:[email protected]" target=3D"_blank">[email protected]</=
a>&gt; wrote:<br>
&gt; &gt;<br>
&gt; &gt; Found!<br>
&gt; &gt;<br>
&gt; &gt; In level-0/l0-misc.lisp there is exactly what i was looking for.<=
br>
&gt; &gt; (ccl::%get-utf-8-cstring ..) It&#39;s a pity I think it is not do=
cumented<br>
&gt; &gt; since now UTF-8 is relatively widely used.<br>
&gt; &gt;<br>
&gt; &gt; All is right now!<br>
&gt;<br>
&gt;<br>
&gt; The exported functionality is ccl:get-encoded-string.<br>
&gt;<br>
&gt; (get-encoded-string :utf-8 cname (#_strlen cname))<br>
&gt;<br>
&gt; <a href=3D"https://ccl.clozure.com/docs/ccl.html#f_get-encoded-string"=
 rel=3D"noreferrer" target=3D"_blank">https://ccl.clozure.com/docs/ccl.html=
#f_get-encoded-string</a><br>
&gt;<br>
&gt; The manual also contains examples of using both ccl:with-encoded-cstrs=
 and ccl:get-encoded-string:<br>
&gt;<br>
&gt; <a href=3D"https://ccl.clozure.com/docs/ccl.html#brief-examples" rel=
=3D"noreferrer" target=3D"_blank">https://ccl.clozure.com/docs/ccl.html#bri=
ef-examples</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; &gt;<br>
&gt; &gt; Thanks<br>
&gt; &gt;<br>
&gt; &gt; Greg<br>
&gt; &gt;<br>
&gt; &gt; Le lun. 29 juil. 2024 =C3=A0 01:34, Gr=C3=A9gory Vanuxem &lt;<a h=
ref=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a=
>&gt; a =C3=A9crit :<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Hello Matthew,<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Le dim. 28 juil. 2024 =C3=A0 07:31, R. Matthew Emerson &lt;<a=
 href=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a>&gt; =
a =C3=A9crit :<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; On Jul 27, 2024, at 8:23=E2=80=AFPM, Gr=C3=A9gory Van=
uxem &lt;<a href=3D"mailto:[email protected]" target=3D"_blank">g.vanuxem=
@gmail.com</a>&gt; wrote:<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; In FriCAS=C2=A0 built on top of Clozure CL I obtain t=
his output in a terminal (WSL2)<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; (gamma(x) =C3=83=C3=82=C2=A2=C3=83=C3=82=C3=83=C3=82 =
reals &amp;&amp; Re(x) &gt; 0) || (x =C3=83=C3=82=C2=A2=C3=83=C3=82=C3=83=
=C3=82 integers &amp;&amp;<br>
&gt; &gt;&gt;&gt;&gt; gamma(x) =C3=83=C3=82=C2=A2=C3=83=C3=82=C3=83=C3=82 r=
eals)<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; instead of (SBCL)<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; (gamma(x) =E2=88=88 reals &amp;&amp; Re(x) &gt; 0) ||=
 (x =E2=88=89 integers &amp;&amp; gamma(x) =E2=88=88 reals)<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; if I (print ...) a string with, for example, =E2=88=
=88, in a pure Clozure CL<br>
&gt; &gt;&gt;&gt;&gt; (recently git cloned) this is correctly printed, no p=
roblem.<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; So I wonder if I have to modify the output stream cha=
racter encoding<br>
&gt; &gt;&gt;&gt;&gt; or the output routine.<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; Check that the external format of the FriCAS output strea=
m is what you expect. In other words, if you pass an explicit :external-for=
mat argument to cl:open, make sure it matches what your terminal requires.<=
br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; I don&#39;t think it is at this stage in fact, I was wrong. B=
etter<br>
&gt; &gt;&gt; checking what is going on, since the string comes from C (sor=
ry I<br>
&gt; &gt;&gt; forgot to mention that) I tend to think my problem comes from=
<br>
&gt; &gt;&gt; ccl::%get-cstring. Tracing it seems to show it&#39;s not &quo=
t;decoding&quot; it and<br>
&gt; &gt;&gt; considers it as a 8859-1 string. But to test this i.e. force =
CCL to<br>
&gt; &gt;&gt; use :utf8 format to &quot;read it&quot; I have not found. The=
re is no option<br>
&gt; &gt;&gt; from what I know to get-cstring like :external-format and usi=
ng<br>
&gt; &gt;&gt; with-encoded-cstrs does not seem to work.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Right now I am using some FFI macros from FriCAS to simplify =
my code,<br>
&gt; &gt;&gt; I will try to revert to pure CCL code first to check my claim=
s,<br>
&gt; &gt;&gt; TIMTOWTDI.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;&gt; Doing (describe *terminal-io*) might show something inter=
esting. Here=E2=80=99s what it shows for me:<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; ? (describe *terminal-io*)<br>
&gt; &gt;&gt;&gt; #&lt;ECHOING-TWO-WAY-STREAM input #&lt;BASIC-CHARACTER-IN=
PUT-STREAM UTF-8 (TTY/0) #x1824C7D6&gt;, output #&lt;BASIC-CHARACTER-OUTPUT=
-STREAM UTF-8 (TTY/1) #x1824C2A6&gt; #x1825FBE6&gt;<br>
&gt; &gt;&gt;&gt; Class: #&lt;STANDARD-CLASS ECHOING-TWO-WAY-STREAM&gt;<br>
&gt; &gt;&gt;&gt; Wrapper: #&lt;CLASS-WRAPPER ECHOING-TWO-WAY-STREAM #x1803=
9A16&gt;<br>
&gt; &gt;&gt;&gt; Instance slots<br>
&gt; &gt;&gt;&gt; SHARED-RESOURCE: NIL<br>
&gt; &gt;&gt;&gt; OPEN-P: T<br>
&gt; &gt;&gt;&gt; INPUT-STREAM: #&lt;BASIC-CHARACTER-INPUT-STREAM UTF-8 (TT=
Y/0) #x1824C7D6&gt;<br>
&gt; &gt;&gt;&gt; OUTPUT-STREAM: #&lt;BASIC-CHARACTER-OUTPUT-STREAM UTF-8 (=
TTY/1) #x1824C2A6&gt;<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; The default external format has been #&lt;EXTERNAL-FORMAT=
 :UTF-8/:UNIX #x18249C6E&gt; for quite a long time now.<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; <a href=3D"https://ccl.clozure.com/docs/ccl.html#characte=
rs-and-external-formats" rel=3D"noreferrer" target=3D"_blank">https://ccl.c=
lozure.com/docs/ccl.html#characters-and-external-formats</a><br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; This is exactly what I have when I use this function in FriCA=
S. I have<br>
&gt; &gt;&gt; read the documentation and the internal utf32 representation =
but here<br>
&gt; &gt;&gt; I am stuck. This is not the most important thing I need to do=
 but it<br>
&gt; &gt;&gt; will be imperative for some next stuff.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; In anyway, thanks!<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Greg<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; And more importantly, how can I achieve that?<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; - Greg<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; PS:<br>
&gt; &gt;&gt;&gt;&gt; (1) -&gt; )lisp CCL:*DEFAULT-EXTERNAL-FORMAT*<br>
&gt; &gt;&gt;&gt;&gt; Value =3D :UNIX<br>
&gt; &gt;&gt;&gt;<br>
&gt;<br>
</div>

--000000000000ca5a6a061e5ef8c1--