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
[5] = {
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];
148 int writeshort(FILE *f
, unsigned short s
)
151 return putc(s
>>8, f
) != EOF
;
154 void print_usage(void)
156 printf("Usage: codepages [-m]\n"
157 "\t-m Create isomini.cp only\n");
158 printf("build date: " __DATE__
"\n\n");
161 int main(int argc
, char **argv
)
169 for (i
= 1;i
< argc
;i
++)
171 if (argv
[i
][0] == '-')
175 case 'm': /* create isomini.cp only */
193 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
197 of
= fopen("isomini.cp", "wb");
200 for (i
=1; i
<5; i
++) {
202 for (j
=0; j
<128; j
++) {
203 k
= (unsigned char)j
+ 128;
204 uni
= iso_decode(&k
, mini_index
[i
], 1);
211 of
= fopen("iso.cp", "wb");
214 for (i
=1; i
<8; i
++) {
216 for (j
=0; j
<128; j
++) {
217 k
= (unsigned char)j
+ 128;
218 uni
= iso_decode(&k
, i
, 1);
224 of
= fopen("932.cp", "wb");
226 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
227 writeshort(of
, cp932_table
[i
]);
230 of
= fopen("936.cp", "wb");
232 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
233 writeshort(of
, cp936_table
[i
]);
236 of
= fopen("949.cp", "wb");
238 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
239 writeshort(of
, cp949_table
[i
]);
242 of
= fopen("950.cp", "wb");
244 for (i
=0; i
< MAX_TABLE_SIZE
; i
++)
245 writeshort(of
, cp950_table
[i
]);