1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
5 * This library is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation.
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
17 * Authors: Jeffrey Stedfast <fejj@ximian.com>
29 ISO_DASH_D_DASH_D_LOWER
= (1 << 0),
30 ISO_DASH_D_DASH_D
= (1 << 1),
31 ISO_D_DASH_D
= (1 << 2),
33 ISO_UNDER_D_DASH_D
= (1 << 4),
34 NO_ISO_D_DASH_D
= (1 << 5),
37 /*ISO_DASH_D_DASH_D_LOWER = (1 << 0),*/
38 /*ISO_DASH_D_DASH_D = (1 << 1),*/
39 /*ISO_D_DASH_D = (1 << 2),*/
40 ISO_DASH_D_LOWER
= (1 << 3),
41 ISO_DASH_D
= (1 << 4),
46 ISO_DASH_D_DASH_S_LOWER
= (1 << 0),
47 ISO_DASH_D_DASH_S
= (1 << 1),
48 ISO_D_DASH_S
= (1 << 2),
59 static CharInfo iso8859_tests
[] = {
60 { "iso-8859-1", "iso-%d-%d", ISO_DASH_D_DASH_D_LOWER
},
61 { "ISO-8859-1", "ISO-%d-%d", ISO_DASH_D_DASH_D
},
62 { "ISO8859-1", "ISO%d-%d", ISO_D_DASH_D
},
63 { "ISO88591", "ISO%d%d", ISO_D_D
},
64 { "ISO_8859-1", "ISO_%d-%d", ISO_UNDER_D_DASH_D
},
65 { "8859-1", "%d-%d", NO_ISO_D_DASH_D
},
68 static int num_iso8859_tests
= sizeof (iso8859_tests
) / sizeof (CharInfo
);
70 static CharInfo iso2022_tests
[] = {
71 { "iso-2022-jp", "iso-%d-%s", ISO_DASH_D_DASH_S_LOWER
},
72 { "ISO-2022-JP", "ISO-%d-%s", ISO_DASH_D_DASH_S
},
73 { "ISO2022-JP", "ISO%d-%s", ISO_D_DASH_S
},
76 static int num_iso2022_tests
= sizeof (iso2022_tests
) / sizeof (CharInfo
);
78 static CharInfo iso10646_tests
[] = {
79 { "iso-10646-1", "iso-%d-%d", ISO_DASH_D_DASH_D_LOWER
},
80 { "ISO-10646-1", "ISO-%d-%d", ISO_DASH_D_DASH_D
},
81 { "ISO10646-1", "ISO%d-%d", ISO_D_DASH_D
},
82 { "iso-10646", "iso-%d", ISO_DASH_D_LOWER
},
83 { "ISO-10646", "ISO-%d", ISO_DASH_D
},
84 { "ISO10646", "ISO%d", ISO_D
},
85 { "UCS-4BE", "UCS-4BE", UCS4
},
88 static int num_iso10646_tests
= sizeof (iso10646_tests
) / sizeof (CharInfo
);
93 char *jp
= "\x1B\x24\x42\x46\x7C\x4B\x5C\x38\x6C";
94 char *utf8
= "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E";
95 char *transbuf
= malloc (10), *trans
= transbuf
;
97 size_t jp_len
= strlen (jp
), utf8_len
= 10;
98 size_t utf8_real_len
= strlen (utf8
);
100 cd
= iconv_open ("UTF-8", "ISO-2022-JP");
101 if (cd
== (iconv_t
) -1)
104 if (iconv (cd
, &jp
, &jp_len
, &trans
, &utf8_len
) == -1 || jp_len
!= 0) {
108 if (memcmp (utf8
, transbuf
, utf8_real_len
) != 0) {
122 unsigned int iso8859
, iso2022
, iso10646
;
131 fp
= fopen ("iconv-detect.h", "w");
135 fprintf (fp
, "/* This is an auto-generated header, DO NOT EDIT! */\n\n");
137 iso8859
= ISO_UNSUPPORTED
;
138 info
= iso8859_tests
;
139 /*printf ("#define DEFAULT_ISO_FORMAT(iso,codepage)\t");*/
140 for (i
= 0; i
< num_iso8859_tests
; i
++) {
141 cd
= iconv_open (info
[i
].charset
, "UTF-8");
142 if (cd
!= (iconv_t
) -1) {
144 /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
145 fprintf (stderr
, "System prefers %s\n", info
[i
].charset
);
146 iso8859
= info
[i
].id
;
151 if (iso8859
== ISO_UNSUPPORTED
) {
152 fprintf (stderr
, "System doesn't support any ISO-8859-1 formats\n");
153 fprintf (fp
, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info
[0].format
);
155 fprintf (fp
, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info
[i
].format
);
158 iso2022
= ISO_UNSUPPORTED
;
159 info
= iso2022_tests
;
160 /*printf ("#define ISO_2022_FORMAT(iso,codepage)\t");*/
161 for (i
= 0; i
< num_iso2022_tests
; i
++) {
162 cd
= iconv_open (info
[i
].charset
, "UTF-8");
163 if (cd
!= (iconv_t
) -1) {
165 /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
166 fprintf (stderr
, "System prefers %s\n", info
[i
].charset
);
167 iso2022
= info
[i
].id
;
172 if (iso2022
== ISO_UNSUPPORTED
) {
173 fprintf (stderr
, "System doesn't support any ISO-2022 formats\n");
174 fprintf (fp
, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info
[0].format
);
176 fprintf (fp
, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info
[i
].format
);
179 iso10646
= ISO_UNSUPPORTED
;
180 info
= iso10646_tests
;
181 /*printf ("#define ISO_10646_FORMAT(iso,codepage)\t");*/
182 for (i
= 0; i
< num_iso10646_tests
; i
++) {
183 cd
= iconv_open (info
[i
].charset
, "UTF-8");
184 if (cd
!= (iconv_t
) -1) {
186 /*if (info[i].id < ISO_DASH_D_LOWER)
187 printf ("(\"%s\", (iso), (codepage))\n", info[i].format);
189 printf ("(\"%s\", (iso))\n", info[i].format);*/
190 fprintf (stderr
, "System prefers %s\n", info
[i
].charset
);
191 iso10646
= info
[i
].id
;
196 /* we don't need a printf format for iso-10646 because there is only 1 */
197 if (iso10646
== ISO_UNSUPPORTED
) {
198 fprintf (stderr
, "System doesn't support any ISO-10646-1 formats\n");
199 fprintf (fp
, "#define ICONV_10646 \"%s\"\n", info
[0].charset
);
201 fprintf (fp
, "#define ICONV_10646 \"%s\"\n", info
[i
].charset
);