Updated Finnish translation
[evolution.git] / iconv-detect.c
blobab0a341948fe1c22ffe64cbd9886c092bc73bbb4
1 /*
2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU Lesser General Public License as published by
4 * the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful, but
7 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9 * for more details.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 * Authors:
16 * Jeffrey Stedfast <fejj@ximian.com>
18 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <iconv.h>
26 enum {
27 ISO_UNSUPPORTED = 0,
29 /* iso-8859-1 */
30 ISO_DASH_D_DASH_D_LOWER = (1 << 0),
31 ISO_DASH_D_DASH_D = (1 << 1),
32 ISO_D_DASH_D = (1 << 2),
33 ISO_D_D = (1 << 3),
34 ISO_UNDER_D_DASH_D = (1 << 4),
35 NO_ISO_D_DASH_D = (1 << 5),
37 /* iso-10646-1 */
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),
43 ISO_D = (1 << 5),
44 UCS4 = (1 << 6),
46 /* iso-2022-jp */
47 ISO_DASH_D_DASH_S_LOWER = (1 << 0),
48 ISO_DASH_D_DASH_S = (1 << 1),
49 ISO_D_DASH_S = (1 << 2),
53 typedef struct {
54 char *charset;
55 char *format;
56 int id;
57 } CharInfo;
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 iso8859, iso2022, iso10646;
95 CharInfo *info;
96 iconv_t cd;
97 FILE *fp;
98 int i;
100 fp = fopen ("iconv-detect.h", "w");
101 if (fp == NULL)
102 exit (255);
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) {
112 iconv_close (cd);
113 /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
114 fprintf (stderr, "System prefers %s\n", info[i].charset);
115 iso8859 = info[i].id;
116 break;
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);
123 #ifdef CONFIGURE_IN
124 exit (1);
125 #endif
126 } else {
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) {
136 iconv_close (cd);
137 /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
138 fprintf (stderr, "System prefers %s\n", info[i].charset);
139 iso2022 = info[i].id;
140 break;
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);
147 #ifdef CONFIGURE_IN
148 exit (3);
149 #endif
150 } else {
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) {
160 iconv_close (cd);
161 /*if (info[i].id < ISO_DASH_D_LOWER)
162 printf ("(\"%s\", (iso), (codepage))\n", info[i].format);
163 else
164 printf ("(\"%s\", (iso))\n", info[i].format);*/
165 fprintf (stderr, "System prefers %s\n", info[i].charset);
166 iso10646 = info[i].id;
167 break;
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);
175 #ifdef CONFIGURE_IN
176 exit (2);
177 #endif
178 } else {
179 fprintf (fp, "#define ICONV_10646 \"%s\"\n", info[i].charset);
182 fclose (fp);
184 exit (0);