]>
Commit | Line | Data |
---|---|---|
a44d2393 | 1 | /* Mapping tables for EUC-KR handling. |
d64b6ad0 | 2 | Copyright (C) 1998, 1999 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 | ||
40b4c81d | 22 | #include <stdint.h> |
a44d2393 UD |
23 | #include <ksc5601.h> |
24 | ||
a44d2393 UD |
25 | |
26 | static inline void | |
8619129f | 27 | euckr_from_ucs4 (uint32_t ch, unsigned char *cp) |
a44d2393 UD |
28 | { |
29 | if (ch > 0x7f) | |
30 | { | |
d64b6ad0 | 31 | if (ucs4_to_ksc5601 (ch, cp, 2) != __UNKNOWN_10646_CHAR) |
bc900b11 UD |
32 | { |
33 | cp[0] |= 0x80; | |
34 | cp[1] |= 0x80; | |
35 | } | |
788e8e7c UD |
36 | else |
37 | cp[0] = '\0'; | |
a44d2393 | 38 | } |
8619129f | 39 | /* XXX Think about 0x5c ; '\'. */ |
a44d2393 UD |
40 | else |
41 | { | |
8619129f UD |
42 | cp[0] = (unsigned char) ch; |
43 | cp[1] = '\0'; | |
a44d2393 UD |
44 | } |
45 | } | |
46 | ||
47 | ||
8619129f | 48 | /* Definitions used in the body of the `gconv' function. */ |
9b26f5c4 | 49 | #define CHARSET_NAME "EUC-KR//" |
8619129f UD |
50 | #define FROM_LOOP from_euc_kr |
51 | #define TO_LOOP to_euc_kr | |
52 | #define DEFINE_INIT 1 | |
53 | #define DEFINE_FINI 1 | |
54 | #define MIN_NEEDED_FROM 1 | |
55 | #define MAX_NEEDED_FROM 2 | |
56 | #define MIN_NEEDED_TO 4 | |
57 | ||
58 | ||
59 | /* First define the conversion function from EUC-KR to UCS4. */ | |
60 | #define MIN_NEEDED_INPUT MIN_NEEDED_FROM | |
61 | #define MAX_NEEDED_INPUT MAX_NEEDED_FROM | |
62 | #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO | |
63 | #define LOOPFCT FROM_LOOP | |
64 | #define BODY \ | |
65 | { \ | |
66 | uint32_t ch = *inptr; \ | |
67 | \ | |
68 | /* Half-width Korean Currency WON sign \ | |
69 | \ | |
70 | if (inchar == 0x5c) \ | |
71 | ch = 0x20a9; \ | |
72 | else if (inchar <= 0x7f) \ | |
9b26f5c4 | 73 | ch = (uint32_t) inchar; \ |
8619129f UD |
74 | */ \ |
75 | \ | |
76 | if (ch <= 0x7f) \ | |
77 | /* Plain ASCII. */ \ | |
78 | ++inptr; \ | |
79 | /* 0xfe(->0x7e : row 94) and 0xc9(->0x59 : row 41) are \ | |
80 | user-defined areas. */ \ | |
81 | else if (ch <= 0xa0 || ch > 0xfe || ch == 0xc9) \ | |
82 | { \ | |
83 | /* This is illegal. */ \ | |
d64b6ad0 | 84 | result = __GCONV_ILLEGAL_INPUT; \ |
8619129f UD |
85 | break; \ |
86 | } \ | |
87 | else \ | |
88 | { \ | |
89 | /* Two-byte character. First test whether the next character \ | |
90 | is also available. */ \ | |
918b9d72 | 91 | ch = ksc5601_to_ucs4 (&inptr, \ |
bc900b11 | 92 | NEED_LENGTH_TEST ? inptr - inend : 2, 0x80); \ |
918b9d72 | 93 | if (NEED_LENGTH_TEST && ch == 0) \ |
8619129f UD |
94 | { \ |
95 | /* The second character is not available. */ \ | |
d64b6ad0 | 96 | result = __GCONV_INCOMPLETE_INPUT; \ |
8619129f UD |
97 | break; \ |
98 | } \ | |
d64b6ad0 | 99 | if (ch == __UNKNOWN_10646_CHAR) \ |
8619129f UD |
100 | { \ |
101 | /* This is an illegal character. */ \ | |
d64b6ad0 | 102 | result = __GCONV_ILLEGAL_INPUT; \ |
8619129f UD |
103 | break; \ |
104 | } \ | |
8619129f UD |
105 | } \ |
106 | \ | |
107 | *((uint32_t *) outptr)++ = ch; \ | |
108 | } | |
109 | #include <iconv/loop.c> | |
110 | ||
111 | ||
112 | /* Next, define the other direction. */ | |
113 | #define MIN_NEEDED_INPUT MIN_NEEDED_TO | |
114 | #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM | |
115 | #define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM | |
116 | #define LOOPFCT TO_LOOP | |
117 | #define BODY \ | |
118 | { \ | |
119 | uint32_t ch = *((uint32_t *) inptr); \ | |
120 | unsigned char cp[2]; \ | |
121 | \ | |
122 | /* Decomposing Hangul syllables not available in KS C 5601 into \ | |
123 | Jamos should be considered either here or in euckr_from_ucs4() */ \ | |
124 | euckr_from_ucs4 (ch, cp) ; \ | |
125 | \ | |
126 | if (cp[0] == '\0' && ch != 0) \ | |
127 | { \ | |
128 | /* Illegal character. */ \ | |
d64b6ad0 | 129 | result = __GCONV_ILLEGAL_INPUT; \ |
8619129f UD |
130 | break; \ |
131 | } \ | |
132 | \ | |
133 | *outptr++ = cp[0]; \ | |
134 | /* Now test for a possible second byte and write this if possible. */ \ | |
135 | if (cp[1] != '\0') \ | |
136 | { \ | |
137 | if (NEED_LENGTH_TEST && outptr >= outend) \ | |
138 | { \ | |
139 | /* The result does not fit into the buffer. */ \ | |
140 | --outptr; \ | |
d64b6ad0 | 141 | result = __GCONV_FULL_OUTPUT; \ |
8619129f UD |
142 | break; \ |
143 | } \ | |
144 | *outptr++ = cp[1]; \ | |
145 | } \ | |
146 | \ | |
147 | inptr += 4; \ | |
148 | } | |
149 | #include <iconv/loop.c> | |
150 | ||
151 | ||
152 | /* Now define the toplevel functions. */ | |
153 | #include <iconv/skeleton.c> |