2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) version 3.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with the program; if not, see <http://www.gnu.org/licenses/>
17 * Jeffrey Stedfast <fejj@ximian.com>
19 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
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
);