(gc): Correctly determine highest used array element in mark.
[glibc/history.git] / iconvdata / euc-kr.c
blob8e9120b7324217257e3dbc174306d2847f9aab83
1 /* Mapping tables for EUC-KR handling.
2 Copyright (C) 1998, 1999, 2000-2002, 2003, 2007
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Jungshik Shin <jshin@pantheon.yale.edu>
6 and Ulrich Drepper <drepper@cygnus.com>, 1998.
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, write to the Free
20 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 02111-1307 USA. */
23 #include <dlfcn.h>
24 #include <stdint.h>
25 #include <ksc5601.h>
28 static inline void
29 __attribute ((always_inline))
30 euckr_from_ucs4 (uint32_t ch, unsigned char *cp)
32 if (ch > 0x9f)
34 if (__builtin_expect (ch, 0) == 0x20a9)
36 /* Half-width Korean Currency WON sign. There is no
37 equivalent in EUC-KR. Some mappings use \x5c because
38 this is what some old Korean ASCII variants used but this
39 is causing problems. We map it to the FULL WIDTH WON SIGN. */
40 cp[0] = '\xa3';
41 cp[1] = '\xdc';
43 else if (__builtin_expect (ucs4_to_ksc5601 (ch, cp, 2), 0)
44 != __UNKNOWN_10646_CHAR)
46 cp[0] |= 0x80;
47 cp[1] |= 0x80;
49 else
50 cp[0] = cp[1] = '\0';
52 else
54 /* There is no mapping for U005c but we nevertheless map it to
55 \x5c. */
56 cp[0] = (unsigned char) ch;
57 cp[1] = '\0';
62 /* Definitions used in the body of the `gconv' function. */
63 #define CHARSET_NAME "EUC-KR//"
64 #define FROM_LOOP from_euc_kr
65 #define TO_LOOP to_euc_kr
66 #define DEFINE_INIT 1
67 #define DEFINE_FINI 1
68 #define MIN_NEEDED_FROM 1
69 #define MAX_NEEDED_FROM 2
70 #define MIN_NEEDED_TO 4
73 /* First define the conversion function from EUC-KR to UCS4. */
74 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
75 #define MAX_NEEDED_INPUT MAX_NEEDED_FROM
76 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
77 #define LOOPFCT FROM_LOOP
78 #define BODY \
79 { \
80 uint32_t ch = *inptr; \
82 if (ch <= 0x9f) \
83 ++inptr; \
84 /* 0xfe(->0x7e : row 94) and 0xc9(->0x59 : row 41) are \
85 user-defined areas. */ \
86 else if (__builtin_expect (ch == 0xa0, 0) \
87 || __builtin_expect (ch > 0xfe, 0) \
88 || __builtin_expect (ch == 0xc9, 0)) \
89 { \
90 /* This is illegal. */ \
91 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
92 } \
93 else \
94 { \
95 /* Two-byte character. First test whether the next byte \
96 is also available. */ \
97 ch = ksc5601_to_ucs4 (&inptr, inend - inptr, 0x80); \
98 if (__builtin_expect (ch == 0, 0)) \
99 { \
100 /* The second byte is not available. */ \
101 result = __GCONV_INCOMPLETE_INPUT; \
102 break; \
104 if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0)) \
105 /* This is an illegal character. */ \
106 STANDARD_FROM_LOOP_ERR_HANDLER (2); \
109 put32 (outptr, ch); \
110 outptr += 4; \
112 #define LOOP_NEED_FLAGS
113 #define ONEBYTE_BODY \
115 if (c <= 0x9f) \
116 return c; \
117 else \
118 return WEOF; \
120 #include <iconv/loop.c>
123 /* Next, define the other direction. */
124 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
125 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
126 #define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
127 #define LOOPFCT TO_LOOP
128 #define BODY \
130 uint32_t ch = get32 (inptr); \
131 unsigned char cp[2]; \
133 /* Decomposing Hangul syllables not available in KS C 5601 into \
134 Jamos should be considered either here or in euckr_from_ucs4() */ \
135 euckr_from_ucs4 (ch, cp); \
137 if (__builtin_expect (cp[0], '\1') == '\0' && ch != 0) \
139 UNICODE_TAG_HANDLER (ch, 4); \
141 /* Illegal character. */ \
142 STANDARD_TO_LOOP_ERR_HANDLER (4); \
145 *outptr++ = cp[0]; \
146 /* Now test for a possible second byte and write this if possible. */ \
147 if (cp[1] != '\0') \
149 if (__builtin_expect (outptr >= outend, 0)) \
151 /* The result does not fit into the buffer. */ \
152 --outptr; \
153 result = __GCONV_FULL_OUTPUT; \
154 break; \
156 *outptr++ = cp[1]; \
159 inptr += 4; \
161 #define LOOP_NEED_FLAGS
162 #include <iconv/loop.c>
165 /* Now define the toplevel functions. */
166 #include <iconv/skeleton.c>