1 /* Mapping tables for EUC-CN handling.
2 Copyright (C) 1998, 1999, 2000-2002 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 /* Definitions used in the body of the `gconv' function. */
26 #define CHARSET_NAME "EUC-CN//"
27 #define FROM_LOOP from_euc_cn
28 #define TO_LOOP to_euc_cn
31 #define MIN_NEEDED_FROM 1
32 #define MAX_NEEDED_FROM 2
33 #define MIN_NEEDED_TO 4
36 /* First define the conversion function from EUC-CN to UCS4. */
37 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
38 #define MAX_NEEDED_INPUT MAX_NEEDED_FROM
39 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
40 #define LOOPFCT FROM_LOOP
43 uint32_t ch = *inptr; \
48 if ((__builtin_expect (ch <= 0xa0, 0) && ch != 0x8e && ch != 0x8f) \
49 || __builtin_expect (ch > 0xfe, 0)) \
51 /* This is illegal. */ \
52 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
56 /* Two or more byte character. First test whether the \
57 next character is also available. */ \
58 const unsigned char *endp; \
60 if (__builtin_expect (inptr + 1 >= inend, 0)) \
62 /* The second character is not available. Store \
63 the intermediate result. */ \
64 result = __GCONV_INCOMPLETE_INPUT; \
70 /* All second bytes of a multibyte character must be >= 0xa1. */ \
71 if (__builtin_expect (ch < 0xa1, 0)) \
72 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
74 /* This is code set 1: GB 2312-80. */ \
77 ch = gb2312_to_ucs4 (&endp, 2, 0x80); \
78 if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0)) \
80 /* This is an illegal character. */ \
81 STANDARD_FROM_LOOP_ERR_HANDLER (2); \
90 #define LOOP_NEED_FLAGS
91 #include <iconv/loop.c>
94 /* Next, define the other direction. */
95 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
96 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
97 #define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
98 #define LOOPFCT TO_LOOP
101 uint32_t ch = get32 (inptr); \
104 /* It's plain ASCII. */ \
105 *outptr++ = (unsigned char) ch; \
110 found = ucs4_to_gb2312 (ch, outptr, outend - outptr); \
111 if (__builtin_expect (found, 1) != 0) \
113 if (__builtin_expect (found, 0) == __UNKNOWN_10646_CHAR) \
115 UNICODE_TAG_HANDLER (ch, 4); \
117 /* Illegal character. */ \
118 STANDARD_TO_LOOP_ERR_HANDLER (4); \
121 /* It's a GB 2312 character, adjust it for EUC-CN. */ \
127 /* We ran out of space. */ \
128 result = __GCONV_FULL_OUTPUT; \
134 #define LOOP_NEED_FLAGS
135 #include <iconv/loop.c>
138 /* Now define the toplevel functions. */
139 #include <iconv/skeleton.c>