1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Frank Dischner
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
24 #include "codepage_tables.h"
26 #define MAX_TABLE_SIZE 32768
28 static const int mini_index
[6] = {
32 static unsigned short iso_table
[MAX_TABLE_SIZE
];
34 unsigned short iso_decode(unsigned char *latin1
, int cp
, int count
)
36 unsigned short ucs
= 0;
38 /* cp tells us which codepage to convert from */
40 case 0x01: /* Greek (ISO-8859-7) */
42 /* first convert to unicode */
45 else if (*latin1
> 0xB7)
46 ucs
= *latin1
++ + 0x02D0;
48 ucs
= iso8859_7_to_uni
[*latin1
++ - 0xA1];
52 case 0x02: /* Hebrew (ISO-8859-8) */
54 /* first convert to unicode */
55 if (*latin1
== 0xAA) {
58 } else if (*latin1
== 0xBA) {
61 } else if (*latin1
== 0xDF) {
64 } else if (*latin1
< 0xC0)
67 ucs
= *latin1
++ + 0x04F0;
71 case 0x03: /* Cyrillic (CP1251) */
73 /* first convert to unicode */
76 else if (*latin1
> 0xBF)
77 ucs
= *latin1
++ + 0x0350;
79 ucs
= cp1251_to_uni
[*latin1
++ - 0x80];
83 case 0x04: /* Thai (ISO-8859-11) */
85 /* first convert to unicode */
89 ucs
= *latin1
++ + 0x0D60;
93 case 0x05: /* Arabic (CP1256) */
95 /* first convert to unicode */
99 ucs
= cp1256_to_uni
[*latin1
++ - 0x80];
103 case 0x06: /* Turkish (ISO-8859-9) */
105 /* first convert to unicode */
134 case 0x07: /* Latin Extended (ISO-8859-2) */
136 /* first convert to unicode */
140 ucs
= iso8859_2_to_uni
[*latin1
++ - 0xA1];
144 case 0x08: /* Central European (CP1250) */
146 /* first convert to unicode */
150 ucs
= cp1250_to_uni
[*latin1
++ - 0x80];
160 int writeshort(FILE *f
, unsigned short s
)
163 return putc(s
>>8, f
) != EOF
;
166 void print_usage(void)
168 printf("Usage: codepages [-m]\n"
169 "\t-m Create isomini.cp only\n");
170 printf("build date: " __DATE__
"\n\n");
173 int main(int argc
, char **argv
)
181 for (i
= 1;i
< argc
;i
++)
183 if (argv
[i
][0] == '-')
187 case 'm': /* create isomini.cp only */
205 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
209 of
= fopen("isomini.cp", "wb");
212 for (i
=1; i
<6; i
++) {
214 for (j
=0; j
<128; j
++) {
215 k
= (unsigned char)j
+ 128;
216 uni
= iso_decode(&k
, mini_index
[i
], 1);
223 of
= fopen("iso.cp", "wb");
226 for (i
=1; i
<9; i
++) {
228 for (j
=0; j
<128; j
++) {
229 k
= (unsigned char)j
+ 128;
230 uni
= iso_decode(&k
, i
, 1);
236 of
= fopen("932.cp", "wb");
238 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
239 writeshort(of
, cp932_table
[i
]);
242 of
= fopen("936.cp", "wb");
244 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
245 writeshort(of
, cp936_table
[i
]);
248 of
= fopen("949.cp", "wb");
250 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
251 writeshort(of
, cp949_table
[i
]);
254 of
= fopen("950.cp", "wb");
256 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
257 writeshort(of
, cp950_table
[i
]);