aboutsummaryrefslogtreecommitdiffstats
path: root/iconv-detect.c
blob: 4eb6597225568768011d9efb2008d5166edf5777 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 *
 * Authors:
 *      Jeffrey Stedfast <fejj@ximian.com>
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <iconv.h>

enum {
    ISO_UNSUPPORTED          = 0,

    /* iso-8859-1 */
    ISO_DASH_D_DASH_D_LOWER  = (1 << 0),
    ISO_DASH_D_DASH_D        = (1 << 1),
    ISO_D_DASH_D             = (1 << 2),
    ISO_D_D                  = (1 << 3),
    ISO_UNDER_D_DASH_D       = (1 << 4),
    NO_ISO_D_DASH_D          = (1 << 5),

    /* iso-10646-1 */
    /*ISO_DASH_D_DASH_D_LOWER  = (1 << 0),*/
    /*ISO_DASH_D_DASH_D        = (1 << 1),*/
    /*ISO_D_DASH_D             = (1 << 2),*/
    ISO_DASH_D_LOWER           = (1 << 3),
    ISO_DASH_D                 = (1 << 4),
    ISO_D                      = (1 << 5),
    UCS4                       = (1 << 6),

    /* iso-2022-jp */
    ISO_DASH_D_DASH_S_LOWER  = (1 << 0),
    ISO_DASH_D_DASH_S        = (1 << 1),
    ISO_D_DASH_S             = (1 << 2),
};


typedef struct {
    char *charset;
    char *format;
    int id;
} CharInfo;


static CharInfo iso8859_tests[] = {
    { "iso-8859-1",  "iso-%d-%d", ISO_DASH_D_DASH_D_LOWER },
    { "ISO-8859-1",  "ISO-%d-%d", ISO_DASH_D_DASH_D },
    { "ISO8859-1",   "ISO%d-%d",  ISO_D_DASH_D },
    { "ISO88591",    "ISO%d%d",   ISO_D_D },
    { "ISO_8859-1",  "ISO_%d-%d", ISO_UNDER_D_DASH_D },
    { "8859-1",      "%d-%d",     NO_ISO_D_DASH_D },
};

static int num_iso8859_tests = sizeof (iso8859_tests) / sizeof (CharInfo);

static CharInfo iso2022_tests[] = {
    { "iso-2022-jp", "iso-%d-%s", ISO_DASH_D_DASH_S_LOWER },
    { "ISO-2022-JP", "ISO-%d-%s", ISO_DASH_D_DASH_S },
    { "ISO2022-JP",  "ISO%d-%s",  ISO_D_DASH_S },
};

static int num_iso2022_tests = sizeof (iso2022_tests) / sizeof (CharInfo);

static CharInfo iso10646_tests[] = {
    { "iso-10646-1", "iso-%d-%d",  ISO_DASH_D_DASH_D_LOWER },
    { "ISO-10646-1", "ISO-%d-%d",  ISO_DASH_D_DASH_D },
    { "ISO10646-1",  "ISO%d-%d",   ISO_D_DASH_D },
    { "iso-10646",   "iso-%d",     ISO_DASH_D_LOWER },
    { "ISO-10646",   "ISO-%d",     ISO_DASH_D },
    { "ISO10646",    "ISO%d",      ISO_D },
    { "UCS-4BE",     "UCS-4BE",    UCS4 },
};

static int num_iso10646_tests = sizeof (iso10646_tests) / sizeof (CharInfo);


