1 /* make_charset_table.c
2 * sample program to generate tables for charsets.c using iconv
14 int main(int argc
, char **argv
) {
15 /* for now only UCS-2 */
16 uint16_t table
[0x100];
22 /* 0x00 ... 0x7F same as ASCII? */
24 /* 0x00 ... 0x9F same as ISO? */
28 printf("usage: %s <charset>\n", argv
[0]);
34 conv
= iconv_open("UCS-2", charset
);
35 if (conv
== (iconv_t
) -1) {
41 for (i
= 0x00; i
< 0x100; i
++) {
42 unsigned char in
[1], out
[2];
43 size_t inlen
= 1, outlen
= 2;
45 char *inbuf
= (char *) in
;
46 char *outbuf
= (char *) out
;
52 conv
= iconv_open("UCS-2BE", charset
);
54 if (conv
== (iconv_t
) -1) {
55 /* shouldn't fail now */
60 ret
= iconv(conv
, &inbuf
, &inlen
, &outbuf
, &outlen
);
62 if (ret
== (size_t) -1 && errno
== EILSEQ
) {
68 if (ret
== (size_t) -1) {
76 if (ret
!= 0 || inlen
!= 0 || outlen
!= 0) {
77 fprintf(stderr
, "%d: smth went wrong: %zu %zu %zu\n", i
, ret
, inlen
, outlen
);
81 if (i
< 0x80 && (out
[0] != 0 || out
[1] != i
))
84 if (i
< 0xA0 && (out
[0] != 0 || out
[1] != i
))
87 table
[i
] = (out
[0] << 8) | out
[1];
90 /* iso_based not supported */
93 printf("/* generated by %s %s */\n", argv
[0], charset
);
102 printf("const gunichar2 charset_table_%s[0x%x] = {\n", charset
, 0x100 - i
);
108 for (j
= 0; j
< 8; j
++, i
++) {
109 if (table
[i
] == UNREPL
)
112 printf("0x%.4x, ", table
[i
]);
115 if ((start
& 0xf) == 0)
116 printf(" /* 0x%.2X - */", start
);
118 printf(" /* - 0x%.2X */", i
- 1);