|
|
 |
 |
 |
 |
TCL(Tool Command Language) Scripting
|
 |
 |
 |
 |
 |
 |
 |
 |
hebrew encoding
I am having encoding nightmare. I try to understand the way the encoding work with no success: I have a simple test script: encoding system iso8859-8 set a " " puts $a in the braces it is shalom in hebrew but you probably need the font. the all episode is on a linux machine. anyway I do: tclsh test.tcl and I get: ???? so I do tclsh %source test.tcl and I get: strange?!%? why is it difference? one is incorrect and the other correct. I change the script encoding: encoding system iso8859-15 set a " " puts $a and both way works ok. even stranger? iso8859-15 is not hebrew encoding and it works better. why? please save me, I have these encoding staff.
On 24 Mai, 14:24, yahalom <yahal@gmail.com> wrote:
> I am having encoding nightmare. I try to understand the way the > encoding work with no success: > I have a simple test script: > encoding system iso8859-8 > set a " " > puts $a > in the braces it is shalom in hebrew but you probably need the font. > the all episode is on a linux machine. > anyway I do: > tclsh test.tcl > and I get: > ???? > so I do > tclsh > %source test.tcl > and I get: > > strange?!%? > why is it difference? one is incorrect and the other correct. > I change the script encoding: > encoding system iso8859-15 > set a " " > puts $a > and both way works ok. > even stranger? iso8859-15 is not hebrew encoding and it works better. > why? > please save me, I have these encoding staff.
Using 'encoding system' is nearly always an error. Encoding system does not change the script encoding, but the encoding assumed as default for interaction with the OS. Its usually correctly set. Scripts are always assumed to be in iso8859-1 IIRC, (the message catalogue files of the msgcat packages are utf-8 by default). In Tcl 8.5 you can start tclsh with -e to specify a script encoding. Michael
On 24 Mai, 15:14, schl@uni-oldenburg.de wrote: > Scripts are always assumed to be in iso8859-1 IIRC, (the message > catalogue files of the msgcat packages are utf-8 by default). > In Tcl 8.5 you can start tclsh with -e to specify a script encoding.
Before 8.5, you can of course do: set f [open $myScript] fconfigure $f -encoding $myEncoding eval [read $f] close $f
schl @uni-oldenburg.de wrote: > Scripts are always assumed to be in iso8859-1 IIRC, (the message > catalogue files of the msgcat packages are utf-8 by default). > In Tcl 8.5 you can start tclsh with -e to specify a script encoding. In 8.4 (or 8.5 when not using the -encoding flag) scripts are assumed to be in [encoding system] since that's almost always right. The only way I can think of to get yahalom's behaviour is if he has a .tclshrc that sets [encoding system], a highly _anti_-recommended trick. Instead, he should be able to just tell Tcl what his language is (via the LANG environment variable, a standard Unix feature) and have Tcl work out for itself how to encode it. If he wants to debug this further to check that things aren't going wrong completely, he should add the following to the *start* of his test script, before the (probably erroneous) call to [encoding system]: puts "LANG=$::env(LANG)\tSysEnc=[encoding system]" Now, in a correct installation, the same message ought to be produced by that line whether run interactively or as a script. (The values ought to be sensible according to the user's settings too!) If they're not, that's what we need to fix. Donal.
> If he wants to debug this further to check that things aren't going > wrong completely, he should add the following to the *start* of his test > script, before the (probably erroneous) call to [encoding system]: > puts "LANG=$::env(LANG)\tSysEnc=[encoding system]" > Now, in a correct installation, the same message ought to be produced by > that line whether run interactively or as a script. (The values ought to > be sensible according to the user's settings too!) If they're not, > that's what we need to fix. > Donal.
now it looks like a bug or a even stranger behaviour. when I add the puts "LANG=$::env(LANG)\tSysEnc=[encoding system]" before the script, it works fine with 'tclsh test.tcl'. when remvoed again the ???? appear. it seems like tcl is changing the encoding because of the puts statement (or because of the checking of environemnt variables). should this be reported as a bug?
the problem arose because we use tclcompiler to obscure the code. the problem is that the scripts are compiled using the system encoding on the system they are compiled on. this encoding does not always match the system encoding of the runtime environment. this is why we used encoding system to force encoding of the compiling environment. if this is incorrect the what will be the best approach for such a case?
yahalom schrieb: > the problem arose because we use tclcompiler to obscure the code. the > problem is that the scripts are compiled using the system encoding on > the system they are compiled on. this encoding does not always match > the system encoding of the runtime environment. this is why we used > encoding system to force encoding of the compiling environment. if > this is incorrect the what will be the best approach for such a case?
Override source and use a trivial start script to source your locale dependent stuff in a controlled manner like Richard has shown you, or put your hebrew messages in a message catalogue and use msgcat::mc. Michael
|
 |
 |
 |
 |
|