Update.
[glibc.git] / iconvdata / euckr.c
blob61046b392b26993f69f31f8bedf277a5f7707fe3
1 /* Mapping tables for EUC-KR handling.
2 Copyright (C) 1998 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jungshik Shin <jshin@pantheon.yale.edu>
5 and Ulrich Drepper <drepper@cygnus.com>, 1998.
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.
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.
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. */
22 #include <stdint.h>
23 #include <ksc5601.h>
26 static inline void
27 euckr_from_ucs4 (uint32_t ch, unsigned char *cp)
29 if (ch > 0x7f)
31 if (ucs4_to_ksc5601 (ch, cp, 2) != UNKNOWN_10646_CHAR)
33 cp[0] |= 0x80;
34 cp[1] |= 0x80;
37 /* XXX Think about 0x5c ; '\'. */
38 else
40 cp[0] = (unsigned char) ch;
41 cp[1] = '\0';
46 /* Definitions used in the body of the `gconv' function. */
47 #define CHARSET_NAME "EUC-KR//"
48 #define FROM_LOOP from_euc_kr
49 #define TO_LOOP to_euc_kr
50 #define DEFINE_INIT 1
51 #define DEFINE_FINI 1
52 #define MIN_NEEDED_FROM 1
53 #define MAX_NEEDED_FROM 2
54 #define MIN_NEEDED_TO 4
57 /* First define the conversion function from EUC-KR to UCS4. */
58 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
59 #define MAX_NEEDED_INPUT MAX_NEEDED_FROM
60 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
61 #define LOOPFCT FROM_LOOP
62 #define BODY \
63 { \
64 uint32_t ch = *inptr; \
66 /* Half-width Korean Currency WON sign \
68 if (inchar == 0x5c) \
69 ch = 0x20a9; \
70 else if (inchar <= 0x7f) \
71 ch = (uint32_t) inchar; \
72 */ \
74 if (ch <= 0x7f) \
75 /* Plain ASCII. */ \
76 ++inptr; \
77 /* 0xfe(->0x7e : row 94) and 0xc9(->0x59 : row 41) are \
78 user-defined areas. */ \
79 else if (ch <= 0xa0 || ch > 0xfe || ch == 0xc9) \
80 { \
81 /* This is illegal. */ \
82 result = GCONV_ILLEGAL_INPUT; \
83 break; \
84 } \
85 else \
86 { \
87 /* Two-byte character. First test whether the next character \
88 is also available. */ \
89 ch = ksc5601_to_ucs4 (&inptr, \
90 NEED_LENGTH_TEST ? inptr - inend : 2, 0x80); \
91 if (NEED_LENGTH_TEST && ch == 0) \
92 { \
93 /* The second character is not available. */ \
94 result = GCONV_INCOMPLETE_INPUT; \
95 break; \
96 } \
97 if (ch == UNKNOWN_10646_CHAR) \
98 { \
99 /* This is an illegal character. */ \
100 result = GCONV_ILLEGAL_INPUT; \
101 break; \
105 *((uint32_t *) outptr)++ = ch; \
107 #include <iconv/loop.c>
110 /* Next, define the other direction. */
111 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
112 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
113 #define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
114 #define LOOPFCT TO_LOOP
115 #define BODY \
117 uint32_t ch = *((uint32_t *) inptr); \
118 unsigned char cp[2]; \
120 /* Decomposing Hangul syllables not available in KS C 5601 into \
121 Jamos should be considered either here or in euckr_from_ucs4() */ \
122 euckr_from_ucs4 (ch, cp) ; \
124 if (cp[0] == '\0' && ch != 0) \
126 /* Illegal character. */ \
127 result = GCONV_ILLEGAL_INPUT; \
128 break; \
131 *outptr++ = cp[0]; \
132 /* Now test for a possible second byte and write this if possible. */ \
133 if (cp[1] != '\0') \
135 if (NEED_LENGTH_TEST && outptr >= outend) \
137 /* The result does not fit into the buffer. */ \
138 --outptr; \
139 result = GCONV_FULL_OUTPUT; \
140 break; \
142 *outptr++ = cp[1]; \
145 inptr += 4; \
147 #include <iconv/loop.c>
150 /* Now define the toplevel functions. */
151 #include <iconv/skeleton.c>