]>
Commit | Line | Data |
---|---|---|
a44d2393 | 1 | /* Mapping tables for EUC-KR handling. |
601d2942 | 2 | Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
a44d2393 | 3 | This file is part of the GNU C Library. |
8619129f UD |
4 | Contributed by Jungshik Shin <jshin@pantheon.yale.edu> |
5 | and Ulrich Drepper <drepper@cygnus.com>, 1998. | |
a44d2393 UD |
6 | |
7 | The GNU C Library is free software; you can redistribute it and/or | |
8 | modify it under the terms of the GNU Library General Public License as | |
9 | published by the Free Software Foundation; either version 2 of the | |
10 | License, or (at your option) any later version. | |
11 | ||
12 | The GNU C Library is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Library General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Library General Public | |
18 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
19 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
55985355 | 22 | #include <dlfcn.h> |
40b4c81d | 23 | #include <stdint.h> |
a44d2393 UD |
24 | #include <ksc5601.h> |
25 | ||
a44d2393 UD |
26 | |
27 | static inline void | |
8619129f | 28 | euckr_from_ucs4 (uint32_t ch, unsigned char *cp) |
a44d2393 | 29 | { |
2528edd3 | 30 | if (ch > 0x9f) |
a44d2393 | 31 | { |
228cc878 UD |
32 | if (__builtin_expect (ch, 0) == 0x20a9) |
33 | { | |
a1e88b9a UD |
34 | /* Half-width Korean Currency WON sign. There is no |
35 | equivalent in EUC-KR. Some mappings use \x5c because | |
36 | this is what some old Korean ASCII variants used but this | |
37 | is causing problems. We map it to the FULL WIDTH WON SIGN. */ | |
38 | cp[0] = '\xa3'; | |
39 | cp[1] = '\xdc'; | |
228cc878 UD |
40 | } |
41 | else if (__builtin_expect (ucs4_to_ksc5601 (ch, cp, 2), 0) | |
89301d68 | 42 | != __UNKNOWN_10646_CHAR) |
bc900b11 UD |
43 | { |
44 | cp[0] |= 0x80; | |
45 | cp[1] |= 0x80; | |
46 | } | |
788e8e7c UD |
47 | else |
48 | cp[0] = '\0'; | |
a44d2393 | 49 | } |
a44d2393 UD |
50 | else |
51 | { | |
228cc878 UD |
52 | /* There is no mapping for U005c but we nevertheless map it to |
53 | \x5c. */ | |
8619129f UD |
54 | cp[0] = (unsigned char) ch; |
55 | cp[1] = '\0'; | |
a44d2393 UD |
56 | } |
57 | } | |
58 | ||
59 | ||
8619129f | 60 | /* Definitions used in the body of the `gconv' function. */ |
9b26f5c4 | 61 | #define CHARSET_NAME "EUC-KR//" |
8619129f UD |
62 | #define FROM_LOOP from_euc_kr |
63 | #define TO_LOOP to_euc_kr | |
64 | #define DEFINE_INIT 1 | |
65 | #define DEFINE_FINI 1 | |
66 | #define MIN_NEEDED_FROM 1 | |
67 | #define MAX_NEEDED_FROM 2 | |
68 | #define MIN_NEEDED_TO 4 | |
69 | ||
70 | ||
71 | /* First define the conversion function from EUC-KR to UCS4. */ | |
72 | #define MIN_NEEDED_INPUT MIN_NEEDED_FROM | |
73 | #define MAX_NEEDED_INPUT MAX_NEEDED_FROM | |
74 | #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO | |
75 | #define LOOPFCT FROM_LOOP | |
76 | #define BODY \ | |
77 | { \ | |
78 | uint32_t ch = *inptr; \ | |
79 | \ | |
2528edd3 | 80 | if (ch <= 0x9f) \ |
a1e88b9a | 81 | ++inptr; \ |
8619129f UD |
82 | /* 0xfe(->0x7e : row 94) and 0xc9(->0x59 : row 41) are \ |
83 | user-defined areas. */ \ | |
2528edd3 | 84 | else if (__builtin_expect (ch, 0xa1) == 0xa0 \ |
89301d68 UD |
85 | || __builtin_expect (ch, 0xa1) > 0xfe \ |
86 | || __builtin_expect (ch, 0xa1) == 0xc9) \ | |
8619129f UD |
87 | { \ |
88 | /* This is illegal. */ \ | |
85830c4c UD |
89 | if (! ignore_errors_p ()) \ |
90 | { \ | |
91 | result = __GCONV_ILLEGAL_INPUT; \ | |
92 | break; \ | |
93 | } \ | |
94 | \ | |
95 | ++inptr; \ | |
38677ace | 96 | ++*irreversible; \ |
85830c4c | 97 | continue; \ |
8619129f UD |
98 | } \ |
99 | else \ | |
100 | { \ | |
101 | /* Two-byte character. First test whether the next character \ | |
102 | is also available. */ \ | |
c7c3b0e9 | 103 | ch = ksc5601_to_ucs4 (&inptr, inend - inptr, 0x80); \ |
55985355 | 104 | if (__builtin_expect (ch, 1) == 0) \ |
8619129f UD |
105 | { \ |
106 | /* The second character is not available. */ \ | |
d64b6ad0 | 107 | result = __GCONV_INCOMPLETE_INPUT; \ |
8619129f UD |
108 | break; \ |
109 | } \ | |
89301d68 | 110 | if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \ |
8619129f UD |
111 | { \ |
112 | /* This is an illegal character. */ \ | |
85830c4c UD |
113 | if (! ignore_errors_p ()) \ |
114 | { \ | |
115 | /* This is an illegal character. */ \ | |
116 | result = __GCONV_ILLEGAL_INPUT; \ | |
117 | break; \ | |
118 | } \ | |
119 | \ | |
120 | inptr += 2; \ | |
38677ace | 121 | ++*irreversible; \ |
85830c4c | 122 | continue; \ |
8619129f | 123 | } \ |
8619129f UD |
124 | } \ |
125 | \ | |
77e1d15a UD |
126 | put32 (outptr, ch); \ |
127 | outptr += 4; \ | |
8619129f | 128 | } |
55985355 | 129 | #define LOOP_NEED_FLAGS |
8619129f UD |
130 | #include <iconv/loop.c> |
131 | ||
132 | ||
133 | /* Next, define the other direction. */ | |
134 | #define MIN_NEEDED_INPUT MIN_NEEDED_TO | |
135 | #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM | |
136 | #define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM | |
137 | #define LOOPFCT TO_LOOP | |
138 | #define BODY \ | |
139 | { \ | |
77e1d15a | 140 | uint32_t ch = get32 (inptr); \ |
8619129f UD |
141 | unsigned char cp[2]; \ |
142 | \ | |
143 | /* Decomposing Hangul syllables not available in KS C 5601 into \ | |
144 | Jamos should be considered either here or in euckr_from_ucs4() */ \ | |
601d2942 | 145 | euckr_from_ucs4 (ch, cp); \ |
8619129f | 146 | \ |
89301d68 | 147 | if (__builtin_expect (cp[0], '\1') == '\0' && ch != 0) \ |
8619129f | 148 | { \ |
601d2942 UD |
149 | UNICODE_TAG_HANDLER (ch, 4); \ |
150 | \ | |
8619129f | 151 | /* Illegal character. */ \ |
d6204268 | 152 | STANDARD_ERR_HANDLER (4); \ |
8619129f UD |
153 | } \ |
154 | \ | |
155 | *outptr++ = cp[0]; \ | |
156 | /* Now test for a possible second byte and write this if possible. */ \ | |
157 | if (cp[1] != '\0') \ | |
158 | { \ | |
55985355 | 159 | if (__builtin_expect (outptr >= outend, 0)) \ |
8619129f UD |
160 | { \ |
161 | /* The result does not fit into the buffer. */ \ | |
162 | --outptr; \ | |
d64b6ad0 | 163 | result = __GCONV_FULL_OUTPUT; \ |
8619129f UD |
164 | break; \ |
165 | } \ | |
166 | *outptr++ = cp[1]; \ | |
167 | } \ | |
168 | \ | |
169 | inptr += 4; \ | |
170 | } | |
55985355 | 171 | #define LOOP_NEED_FLAGS |
8619129f UD |
172 | #include <iconv/loop.c> |
173 | ||
174 | ||
175 | /* Now define the toplevel functions. */ | |
176 | #include <iconv/skeleton.c> |