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 const int mini_index
[6] = {
30 static unsigned short iso_table
[MAX_TABLE_SIZE
];
32 unsigned short iso_decode(unsigned char *latin1
, int cp
, int count
)
34 unsigned short ucs
= 0;
36 /* cp tells us which codepage to convert from */
38 case 0x01: /* Greek (ISO-8859-7) */
40 /* first convert to unicode */
43 else if (*latin1
> 0xB7)
44 ucs
= *latin1
++ + 0x02D0;
46 ucs
= iso8859_7_to_uni
[*latin1
++ - 0xA1];
50 case 0x02: /* Hebrew (ISO-8859-8) */
52 /* first convert to unicode */
53 if (*latin1
== 0xAA) {
56 } else if (*latin1
== 0xBA) {
59 } else if (*latin1
== 0xDF) {
62 } else if (*latin1
< 0xC0)
65 ucs
= *latin1
++ + 0x04F0;
69 case 0x03: /* Cyrillic (CP1251) */
71 /* first convert to unicode */
74 else if (*latin1
> 0xBF)
75 ucs
= *latin1
++ + 0x0350;
77 ucs
= cp1251_to_uni
[*latin1
++ - 0x80];
81 case 0x04: /* Thai (ISO-8859-11) */
83 /* first convert to unicode */
87 ucs
= *latin1
++ + 0x0D60;
91 case 0x05: /* Arabic (CP1256) */
93 /* first convert to unicode */
97 ucs
= cp1256_to_uni
[*latin1
++ - 0x80];
101 case 0x06: /* Turkish (ISO-8859-9) */
103 /* first convert to unicode */
132 case 0x07: /* Latin Extended (ISO-8859-2) */
134 /* first convert to unicode */
138 ucs
= iso8859_2_to_uni
[*latin1
++ - 0xA1];
142 case 0x08: /* Central European (CP1250) */
144 /* first convert to unicode */
148 ucs
= cp1250_to_uni
[*latin1
++ - 0x80];
158 int writeshort(FILE *f
, unsigned short s
)
161 return putc(s
>>8, f
) != EOF
;
164 void print_usage(void)
166 printf("Usage: codepages [-m]\n"
167 "\t-m Create isomini.cp only\n");
168 printf("build date: " __DATE__
"\n\n");
171 int main(int argc
, char **argv
)
179 for (i
= 1;i
< argc
;i
++)
181 if (argv
[i
][0] == '-')
185 case 'm': /* create isomini.cp only */
203 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
207 of
= fopen("isomini.cp", "wb");
210 for (i
=1; i
<6; i
++) {
212 for (j
=0; j
<128; j
++) {
213 k
= (unsigned char)j
+ 128;
214 uni
= iso_decode(&k
, mini_index
[i
], 1);
221 of
= fopen("iso.cp", "wb");
224 for (i
=1; i
<9; i
++) {
226 for (j
=0; j
<128; j
++) {
227 k
= (unsigned char)j
+ 128;
228 uni
= iso_decode(&k
, i
, 1);
234 of
= fopen("932.cp", "wb");
236 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
237 writeshort(of
, cp932_table
[i
]);
240 of
= fopen("936.cp", "wb");
242 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
243 writeshort(of
, cp936_table
[i
]);
246 of
= fopen("949.cp", "wb");
248 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
249 writeshort(of
, cp949_table
[i
]);
252 of
= fopen("950.cp", "wb");
254 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
255 writeshort(of
, cp950_table
[i
]);