1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 1999-2012 Jeffrey Stedfast
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1
8 * of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
30 ISO_DASH_UINT_DASH_UINT_LOWER = (1 << 0),
31 ISO_DASH_UINT_DASH_UINT = (1 << 1),
32 ISO_UINT_DASH_UINT = (1 << 2),
33 ISO_UINT_UINT = (1 << 3),
34 ISO_UNDER_UINT_DASH_UINT = (1 << 4),
35 NO_ISO_UINT_DASH_UINT = (1 << 5),
38 /*ISO_DASH_UINT_DASH_UINT_LOWER = (1 << 0),*/
39 /*ISO_DASH_UINT_DASH_UINT = (1 << 1),*/
40 /*ISO_UINT_DASH_UINT = (1 << 2),*/
41 ISO_DASH_UINT_LOWER = (1 << 3),
42 ISO_DASH_UINT = (1 << 4),
47 ISO_DASH_UINT_DASH_STR_LOWER = (1 << 0),
48 ISO_DASH_UINT_DASH_STR = (1 << 1),
49 ISO_UINT_DASH_STR = (1 << 2),
60 static CharInfo iso8859_tests[] = {
61 { "iso-8859-1", "iso-%u-%u", ISO_DASH_UINT_DASH_UINT_LOWER },
62 { "ISO-8859-1", "ISO-%u-%u", ISO_DASH_UINT_DASH_UINT },
63 { "ISO8859-1", "ISO%u-%u", ISO_UINT_DASH_UINT },
64 { "ISO88591", "ISO%u%u", ISO_UINT_UINT },
65 { "ISO_8859-1", "ISO_%u-%u", ISO_UNDER_UINT_DASH_UINT },
66 { "8859-1", "%u-%u", NO_ISO_UINT_DASH_UINT },
69 static int num_iso8859_tests = sizeof (iso8859_tests) / sizeof (CharInfo);
71 static CharInfo iso2022_tests[] = {
72 { "iso-2022-jp", "iso-%u-%s", ISO_DASH_UINT_DASH_STR_LOWER },
73 { "ISO-2022-JP", "ISO-%u-%s", ISO_DASH_UINT_DASH_STR },
74 { "ISO2022-JP", "ISO%u-%s", ISO_UINT_DASH_STR },
77 static int num_iso2022_tests = sizeof (iso2022_tests) / sizeof (CharInfo);
79 static CharInfo iso10646_tests[] = {
80 { "iso-10646-1", "iso-%u-%u", ISO_DASH_UINT_DASH_UINT_LOWER },
81 { "ISO-10646-1", "ISO-%u-%u", ISO_DASH_UINT_DASH_UINT },
82 { "ISO10646-1", "ISO%u-%u", ISO_UINT_DASH_UINT },
83 { "iso-10646", "iso-%u", ISO_DASH_UINT_LOWER },
84 { "ISO-10646", "ISO-%u", ISO_DASH_UINT },
85 { "ISO10646", "ISO%u", ISO_UINT },
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 iso8859, iso2022, iso10646;
100 if (!(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_INT_FORMAT \"%s\"\n", info[0].format);
126 fprintf (fp, "#define ICONV_ISO_INT_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_STR_FORMAT \"%s\"\n", info[0].format);
150 fprintf (fp, "#define ICONV_ISO_STR_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_UINT_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);