1
by brian
clean slate |
1 |
/* Copyright (C) 2003-2004 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
15 |
||
16 |
#include <stdio.h> |
|
17 |
#include <string.h> |
|
18 |
||
19 |
static void print_short_array(unsigned short *a, size_t width) |
|
20 |
{
|
|
21 |
int i; |
|
22 |
printf("{\n"); |
|
23 |
for (i=0; i<=0xFF; i++) |
|
24 |
{
|
|
25 |
const char *fmt= (width==4) ? "0x%04X" : "0x%02X"; |
|
26 |
printf(fmt,(int)a[i]); |
|
27 |
printf("%s%s",i<0xFF?",":"",(i+1) % 8 ? "" :"\n"); |
|
28 |
}
|
|
29 |
printf("};\n"); |
|
30 |
||
31 |
}
|
|
32 |
||
33 |
||
34 |
||
35 |
int main(void) |
|
36 |
{
|
|
37 |
char str[160]; |
|
38 |
unsigned short touni[256]; |
|
39 |
unsigned short fromuni[65536]; |
|
40 |
unsigned short fromstat[256]; |
|
41 |
int i; |
|
42 |
||
43 |
bzero((void*)touni,sizeof(touni)); |
|
44 |
bzero((void*)fromuni,sizeof(fromuni)); |
|
45 |
bzero((void*)fromstat,sizeof(fromstat)); |
|
46 |
||
47 |
while (fgets(str,sizeof(str),stdin)) |
|
48 |
{
|
|
49 |
unsigned int c,u; |
|
50 |
||
51 |
if ((str[0]=='#') || (2!=sscanf(str,"%x%x",&c,&u))) |
|
52 |
continue; |
|
53 |
if (c>0xFF || u>0xFFFF) |
|
54 |
continue; |
|
55 |
||
56 |
touni[c]= u; |
|
57 |
fromuni[u]= c; |
|
58 |
}
|
|
59 |
||
60 |
printf("unsigned short cs_to_uni[256]="); |
|
61 |
print_short_array(touni, 4); |
|
62 |
||
63 |
for (i=0;i<=0xFF;i++) |
|
64 |
{
|
|
65 |
fromstat[touni[i]>>8]++; |
|
66 |
}
|
|
67 |
||
68 |
for (i=0;i<=256;i++) |
|
69 |
{
|
|
70 |
if (fromstat[i]) |
|
71 |
{
|
|
72 |
printf("unsigned char pl%02X[256]=",i); |
|
73 |
print_short_array(fromuni+i*256, 2); |
|
74 |
}
|
|
75 |
}
|
|
76 |
||
77 |
printf("unsigned short *uni_to_cs[256]={\n"); |
|
78 |
for (i=0;i<=255;i++) |
|
79 |
{
|
|
80 |
if (fromstat[i]) |
|
81 |
printf("pl%02X",i); |
|
82 |
else
|
|
83 |
printf("NULL"); |
|
84 |
printf("%s%s",i<255?",":"",((i+1) % 8) ? "":"\n"); |
|
85 |
}
|
|
86 |
printf("};\n"); |
|
87 |
||
88 |
return 0; |
|
89 |
}
|