1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright 2002 Ximian, Inc. (www.ximian.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
30 ISO_DASH_D_DASH_D_LOWER = (1 << 0),
31 ISO_DASH_D_DASH_D = (1 << 1),
32 ISO_D_DASH_D = (1 << 2),
34 ISO_UNDER_D_DASH_D = (1 << 4),
35 NO_ISO_D_DASH_D = (1 << 5),
38 /*ISO_DASH_D_DASH_D_LOWER = (1 << 0),*/
39 /*ISO_DASH_D_DASH_D = (1 << 1),*/
40 /*ISO_D_DASH_D = (1 << 2),*/
41 ISO_DASH_D_LOWER = (1 << 3),
42 ISO_DASH_D = (1 << 4),
47 ISO_DASH_D_DASH_S_LOWER = (1 << 0),
48 ISO_DASH_D_DASH_S = (1 << 1),
49 ISO_D_DASH_S = (1 << 2),
60 static CharInfo iso8859_tests[] = {
61 { "iso-8859-1", "iso-%d-%d", ISO_DASH_D_DASH_D_LOWER },
62 { "ISO-8859-1", "ISO-%d-%d", ISO_DASH_D_DASH_D },
63 { "ISO8859-1", "ISO%d-%d", ISO_D_DASH_D },
64 { "ISO88591", "ISO%d%d", ISO_D_D },
65 { "ISO_8859-1", "ISO_%d-%d", ISO_UNDER_D_DASH_D },
66 { "8859-1", "%d-%d", NO_ISO_D_DASH_D },
69 static int num_iso8859_tests = sizeof (iso8859_tests) / sizeof (CharInfo);
71 static CharInfo iso2022_tests[] = {
72 { "iso-2022-jp", "iso-%d-%s", ISO_DASH_D_DASH_S_LOWER },
73 { "ISO-2022-JP", "ISO-%d-%s", ISO_DASH_D_DASH_S },
74 { "ISO2022-JP", "ISO%d-%s", ISO_D_DASH_S },
77 static int num_iso2022_tests = sizeof (iso2022_tests) / sizeof (CharInfo);
79 static CharInfo iso10646_tests[] = {
80 { "iso-10646-1", "iso-%d-%d", ISO_DASH_D_DASH_D_LOWER },
81 { "ISO-10646-1", "ISO-%d-%d", ISO_DASH_D_DASH_D },
82 { "ISO10646-1", "ISO%d-%d", ISO_D_DASH_D },
83 { "iso-10646", "iso-%d", ISO_DASH_D_LOWER },
84 { "ISO-10646", "ISO-%d", ISO_DASH_D },
85 { "ISO10646", "ISO%d", ISO_D },
86 { "UCS-4BE", "UCS-4BE", UCS4 },
89 static int num_iso10646_tests = sizeof (iso10646_tests) / sizeof (CharInfo);
92 int main (int argc, char **argv)
94 unsigned int bits, iso8859, iso2022, iso10646;
100 fp = fopen ("iconv-detect.h", "w");
104 fprintf (fp, "/* This is an auto-generated header, DO NOT EDIT! */\n\n");
106 iso8859 = ISO_UNSUPPORTED;
107 info = iso8859_tests;
108 /*printf ("#define DEFAULT_ISO_FORMAT(iso,codepage)\t");*/
109 for (i = 0; i < num_iso8859_tests; i++) {
110 cd = iconv_open (info[i].charset, "UTF-8");
111 if (cd != (iconv_t) -1) {
113 /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
114 fprintf (stderr, "System prefers %s\n", info[i].charset);
115 iso8859 = info[i].id;
120 if (iso8859 == ISO_UNSUPPORTED) {
121 fprintf (stderr, "System doesn't support any ISO-8859-1 formats\n");
122 fprintf (fp, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info[0].format);
127 fprintf (fp, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info[i].format);
130 iso2022 = ISO_UNSUPPORTED;
131 info = iso2022_tests;
132 /*printf ("#define ISO_2022_FORMAT(iso,codepage)\t");*/
133 for (i = 0; i < num_iso2022_tests; i++) {
134 cd = iconv_open (info[i].charset, "UTF-8");
135 if (cd != (iconv_t) -1) {
137 /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
138 fprintf (stderr, "System prefers %s\n", info[i].charset);
139 iso2022 = info[i].id;
144 if (iso2022 == ISO_UNSUPPORTED) {
145 fprintf (stderr, "System doesn't support any ISO-2022 formats\n");
146 fprintf (fp, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info[0].format);
151 fprintf (fp, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info[i].format);
154 iso10646 = ISO_UNSUPPORTED;
155 info = iso10646_tests;
156 /*printf ("#define ISO_10646_FORMAT(iso,codepage)\t");*/
157 for (i = 0; i < num_iso10646_tests; i++) {
158 cd = iconv_open (info[i].charset, "UTF-8");
159 if (cd != (iconv_t) -1) {
161 /*if (info[i].id < ISO_DASH_D_LOWER)
162 printf ("(\"%s\", (iso), (codepage))\n", info[i].format);
164 printf ("(\"%s\", (iso))\n", info[i].format);*/
165 fprintf (stderr, "System prefers %s\n", info[i].charset);
166 iso10646 = info[i].id;
171 /* we don't need a printf format for iso-10646 because there is only 1 */
172 if (iso10646 == ISO_UNSUPPORTED) {
173 fprintf (stderr, "System doesn't support any ISO-10646-1 formats\n");
174 fprintf (fp, "#define ICONV_10646 \"%s\"\n", info[0].charset);
179 fprintf (fp, "#define ICONV_10646 \"%s\"\n", info[i].charset);