1 | n/a | /* |
---|
2 | n/a | * _codecs_kr.c: Codecs collection for Korean encodings |
---|
3 | n/a | * |
---|
4 | n/a | * Written by Hye-Shik Chang <perky@FreeBSD.org> |
---|
5 | n/a | */ |
---|
6 | n/a | |
---|
7 | n/a | #include "cjkcodecs.h" |
---|
8 | n/a | #include "mappings_kr.h" |
---|
9 | n/a | |
---|
10 | n/a | /* |
---|
11 | n/a | * EUC-KR codec |
---|
12 | n/a | */ |
---|
13 | n/a | |
---|
14 | n/a | #define EUCKR_JAMO_FIRSTBYTE 0xA4 |
---|
15 | n/a | #define EUCKR_JAMO_FILLER 0xD4 |
---|
16 | n/a | |
---|
17 | n/a | static const unsigned char u2cgk_choseong[19] = { |
---|
18 | n/a | 0xa1, 0xa2, 0xa4, 0xa7, 0xa8, 0xa9, 0xb1, 0xb2, |
---|
19 | n/a | 0xb3, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, |
---|
20 | n/a | 0xbc, 0xbd, 0xbe |
---|
21 | n/a | }; |
---|
22 | n/a | static const unsigned char u2cgk_jungseong[21] = { |
---|
23 | n/a | 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, |
---|
24 | n/a | 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, |
---|
25 | n/a | 0xcf, 0xd0, 0xd1, 0xd2, 0xd3 |
---|
26 | n/a | }; |
---|
27 | n/a | static const unsigned char u2cgk_jongseong[28] = { |
---|
28 | n/a | 0xd4, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, |
---|
29 | n/a | 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, |
---|
30 | n/a | 0xb1, 0xb2, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xba, |
---|
31 | n/a | 0xbb, 0xbc, 0xbd, 0xbe |
---|
32 | n/a | }; |
---|
33 | n/a | |
---|
34 | n/a | ENCODER(euc_kr) |
---|
35 | n/a | { |
---|
36 | n/a | while (*inpos < inlen) { |
---|
37 | n/a | Py_UCS4 c = INCHAR1; |
---|
38 | n/a | DBCHAR code; |
---|
39 | n/a | |
---|
40 | n/a | if (c < 0x80) { |
---|
41 | n/a | WRITEBYTE1((unsigned char)c); |
---|
42 | n/a | NEXT(1, 1); |
---|
43 | n/a | continue; |
---|
44 | n/a | } |
---|
45 | n/a | |
---|
46 | n/a | if (c > 0xFFFF) |
---|
47 | n/a | return 1; |
---|
48 | n/a | |
---|
49 | n/a | REQUIRE_OUTBUF(2); |
---|
50 | n/a | if (TRYMAP_ENC(cp949, code, c)) |
---|
51 | n/a | ; |
---|
52 | n/a | else |
---|
53 | n/a | return 1; |
---|
54 | n/a | |
---|
55 | n/a | if ((code & 0x8000) == 0) { |
---|
56 | n/a | /* KS X 1001 coded character */ |
---|
57 | n/a | OUTBYTE1((code >> 8) | 0x80); |
---|
58 | n/a | OUTBYTE2((code & 0xFF) | 0x80); |
---|
59 | n/a | NEXT(1, 2); |
---|
60 | n/a | } |
---|
61 | n/a | else { |
---|
62 | n/a | /* Mapping is found in CP949 extension, |
---|
63 | n/a | but we encode it in KS X 1001:1998 Annex 3, |
---|
64 | n/a | make-up sequence for EUC-KR. */ |
---|
65 | n/a | |
---|
66 | n/a | REQUIRE_OUTBUF(8); |
---|
67 | n/a | |
---|
68 | n/a | /* syllable composition precedence */ |
---|
69 | n/a | OUTBYTE1(EUCKR_JAMO_FIRSTBYTE); |
---|
70 | n/a | OUTBYTE2(EUCKR_JAMO_FILLER); |
---|
71 | n/a | |
---|
72 | n/a | /* All code points in CP949 extension are in unicode |
---|
73 | n/a | * Hangul Syllable area. */ |
---|
74 | n/a | assert(0xac00 <= c && c <= 0xd7a3); |
---|
75 | n/a | c -= 0xac00; |
---|
76 | n/a | |
---|
77 | n/a | OUTBYTE3(EUCKR_JAMO_FIRSTBYTE); |
---|
78 | n/a | OUTBYTE4(u2cgk_choseong[c / 588]); |
---|
79 | n/a | NEXT_OUT(4); |
---|
80 | n/a | |
---|
81 | n/a | OUTBYTE1(EUCKR_JAMO_FIRSTBYTE); |
---|
82 | n/a | OUTBYTE2(u2cgk_jungseong[(c / 28) % 21]); |
---|
83 | n/a | OUTBYTE3(EUCKR_JAMO_FIRSTBYTE); |
---|
84 | n/a | OUTBYTE4(u2cgk_jongseong[c % 28]); |
---|
85 | n/a | NEXT(1, 4); |
---|
86 | n/a | } |
---|
87 | n/a | } |
---|
88 | n/a | |
---|
89 | n/a | return 0; |
---|
90 | n/a | } |
---|
91 | n/a | |
---|
92 | n/a | #define NONE 127 |
---|
93 | n/a | |
---|
94 | n/a | static const unsigned char cgk2u_choseong[] = { /* [A1, BE] */ |
---|
95 | n/a | 0, 1, NONE, 2, NONE, NONE, 3, 4, |
---|
96 | n/a | 5, NONE, NONE, NONE, NONE, NONE, NONE, NONE, |
---|
97 | n/a | 6, 7, 8, NONE, 9, 10, 11, 12, |
---|
98 | n/a | 13, 14, 15, 16, 17, 18 |
---|
99 | n/a | }; |
---|
100 | n/a | static const unsigned char cgk2u_jongseong[] = { /* [A1, BE] */ |
---|
101 | n/a | 1, 2, 3, 4, 5, 6, 7, NONE, |
---|
102 | n/a | 8, 9, 10, 11, 12, 13, 14, 15, |
---|
103 | n/a | 16, 17, NONE, 18, 19, 20, 21, 22, |
---|
104 | n/a | NONE, 23, 24, 25, 26, 27 |
---|
105 | n/a | }; |
---|
106 | n/a | |
---|
107 | n/a | DECODER(euc_kr) |
---|
108 | n/a | { |
---|
109 | n/a | while (inleft > 0) { |
---|
110 | n/a | unsigned char c = INBYTE1; |
---|
111 | n/a | Py_UCS4 decoded; |
---|
112 | n/a | |
---|
113 | n/a | if (c < 0x80) { |
---|
114 | n/a | OUTCHAR(c); |
---|
115 | n/a | NEXT_IN(1); |
---|
116 | n/a | continue; |
---|
117 | n/a | } |
---|
118 | n/a | |
---|
119 | n/a | REQUIRE_INBUF(2); |
---|
120 | n/a | |
---|
121 | n/a | if (c == EUCKR_JAMO_FIRSTBYTE && |
---|
122 | n/a | INBYTE2 == EUCKR_JAMO_FILLER) { |
---|
123 | n/a | /* KS X 1001:1998 Annex 3 make-up sequence */ |
---|
124 | n/a | DBCHAR cho, jung, jong; |
---|
125 | n/a | |
---|
126 | n/a | REQUIRE_INBUF(8); |
---|
127 | n/a | if ((*inbuf)[2] != EUCKR_JAMO_FIRSTBYTE || |
---|
128 | n/a | (*inbuf)[4] != EUCKR_JAMO_FIRSTBYTE || |
---|
129 | n/a | (*inbuf)[6] != EUCKR_JAMO_FIRSTBYTE) |
---|
130 | n/a | return 1; |
---|
131 | n/a | |
---|
132 | n/a | c = (*inbuf)[3]; |
---|
133 | n/a | if (0xa1 <= c && c <= 0xbe) |
---|
134 | n/a | cho = cgk2u_choseong[c - 0xa1]; |
---|
135 | n/a | else |
---|
136 | n/a | cho = NONE; |
---|
137 | n/a | |
---|
138 | n/a | c = (*inbuf)[5]; |
---|
139 | n/a | jung = (0xbf <= c && c <= 0xd3) ? c - 0xbf : NONE; |
---|
140 | n/a | |
---|
141 | n/a | c = (*inbuf)[7]; |
---|
142 | n/a | if (c == EUCKR_JAMO_FILLER) |
---|
143 | n/a | jong = 0; |
---|
144 | n/a | else if (0xa1 <= c && c <= 0xbe) |
---|
145 | n/a | jong = cgk2u_jongseong[c - 0xa1]; |
---|
146 | n/a | else |
---|
147 | n/a | jong = NONE; |
---|
148 | n/a | |
---|
149 | n/a | if (cho == NONE || jung == NONE || jong == NONE) |
---|
150 | n/a | return 1; |
---|
151 | n/a | |
---|
152 | n/a | OUTCHAR(0xac00 + cho*588 + jung*28 + jong); |
---|
153 | n/a | NEXT_IN(8); |
---|
154 | n/a | } |
---|
155 | n/a | else if (TRYMAP_DEC(ksx1001, decoded, c ^ 0x80, INBYTE2 ^ 0x80)) { |
---|
156 | n/a | OUTCHAR(decoded); |
---|
157 | n/a | NEXT_IN(2); |
---|
158 | n/a | } |
---|
159 | n/a | else |
---|
160 | n/a | return 1; |
---|
161 | n/a | } |
---|
162 | n/a | |
---|
163 | n/a | return 0; |
---|
164 | n/a | } |
---|
165 | n/a | #undef NONE |
---|
166 | n/a | |
---|
167 | n/a | |
---|
168 | n/a | /* |
---|
169 | n/a | * CP949 codec |
---|
170 | n/a | */ |
---|
171 | n/a | |
---|
172 | n/a | ENCODER(cp949) |
---|
173 | n/a | { |
---|
174 | n/a | while (*inpos < inlen) { |
---|
175 | n/a | Py_UCS4 c = INCHAR1; |
---|
176 | n/a | DBCHAR code; |
---|
177 | n/a | |
---|
178 | n/a | if (c < 0x80) { |
---|
179 | n/a | WRITEBYTE1((unsigned char)c); |
---|
180 | n/a | NEXT(1, 1); |
---|
181 | n/a | continue; |
---|
182 | n/a | } |
---|
183 | n/a | |
---|
184 | n/a | if (c > 0xFFFF) |
---|
185 | n/a | return 1; |
---|
186 | n/a | |
---|
187 | n/a | REQUIRE_OUTBUF(2); |
---|
188 | n/a | if (TRYMAP_ENC(cp949, code, c)) |
---|
189 | n/a | ; |
---|
190 | n/a | else |
---|
191 | n/a | return 1; |
---|
192 | n/a | |
---|
193 | n/a | OUTBYTE1((code >> 8) | 0x80); |
---|
194 | n/a | if (code & 0x8000) |
---|
195 | n/a | OUTBYTE2(code & 0xFF); /* MSB set: CP949 */ |
---|
196 | n/a | else |
---|
197 | n/a | OUTBYTE2((code & 0xFF) | 0x80); /* MSB unset: ks x 1001 */ |
---|
198 | n/a | NEXT(1, 2); |
---|
199 | n/a | } |
---|
200 | n/a | |
---|
201 | n/a | return 0; |
---|
202 | n/a | } |
---|
203 | n/a | |
---|
204 | n/a | DECODER(cp949) |
---|
205 | n/a | { |
---|
206 | n/a | while (inleft > 0) { |
---|
207 | n/a | unsigned char c = INBYTE1; |
---|
208 | n/a | Py_UCS4 decoded; |
---|
209 | n/a | |
---|
210 | n/a | if (c < 0x80) { |
---|
211 | n/a | OUTCHAR(c); |
---|
212 | n/a | NEXT_IN(1); |
---|
213 | n/a | continue; |
---|
214 | n/a | } |
---|
215 | n/a | |
---|
216 | n/a | REQUIRE_INBUF(2); |
---|
217 | n/a | if (TRYMAP_DEC(ksx1001, decoded, c ^ 0x80, INBYTE2 ^ 0x80)) |
---|
218 | n/a | OUTCHAR(decoded); |
---|
219 | n/a | else if (TRYMAP_DEC(cp949ext, decoded, c, INBYTE2)) |
---|
220 | n/a | OUTCHAR(decoded); |
---|
221 | n/a | else |
---|
222 | n/a | return 1; |
---|
223 | n/a | |
---|
224 | n/a | NEXT_IN(2); |
---|
225 | n/a | } |
---|
226 | n/a | |
---|
227 | n/a | return 0; |
---|
228 | n/a | } |
---|
229 | n/a | |
---|
230 | n/a | |
---|
231 | n/a | /* |
---|
232 | n/a | * JOHAB codec |
---|
233 | n/a | */ |
---|
234 | n/a | |
---|
235 | n/a | static const unsigned char u2johabidx_choseong[32] = { |
---|
236 | n/a | 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
---|
237 | n/a | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
---|
238 | n/a | 0x10, 0x11, 0x12, 0x13, 0x14, |
---|
239 | n/a | }; |
---|
240 | n/a | static const unsigned char u2johabidx_jungseong[32] = { |
---|
241 | n/a | 0x03, 0x04, 0x05, 0x06, 0x07, |
---|
242 | n/a | 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
---|
243 | n/a | 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
---|
244 | n/a | 0x1a, 0x1b, 0x1c, 0x1d, |
---|
245 | n/a | }; |
---|
246 | n/a | static const unsigned char u2johabidx_jongseong[32] = { |
---|
247 | n/a | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
---|
248 | n/a | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
---|
249 | n/a | 0x10, 0x11, 0x13, 0x14, 0x15, 0x16, 0x17, |
---|
250 | n/a | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, |
---|
251 | n/a | }; |
---|
252 | n/a | static const DBCHAR u2johabjamo[] = { |
---|
253 | n/a | 0x8841, 0x8c41, 0x8444, 0x9041, 0x8446, 0x8447, 0x9441, |
---|
254 | n/a | 0x9841, 0x9c41, 0x844a, 0x844b, 0x844c, 0x844d, 0x844e, 0x844f, |
---|
255 | n/a | 0x8450, 0xa041, 0xa441, 0xa841, 0x8454, 0xac41, 0xb041, 0xb441, |
---|
256 | n/a | 0xb841, 0xbc41, 0xc041, 0xc441, 0xc841, 0xcc41, 0xd041, 0x8461, |
---|
257 | n/a | 0x8481, 0x84a1, 0x84c1, 0x84e1, 0x8541, 0x8561, 0x8581, 0x85a1, |
---|
258 | n/a | 0x85c1, 0x85e1, 0x8641, 0x8661, 0x8681, 0x86a1, 0x86c1, 0x86e1, |
---|
259 | n/a | 0x8741, 0x8761, 0x8781, 0x87a1, |
---|
260 | n/a | }; |
---|
261 | n/a | |
---|
262 | n/a | ENCODER(johab) |
---|
263 | n/a | { |
---|
264 | n/a | while (*inpos < inlen) { |
---|
265 | n/a | Py_UCS4 c = INCHAR1; |
---|
266 | n/a | DBCHAR code; |
---|
267 | n/a | |
---|
268 | n/a | if (c < 0x80) { |
---|
269 | n/a | WRITEBYTE1((unsigned char)c); |
---|
270 | n/a | NEXT(1, 1); |
---|
271 | n/a | continue; |
---|
272 | n/a | } |
---|
273 | n/a | |
---|
274 | n/a | if (c > 0xFFFF) |
---|
275 | n/a | return 1; |
---|
276 | n/a | |
---|
277 | n/a | REQUIRE_OUTBUF(2); |
---|
278 | n/a | |
---|
279 | n/a | if (c >= 0xac00 && c <= 0xd7a3) { |
---|
280 | n/a | c -= 0xac00; |
---|
281 | n/a | code = 0x8000 | |
---|
282 | n/a | (u2johabidx_choseong[c / 588] << 10) | |
---|
283 | n/a | (u2johabidx_jungseong[(c / 28) % 21] << 5) | |
---|
284 | n/a | u2johabidx_jongseong[c % 28]; |
---|
285 | n/a | } |
---|
286 | n/a | else if (c >= 0x3131 && c <= 0x3163) |
---|
287 | n/a | code = u2johabjamo[c - 0x3131]; |
---|
288 | n/a | else if (TRYMAP_ENC(cp949, code, c)) { |
---|
289 | n/a | unsigned char c1, c2, t2; |
---|
290 | n/a | unsigned short t1; |
---|
291 | n/a | |
---|
292 | n/a | assert((code & 0x8000) == 0); |
---|
293 | n/a | c1 = code >> 8; |
---|
294 | n/a | c2 = code & 0xff; |
---|
295 | n/a | if (((c1 >= 0x21 && c1 <= 0x2c) || |
---|
296 | n/a | (c1 >= 0x4a && c1 <= 0x7d)) && |
---|
297 | n/a | (c2 >= 0x21 && c2 <= 0x7e)) { |
---|
298 | n/a | t1 = (c1 < 0x4a ? (c1 - 0x21 + 0x1b2) : |
---|
299 | n/a | (c1 - 0x21 + 0x197)); |
---|
300 | n/a | t2 = ((t1 & 1) ? 0x5e : 0) + (c2 - 0x21); |
---|
301 | n/a | OUTBYTE1(t1 >> 1); |
---|
302 | n/a | OUTBYTE2(t2 < 0x4e ? t2 + 0x31 : t2 + 0x43); |
---|
303 | n/a | NEXT(1, 2); |
---|
304 | n/a | continue; |
---|
305 | n/a | } |
---|
306 | n/a | else |
---|
307 | n/a | return 1; |
---|
308 | n/a | } |
---|
309 | n/a | else |
---|
310 | n/a | return 1; |
---|
311 | n/a | |
---|
312 | n/a | OUTBYTE1(code >> 8); |
---|
313 | n/a | OUTBYTE2(code & 0xff); |
---|
314 | n/a | NEXT(1, 2); |
---|
315 | n/a | } |
---|
316 | n/a | |
---|
317 | n/a | return 0; |
---|
318 | n/a | } |
---|
319 | n/a | |
---|
320 | n/a | #define FILL 0xfd |
---|
321 | n/a | #define NONE 0xff |
---|
322 | n/a | |
---|
323 | n/a | static const unsigned char johabidx_choseong[32] = { |
---|
324 | n/a | NONE, FILL, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, |
---|
325 | n/a | 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, |
---|
326 | n/a | 0x0e, 0x0f, 0x10, 0x11, 0x12, NONE, NONE, NONE, |
---|
327 | n/a | NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, |
---|
328 | n/a | }; |
---|
329 | n/a | static const unsigned char johabidx_jungseong[32] = { |
---|
330 | n/a | NONE, NONE, FILL, 0x00, 0x01, 0x02, 0x03, 0x04, |
---|
331 | n/a | NONE, NONE, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, |
---|
332 | n/a | NONE, NONE, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, |
---|
333 | n/a | NONE, NONE, 0x11, 0x12, 0x13, 0x14, NONE, NONE, |
---|
334 | n/a | }; |
---|
335 | n/a | static const unsigned char johabidx_jongseong[32] = { |
---|
336 | n/a | NONE, FILL, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, |
---|
337 | n/a | 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, |
---|
338 | n/a | 0x0f, 0x10, NONE, 0x11, 0x12, 0x13, 0x14, 0x15, |
---|
339 | n/a | 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, NONE, NONE, |
---|
340 | n/a | }; |
---|
341 | n/a | |
---|
342 | n/a | static const unsigned char johabjamo_choseong[32] = { |
---|
343 | n/a | NONE, FILL, 0x31, 0x32, 0x34, 0x37, 0x38, 0x39, |
---|
344 | n/a | 0x41, 0x42, 0x43, 0x45, 0x46, 0x47, 0x48, 0x49, |
---|
345 | n/a | 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, NONE, NONE, NONE, |
---|
346 | n/a | NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, |
---|
347 | n/a | }; |
---|
348 | n/a | static const unsigned char johabjamo_jungseong[32] = { |
---|
349 | n/a | NONE, NONE, FILL, 0x4f, 0x50, 0x51, 0x52, 0x53, |
---|
350 | n/a | NONE, NONE, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, |
---|
351 | n/a | NONE, NONE, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, |
---|
352 | n/a | NONE, NONE, 0x60, 0x61, 0x62, 0x63, NONE, NONE, |
---|
353 | n/a | }; |
---|
354 | n/a | static const unsigned char johabjamo_jongseong[32] = { |
---|
355 | n/a | NONE, FILL, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, |
---|
356 | n/a | 0x37, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, |
---|
357 | n/a | 0x40, 0x41, NONE, 0x42, 0x44, 0x45, 0x46, 0x47, |
---|
358 | n/a | 0x48, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, NONE, NONE, |
---|
359 | n/a | }; |
---|
360 | n/a | |
---|
361 | n/a | DECODER(johab) |
---|
362 | n/a | { |
---|
363 | n/a | while (inleft > 0) { |
---|
364 | n/a | unsigned char c = INBYTE1, c2; |
---|
365 | n/a | Py_UCS4 decoded; |
---|
366 | n/a | |
---|
367 | n/a | if (c < 0x80) { |
---|
368 | n/a | OUTCHAR(c); |
---|
369 | n/a | NEXT_IN(1); |
---|
370 | n/a | continue; |
---|
371 | n/a | } |
---|
372 | n/a | |
---|
373 | n/a | REQUIRE_INBUF(2); |
---|
374 | n/a | c2 = INBYTE2; |
---|
375 | n/a | |
---|
376 | n/a | if (c < 0xd8) { |
---|
377 | n/a | /* johab hangul */ |
---|
378 | n/a | unsigned char c_cho, c_jung, c_jong; |
---|
379 | n/a | unsigned char i_cho, i_jung, i_jong; |
---|
380 | n/a | |
---|
381 | n/a | c_cho = (c >> 2) & 0x1f; |
---|
382 | n/a | c_jung = ((c << 3) | c2 >> 5) & 0x1f; |
---|
383 | n/a | c_jong = c2 & 0x1f; |
---|
384 | n/a | |
---|
385 | n/a | i_cho = johabidx_choseong[c_cho]; |
---|
386 | n/a | i_jung = johabidx_jungseong[c_jung]; |
---|
387 | n/a | i_jong = johabidx_jongseong[c_jong]; |
---|
388 | n/a | |
---|
389 | n/a | if (i_cho == NONE || i_jung == NONE || i_jong == NONE) |
---|
390 | n/a | return 1; |
---|
391 | n/a | |
---|
392 | n/a | /* we don't use U+1100 hangul jamo yet. */ |
---|
393 | n/a | if (i_cho == FILL) { |
---|
394 | n/a | if (i_jung == FILL) { |
---|
395 | n/a | if (i_jong == FILL) |
---|
396 | n/a | OUTCHAR(0x3000); |
---|
397 | n/a | else |
---|
398 | n/a | OUTCHAR(0x3100 | |
---|
399 | n/a | johabjamo_jongseong[c_jong]); |
---|
400 | n/a | } |
---|
401 | n/a | else { |
---|
402 | n/a | if (i_jong == FILL) |
---|
403 | n/a | OUTCHAR(0x3100 | |
---|
404 | n/a | johabjamo_jungseong[c_jung]); |
---|
405 | n/a | else |
---|
406 | n/a | return 1; |
---|
407 | n/a | } |
---|
408 | n/a | } else { |
---|
409 | n/a | if (i_jung == FILL) { |
---|
410 | n/a | if (i_jong == FILL) |
---|
411 | n/a | OUTCHAR(0x3100 | |
---|
412 | n/a | johabjamo_choseong[c_cho]); |
---|
413 | n/a | else |
---|
414 | n/a | return 1; |
---|
415 | n/a | } |
---|
416 | n/a | else |
---|
417 | n/a | OUTCHAR(0xac00 + |
---|
418 | n/a | i_cho * 588 + |
---|
419 | n/a | i_jung * 28 + |
---|
420 | n/a | (i_jong == FILL ? 0 : i_jong)); |
---|
421 | n/a | } |
---|
422 | n/a | NEXT_IN(2); |
---|
423 | n/a | } else { |
---|
424 | n/a | /* KS X 1001 except hangul jamos and syllables */ |
---|
425 | n/a | if (c == 0xdf || c > 0xf9 || |
---|
426 | n/a | c2 < 0x31 || (c2 >= 0x80 && c2 < 0x91) || |
---|
427 | n/a | (c2 & 0x7f) == 0x7f || |
---|
428 | n/a | (c == 0xda && (c2 >= 0xa1 && c2 <= 0xd3))) |
---|
429 | n/a | return 1; |
---|
430 | n/a | else { |
---|
431 | n/a | unsigned char t1, t2; |
---|
432 | n/a | |
---|
433 | n/a | t1 = (c < 0xe0 ? 2 * (c - 0xd9) : |
---|
434 | n/a | 2 * c - 0x197); |
---|
435 | n/a | t2 = (c2 < 0x91 ? c2 - 0x31 : c2 - 0x43); |
---|
436 | n/a | t1 = t1 + (t2 < 0x5e ? 0 : 1) + 0x21; |
---|
437 | n/a | t2 = (t2 < 0x5e ? t2 : t2 - 0x5e) + 0x21; |
---|
438 | n/a | |
---|
439 | n/a | if (TRYMAP_DEC(ksx1001, decoded, t1, t2)) { |
---|
440 | n/a | OUTCHAR(decoded); |
---|
441 | n/a | NEXT_IN(2); |
---|
442 | n/a | } |
---|
443 | n/a | else { |
---|
444 | n/a | return 1; |
---|
445 | n/a | } |
---|
446 | n/a | } |
---|
447 | n/a | } |
---|
448 | n/a | } |
---|
449 | n/a | |
---|
450 | n/a | return 0; |
---|
451 | n/a | } |
---|
452 | n/a | #undef NONE |
---|
453 | n/a | #undef FILL |
---|
454 | n/a | |
---|
455 | n/a | |
---|
456 | n/a | BEGIN_MAPPINGS_LIST |
---|
457 | n/a | MAPPING_DECONLY(ksx1001) |
---|
458 | n/a | MAPPING_ENCONLY(cp949) |
---|
459 | n/a | MAPPING_DECONLY(cp949ext) |
---|
460 | n/a | END_MAPPINGS_LIST |
---|
461 | n/a | |
---|
462 | n/a | BEGIN_CODECS_LIST |
---|
463 | n/a | CODEC_STATELESS(euc_kr) |
---|
464 | n/a | CODEC_STATELESS(cp949) |
---|
465 | n/a | CODEC_STATELESS(johab) |
---|
466 | n/a | END_CODECS_LIST |
---|
467 | n/a | |
---|
468 | n/a | I_AM_A_MODULE_FOR(kr) |
---|