Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Rich Newsgroups: comp.lang.tcl Subject: Re: Tcl9: source files are interpreted as utf-8 by default Date: Wed, 8 Jan 2025 17:04:26 -0000 (UTC) Organization: A noiseless patient Spider Lines: 41 Message-ID: References: <20250107160810.07ddbbe6@lud1.home> <20250108113519.42eb3746@lud1.home> <20250108114254.7f56f049@lud1.home> <20250108124055.15c92a05@lud1.home> Injection-Date: Wed, 08 Jan 2025 18:04:27 +0100 (CET) Injection-Info: dont-email.me; posting-host="bfc47b907fca7cd15e0f04fd46849852"; logging-data="3026611"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FJHknT4rCIj9IQdyVAbZJ" User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64)) Cancel-Lock: sha1:NDWOiZ79LawkexL3xzCQEickLaA= Bytes: 3119 Luc 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.