]>
Commit | Line | Data |
---|---|---|
045c4fab | 1 | |
045c4fab VS |
2 | |
3 | #include <stdio.h> | |
4 | ||
5 | typedef struct { | |
6 | unsigned char c; | |
7 | unsigned short u; | |
8 | } charsetItem; | |
9 | ||
10 | ||
11 | ||
12 | int cmpt(const void *i1, const void *i2) | |
13 | { | |
14 | unsigned short u1 = ((charsetItem*)i1) -> u; | |
15 | unsigned short u2 = ((charsetItem*)i2) -> u; | |
16 | return (u1 - u2); | |
17 | } | |
18 | ||
19 | ||
20 | ||
21 | int main(int argc, char *argv[]) | |
22 | { | |
23 | unsigned enc, unic; | |
24 | unsigned i; | |
25 | charsetItem table[256]; | |
26 | ||
27 | for (i = 0; i < 256; i++) { table[i].c = i, table[i].u = 0; /* unknown */} | |
28 | ||
29 | while (!feof(stdin)) | |
30 | { | |
31 | scanf("%i\t%i\n", &enc, &unic); | |
32 | table[enc].u = unic; | |
33 | table[enc].c = enc; | |
34 | if (enc < 128 && enc != unic) | |
35 | fprintf(stderr, "7bit ASCII incompatibilit (%s): %i->%i\n", | |
36 | argv[2], enc, unic); | |
37 | } | |
38 | ||
39 | /* dump it: */ | |
40 | ||
41 | printf("\n\n" | |
c260cbf8 MR |
42 | "/*\n" |
43 | " * %s to Unicode recoding table\n" | |
045c4fab VS |
44 | " * based on file %s by Unicode Consortium\n" |
45 | " */\n\n" | |
cd1a22d1 | 46 | "static const wxUint16 encoding_table__%s[128] = {", |
045c4fab VS |
47 | argv[2], argv[1], argv[2]); |
48 | ||
49 | for (i = 128; i < 256; i++) | |
50 | { | |
51 | if (i % 8 == 0) | |
c260cbf8 MR |
52 | printf("\n "); |
53 | printf(" 0x%04X%c", table[i].u, (i == 255) ? '\n' : ','); | |
045c4fab | 54 | } |
c260cbf8 | 55 | printf(" };\n"); |
045c4fab VS |
56 | |
57 | qsort(table + 128, 128, sizeof(table[0]), cmpt); | |
58 | ||
59 | ||
60 | /* | |
61 | NO, WE DON'T NEED REVERSE TABLE, WE CAN BUILD IT AT RUNTIME | |
62 | (won't take that much time, after all you don't init | |
63 | conversion so often...) | |
64 | ||
65 | printf("\n" | |
66 | "static wxUint16 encoding_table_rev__%s[128] = {", | |
67 | argv[2]); | |
68 | ||
69 | for (i = 128; i < 256; i++) | |
70 | { | |
71 | if (i % 4 == 0) | |
72 | printf("\n "); | |
73 | printf("{c:0x%02X,u:0x%04X}%c ", table[i].c, table[i].u, (i == 255) ? '\n' : ','); | |
74 | } | |
75 | printf("};\n"); | |
76 | */ | |
77 | ||
78 | return 1; | |
79 | } |