1 /* Mapping tables for EUC-TW handling.
2 Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include <cns11643l1.h>
26 /* Definitions used in the body of the `gconv' function. */
27 #define CHARSET_NAME "EUC-TW//"
28 #define FROM_LOOP from_euc_tw
29 #define TO_LOOP to_euc_tw
32 #define MIN_NEEDED_FROM 1
33 #define MAX_NEEDED_FROM 4
34 #define MIN_NEEDED_TO 4
37 /* First define the conversion function from EUC-TW to UCS4. */
38 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
39 #define MAX_NEEDED_INPUT MAX_NEEDED_FROM
40 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
41 #define LOOPFCT FROM_LOOP
44 uint32_t ch = *inptr; \
49 else if ((ch <= 0xa0 || ch > 0xfe) && ch != 0x8e) \
51 /* This is illegal. */ \
52 if (! ignore_errors_p ()) \
54 result = __GCONV_ILLEGAL_INPUT; \
64 /* Two or more byte character. First test whether the next \
65 character is also available. */ \
68 if (inptr + 1 >= inend) \
70 /* The second character is not available. Store the \
71 intermediate result. */ \
72 result = __GCONV_INCOMPLETE_INPUT; \
78 /* All second bytes of a multibyte character must be >= 0xa1. */ \
79 if (ch2 < 0xa1 || ch2 == 0xff) \
81 /* This is illegal. */ \
82 if (! ignore_errors_p ()) \
84 result = __GCONV_ILLEGAL_INPUT; \
95 /* This is code set 2: CNS 11643, planes 1 to 16. */ \
96 const char *endp = inptr + 1; \
98 ch = cns11643_to_ucs4 (&endp, inend - inptr - 1, 0x80); \
102 /* The third or fourth character is not available. Store \
103 the intermediate result. */ \
104 result = __GCONV_INCOMPLETE_INPUT; \
108 if (ch == __UNKNOWN_10646_CHAR) \
110 /* Illegal input. */ \
111 if (! ignore_errors_p ()) \
113 /* This is an illegal character. */ \
114 result = __GCONV_ILLEGAL_INPUT; \
127 /* This is code set 1: CNS 11643, plane 1. */ \
128 const unsigned char *endp = inptr; \
130 ch = cns11643l1_to_ucs4 (&endp, inend - inptr, 0x80); \
131 /* Please note that we need not test for the missing input \
132 characters here anymore. */ \
133 if (ch == __UNKNOWN_10646_CHAR) \
135 /* Illegal input. */ \
136 if (! ignore_errors_p ()) \
138 /* This is an illegal character. */ \
139 result = __GCONV_ILLEGAL_INPUT; \
152 put32 (outptr, ch); \
155 #define LOOP_NEED_FLAGS
156 #include <iconv/loop.c>
159 /* Next, define the other direction. */
160 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
161 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
162 #define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
163 #define LOOPFCT TO_LOOP
166 uint32_t ch = get32 (inptr); \
169 /* It's plain ASCII. */ \
173 /* Try the JIS character sets. */ \
176 found = ucs4_to_cns11643l1 (ch, outptr, outend - outptr); \
177 if (__builtin_expect (found, 1) == 0) \
179 /* We ran out of space. */ \
180 result = __GCONV_INCOMPLETE_INPUT; \
183 if (__builtin_expect (found, 1) != __UNKNOWN_10646_CHAR) \
185 /* It's a CNS 11643, plane 1 character, adjust it for EUC-TW. */ \
191 /* No CNS 11643, plane 1 character. */ \
193 found = ucs4_to_cns11643 (ch, outptr + 1, outend - outptr - 1); \
194 if (__builtin_expect (found, 1) == 0) \
196 /* We ran out of space. */ \
197 result = __GCONV_INCOMPLETE_INPUT; \
200 if (__builtin_expect (found, 0) == __UNKNOWN_10646_CHAR) \
202 /* Illegal character. */ \
203 STANDARD_ERR_HANDLER (4); \
206 /* It's a CNS 11643 character, adjust it for EUC-TW. */ \
207 *outptr++ = '\x8e'; \
216 #define LOOP_NEED_FLAGS
217 #include <iconv/loop.c>
220 /* Now define the toplevel functions. */
221 #include <iconv/skeleton.c>