1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
7 * This library is free software you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library; if not, see <http://www.gnu.org/licenses/>.
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);
91 int main (int argc, char **argv)
93 unsigned int iso8859, iso2022, iso10646;
99 fp = fopen ("iconv-detect.h", "w");
103 fprintf (fp, "/* This is an auto-generated header, DO NOT EDIT! */\n\n");
105 iso8859 = ISO_UNSUPPORTED;
106 info = iso8859_tests;
107 /*printf ("#define DEFAULT_ISO_FORMAT(iso,codepage)\t");*/
108 for (i = 0; i < num_iso8859_tests; i++) {
109 cd = iconv_open (info[i].charset, "UTF-8");
110 if (cd != (iconv_t) -1) {
112 /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
113 fprintf (stderr, "System prefers %s\n", info[i].charset);
114 iso8859 = info[i].id;
119 if (iso8859 == ISO_UNSUPPORTED) {
120 fprintf (stderr, "System doesn't support any ISO-8859-1 formats\n");
121 fprintf (fp, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info[0].format);
126 fprintf (fp, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info[i].format);
129 iso2022 = ISO_UNSUPPORTED;
130 info = iso2022_tests;
131 /*printf ("#define ISO_2022_FORMAT(iso,codepage)\t");*/
132 for (i = 0; i < num_iso2022_tests; i++) {
133 cd = iconv_open (info[i].charset, "UTF-8");
134 if (cd != (iconv_t) -1) {
136 /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
137 fprintf (stderr, "System prefers %s\n", info[i].charset);
138 iso2022 = info[i].id;
143 if (iso2022 == ISO_UNSUPPORTED) {
144 fprintf (stderr, "System doesn't support any ISO-2022 formats\n");
145 fprintf (fp, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info[0].format);
150 fprintf (fp, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info[i].format);
153 iso10646 = ISO_UNSUPPORTED;
154 info = iso10646_tests;
155 /*printf ("#define ISO_10646_FORMAT(iso,codepage)\t");*/
156 for (i = 0; i < num_iso10646_tests; i++) {
157 cd = iconv_open (info[i].charset, "UTF-8");
158 if (cd != (iconv_t) -1) {
160 /*if (info[i].id < ISO_DASH_D_LOWER)
161 printf ("(\"%s\", (iso), (codepage))\n", info[i].format);
163 printf ("(\"%s\", (iso))\n", info[i].format);*/
164 fprintf (stderr, "System prefers %s\n", info[i].charset);
165 iso10646 = info[i].id;
170 /* we don't need a printf format for iso-10646 because there is only 1 */
171 if (iso10646 == ISO_UNSUPPORTED) {
172 fprintf (stderr, "System doesn't support any ISO-10646-1 formats\n");
173 fprintf (fp, "#define ICONV_10646 \"%s\"\n", info[0].charset);
178 fprintf (fp, "#define ICONV_10646 \"%s\"\n", info[i].charset);