1 /* Mapping tables for EUC-TW handling.
2 Copyright (C) 1998-2014 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 Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the 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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
22 #include <cns11643l1.h>
25 /* Definitions used in the body of the `gconv' function. */
26 #define CHARSET_NAME "EUC-TW//"
27 #define FROM_LOOP from_euc_tw
28 #define TO_LOOP to_euc_tw
31 #define MIN_NEEDED_FROM 1
32 #define MAX_NEEDED_FROM 4
33 #define MIN_NEEDED_TO 4
34 #define ONE_DIRECTION 0
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 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
56 /* Two or more byte character. First test whether the next byte \
57 is also available. */ \
60 if (inptr + 1 >= inend) \
62 /* The second byte is not available. Store the intermediate \
64 result = __GCONV_INCOMPLETE_INPUT; \
70 /* All second bytes of a multibyte character must be >= 0xa1. */ \
71 if (ch2 < 0xa1 || ch2 == 0xff) \
72 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
76 /* This is code set 2: CNS 11643, planes 1 to 16. */ \
77 const unsigned char *endp = inptr + 1; \
79 ch = cns11643_to_ucs4 (&endp, inend - inptr - 1, 0x80); \
83 /* The third or fourth byte is not available. Store \
84 the intermediate result. */ \
85 result = __GCONV_INCOMPLETE_INPUT; \
89 if (ch == __UNKNOWN_10646_CHAR) \
90 /* Illegal input. */ \
91 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
97 /* This is code set 1: CNS 11643, plane 1. */ \
98 const unsigned char *endp = inptr; \
100 ch = cns11643l1_to_ucs4 (&endp, inend - inptr, 0x80); \
101 /* Please note that we need not test for the missing input \
102 characters here anymore. */ \
103 if (ch == __UNKNOWN_10646_CHAR) \
104 /* Illegal input. */ \
105 STANDARD_FROM_LOOP_ERR_HANDLER (2); \
111 put32 (outptr, ch); \
114 #define LOOP_NEED_FLAGS
115 #define ONEBYTE_BODY \
122 #include <iconv/loop.c>
125 /* Next, define the other direction. */
126 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
127 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
128 #define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
129 #define LOOPFCT TO_LOOP
132 uint32_t ch = get32 (inptr); \
135 /* It's plain ASCII. */ \
139 /* Try the CNS 11643 planes. */ \
142 found = ucs4_to_cns11643l1 (ch, outptr, outend - outptr); \
143 if (__builtin_expect (found, 1) == 0) \
145 /* We ran out of space. */ \
146 result = __GCONV_FULL_OUTPUT; \
149 if (__builtin_expect (found, 1) != __UNKNOWN_10646_CHAR) \
151 /* It's a CNS 11643, plane 1 character, adjust it for EUC-TW. */ \
157 /* No CNS 11643, plane 1 character. */ \
159 found = ucs4_to_cns11643 (ch, outptr + 1, outend - outptr - 1); \
160 if (__builtin_expect (found, 1) == 0) \
162 /* We ran out of space. */ \
163 result = __GCONV_FULL_OUTPUT; \
166 if (__builtin_expect (found, 0) == __UNKNOWN_10646_CHAR) \
168 UNICODE_TAG_HANDLER (ch, 4); \
170 /* Illegal character. */ \
171 STANDARD_TO_LOOP_ERR_HANDLER (4); \
174 /* It's a CNS 11643 character, adjust it for EUC-TW. */ \
175 *outptr++ = '\x8e'; \
184 #define LOOP_NEED_FLAGS
185 #include <iconv/loop.c>
188 /* Now define the toplevel functions. */
189 #include <iconv/skeleton.c>