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. */
22 #include <cns11643l1.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
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
43 uint32_t ch = *inptr; \
48 else if ((ch <= 0xa0 || ch > 0xfe) && ch != 0x8e) \
50 /* This is illegal. */ \
51 result = GCONV_ILLEGAL_INPUT; \
56 /* Two or more byte character. First test whether the next \
57 character is also available. */ \
60 if (NEED_LENGTH_TEST && inptr + (ch == 0x8e ? 3 : 1) >= inend) \
62 /* The second character is not available. Store the \
63 intermediate result. */ \
64 result = GCONV_INCOMPLETE_INPUT; \
70 /* All second bytes of a multibyte character must be >= 0xa1. */ \
71 if (ch2 < 0xa1 || ch2 == 0xff) \
73 /* This is an illegal character. */ \
74 result = GCONV_ILLEGAL_INPUT; \
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, \
86 /* Please note that we need not test for the missing input \
87 characters here anymore. */ \
88 if (ch == UNKNOWN_10646_CHAR) \
90 /* Illegal input. */ \
91 result = GCONV_ILLEGAL_INPUT; \
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, \
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; \
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
130 uint32_t ch = *((uint32_t *) inptr); \
133 /* It's plain ASCII. */ \
137 /* Try the JIS character sets. */ \
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; \
148 if (found != UNKNOWN_10646_CHAR) \
150 /* It's a CNS 11643, plane 1 character, adjust it for EUC-TW. */ \
156 /* No CNS 11643, plane 1 character. */ \
158 found = ucs4_to_cns11643 (ch, outptr + 1, \
160 ? outend - outptr - 1 : 3)); \
161 if (NEED_LENGTH_TEST && found == 0) \
163 /* We ran out of space. */ \
164 result = GCONV_INCOMPLETE_INPUT; \
167 if (found == UNKNOWN_10646_CHAR) \
169 /* No legal input. */ \
170 result = GCONV_ILLEGAL_INPUT; \
174 /* It's a CNS 11643 character, adjust it for EUC-TW. */ \
175 *outptr++ = '\x8e'; \
184 #include <iconv/loop.c>
187 /* Now define the toplevel functions. */
188 #include <iconv/skeleton.c>