1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Frank Dischner
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 #include "codepage_tables.h"
24 #define MAX_TABLE_SIZE 32768
26 static unsigned short iso_table
[MAX_TABLE_SIZE
];
28 unsigned short iso_decode(unsigned char *latin1
, int cp
, int count
)
30 unsigned short ucs
= 0;
32 /* cp tells us which codepage to convert from */
34 case 0x01: /* Greek (ISO-8859-7) */
36 /* first convert to unicode */
39 else if (*latin1
> 0xB7)
40 ucs
= *latin1
++ + 0x02D0;
42 ucs
= iso8859_7_to_uni
[*latin1
++ - 0xA1];
46 case 0x02: /* Hebrew (ISO-8859-8) */
48 /* first convert to unicode */
49 if (*latin1
== 0xAA) {
52 } else if (*latin1
== 0xBA) {
55 } else if (*latin1
== 0xDF) {
58 } else if (*latin1
< 0xC0)
61 ucs
= *latin1
++ + 0x04F0;
65 case 0x03: /* Cyrillic (CP1251) */
67 /* first convert to unicode */
70 else if (*latin1
> 0xBF)
71 ucs
= *latin1
++ + 0x0350;
73 ucs
= cp1251_to_uni
[*latin1
++ - 0x80];
77 case 0x04: /* Thai (ISO-8859-11) */
79 /* first convert to unicode */
83 ucs
= *latin1
++ + 0x0D60;
87 case 0x05: /* Arabic (CP1256) */
89 /* first convert to unicode */
93 ucs
= cp1256_to_uni
[*latin1
++ - 0x80];
97 case 0x06: /* Turkish (ISO-8859-9) */
99 /* first convert to unicode */
128 case 0x07: /* Latin Extended (ISO-8859-2) */
130 /* first convert to unicode */
134 ucs
= iso8859_2_to_uni
[*latin1
++ - 0xA1];
144 int writeshort(FILE *f
, unsigned short s
)
147 return putc(s
>>8, f
) != EOF
;
158 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
161 of
= fopen("iso.cp", "wb");
164 for (i
=1; i
<8; i
++) {
166 for (j
=0; j
<128; j
++) {
167 k
= (unsigned char)j
+ 128;
168 uni
= iso_decode(&k
, i
, 1);
174 of
= fopen("932.cp", "wb");
176 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
177 writeshort(of
, cp932_table
[i
]);
180 of
= fopen("936.cp", "wb");
182 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
183 writeshort(of
, cp936_table
[i
]);
186 of
= fopen("949.cp", "wb");
188 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
189 writeshort(of
, cp949_table
[i
]);
192 of
= fopen("950.cp", "wb");
194 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
195 writeshort(of
, cp950_table
[i
]);