Re: tcl "binary format" error
From: Andreas Leitgeb (avl_at_gamma.logic.tuwien.ac.at)
Date: 03/24/04
- Next message: Arjen Markus: "Re: Curious hardware dependency with large integers"
- Previous message: Andreas Leitgeb: "Re: Curious hardware dependency with large integers"
- In reply to: joachim schuessler: "tcl "binary format" error"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 24 Mar 2004 12:27:59 GMT
joachim schuessler <schuessler@hhi.fhg.de> wrote:
> set env_fl [ open $nm w ]
> for { set i 0 } { $i <= 255 } { incr i } {
> puts -nonewline $env_fl [ binary format c $i ]
> }
> close $env_fl
> The hex_test.bin File contains
> .. a2 a3 3f a5 3f a7 3f a9 ...... b3 3f b5 b6 b7 3f b9 ba bb 3f 3f 3f bf
> correct is
> .. a2 a3 a4 a5 a6 a7 a8 a9 ...... b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf
Those "3f"'s you're seeing are question-marks, that are substed
for characters that tcl thinks it cannot convert to your native
charset during writing to file. This "native charset" (as seen by
tcl) is what varies between the platforms (or distributions).
using:
fconfigure $env_fl -translation binary
immediately after the line doing the [open ...]
will avoid this problem, because it will tell
Tcl not to convert at all.
This raises the question, whether:
[open $fname wb] (or rb) could be made to internally
do the fconfigure to binary, since this seems to be the
intent of the "b" flag in ansi-C's fopen(), iirc.
(for the list-form of open's access-parameter, "BINARY"
would seem to be a fit keyword)
Just for the elegance of it.
(currently playing with parsing and composing of midi-files, I
was quite often reminded that I had to spell out the fconfigure
to get reading and writing work correctly for binary formats)
- Next message: Arjen Markus: "Re: Curious hardware dependency with large integers"
- Previous message: Andreas Leitgeb: "Re: Curious hardware dependency with large integers"
- In reply to: joachim schuessler: "tcl "binary format" error"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|