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