Re: Problem with freewrap and encoding (please just give it a try)

From: Dennis LaBelle (labelled_at_nycap.rr.com)
Date: 10/19/04


Date: Tue, 19 Oct 2004 00:16:22 GMT

Dennis LaBelle wrote:

> Stefano wrote:
>
>> Hi,
>> I guess this is my last resort. If no one from this group can answer
>> my question I guess I'll have to give up with freewrap. Even if I have
>> to admit that this is the only problem I had with it. But I usually
>> handle documents written with all kind of european characters, and
>> this seems to be a problem for freewrap version 5.61
>> (http://freewrap.sourceforge.net). I don't know if older versions are
>> bug free, but I don't know how to use encodings with older versions. I
>> found a comment of Dennis Labelle (freewrap's author) from 2002 on
>> this news group, but now the howto file of freewrap has changed as for
>> encodings, so I don't know how I could apply that suggestion.
>>
>> I would like to know if other people can replicate the "bug" I found,
>> or if this is just a problem of my PC configuration.
>>
>> I wrote a simple routine to get rid of special characters embedded in
>> an ASP file. This is the routine:
>>
>> ##### routine STARTS here
>> set autoweb(filename) {scheda0-orig.asp}
>> set autoweb(filenameout) {scheda0-out.asp}
>>
>> set fileId [open $autoweb(filename) "r"]
>> set htmlcontent [read $fileId]
>> close $fileId
>>
>> # creates string map array
>> set cmap {}
>> for {set i 161} {$i < 256} {incr i} {
>> lappend cmap [format "%c" $i] "&#$i;"
>> }
>>
>> # convert special characters to HTML codes
>> set htmlcontent [string map $cmap $htmlcontent]
>>
>> # clean ASP code from html document
>> regsub -all {<%.*%>} $htmlcontent {} htmlcontent
>>
>> # writes document back to local file
>> set parFileId [open $autoweb(filenameout) w]
>> puts $parFileId "${htmlcontent}"
>> close $parFileId
>>
>> exit
>> ##### routine ENDS here
>>
>> When I run this routine in Windows (windows 2000, english version)
>> just doubleclicking on the tcl file, everything works fine. I use Tcl
>> version 8.4.6. Instead, if I compile with freewrap 5.61, the output
>> file will be still readable but will contain some evident garbage
>> characters. I created a simplified version of my ASP file. I verified
>> that copying and pasting the following code does exactly reproduce the
>> problem:
>>
>> <html>
>> <head>
>> </head>
>> <body>
>> <h1>Progetto n°</h1>
>> </body>
>> </html>
>
>
> OK, exactly what do you mean by "copying and pasting the following code"?
> Those last few lines don't look like any special ASP stuff to me.
>
> And how does "copying and pasting" simulate the problems with some
> computer code?
>

If the local system encoding of the machine on which your program might run
is not suitable for your task, simply change the system encoding with a
line of code such as:

encoding system /tcl/encoding/iso8859-1

Contrary to what Victor Wagner says, freeWrap 5.61 contains all the encoding
files distributed with the normal TCL/TK package. They are accessible as
long as you use a full path when your code refers to them. They can be
found in the virtual file system directory /tcl/encoding. These files can
be listed using the command:

zvfs::list /tcl/encoding/*

I believe that adding the line with the encoding command above to your code
produces your desired result.

##### routine STARTS here
encoding system /tcl/encoding/iso8859-1

set autoweb(filename) {scheda0-orig.asp}
set autoweb(filenameout) {scheda0-out.asp}

set fileId [open $autoweb(filename) "r"]
set htmlcontent [read $fileId]
close $fileId

# creates string map array
set cmap {}
for {set i 161} {$i < 256} {incr i} {
lappend cmap [format "%c" $i] "&#$i;"
}

# convert special characters to HTML codes
set htmlcontent [string map $cmap $htmlcontent]

# clean ASP code from html document
regsub -all {<%.*%>} $htmlcontent {} htmlcontent

# writes document back to local file
set parFileId [open $autoweb(filenameout) w]
puts $parFileId "${htmlcontent}"
close $parFileId

exit
##### routine ENDS here



Relevant Pages

  • Re: Tk 8.4.11 / Windows XP / Encoding problem
    ... Some of our clients are experiencing a weird problem on their Windows XP PCs. ... I also checked to see if the encoding in our ... but it reported "utf-8" as it should. ... Tcl usually does proper detection of the system encoding. ...
    (comp.lang.tcl)
  • Re: Special Characters (Unicode, Ascii) in Python and MySQL
    ... Special characters and punctuation all seem not to be stored and ... perhaps the encoding of the database itself should be different? ... 'ascii' codec can't decode byte 0xe2 in position ... and pasted from Microsoft Word. ...
    (comp.lang.python)
  • Re: PHP - using mail() and unicode text - text gets disturbed
    ... One way to deal with this is to escape the UTF-8 ... In the HTML part, encoding the special ... > However, when I receive the text in my mailbox, all special characters ... > Is this a server configuration issue? ...
    (comp.lang.php)
  • Codepage problems with generate XML
    ... We think we're having problems with special characters when we generate an XML streamfile. ... We have it working without special characters, and i was wondering if this method could be adapted to work with special characters. ... To my view the internal formatting using ccsid 37 is wrong and should be dependent on the encoding used. ... Eval Formatter@ = ...
    (comp.sys.ibm.as400.misc)
  • Re: question about character encodings with Tcl interpreter embedded in C++
    ... in 8859-1, in both 8859-1 encoding, and in utf-8 encoding. ... size_t read_rv = read(fdScriptInputFile, script, sizeof(script)); ... system encoding: iso8859-1 ... macRomania macTurkish gb1988 iso2022-kr macGreek ascii cp437 macRoman ...
    (comp.lang.tcl)