Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-11-12
23:09 • Closed ticket [840577ffff]: Problem in reading nonascii character. plus 10 o... artifact: 5c9047a415 user: dkf
09:00 • New ticket [840577ffff]. artifact: bcfb26dc88 user: aniixx

Problem in reading nonascii character.

Closed / Invalid840577ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2003-11-12 09:00:29
Hi,

We have Tcl integrated with C++ application. The user 
commands from tclsh are mapped to the C++ functions & 
handled in the C++ application. 
We are facing some problem while reading nonascii 
characters from a file. I have given some commands that 
I have tried for your reference below. Check the octal 
dumps to verify the contents of the file.
While reading or storing it in a Tcl variable, Tcl does 
some kind of encoding (possibly UTF-8 encoding). But 
puts strips the extra character off or decodes it.  
Any idea if it's a Tcl bug?

We pass this variable to C++ application & on the other 
end we get wrong output (extra character). 

Thanx,
Aniket 


$ echo "abc\200xyz" > /tmp/wipro
$ od -xC /tmp/wipro
0000000    6162    6380    7879    7a0a
           a   b   c 200   x   y   z  \n
0000010
$ xmytclsh                                      
> set fd [ open /tmp/wipro r]     
> set data [ read -nonewline $fd ]
> puts $data
abcxyz
> echo $data
abcÂxyz
> set fd [ open /tmp/wipro r]
> set data [ read $fd ]
> puts $data
abcxyz
> echo $data
abcÂxyz
> set fdw [ open /tmp/wipro_write w]
> puts $fdw $data
> close $fdw
> set data "abc\0200xyz"
> echo $data
abc0xyz
> puts $data
abc0xyz
> exit
$ od -xC /tmp/wipro_write
0000000    6162    6380    7879    7a0a    0a00
           a   b   c 200   x   y   z  \n  \n
0000011

Note: Octal dump if abcÂxyz is passed to C++ appln & 
received at output is
0000000    6162    63c2    8078    797a
           a   b   c   Â 200   x   y   z
0000010

You can surely see additional character  here.
dkfplain2003-11-12 23:09:04
Logged In: YES 
user_id=79902

You're in a twist over encodings it seems.  What character
is that \200 meant to be?  What is your system encoding? 
(Use [encoding system] to find that out.)  What platform are
you on?

Hmm.  Guessing that your system encoding is UTF-8 (which
might be the case on MacOSX and might be true elsewhere too)
you're going to have to use [fconfigure] to help out,
perhaps like this:
  fconfigure $fd -encoding iso8859-1
Another alternative is to put the channel into binary mode:
  fconfigure $fd -translation binary
I'd need to know your situation in detail to tell you which
is best.
Log in (anonymous is fine) to add a comment.