| 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
|---|
| 2 | /* |
|---|
| 3 | * Authors: Jeffrey Stedfast <fejj@ximian.com> |
|---|
| 4 | * |
|---|
| 5 | * Copyright 2002 Ximian, Inc. (www.ximian.com) |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU 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. |
|---|
| 11 | * |
|---|
| 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 General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU 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. |
|---|
| 20 | * |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #include <stdio.h> |
|---|
| 25 | #include <iconv.h> |
|---|
| 26 | |
|---|
| 27 | enum { |
|---|
| 28 | ISO_UNSUPPORTED = 0, |
|---|
| 29 | |
|---|
| 30 | /* iso-8859-1 */ |
|---|
| 31 | ISO_DASH_D_DASH_D_LOWER = (1 << 0), |
|---|
| 32 | ISO_DASH_D_DASH_D = (1 << 1), |
|---|
| 33 | ISO_D_DASH_D = (1 << 2), |
|---|
| 34 | ISO_D_D = (1 << 3), |
|---|
| 35 | ISO_UNDER_D_DASH_D = (1 << 4), |
|---|
| 36 | NO_ISO_D_DASH_D = (1 << 5), |
|---|
| 37 | |
|---|
| 38 | /* iso-10646-1 */ |
|---|
| 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), |
|---|
| 44 | ISO_D = (1 << 5), |
|---|
| 45 | UCS4 = (1 << 6), |
|---|
| 46 | |
|---|
| 47 | /* iso-2022-jp */ |
|---|
| 48 | ISO_DASH_D_DASH_S_LOWER = (1 << 0), |
|---|
| 49 | ISO_DASH_D_DASH_S = (1 << 1), |
|---|
| 50 | ISO_D_DASH_S = (1 << 2), |
|---|
| 51 | }; |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | typedef struct { |
|---|
| 55 | char *charset; |
|---|
| 56 | char *format; |
|---|
| 57 | int id; |
|---|
| 58 | } CharInfo; |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 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 }, |
|---|
| 68 | }; |
|---|
| 69 | |
|---|
| 70 | static int num_iso8859_tests = sizeof (iso8859_tests) / sizeof (CharInfo); |
|---|
| 71 | |
|---|
| 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 }, |
|---|
| 76 | }; |
|---|
| 77 | |
|---|
| 78 | static int num_iso2022_tests = sizeof (iso2022_tests) / sizeof (CharInfo); |
|---|
| 79 | |
|---|
| 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 }, |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | static int num_iso10646_tests = sizeof (iso10646_tests) / sizeof (CharInfo); |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | int main (int argc, char **argv) |
|---|
| 94 | { |
|---|
| 95 | unsigned int bits, iso8859, iso2022, iso10646; |
|---|
| 96 | CharInfo *info; |
|---|
| 97 | iconv_t cd; |
|---|
| 98 | FILE *fp; |
|---|
| 99 | int i; |
|---|
| 100 | |
|---|
| 101 | fp = fopen ("iconv-detect.h", "w"); |
|---|
| 102 | if (fp == NULL) |
|---|
| 103 | exit (255); |
|---|
| 104 | |
|---|
| 105 | fprintf (fp, "/* This is an auto-generated header, DO NOT EDIT! */\n\n"); |
|---|
| 106 | |
|---|
| 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) { |
|---|
| 113 | iconv_close (cd); |
|---|
| 114 | /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/ |
|---|
| 115 | fprintf (stderr, "System prefers %s\n", info[i].charset); |
|---|
| 116 | iso8859 = info[i].id; |
|---|
| 117 | break; |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 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); |
|---|
| 124 | #ifdef CONFIGURE_IN |
|---|
| 125 | exit (1); |
|---|
| 126 | #endif |
|---|
| 127 | } else { |
|---|
| 128 | fprintf (fp, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info[i].format); |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 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) { |
|---|
| 137 | iconv_close (cd); |
|---|
| 138 | /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/ |
|---|
| 139 | fprintf (stderr, "System prefers %s\n", info[i].charset); |
|---|
| 140 | iso2022 = info[i].id; |
|---|
| 141 | break; |
|---|
| 142 | } |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 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); |
|---|
| 148 | #ifdef CONFIGURE_IN |
|---|
| 149 | exit (3); |
|---|
| 150 | #endif |
|---|
| 151 | } else { |
|---|
| 152 | fprintf (fp, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info[i].format); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 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) { |
|---|
| 161 | iconv_close (cd); |
|---|
| 162 | /*if (info[i].id < ISO_DASH_D_LOWER) |
|---|
| 163 | printf ("(\"%s\", (iso), (codepage))\n", info[i].format); |
|---|
| 164 | else |
|---|
| 165 | printf ("(\"%s\", (iso))\n", info[i].format);*/ |
|---|
| 166 | fprintf (stderr, "System prefers %s\n", info[i].charset); |
|---|
| 167 | iso10646 = info[i].id; |
|---|
| 168 | break; |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 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); |
|---|
| 176 | #ifdef CONFIGURE_IN |
|---|
| 177 | exit (2); |
|---|
| 178 | #endif |
|---|
| 179 | } else { |
|---|
| 180 | fprintf (fp, "#define ICONV_10646 \"%s\"\n", info[i].charset); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | fclose (fp); |
|---|
| 184 | |
|---|
| 185 | exit (0); |
|---|
| 186 | } |
|---|