]>
Commit | Line | Data |
---|---|---|
2b474353 | 1 | /* Mapping tables for EUC-JP handling. |
d4697bc9 | 2 | Copyright (C) 1998-2014 Free Software Foundation, Inc. |
2b474353 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. | |
2b474353 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. |
2b474353 | 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/>. */ | |
2b474353 | 19 | |
55985355 | 20 | #include <dlfcn.h> |
2b474353 | 21 | #include <stdint.h> |
8619129f | 22 | #include <gconv.h> |
2b474353 UD |
23 | #include <jis0201.h> |
24 | #include <jis0208.h> | |
25 | #include <jis0212.h> | |
26 | ||
8619129f | 27 | /* Definitions used in the body of the `gconv' function. */ |
9b26f5c4 | 28 | #define CHARSET_NAME "EUC-JP//" |
8619129f UD |
29 | #define FROM_LOOP from_euc_jp |
30 | #define TO_LOOP to_euc_jp | |
31 | #define DEFINE_INIT 1 | |
32 | #define DEFINE_FINI 1 | |
33 | #define MIN_NEEDED_FROM 1 | |
34 | #define MAX_NEEDED_FROM 3 | |
35 | #define MIN_NEEDED_TO 4 | |
36 | ||
37 | ||
38 | /* First define the conversion function from EUC-JP to UCS4. */ | |
39 | #define MIN_NEEDED_INPUT MIN_NEEDED_FROM | |
40 | #define MAX_NEEDED_INPUT MAX_NEEDED_FROM | |
41 | #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO | |
42 | #define LOOPFCT FROM_LOOP | |
43 | #define BODY \ | |
44 | { \ | |
45 | uint32_t ch = *inptr; \ | |
46 | \ | |
2528edd3 | 47 | if (ch < 0x8e || (ch >= 0x90 && ch <= 0x9f)) \ |
8619129f | 48 | ++inptr; \ |
2528edd3 | 49 | else if (ch == 0xff) \ |
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 next \ | |
e2806aaf | 57 | byte is also available. */ \ |
8619129f UD |
58 | int ch2; \ |
59 | \ | |
a1ffb40e | 60 | if (__glibc_unlikely (inptr + 1 >= inend)) \ |
8619129f | 61 | { \ |
e2806aaf | 62 | /* The second byte is not available. Store the \ |
8619129f | 63 | intermediate result. */ \ |
d64b6ad0 | 64 | result = __GCONV_INCOMPLETE_INPUT; \ |
8619129f UD |
65 | break; \ |
66 | } \ | |
67 | \ | |
68 | ch2 = inptr[1]; \ | |
69 | \ | |
70 | /* All second bytes of a multibyte character must be >= 0xa1. */ \ | |
a1ffb40e | 71 | if (__glibc_unlikely (ch2 < 0xa1)) \ |
e438a468 | 72 | STANDARD_FROM_LOOP_ERR_HANDLER (1); \ |
8619129f UD |
73 | \ |
74 | if (ch == 0x8e) \ | |
75 | { \ | |
76 | /* This is code set 2: half-width katakana. */ \ | |
77 | ch = jisx0201_to_ucs4 (ch2); \ | |
392ac969 | 78 | if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \ |
e438a468 | 79 | STANDARD_FROM_LOOP_ERR_HANDLER (1); \ |
392ac969 | 80 | \ |
8619129f UD |
81 | inptr += 2; \ |
82 | } \ | |
83 | else \ | |
84 | { \ | |
85 | const unsigned char *endp; \ | |
86 | \ | |
87 | if (ch == 0x8f) \ | |
88 | { \ | |
89 | /* This is code set 3: JIS X 0212-1990. */ \ | |
90 | endp = inptr + 1; \ | |
91 | \ | |
55985355 | 92 | ch = jisx0212_to_ucs4 (&endp, inend - endp, 0x80); \ |
8619129f UD |
93 | } \ |
94 | else \ | |
95 | { \ | |
96 | /* This is code set 1: JIS X 0208. */ \ | |
97 | endp = inptr; \ | |
98 | \ | |
55985355 | 99 | ch = jisx0208_to_ucs4 (&endp, inend - inptr, 0x80); \ |
8619129f UD |
100 | } \ |
101 | \ | |
55985355 | 102 | if (__builtin_expect (ch, 1) == 0) \ |
8619129f UD |
103 | { \ |
104 | /* Not enough input available. */ \ | |
d64b6ad0 | 105 | result = __GCONV_INCOMPLETE_INPUT; \ |
8619129f UD |
106 | break; \ |
107 | } \ | |
a1ffb40e | 108 | if (__glibc_unlikely (ch == __UNKNOWN_10646_CHAR)) \ |
e438a468 UD |
109 | /* Illegal character. */ \ |
110 | STANDARD_FROM_LOOP_ERR_HANDLER (1); \ | |
85830c4c | 111 | \ |
8619129f UD |
112 | inptr = endp; \ |
113 | } \ | |
114 | } \ | |
115 | \ | |
77e1d15a UD |
116 | put32 (outptr, ch); \ |
117 | outptr += 4; \ | |
8619129f | 118 | } |
f9ad060c UD |
119 | #define ONEBYTE_BODY \ |
120 | { \ | |
121 | if (c < 0x8e || (c >= 0x90 && c <= 0x9f)) \ | |
122 | return c; \ | |
123 | else \ | |
124 | return WEOF; \ | |
125 | } | |
55985355 | 126 | #define LOOP_NEED_FLAGS |
8619129f UD |
127 | #include <iconv/loop.c> |
128 | ||
129 | ||
130 | /* Next, define the other direction. */ | |
131 | #define MIN_NEEDED_INPUT MIN_NEEDED_TO | |
132 | #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM | |
133 | #define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM | |
134 | #define LOOPFCT TO_LOOP | |
135 | #define BODY \ | |
136 | { \ | |
77e1d15a | 137 | uint32_t ch = get32 (inptr); \ |
8619129f | 138 | \ |
2528edd3 UD |
139 | if (ch < 0x8e || (ch >= 0x90 && ch <= 0x9f)) \ |
140 | /* It's plain ASCII or C1. */ \ | |
8619129f | 141 | *outptr++ = ch; \ |
5c2a0669 UD |
142 | else if (ch == 0xa5) \ |
143 | /* YEN sign => backslash */ \ | |
144 | *outptr++ = 0x5c; \ | |
145 | else if (ch == 0x203e) \ | |
146 | /* overscore => asciitilde */ \ | |
147 | *outptr++ = 0x7e; \ | |
8619129f UD |
148 | else \ |
149 | { \ | |
150 | /* Try the JIS character sets. */ \ | |
151 | size_t found; \ | |
152 | \ | |
153 | /* See whether we have room for at least two characters. */ \ | |
a1ffb40e | 154 | if (__glibc_unlikely (outptr + 1 >= outend)) \ |
8619129f | 155 | { \ |
d64b6ad0 | 156 | result = __GCONV_FULL_OUTPUT; \ |
8619129f UD |
157 | break; \ |
158 | } \ | |
159 | \ | |
160 | found = ucs4_to_jisx0201 (ch, outptr + 1); \ | |
d64b6ad0 | 161 | if (found != __UNKNOWN_10646_CHAR) \ |
8619129f UD |
162 | { \ |
163 | /* Yes, it's a JIS 0201 character. Store the shift byte. */ \ | |
164 | *outptr = 0x8e; \ | |
165 | outptr += 2; \ | |
166 | } \ | |
167 | else \ | |
168 | { \ | |
169 | /* No JIS 0201 character. */ \ | |
170 | found = ucs4_to_jisx0208 (ch, outptr, 2); \ | |
171 | /* Please note that we always have enough room for the output. */ \ | |
d64b6ad0 | 172 | if (found != __UNKNOWN_10646_CHAR) \ |
8619129f UD |
173 | { \ |
174 | /* It's a JIS 0208 character, adjust it for EUC-JP. */ \ | |
175 | *outptr++ += 0x80; \ | |
176 | *outptr++ += 0x80; \ | |
177 | } \ | |
178 | else \ | |
179 | { \ | |
180 | /* No JIS 0208 character. */ \ | |
181 | found = ucs4_to_jisx0212 (ch, outptr + 1, \ | |
55985355 | 182 | outend - outptr - 1); \ |
8619129f | 183 | \ |
89301d68 | 184 | if (__builtin_expect (found, 1) == 0) \ |
8619129f UD |
185 | { \ |
186 | /* We ran out of space. */ \ | |
d64b6ad0 | 187 | result = __GCONV_FULL_OUTPUT; \ |
8619129f UD |
188 | break; \ |
189 | } \ | |
89301d68 | 190 | else if (__builtin_expect (found, 0) != __UNKNOWN_10646_CHAR) \ |
8619129f UD |
191 | { \ |
192 | /* It's a JIS 0212 character, adjust it for EUC-JP. */ \ | |
193 | *outptr++ = 0x8f; \ | |
194 | *outptr++ += 0x80; \ | |
195 | *outptr++ += 0x80; \ | |
196 | } \ | |
197 | else \ | |
198 | { \ | |
601d2942 UD |
199 | UNICODE_TAG_HANDLER (ch, 4); \ |
200 | \ | |
8619129f | 201 | /* Illegal character. */ \ |
e438a468 | 202 | STANDARD_TO_LOOP_ERR_HANDLER (4); \ |
8619129f UD |
203 | } \ |
204 | } \ | |
205 | } \ | |
206 | } \ | |
207 | \ | |
208 | inptr += 4; \ | |
209 | } | |
55985355 | 210 | #define LOOP_NEED_FLAGS |
8619129f UD |
211 | #include <iconv/loop.c> |
212 | ||
213 | ||
214 | /* Now define the toplevel functions. */ | |
215 | #include <iconv/skeleton.c> |