Sujet : Re: Tcl9: source files are interpreted as utf-8 by default
De : rich (at) *nospam* example.invalid (Rich)
Groupes : comp.lang.tclDate : 08. Jan 2025, 18:04:26
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vlmb6q$2sblj$1@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Luc <
luc@sep.invalid> wrote:
On Wed, 8 Jan 2025 16:04:26 +0100, Uwe Schmitz wrote:
Another idea: force all scripts to source a set_encoding.tcl file
stored somewhere. If you ever have to change, you change the one file
and move on. You could even make it blank if convenient or necessary.
Nice try, but I don't think it's possible to set the encoding within the
file. And that for one simple reason: the file has already been read.
**************************
That doesn't sound quite true to me. Why is there an 'encoding' command
then? Is it useless because whenever you use it it's too late because
the file has already been read? Unlikely.
Source the set_encoding.tcl file before anything else, before you even
try to read anything. If you can set the encoding on the command line,
you can set it on the first line of the script that command line is
supposed to run.
Uwe's issue is two part:
1) encoding for scripts his 'main' script itself sources. Your
suggestion for renaming 'source' early would avoid having to change
every [source] invocation from that point forward in the main script
or in any script it sources.
2) encoding for the 'main' script itself (the very first one loaded
when his application is started). This one is "sourced" by the main
Tcl interpreter, and is read in and parsed using the default
character encoding the interpreter is using, before any commands in
that script are run. So this situation creates a chicken-or-the-egg
situation. If the script is iso-8859 encoded, but Tcl's default
parsing reads it as UTF-8, then all of the iso-8859 characters
inside are already corrupted *before* even the first command in the
script is executed. So there's no way to "source" a
"set_encoding.tcl" /in the main script itself/, that would adjust
the encoding before the main script is parsed using the wrong
encoding.