]> git.ipfire.org Git - thirdparty/glibc.git/blame - iconvdata/euc-cn.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / iconvdata / euc-cn.c
CommitLineData
40b4c81d 1/* Mapping tables for EUC-CN handling.
b168057a 2 Copyright (C) 1998-2015 Free Software Foundation, Inc.
40b4c81d
UD
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5
6 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
40b4c81d
UD
10
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
41bdb6e2 14 Lesser General Public License for more details.
40b4c81d 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
40b4c81d 19
55985355 20#include <dlfcn.h>
40b4c81d 21#include <gb2312.h>
8619129f 22#include <stdint.h>
40b4c81d 23
8619129f 24/* Definitions used in the body of the `gconv' function. */
9b26f5c4 25#define CHARSET_NAME "EUC-CN//"
8619129f
UD
26#define FROM_LOOP from_euc_cn
27#define TO_LOOP to_euc_cn
28#define DEFINE_INIT 1
29#define DEFINE_FINI 1
30#define MIN_NEEDED_FROM 1
31#define MAX_NEEDED_FROM 2
32#define MIN_NEEDED_TO 4
13e402e7 33#define ONE_DIRECTION 0
8619129f
UD
34
35
ffa156af 36/* First define the conversion function from EUC-CN to UCS4. */
8619129f
UD
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
41#define BODY \
42 { \
43 uint32_t ch = *inptr; \
44 \
45 if (ch <= 0x7f) \
46 ++inptr; \
47 else \
db2d05f9
UD
48 if ((__builtin_expect (ch <= 0xa0, 0) && ch != 0x8e && ch != 0x8f) \
49 || __builtin_expect (ch > 0xfe, 0)) \
8619129f
UD
50 { \
51 /* This is illegal. */ \
e438a468 52 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
8619129f
UD
53 } \
54 else \
55 { \
56 /* Two or more byte character. First test whether the \
f9ad060c 57 next byte is also available. */ \
bc900b11 58 const unsigned char *endp; \
8619129f 59 \
a1ffb40e 60 if (__glibc_unlikely (inptr + 1 >= inend)) \
8619129f
UD
61 { \
62 /* The second character is not available. Store \
63 the intermediate result. */ \
d64b6ad0 64 result = __GCONV_INCOMPLETE_INPUT; \
8619129f
UD
65 break; \
66 } \
67 \
68 ch = inptr[1]; \
69 \
70 /* All second bytes of a multibyte character must be >= 0xa1. */ \
a1ffb40e 71 if (__glibc_unlikely (ch < 0xa1)) \
e438a468 72 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
8619129f
UD
73 \
74 /* This is code set 1: GB 2312-80. */ \
75 endp = inptr; \
76 \
77 ch = gb2312_to_ucs4 (&endp, 2, 0x80); \
a1ffb40e 78 if (__glibc_unlikely (ch == __UNKNOWN_10646_CHAR)) \
8619129f
UD
79 { \
80 /* This is an illegal character. */ \
e438a468 81 STANDARD_FROM_LOOP_ERR_HANDLER (2); \
8619129f
UD
82 } \
83 \
84 inptr += 2; \
85 } \
86 \
77e1d15a
UD
87 put32 (outptr, ch); \
88 outptr += 4; \
8619129f 89 }
55985355 90#define LOOP_NEED_FLAGS
f9ad060c
UD
91#define ONEBYTE_BODY \
92 { \
93 if (c < 0x80) \
94 return c; \
95 else \
96 return WEOF; \
97 }
8619129f
UD
98#include <iconv/loop.c>
99
100
101/* Next, define the other direction. */
102#define MIN_NEEDED_INPUT MIN_NEEDED_TO
103#define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
104#define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
105#define LOOPFCT TO_LOOP
106#define BODY \
107 { \
77e1d15a 108 uint32_t ch = get32 (inptr); \
8619129f
UD
109 \
110 if (ch <= L'\x7f') \
111 /* It's plain ASCII. */ \
112 *outptr++ = (unsigned char) ch; \
113 else \
114 { \
115 size_t found; \
116 \
55985355
UD
117 found = ucs4_to_gb2312 (ch, outptr, outend - outptr); \
118 if (__builtin_expect (found, 1) != 0) \
8619129f 119 { \
89301d68 120 if (__builtin_expect (found, 0) == __UNKNOWN_10646_CHAR) \
8619129f 121 { \
601d2942
UD
122 UNICODE_TAG_HANDLER (ch, 4); \
123 \
8619129f 124 /* Illegal character. */ \
e438a468 125 STANDARD_TO_LOOP_ERR_HANDLER (4); \
8619129f
UD
126 } \
127 \
128 /* It's a GB 2312 character, adjust it for EUC-CN. */ \
129 *outptr++ += 0x80; \
130 *outptr++ += 0x80; \
131 } \
132 else \
133 { \
134 /* We ran out of space. */ \
d64b6ad0 135 result = __GCONV_FULL_OUTPUT; \
8619129f
UD
136 break; \
137 } \
138 } \
139 inptr += 4; \
140 }
55985355 141#define LOOP_NEED_FLAGS
8619129f
UD
142#include <iconv/loop.c>
143
144
145/* Now define the toplevel functions. */
146#include <iconv/skeleton.c>