]>
Commit | Line | Data |
---|---|---|
a44d2393 UD |
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. | |
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 | { | |
8619129f | 31 | uint16_t idx = 0; |
a44d2393 UD |
32 | |
33 | if (ucs4_to_ksc5601 (ch, &idx)) | |
34 | idx |= 0x8080; | |
35 | ||
8619129f UD |
36 | cp[0] = (unsigned char) (idx / 256); |
37 | cp[1] = (unsigned char) (idx & 0xff); | |
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 UD |
48 | /* Definitions used in the body of the `gconv' function. */ |
49 | #define CHARSET_NAME "EUC-KR" | |
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) \ | |
73 | ch = (wchar_t) inchar; \ | |
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. */ \ | |
84 | result = GCONV_ILLEGAL_INPUT; \ | |
85 | break; \ | |
86 | } \ | |
87 | else \ | |
88 | { \ | |
89 | /* Two-byte character. First test whether the next character \ | |
90 | is also available. */ \ | |
91 | int ch2; \ | |
92 | \ | |
93 | if (NEED_LENGTH_TEST && inptr + 1 >= inend) \ | |
94 | { \ | |
95 | /* The second character is not available. */ \ | |
96 | result = GCONV_INCOMPLETE_INPUT; \ | |
97 | break; \ | |
98 | } \ | |
99 | \ | |
100 | ch2 = inptr[1]; \ | |
101 | \ | |
102 | if (ch2 < 0xa1 || ch2 >= 0xfe \ | |
103 | || ((ch = ksc5601_to_ucs4 ((uint16_t) (ch * 256 + ch2) & 0x7f7f)) \ | |
104 | == UNKNOWN_10646_CHAR)) \ | |
105 | { \ | |
106 | /* This is an illegal character. */ \ | |
107 | result = GCONV_ILLEGAL_INPUT; \ | |
108 | break; \ | |
109 | } \ | |
110 | \ | |
111 | inptr += 2; \ | |
112 | } \ | |
113 | \ | |
114 | *((uint32_t *) outptr)++ = ch; \ | |
115 | } | |
116 | #include <iconv/loop.c> | |
117 | ||
118 | ||
119 | /* Next, define the other direction. */ | |
120 | #define MIN_NEEDED_INPUT MIN_NEEDED_TO | |
121 | #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM | |
122 | #define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM | |
123 | #define LOOPFCT TO_LOOP | |
124 | #define BODY \ | |
125 | { \ | |
126 | uint32_t ch = *((uint32_t *) inptr); \ | |
127 | unsigned char cp[2]; \ | |
128 | \ | |
129 | /* Decomposing Hangul syllables not available in KS C 5601 into \ | |
130 | Jamos should be considered either here or in euckr_from_ucs4() */ \ | |
131 | euckr_from_ucs4 (ch, cp) ; \ | |
132 | \ | |
133 | if (cp[0] == '\0' && ch != 0) \ | |
134 | { \ | |
135 | /* Illegal character. */ \ | |
136 | result = GCONV_ILLEGAL_INPUT; \ | |
137 | break; \ | |
138 | } \ | |
139 | \ | |
140 | *outptr++ = cp[0]; \ | |
141 | /* Now test for a possible second byte and write this if possible. */ \ | |
142 | if (cp[1] != '\0') \ | |
143 | { \ | |
144 | if (NEED_LENGTH_TEST && outptr >= outend) \ | |
145 | { \ | |
146 | /* The result does not fit into the buffer. */ \ | |
147 | --outptr; \ | |
148 | result = GCONV_FULL_OUTPUT; \ | |
149 | break; \ | |
150 | } \ | |
151 | *outptr++ = cp[1]; \ | |
152 | } \ | |
153 | \ | |
154 | inptr += 4; \ | |
155 | } | |
156 | #include <iconv/loop.c> | |
157 | ||
158 | ||
159 | /* Now define the toplevel functions. */ | |
160 | #include <iconv/skeleton.c> |