1 /* Mapping tables for EUC-JP handling.
2 Copyright (C) 1998-2017 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/>. */
27 /* Definitions used in the body of the `gconv' function. */
28 #define CHARSET_NAME "EUC-JP//"
29 #define FROM_LOOP from_euc_jp
30 #define TO_LOOP to_euc_jp
33 #define MIN_NEEDED_FROM 1
34 #define MAX_NEEDED_FROM 3
35 #define MIN_NEEDED_TO 4
36 #define ONE_DIRECTION 0
39 /* First define the conversion function from EUC-JP to UCS4. */
40 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
41 #define MAX_NEEDED_INPUT MAX_NEEDED_FROM
42 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
43 #define LOOPFCT FROM_LOOP
46 uint32_t ch = *inptr; \
48 if (ch < 0x8e || (ch >= 0x90 && ch <= 0x9f)) \
50 else if (ch == 0xff) \
52 /* This is illegal. */ \
53 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
57 /* Two or more byte character. First test whether the next \
58 byte is also available. */ \
61 if (__glibc_unlikely (inptr + 1 >= inend)) \
63 /* The second byte is not available. Store the \
64 intermediate result. */ \
65 result = __GCONV_INCOMPLETE_INPUT; \
71 /* All second bytes of a multibyte character must be >= 0xa1. */ \
72 if (__glibc_unlikely (ch2 < 0xa1)) \
73 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
77 /* This is code set 2: half-width katakana. */ \
78 ch = jisx0201_to_ucs4 (ch2); \
79 if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \
80 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
86 const unsigned char *endp; \
90 /* This is code set 3: JIS X 0212-1990. */ \
93 ch = jisx0212_to_ucs4 (&endp, inend - endp, 0x80); \
97 /* This is code set 1: JIS X 0208. */ \
100 ch = jisx0208_to_ucs4 (&endp, inend - inptr, 0x80); \
103 if (__builtin_expect (ch, 1) == 0) \
105 /* Not enough input available. */ \
106 result = __GCONV_INCOMPLETE_INPUT; \
109 if (__glibc_unlikely (ch == __UNKNOWN_10646_CHAR)) \
110 /* Illegal character. */ \
111 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
117 put32 (outptr, ch); \
120 #define ONEBYTE_BODY \
122 if (c < 0x8e || (c >= 0x90 && c <= 0x9f)) \
127 #define LOOP_NEED_FLAGS
128 #include <iconv/loop.c>
131 /* Next, define the other direction. */
132 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
133 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
134 #define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
135 #define LOOPFCT TO_LOOP
138 uint32_t ch = get32 (inptr); \
140 if (ch < 0x8e || (ch >= 0x90 && ch <= 0x9f)) \
141 /* It's plain ASCII or C1. */ \
143 else if (ch == 0xa5) \
144 /* YEN sign => backslash */ \
146 else if (ch == 0x203e) \
147 /* overscore => asciitilde */ \
151 /* Try the JIS character sets. */ \
154 /* See whether we have room for at least two characters. */ \
155 if (__glibc_unlikely (outptr + 1 >= outend)) \
157 result = __GCONV_FULL_OUTPUT; \
161 found = ucs4_to_jisx0201 (ch, outptr + 1); \
162 if (found != __UNKNOWN_10646_CHAR) \
164 /* Yes, it's a JIS 0201 character. Store the shift byte. */ \
170 /* No JIS 0201 character. */ \
171 found = ucs4_to_jisx0208 (ch, outptr, 2); \
172 /* Please note that we always have enough room for the output. */ \
173 if (found != __UNKNOWN_10646_CHAR) \
175 /* It's a JIS 0208 character, adjust it for EUC-JP. */ \
181 /* No JIS 0208 character. */ \
182 found = ucs4_to_jisx0212 (ch, outptr + 1, \
183 outend - outptr - 1); \
185 if (__builtin_expect (found, 1) == 0) \
187 /* We ran out of space. */ \
188 result = __GCONV_FULL_OUTPUT; \
191 else if (__builtin_expect (found, 0) != __UNKNOWN_10646_CHAR) \
193 /* It's a JIS 0212 character, adjust it for EUC-JP. */ \
200 UNICODE_TAG_HANDLER (ch, 4); \
202 /* Illegal character. */ \
203 STANDARD_TO_LOOP_ERR_HANDLER (4); \
211 #define LOOP_NEED_FLAGS
212 #include <iconv/loop.c>
215 /* Now define the toplevel functions. */
216 #include <iconv/skeleton.c>