]> git.ipfire.org Git - thirdparty/glibc.git/blame - iconvdata/euc-kr.c
Update.
[thirdparty/glibc.git] / iconvdata / euc-kr.c
CommitLineData
a44d2393 1/* Mapping tables for EUC-KR handling.
dd9423a6 2 Copyright (C) 1998, 1999, 2000-2002, 2003 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
41bdb6e2
AJ
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
a44d2393
UD
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
41bdb6e2 15 Lesser General Public License for more details.
a44d2393 16
41bdb6e2
AJ
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
a44d2393 21
55985355 22#include <dlfcn.h>
40b4c81d 23#include <stdint.h>
a44d2393
UD
24#include <ksc5601.h>
25
a44d2393
UD
26
27static inline void
dd9423a6 28__attribute ((always_inline))
8619129f 29euckr_from_ucs4 (uint32_t ch, unsigned char *cp)
a44d2393 30{
2528edd3 31 if (ch > 0x9f)
a44d2393 32 {
228cc878
UD
33 if (__builtin_expect (ch, 0) == 0x20a9)
34 {
a1e88b9a
UD
35 /* Half-width Korean Currency WON sign. There is no
36 equivalent in EUC-KR. Some mappings use \x5c because
37 this is what some old Korean ASCII variants used but this
38 is causing problems. We map it to the FULL WIDTH WON SIGN. */
39 cp[0] = '\xa3';
40 cp[1] = '\xdc';
228cc878
UD
41 }
42 else if (__builtin_expect (ucs4_to_ksc5601 (ch, cp, 2), 0)
89301d68 43 != __UNKNOWN_10646_CHAR)
bc900b11
UD
44 {
45 cp[0] |= 0x80;
46 cp[1] |= 0x80;
47 }
788e8e7c
UD
48 else
49 cp[0] = '\0';
a44d2393 50 }
a44d2393
UD
51 else
52 {
228cc878
UD
53 /* There is no mapping for U005c but we nevertheless map it to
54 \x5c. */
8619129f
UD
55 cp[0] = (unsigned char) ch;
56 cp[1] = '\0';
a44d2393
UD
57 }
58}
59
60
8619129f 61/* Definitions used in the body of the `gconv' function. */
9b26f5c4 62#define CHARSET_NAME "EUC-KR//"
8619129f
UD
63#define FROM_LOOP from_euc_kr
64#define TO_LOOP to_euc_kr
65#define DEFINE_INIT 1
66#define DEFINE_FINI 1
67#define MIN_NEEDED_FROM 1
68#define MAX_NEEDED_FROM 2
69#define MIN_NEEDED_TO 4
70
71
72/* First define the conversion function from EUC-KR to UCS4. */
73#define MIN_NEEDED_INPUT MIN_NEEDED_FROM
74#define MAX_NEEDED_INPUT MAX_NEEDED_FROM
75#define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
76#define LOOPFCT FROM_LOOP
77#define BODY \
78 { \
79 uint32_t ch = *inptr; \
80 \
2528edd3 81 if (ch <= 0x9f) \
a1e88b9a 82 ++inptr; \
8619129f
UD
83 /* 0xfe(->0x7e : row 94) and 0xc9(->0x59 : row 41) are \
84 user-defined areas. */ \
db2d05f9
UD
85 else if (__builtin_expect (ch == 0xa0, 0) \
86 || __builtin_expect (ch > 0xfe, 0) \
87 || __builtin_expect (ch == 0xc9, 0)) \
8619129f
UD
88 { \
89 /* This is illegal. */ \
e438a468 90 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
8619129f
UD
91 } \
92 else \
93 { \
f9ad060c 94 /* Two-byte character. First test whether the next byte \
8619129f 95 is also available. */ \
c7c3b0e9 96 ch = ksc5601_to_ucs4 (&inptr, inend - inptr, 0x80); \
e438a468 97 if (__builtin_expect (ch == 0, 0)) \
8619129f 98 { \
e438a468 99 /* The second byte is not available. */ \
d64b6ad0 100 result = __GCONV_INCOMPLETE_INPUT; \
8619129f
UD
101 break; \
102 } \
e438a468
UD
103 if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0)) \
104 /* This is an illegal character. */ \
105 STANDARD_FROM_LOOP_ERR_HANDLER (2); \
8619129f
UD
106 } \
107 \
77e1d15a
UD
108 put32 (outptr, ch); \
109 outptr += 4; \
8619129f 110 }
55985355 111#define LOOP_NEED_FLAGS
f9ad060c
UD
112#define ONEBYTE_BODY \
113 { \
114 if (c <= 0x9f) \
115 return c; \
116 else \
117 return WEOF; \
118 }
8619129f
UD
119#include <iconv/loop.c>
120
121
122/* Next, define the other direction. */
123#define MIN_NEEDED_INPUT MIN_NEEDED_TO
124#define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
125#define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
126#define LOOPFCT TO_LOOP
127#define BODY \
128 { \
77e1d15a 129 uint32_t ch = get32 (inptr); \
8619129f
UD
130 unsigned char cp[2]; \
131 \
132 /* Decomposing Hangul syllables not available in KS C 5601 into \
133 Jamos should be considered either here or in euckr_from_ucs4() */ \
601d2942 134 euckr_from_ucs4 (ch, cp); \
8619129f 135 \
89301d68 136 if (__builtin_expect (cp[0], '\1') == '\0' && ch != 0) \
8619129f 137 { \
601d2942
UD
138 UNICODE_TAG_HANDLER (ch, 4); \
139 \
8619129f 140 /* Illegal character. */ \
e438a468 141 STANDARD_TO_LOOP_ERR_HANDLER (4); \
8619129f
UD
142 } \
143 \
144 *outptr++ = cp[0]; \
145 /* Now test for a possible second byte and write this if possible. */ \
146 if (cp[1] != '\0') \
147 { \
55985355 148 if (__builtin_expect (outptr >= outend, 0)) \
8619129f
UD
149 { \
150 /* The result does not fit into the buffer. */ \
151 --outptr; \
d64b6ad0 152 result = __GCONV_FULL_OUTPUT; \
8619129f
UD
153 break; \
154 } \
155 *outptr++ = cp[1]; \
156 } \
157 \
158 inptr += 4; \
159 }
55985355 160#define LOOP_NEED_FLAGS
8619129f
UD
161#include <iconv/loop.c>
162
163
164/* Now define the toplevel functions. */
165#include <iconv/skeleton.c>