• Problem with locale

    From Roderick@hruodr@gmail.com to comp.lang.tcl on Mon Jan 20 16:22:40 2025
    From Newsgroup: comp.lang.tcl

    This message is in MIME format. The first part should be readable text,
    while the remaining parts are likely unreadable without MIME-aware tools.

    --2827311070-393800269-1737390163=:2240
    Content-Type: text/plain; format=flowed; charset=ISO-8859-15 Content-Transfer-Encoding: QUOTED-PRINTABLE


    I am having problems with a cgi script, it does not represent correctly
    the UTF-8 strings of a sqlitedb.

    Is there a way to change the locale from inside a script?

    I wrote the following testig script:

    ---
    #!/usr/opt/bin/tclsh
    puts "Content-Type: text/text; charset=3Dutf-8\r\n\r"
    puts AOU=3D=E4=F6=FC
    puts stdout=3D[fconfigure stdout -encoding]
    puts system=3D[encoding system]
    puts $env(LC_ALL)
    ----

    If I run it on a shel I get:

    ----
    Content-Type: text/text; charset=3Dutf-8

    AOU=3D=E4=F6=FC
    stdout=3Dutf-8
    system=3Dutf-8
    en_US.UTF-8
    -----

    If I run it through CGI I get in the browser:

    ----
    AOU=3D=E4=F6=FC
    stdout=3Diso8859-1
    system=3Diso8859-1
    ---

    We see:

    1) the variable $env(LC_ALL) is not set in CGI.
    2) although everywhere the encoding is iso8859-1,
    it does understand the UTF-8 of the script (AOU=3D=E4=F6=FC)!!!!!

    I am really confused, any hint?

    Thanks a lot
    Rod.

    --2827311070-393800269-1737390163=:2240--
    --- Synchronet 3.20c-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Mon Jan 20 18:18:34 2025
    From Newsgroup: comp.lang.tcl

    This message is in MIME format. The first part should be readable text,
    while the remaining parts are likely unreadable without MIME-aware tools.

    --2827311070-801647265-1737397116=:2728
    Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE


    The following solves the problem:

    1) Begin the script with

    #!/bin/sh
    exec tclsh -encoding utf-8 "$0" ${1+"$@"}

    2) Put in the script the command

    encoding system utf-8

    --

    I would preffer

    #!/usr/opt/bin/tclsh -encoding utf-8

    But FreeBSD seems not to allow it.

    Rod



    On Mon, 20 Jan 2025, Roderick wrote:


    I am having problems with a cgi script, it does not represent correctly
    the UTF-8 strings of a sqlitedb.

    Is there a way to change the locale from inside a script?

    I wrote the following testig script:

    ---
    #!/usr/opt/bin/tclsh
    puts "Content-Type: text/text; charset=3Dutf-8\r\n\r"
    puts AOU=3D=E4=F6=FC
    puts stdout=3D[fconfigure stdout -encoding]
    puts system=3D[encoding system]
    puts $env(LC_ALL)
    ----

    If I run it on a shel I get:

    ----
    Content-Type: text/text; charset=3Dutf-8

    AOU=3D=E4=F6=FC
    stdout=3Dutf-8
    system=3Dutf-8
    en_US.UTF-8
    -----

    If I run it through CGI I get in the browser:

    ----
    AOU=3D=E4=F6=FC
    stdout=3Diso8859-1
    system=3Diso8859-1
    ---

    We see:

    1) the variable $env(LC_ALL) is not set in CGI.
    2) although everywhere the encoding is iso8859-1,
    it does understand the UTF-8 of the script (AOU=3D=E4=F6=FC)!!!!!

    I am really confused, any hint?

    Thanks a lot
    Rod.

    --2827311070-801647265-1737397116=:2728--
    --- Synchronet 3.20c-Linux NewsLink 1.2