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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 ISO_DASH_D_DASH_D_LOWER = (1 << 0),
32 ISO_DASH_D_DASH_D = (1 << 1),
33 ISO_D_DASH_D = (1 << 2),
35 ISO_UNDER_D_DASH_D = (1 << 4),
36 NO_ISO_D_DASH_D = (1 << 5),
39 /*ISO_DASH_D_DASH_D_LOWER = (1 << 0),*/
40 /*ISO_DASH_D_DASH_D = (1 << 1),*/
41 /*ISO_D_DASH_D = (1 << 2),*/
42 ISO_DASH_D_LOWER = (1 << 3),
43 ISO_DASH_D = (1 << 4),
48 ISO_DASH_D_DASH_S_LOWER = (1 << 0),
49 ISO_DASH_D_DASH_S = (1 << 1),
50 ISO_D_DASH_S = (1 << 2),
61 static CharInfo iso8859_tests[] = {
62 { "iso-8859-1", "iso-%d-%d", ISO_DASH_D_DASH_D_LOWER },
63 { "ISO-8859-1", "ISO-%d-%d", ISO_DASH_D_DASH_D },
64 { "ISO8859-1", "ISO%d-%d", ISO_D_DASH_D },
65 { "ISO88591", "ISO%d%d", ISO_D_D },
66 { "ISO_8859-1", "ISO_%d-%d", ISO_UNDER_D_DASH_D },
67 { "8859-1", "%d-%d", NO_ISO_D_DASH_D },
70 static int num_iso8859_tests = sizeof (iso8859_tests) / sizeof (CharInfo);
72 static CharInfo iso2022_tests[] = {
73 { "iso-2022-jp", "iso-%d-%s", ISO_DASH_D_DASH_S_LOWER },
74 { "ISO-2022-JP", "ISO-%d-%s", ISO_DASH_D_DASH_S },
75 { "ISO2022-JP", "ISO%d-%s", ISO_D_DASH_S },
78 static int num_iso2022_tests = sizeof (iso2022_tests) / sizeof (CharInfo);
80 static CharInfo iso10646_tests[] = {
81 { "iso-10646-1", "iso-%d-%d", ISO_DASH_D_DASH_D_LOWER },
82 { "ISO-10646-1", "ISO-%d-%d", ISO_DASH_D_DASH_D },
83 { "ISO10646-1", "ISO%d-%d", ISO_D_DASH_D },
84 { "iso-10646", "iso-%d", ISO_DASH_D_LOWER },
85 { "ISO-10646", "ISO-%d", ISO_DASH_D },
86 { "ISO10646", "ISO%d", ISO_D },
87 { "UCS-4BE", "UCS-4BE", UCS4 },
90 static int num_iso10646_tests = sizeof (iso10646_tests) / sizeof (CharInfo);
93 int main (int argc, char **argv)
95 unsigned int iso8859, iso2022, iso10646;
101 fp = fopen ("iconv-detect.h", "w");
105 fprintf (fp, "/* This is an auto-generated header, DO NOT EDIT! */\n\n");
107 iso8859 = ISO_UNSUPPORTED;
108 info = iso8859_tests;
109 /*printf ("#define DEFAULT_ISO_FORMAT(iso,codepage)\t");*/
110 for (i = 0; i < num_iso8859_tests; i++) {
111 cd = iconv_open (info[i].charset, "UTF-8");
112 if (cd != (iconv_t) -1) {
114 /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
115 fprintf (stderr, "System prefers %s\n", info[i].charset);
116 iso8859 = info[i].id;
121 if (iso8859 == ISO_UNSUPPORTED) {
122 fprintf (stderr, "System doesn't support any ISO-8859-1 formats\n");
123 fprintf (fp, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info[0].format);
128 fprintf (fp, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info[i].format);
131 iso2022 = ISO_UNSUPPORTED;
132 info = iso2022_tests;
133 /*printf ("#define ISO_2022_FORMAT(iso,codepage)\t");*/
134 for (i = 0; i < num_iso2022_tests; i++) {
135 cd = iconv_open (info[i].charset, "UTF-8");
136 if (cd != (iconv_t) -1) {
138 /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
139 fprintf (stderr, "System prefers %s\n", info[i].charset);
140 iso2022 = info[i].id;
145 if (iso2022 == ISO_UNSUPPORTED) {
146 fprintf (stderr, "System doesn't support any ISO-2022 formats\n");
147 fprintf (fp, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info[0].format);
152 fprintf (fp, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info[i].format);
155 iso10646 = ISO_UNSUPPORTED;
156 info = iso10646_tests;
157 /*printf ("#define ISO_10646_FORMAT(iso,codepage)\t");*/
158 for (i = 0; i < num_iso10646_tests; i++) {
159 cd = iconv_open (info[i].charset, "UTF-8");
160 if (cd != (iconv_t) -1) {
162 /*if (info[i].id < ISO_DASH_D_LOWER)
163 printf ("(\"%s\", (iso), (codepage))\n", info[i].format);
165 printf ("(\"%s\", (iso))\n", info[i].format);*/
166 fprintf (stderr, "System prefers %s\n", info[i].charset);
167 iso10646 = info[i].id;
172 /* we don't need a printf format for iso-10646 because there is only 1 */
173 if (iso10646 == ISO_UNSUPPORTED) {
174 fprintf (stderr, "System doesn't support any ISO-10646-1 formats\n");
175 fprintf (fp, "#define ICONV_10646 \"%s\"\n", info[0].charset);
180 fprintf (fp, "#define ICONV_10646 \"%s\"\n", info[i].charset);