int main (int argc, char **argv)
{
    unsigned int iso8859, iso2022, iso10646;
    CharInfo *info;
    iconv_t cd;
    FILE *fp;
    int i;

    fp = fopen ("iconv-detect.h", "w");
    if (fp == NULL)
        exit (255);

    fprintf (fp, "/* This is an auto-generated header, DO NOT EDIT! */\n\n");

    iso8859 = ISO_UNSUPPORTED;
    info = iso8859_tests;
    /*printf ("#define DEFAULT_ISO_FORMAT(iso,codepage)\t");*/
    for (i = 0; i < num_iso8859_tests; i++) {
        cd = iconv_open (info[i].charset, "UTF-8");
        if (cd != (iconv_t) -1) {
            iconv_close (cd);
            /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
            fprintf (stderr, "System prefers %s\n", info[i].charset);
            iso8859 = info[i].id;
            break;
        }
    }

    if (iso8859 == ISO_UNSUPPORTED) {
        fprintf (stderr, "System doesn't support any ISO-8859-1 formats\n");
        fprintf (fp, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info[0].format);
#ifdef CONFIGURE_IN
        exit (1);
#endif
    } else {
        fprintf (fp, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info[i].format);
    }

    iso2022 = ISO_UNSUPPORTED;
    info = iso2022_tests;
    /*printf ("#define ISO_2022_FORMAT(iso,codepage)\t");*/
    for (i = 0; i < num_iso2022_tests; i++) {
        cd = iconv_open (info[i].charset, "UTF-8");
        if (cd != (iconv_t) -1) {
            iconv_close (cd);
            /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
            fprintf (stderr, "System prefers %s\n", info[i].charset);
            iso2022 = info[i].id;
            break;
        }
    }

    if (iso2022 == ISO_UNSUPPORTED) {
        fprintf (stderr, "System doesn't support any ISO-2022 formats\n");
        fprintf (fp, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info[0].format);
#ifdef CONFIGURE_IN
        exit (3);
#endif
    } else {
        fprintf (fp, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info[i].format);
    }

    iso10646 = ISO_UNSUPPORTED;
    info = iso10646_tests;
    /*printf ("#define ISO_10646_FORMAT(iso,codepage)\t");*/
    for (i = 0; i < num_iso10646_tests; i++) {
        cd = iconv_open (info[i].charset, "UTF-8");
        if (cd != (iconv_t) -1) {
            iconv_close (cd);
            /*if (info[i].id < ISO_DASH_D_LOWER)
                printf ("(\"%s\", (iso), (codepage))\n", info[i].format);
            else
            printf ("(\"%s\", (iso))\n", info[i].format);*/
            fprintf (stderr, "System prefers %s\n", info[i].charset);
            iso10646 = info[i].id;
            break;
        }
    }

    /* we don't need a printf format for iso-10646 because there is only 1 */
    if (iso10646 == ISO_UNSUPPORTED) {
        fprintf (stderr, "System doesn't support any ISO-10646-1 formats\n");
        fprintf (fp, "#define ICONV_10646 \"%s\"\n", info[0].charset);
#ifdef CONFIGURE_IN
        exit (2);
#endif
    } else {
        fprintf (fp, "#define ICONV_10646 \"%s\"\n", info[i].charset);
    }

    fclose (fp);

    exit (0);
}
pan> | | | | | | | | | | | | | feature/instant/move-features-over-from-zrx-buyer | * | | | Update yarn.lockFabio Berger2018-10-111-7/+0 | | | | | | * | | | fix(website): replace Rollbar UMD with regular npm packageFabio Berger2018-10-111-1/+47 | | |_|/ | |/| | | * | | Merge pull request #1125 from 0xProject/feature/starter-dev-tools-pagesLeonid Logvinov2018-10-111-39/+9 | |\ \ \ | | | | | | | | | | Initial project scaffolding for dev tools pages | | * | | Add stuffFabio Berger2018-10-101-39/+9 | | | | | | | * | | Initial project scaffoldingLeonid Logvinov2018-10-101-91/+3 | | | | | * | | | | feat: model asset meta data and add dynamic assetData statefragosti2018-10-131-0/+15 |/ / / / * | | | Upgrade to more recent types, fix yarn.lockfragosti2018-10-111-9/+4 | | | | * | | | Merge branch 'development' of https://github.com/0xProject/0x-monorepo into ↵fragosti2018-10-101-868/+201 |\| | | | | | | | | | | | | | | feature/instant/redux-styles-container | * | | Fix merge conflictsLeonid Logvinov2018-10-091-0/+39 | | | | | * | | Fix ethers build issueLeonid Logvinov2018-10-091-43/+8 | | | | | * | | Use bundlewatch instead of bundlesizeLeonid Logvinov2018-10-091-4/+70 | | | | | * | | Throw and handle errors from Providers.Jacob Evans2018-10-091-61/+3 | | | | | | | | | | | | | | | | | | | | | | | | | | | | In web3 wrapper when a response contains an error field we throw this rather than return response.result which is often undefined. In Signature Utils we handle the error thrown when a user rejects the signing dialogue to prevent double signing. Exposed the ZeroExTransaction JSON schema. In Website only use the MetamaskSubprovider if we can detect the provider is Metamask | * | | Introduce Metamask Subprovider.Jacob Evans2018-10-051-225/+52 | | | | | | | | | | | | | | | | MM has a number of inconsistencies with other providers when implementing the JSON RPC interface. This subprovider wraps those nuances so they do not leak into the rest of our code | * | | Expose eth_signTypedData functionality for order signingJacob Evans2018-10-051-514/+100 | | |/ | |/| * | | Fix currupted yarn lock filefragosti2018-10-051-6/+6 | | | * | | Remove deps we probably dont needfragosti2018-10-051-47/+35 | | | * | | Merge branch 'development' of https://github.com/0xProject/0x-monorepo into ↵fragosti2018-10-051-380/+195 |\| | | | | | | | | | | feature/instant/redux-styles-container | * | Upgrade webpackFabio Berger2018-10-041-380/+195 | | | * | | Add some ui componentsfragosti2018-10-041-0/+6 | | | * | | Add redux to 0x instantfragosti2018-10-041-22/+11 | | | * | | Add styled-components with themefragosti2018-10-041-0/+32 |/ / * | Merge branch 'development' of https://github.com/0xProject/0x-monorepo into ↵fragosti2018-10-031-18/+162 |\ \ | | | | | | | | | feature/instant/init | * | Add a command to run bundle size reporterLeonid Logvinov2018-10-021-35/+134 | | | | * | Add missing yarn.lock changesFabio Berger2018-10-021-0/+27 | |/ * | Add dev environmentfragosti2018-10-031-18/+125 | | * | Clean up package jsonfragosti2018-10-031-42/+1174 | | * | Have React setup with basic build workingfragosti2018-09-281-40/+371 |/ * Remove yarn postinstall hack (#1098)Alex Browne2018-09-281-2/+2 | * Merge pull request #1069 from 0xProject/feature/ts-ethersLeonid Logvinov2018-09-271-4/+23 |\ | | | | Upgrade to TS version of ethers | * Merge branch 'development' into feature/ts-ethersLeonid Logvinov2018-09-261-34/+38 | |\ | * | Upgrade to TS version of ethersLeonid Logvinov2018-09-191-4/+23 | | | * | | Update everything to Coinbase Wallet instead of Toshifragosti2018-09-261-1/+54 | |/ |/| * | Update yarn.lockFabio Berger2018-09-261-33/+29 | | * | Upgrade blockstream to version that supports fetching logs by blockHash, ↵Fabio Berger2018-09-211-1/+9 |/ | | | fixing reliability issues * [testnet-faucets] update to v2Jacob Evans2018-09-051-91/+16 | * Run linterfragosti2018-09-051-3/+3 | * Use order parser utils from order utilsfragosti2018-09-051-35/+75 | * Merge https://github.com/0xProject/0x-monorepo into ↵fragosti2018-09-051-34/+36 |\ | | | | | | feature/website/update-portal-v2 | * Update yarn.lockFabio Berger2018-09-041-33/+29 | | | * Update yarn lockBrandon Millman2018-08-311-30/+34 | | | * Final tweaks for landing pagefragosti2018-08-311-34/+30 | | | * Update yarn lockBrandon Millman2018-08-311-4/+4 | | | * Add TypedText component and use it on landing pagefragosti2018-08-311-1/+7 | | * | Update yarn lockBrandon Millman2018-08-311-25/+4 | | * | Token registry from old 0x versionBrandon Millman2018-08-311-2/+60 | | * | Initial changes for v2 portalBrandon Millman2018-08-311-89/+22 |/ * Merge branch 'development' of https://github.com/0xProject/0x-monorepo into ↵fragosti2018-08-301-60/+1 |\ | | | | | | website/feature/react-16 | * feat: Add support for TypeScript project references (#991)Alex Browne2018-08-301-60/+1 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Update all package.json and tsconfig.json * fix(contracts): Make test/utils/web3_wrapper.ts compatible with project refs * Fix webpack config for 0x.js * Fix linter errors by adding rootDir to tsconfig.json as needed * Add build:ts and watch:ts commands to package.json * Update sra-spec to work with project references * Update tsconfig.json with latest new/removed packages * Add TypeScript as devDependency at root * Add missing rootDir to forwarder-helper package * Use a separate tsconfig file for typedoc * Fix linter errors * Apply PR feedback (add comments) * Fix 0x.js tsconfig * | Change VersionDropDown to use material-ui 3fragosti2018-08-291-3/+208 | | * | Upgrade version of react-shared in websitefragosti2018-08-291-37/+1 | | * | Upgrade react-copy-to-clipboardfragosti2018-08-291-16/+7 | | * | Remove react-tap-event-plugin from react-sharedfragosti2018-08-291-10/+4 | | * | Upgrade material ui in react-docsfragosti2018-08-291-60/+7 | | * | Update lockfilefragosti2018-08-291-3/+3 | | * | Update material-ui in react-sharedfragosti2018-08-291-1/+37 | | * | Upgrade material ui to 0.20.0fragosti2018-08-291-2/+62 | | * | Bump react-highlight in react-shared once morefragosti2018-08-251-5/+5 | | * | Upgrade react-shared used by website to one that depends on react 16fragosti2018-08-251-154/+9 | | * | Upgrade react-highlight to version that depends on React 16fragosti2018-08-251-0/+9 | | * | Update react and remove tap event plugin [deprecated]fragosti2018-08-251-32/+36 | |