Hi, there was a demand for a decoding/encoding program between
MAC and PC. Here's the one I use for some Czech code pages:
Rebol [
Title: "Code"
Date: 27/10/1999
File: %code.r
]
; a function to translate coding table into a 256 character string
translate-coding: func[table [block!] /local result] [
; create a 256-character string
result: make string! 256
; and fill it with identical encoding
for i 0 255 1 [append result to-char i]
; change the encoding according to the given table
foreach [chr nchr] table [
change skip result to-integer chr nchr
]
result
]
code: func ["Encode/decode text"
input [file! string! port!] "input text"
output [file! string! port!] "output text"
table [string!] "encoding info"
/local chr nchr
] [
if file? input [input: open/read input]
if file? output [
if exists? output [delete output]
output: open/new output
]
while [not tail? input] [
chr: first input
nchr: first skip table to-integer chr
output: insert output nchr
input: next input
]
if port? input [close input]
if port? output [close output]
]
; Example:
; table1 contains encoding information - pairs of type:
; source-character result-character
; this example is used for some Czech encoding/decoding
; it may not survive the e-mail transport
table1: [
#"" #""
#"e" #""
#"" #"C"
#"" #""
#"" #""
#"" #""
#"" #""
#" " #""
#"?" #""
#"z" #"c"
#"R" #"e"
#"" #"r"
#"L" #""
#"." #"u"
#"" #"Z"
#"" #"R"
]
; table2 contains translated encoding information
table2: translate-coding table1
; now the work:
result: copy ""
code "" result table2
result