cp850
Description of the page content
Forth program that creates PHP source code to define an array that will be used to translate characters from CP850 to Unicode.
I programmed this tool in order to improve the WRS I wrote to manage programandala.net. I needed to translate the characters of my old DOS listings in order to include them into the web pages (I already had programmed the translations needed for the character sets of Sinclair QL, Sinclair ZX Spectrum, Psion 5mx and others). I got the the Unicode codes from the Wikipedia's page Code Page 850; I made a list with the hexadecimal codes and then the Forth program did the dirty work.
Source code
\ cp850.fs
\ Copyright (C) 2009,2014 Marcos Cruz (http://programandala.net)
\ Licencia/License: http://programandala.net/license
\ This program creates PHP code with an array to translate CP850 codes into HTML Unicode.
\ Written in ANS Forth.
\ Tested with Gforth.
\ 2009-06-09: First version.
\ 2014-10-17: Changes:
\ - "<?php" and "?>" added to the output file;
\ - explicit hex notation used in the translation data;
\ - 'bye' added at the end of the process.
\ - source code layout changed;
\ - main word renamed to 'run'.
\ Usage:
\ gforth cp850.fs -e run > cp850.inc.php
\ CP850 translations to Unicode
0x00 0x0000 \ end of data
0x01 0x263A
0x02 0x263B
0x03 0x2665
0x04 0x2666
0x05 0x2665
0x06 0x2660
0x07 0x2022
0x08 0x25D8
0x09 0x25CB
0x0A 0x25D9
0x0B 0x2642
0x0C 0x2640
0x0D 0x266A
0x0E 0x266B
0x0F 0x263C
0x10 0x25BA
0x11 0x25C4
0x12 0x2195
0x13 0x203C
0x14 0x00B6
0x15 0x00A7
0x16 0x25AC
0x17 0x21A8
0x18 0x2191
0x19 0x2193
0x1A 0x2192
0x1B 0x2190
0x1C 0x221F
0x1D 0x2194
0x1E 0x25B2
0x1F 0x25B5
0x7F 0x2302
0x80 0x00C7
0x81 0x00FC
0x82 0x00E9
0x83 0x00E2
0x84 0x00E4
0x85 0x00E0
0x86 0x00E5
0x87 0x00E7
0x88 0x00EA
0x89 0x00EB
0x8A 0x00E8
0x8B 0x00EF
0x8C 0x00EE
0x8D 0x00EC
0x8E 0x00C4
0x8F 0x00C5
0x90 0x00C9
0x91 0x00E6
0x92 0x00C6
0x93 0x00F4
0x94 0x00F6
0x95 0x00F2
0x96 0x00FB
0x97 0x00F9
0x98 0x00FF
0x99 0x00D6
0x9A 0x00DC
0x9B 0x00F8
0x9C 0x00A3
0x9D 0x00D8
0x9E 0x00D7
0x9F 0x0192
0xA0 0x00E1
0xA1 0x00ED
0xA2 0x00F3
0xA3 0x00FA
0xA4 0x00F1
0xA5 0x00D1
0xA6 0x00AA
0xA7 0x00BA
0xA8 0x00BF
0xA9 0x00AE
0xAA 0x00AC
0xAB 0x00BD
0xAC 0x00BC
0xAD 0x00A1
0xAE 0x00AB
0xAF 0x00BB
0xB0 0x2591
0xB1 0x2992
0xB2 0x2593
0xB3 0x2502
0xB4 0x2524
0xB5 0x00C1
0xB6 0x00C2
0xB7 0x00C0
0xB8 0x00A9
0xB9 0x2563
0xBA 0x2551
0xBB 0x2557
0xBC 0x255D
0xBD 0x00A2
0xBE 0x00A5
0xBF 0x2510
0xC0 0x2514
0xC1 0x2534
0xC2 0x252C
0xC3 0x251C
0xC4 0x2500
0xC5 0x253C
0xC6 0x00E3
0xC7 0x00C3
0xC8 0x255A
0xC9 0x2554
0xCA 0x2569
0xCB 0x2566
0xCC 0x2560
0xCD 0x2550
0xCE 0x256C
0xCF 0x00A4
0xD0 0x00F0
0xD1 0x00D0
0xD2 0x00CA
0xD3 0x00CB
0xD4 0x00C8
0xD5 0x0131
0xD6 0x00CD
0xD7 0x00CE
0xD8 0x00CF
0xD9 0x2518
0xDA 0x250C
0xDB 0x2588
0xDC 0x2584
0xDD 0x00A6
0xDE 0x00CC
0xDF 0x2580
0xE0 0x00D3
0xE1 0x00DF
0xE2 0x00D4
0xE3 0x00D2
0xE4 0x00F5
0xE5 0x00D5
0xE6 0x00B5
0xE7 0x00FE
0xE8 0x00DE
0xE9 0x00DA
0xEA 0x00DB
0xEB 0x00D9
0xEC 0x00FD
0xED 0x00DD
0xEE 0x00AF
0xEF 0x00B4
0xF0 0x00AD
0xF1 0x00B1
0xF2 0x2017
0xF3 0x00BE
0xF4 0x00B6
0xF5 0x00A7
0xF6 0x00F7
0xF7 0x00B8
0xF8 0x00B0
0xF9 0x00A8
0xFA 0x00B7
0xFB 0x00B9
0xFC 0x00B3
0xFD 0x00B2
0xFE 0x25A0
0xFF 0x00A0
: .cp850 ( c -- )
[char] " emit ." \x" hex 1 .r [char] " emit decimal ;
: .unicode ( u -- )
." '&#" 1 .r ." ;'" ;
: more? ( c u -- c u f )
2dup + ;
: .comma ( c u -- c u )
more? if [char] , emit then ;
: .element ( c u -- )
swap .cp850 ." => " .unicode .comma cr ;
: .elements ( 0 0 c1 u1 ... cn un -- )
begin more? while .element repeat 2drop ;
: .start ( -- )
." <?php" cr cr ." $cp850 = array (" cr cr ;
: .end ( -- )
cr ." );" cr cr ." ?>" cr ;
: run ( 0 0 c1 u1 ... cn un -- )
.start .elements .end bye ;
\ end of cp850.fs
Result
This is the output of the program, ready to be included into my PHP program:
<?php
$cp850 = array (
"\xFF" => ' ',
"\xFE" => '■',
"\xFD" => '²',
"\xFC" => '³',
"\xFB" => '¹',
"\xFA" => '·',
"\xF9" => '¨',
"\xF8" => '°',
"\xF7" => '¸',
"\xF6" => '÷',
"\xF5" => '§',
"\xF4" => '¶',
"\xF3" => '¾',
"\xF2" => '‗',
"\xF1" => '±',
"\xF0" => '­',
"\xEF" => '´',
"\xEE" => '¯',
"\xED" => 'Ý',
"\xEC" => 'ý',
"\xEB" => 'Ù',
"\xEA" => 'Û',
"\xE9" => 'Ú',
"\xE8" => 'Þ',
"\xE7" => 'þ',
"\xE6" => 'µ',
"\xE5" => 'Õ',
"\xE4" => 'õ',
"\xE3" => 'Ò',
"\xE2" => 'Ô',
"\xE1" => 'ß',
"\xE0" => 'Ó',
"\xDF" => '▀',
"\xDE" => 'Ì',
"\xDD" => '¦',
"\xDC" => '▄',
"\xDB" => '█',
"\xDA" => '┌',
"\xD9" => '┘',
"\xD8" => 'Ï',
"\xD7" => 'Î',
"\xD6" => 'Í',
"\xD5" => 'ı',
"\xD4" => 'È',
"\xD3" => 'Ë',
"\xD2" => 'Ê',
"\xD1" => 'Ð',
"\xD0" => 'ð',
"\xCF" => '¤',
"\xCE" => '╬',
"\xCD" => '═',
"\xCC" => '╠',
"\xCB" => '╦',
"\xCA" => '╩',
"\xC9" => '╔',
"\xC8" => '╚',
"\xC7" => 'Ã',
"\xC6" => 'ã',
"\xC5" => '┼',
"\xC4" => '─',
"\xC3" => '├',
"\xC2" => '┬',
"\xC1" => '┴',
"\xC0" => '└',
"\xBF" => '┐',
"\xBE" => '¥',
"\xBD" => '¢',
"\xBC" => '╝',
"\xBB" => '╗',
"\xBA" => '║',
"\xB9" => '╣',
"\xB8" => '©',
"\xB7" => 'À',
"\xB6" => 'Â',
"\xB5" => 'Á',
"\xB4" => '┤',
"\xB3" => '│',
"\xB2" => '▓',
"\xB1" => '⦒',
"\xB0" => '░',
"\xAF" => '»',
"\xAE" => '«',
"\xAD" => '¡',
"\xAC" => '¼',
"\xAB" => '½',
"\xAA" => '¬',
"\xA9" => '®',
"\xA8" => '¿',
"\xA7" => 'º',
"\xA6" => 'ª',
"\xA5" => 'Ñ',
"\xA4" => 'ñ',
"\xA3" => 'ú',
"\xA2" => 'ó',
"\xA1" => 'í',
"\xA0" => 'á',
"\x9F" => 'ƒ',
"\x9E" => '×',
"\x9D" => 'Ø',
"\x9C" => '£',
"\x9B" => 'ø',
"\x9A" => 'Ü',
"\x99" => 'Ö',
"\x98" => 'ÿ',
"\x97" => 'ù',
"\x96" => 'û',
"\x95" => 'ò',
"\x94" => 'ö',
"\x93" => 'ô',
"\x92" => 'Æ',
"\x91" => 'æ',
"\x90" => 'É',
"\x8F" => 'Å',
"\x8E" => 'Ä',
"\x8D" => 'ì',
"\x8C" => 'î',
"\x8B" => 'ï',
"\x8A" => 'è',
"\x89" => 'ë',
"\x88" => 'ê',
"\x87" => 'ç',
"\x86" => 'å',
"\x85" => 'à',
"\x84" => 'ä',
"\x83" => 'â',
"\x82" => 'é',
"\x81" => 'ü',
"\x80" => 'Ç',
"\x7F" => '⌂',
"\x1F" => '▵',
"\x1E" => '▲',
"\x1D" => '↔',
"\x1C" => '∟',
"\x1B" => '←',
"\x1A" => '→',
"\x19" => '↓',
"\x18" => '↑',
"\x17" => '↨',
"\x16" => '▬',
"\x15" => '§',
"\x14" => '¶',
"\x13" => '‼',
"\x12" => '↕',
"\x11" => '◄',
"\x10" => '►',
"\xF" => '☼',
"\xE" => '♫',
"\xD" => '♪',
"\xC" => '♀',
"\xB" => '♂',
"\xA" => '◙',
"\x9" => '○',
"\x8" => '◘',
"\x7" => '•',
"\x6" => '♠',
"\x5" => '♥',
"\x4" => '♦',
"\x3" => '♥',
"\x2" => '☻',
"\x1" => '☺'
);
?>