1#ifndef lint
2static char *rcsid = "$Id: iconvchk.c,v 1.1 2003/06/04 00:26:54 marka Exp $";
3#endif
4
5/*
6 * Copyright (c) 2002 Japan Network Information Center.
7 * All rights reserved.
8 *
9 * By using this file, you agree to the terms and conditions set forth bellow.
10 *
11 * 			LICENSE TERMS AND CONDITIONS
12 *
13 * The following License Terms and Conditions apply, unless a different
14 * license is obtained from Japan Network Information Center ("JPNIC"),
15 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
16 * Chiyoda-ku, Tokyo 101-0047, Japan.
17 *
18 * 1. Use, Modification and Redistribution (including distribution of any
19 *    modified or derived work) in source and/or binary forms is permitted
20 *    under this License Terms and Conditions.
21 *
22 * 2. Redistribution of source code must retain the copyright notices as they
23 *    appear in each source code file, this License Terms and Conditions.
24 *
25 * 3. Redistribution in binary form must reproduce the Copyright Notice,
26 *    this License Terms and Conditions, in the documentation and/or other
27 *    materials provided with the distribution.  For the purposes of binary
28 *    distribution the "Copyright Notice" refers to the following language:
29 *    "Copyright (c) 2000-2002 Japan Network Information Center.  All rights reserved."
30 *
31 * 4. The name of JPNIC may not be used to endorse or promote products
32 *    derived from this Software without specific prior written approval of
33 *    JPNIC.
34 *
35 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
36 *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
38 *    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL JPNIC BE LIABLE
39 *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40 *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41 *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42 *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
43 *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
44 *    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
45 *    ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46 */
47
48#include <stdio.h>
49#include <stdlib.h>
50
51#include <idn/api.h>
52#include <idn/converter.h>
53#include <idn/result.h>
54
55#include "codeset.h"
56
57#define IDN_UTF8_ENCODING_NAME	"UTF-8"
58
59void
60eucjp_check(void)
61{
62	idn_result_t r;
63	idn_converter_t eucjp_ctx = NULL;
64
65	r = idn_nameinit(0);
66	if (r != idn_success) {
67		fprintf(stderr, "idn_nameinit(): failed\n");
68		exit (1);
69	}
70
71	r = idn_converter_create(EUCJP_ENCODING_NAME, &eucjp_ctx, 0);
72
73	if (eucjp_ctx != NULL) {
74		idn_converter_destroy(eucjp_ctx);
75	}
76
77	if (r != idn_success) {
78		if (r == idn_invalid_name) {
79			fprintf(stderr, \
80				"\"%s\" is invalid codeset name, edit codeset.h\n", \
81				EUCJP_ENCODING_NAME);
82			exit (1);
83		} else {
84			fprintf(stderr, \
85				"idn_converter_create() failed with error \"%s\"\n", \
86				idn_result_tostring(r));
87			exit (1);
88		}
89	}
90}
91
92void
93sjis_check(void)
94{
95	idn_result_t r;
96	idn_converter_t sjis_ctx = NULL;
97
98	r = idn_nameinit(0);
99	if (r != idn_success) {
100		fprintf(stderr, "idn_nameinit(): failed\n");
101		exit (1);
102	}
103
104	r = idn_converter_create(SJIS_ENCODING_NAME, &sjis_ctx, 0);
105
106	if (sjis_ctx != NULL) {
107		idn_converter_destroy(sjis_ctx);
108	}
109
110	if (r != idn_success) {
111		if (r == idn_invalid_name) {
112			fprintf(stderr, \
113				"\"%s\" is invalid codeset name, edit codeset.h\n", \
114				SJIS_ENCODING_NAME);
115			exit (1);
116		} else {
117			fprintf(stderr, \
118				"idn_converter_create() failed with error \"%s\"\n", \
119				idn_result_tostring(r));
120			exit (1);
121		}
122	}
123}
124
125int
126main (int ac, char **av)
127{
128	eucjp_check();
129	sjis_check();
130
131	exit (0);
132}
133