Update.
[glibc.git] / iconvdata / euc-tw.c
blobca1cdac40e7d31f302358ed7ed1b949b9adb4fb9
1 /* Mapping tables for EUC-TW handling.
2 Copyright (C) 1998 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include <stdint.h>
22 #include <cns11643l1.h>
23 #include <cns11643.h>
25 /* Definitions used in the body of the `gconv' function. */
26 #define CHARSET_NAME "EUC-TW//"
27 #define FROM_LOOP from_euc_tw
28 #define TO_LOOP to_euc_tw
29 #define DEFINE_INIT 1
30 #define DEFINE_FINI 1
31 #define MIN_NEEDED_FROM 1
32 #define MAX_NEEDED_FROM 4
33 #define MIN_NEEDED_TO 4
36 /* First define the conversion function from EUC-TW to UCS4. */
37 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
38 #define MAX_NEEDED_INPUT MAX_NEEDED_FROM
39 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
40 #define LOOPFCT FROM_LOOP
41 #define BODY \
42 { \
43 uint32_t ch = *inptr; \
45 if (ch <= 0x7f) \
46 /* Plain ASCII. */ \
47 ++inptr; \
48 else if ((ch <= 0xa0 || ch > 0xfe) && ch != 0x8e) \
49 { \
50 /* This is illegal. */ \
51 result = GCONV_ILLEGAL_INPUT; \
52 break; \
53 } \
54 else \
55 { \
56 /* Two or more byte character. First test whether the next \
57 character is also available. */ \
58 uint32_t ch2; \
60 if (NEED_LENGTH_TEST && inptr + (ch == 0x8e ? 3 : 1) >= inend) \
61 { \
62 /* The second character is not available. Store the \
63 intermediate result. */ \
64 result = GCONV_INCOMPLETE_INPUT; \
65 break; \
66 } \
68 ch2 = *inptr; \
70 /* All second bytes of a multibyte character must be >= 0xa1. */ \
71 if (ch2 < 0xa1 || ch2 == 0xff) \
72 { \
73 /* This is an illegal character. */ \
74 result = GCONV_ILLEGAL_INPUT; \
75 break; \
76 } \
78 if (ch == 0x8e) \
79 { \
80 /* This is code set 2: CNS 11643, planes 1 to 16. */ \
81 const char *endp = inptr + 1; \
83 ch = cns11643_to_ucs4 (&endp, \
84 NEED_LENGTH_TEST ? inend - inptr - 1 : 3, \
85 0x80); \
86 /* Please note that we need not test for the missing input \
87 characters here anymore. */ \
88 if (ch == UNKNOWN_10646_CHAR) \
89 { \
90 /* Illegal input. */ \
91 result = GCONV_ILLEGAL_INPUT; \
92 break; \
93 } \
95 inptr += 4; \
96 } \
97 else \
98 { \
99 /* This is code set 1: CNS 11643, plane 1. */ \
100 const char *endp = inptr; \
102 ch = cns11643l1_to_ucs4 (&endp, \
103 NEED_LENGTH_TEST ? inend - inptr : 2, \
104 0x80); \
105 /* Please note that we need not test for the missing input \
106 characters here anymore. */ \
107 if (ch == UNKNOWN_10646_CHAR) \
109 /* Illegal input. */ \
110 result = GCONV_ILLEGAL_INPUT; \
111 break; \
114 inptr += 2; \
118 *((uint32_t *) outptr)++ = ch; \
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 = *((uint32_t *) inptr); \
132 if (ch <= 0x7f) \
133 /* It's plain ASCII. */ \
134 *outptr++ = ch; \
135 else \
137 /* Try the JIS character sets. */ \
138 size_t found; \
140 found = ucs4_to_cns11643l1 (ch, outptr, \
141 NEED_LENGTH_TEST ? outend - outptr : 2); \
142 if (NEED_LENGTH_TEST && found == 0) \
144 /* We ran out of space. */ \
145 result = GCONV_INCOMPLETE_INPUT; \
146 break; \
148 if (found != UNKNOWN_10646_CHAR) \
150 /* It's a CNS 11643, plane 1 character, adjust it for EUC-TW. */ \
151 *outptr++ += 0x80; \
152 *outptr++ += 0x80; \
154 else \
156 /* No CNS 11643, plane 1 character. */ \
158 found = ucs4_to_cns11643 (ch, outptr + 1, \
159 (NEED_LENGTH_TEST \
160 ? outend - outptr - 1 : 3)); \
161 if (NEED_LENGTH_TEST && found == 0) \
163 /* We ran out of space. */ \
164 result = GCONV_INCOMPLETE_INPUT; \
165 break; \
167 if (found == UNKNOWN_10646_CHAR) \
169 /* No legal input. */ \
170 result = GCONV_ILLEGAL_INPUT; \
171 break; \
174 /* It's a CNS 11643 character, adjust it for EUC-TW. */ \
175 *outptr++ = '\x8e'; \
176 *outptr++ += 0xa0; \
177 *outptr++ += 0x80; \
178 *outptr++ += 0x80; \
182 inptr += 4; \
184 #include <iconv/loop.c>
187 /* Now define the toplevel functions. */
188 #include <iconv/skeleton.c>