Files
glibc/iconvdata/euc-tw.c
T

189 lines
6.2 KiB
C
Raw Normal View History

1998-04-13 15:01:09 +00:00
/* Mapping tables for EUC-TW handling.
Copyright (C) 1998-2026 Free Software Foundation, Inc.
1998-04-13 15:01:09 +00:00
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
2001-07-06 04:58:11 +00:00
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
1998-04-13 15:01:09 +00:00
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2001-07-06 04:58:11 +00:00
Lesser General Public License for more details.
1998-04-13 15:01:09 +00:00
2001-07-06 04:58:11 +00:00
You should have received a copy of the GNU Lesser General Public
2012-02-09 23:18:22 +00:00
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
1998-04-13 15:01:09 +00:00
2000-06-12 19:47:50 +00:00
#include <dlfcn.h>
1998-04-13 15:01:09 +00:00
#include <stdint.h>
#include <cns11643l1.h>
#include <cns11643.h>
1998-04-20 18:41:05 +00:00
/* Definitions used in the body of the `gconv' function. */
1998-04-24 07:07:59 +00:00
#define CHARSET_NAME "EUC-TW//"
1998-04-20 18:41:05 +00:00
#define FROM_LOOP from_euc_tw
#define TO_LOOP to_euc_tw
#define DEFINE_INIT 1
#define DEFINE_FINI 1
#define MIN_NEEDED_FROM 1
#define MAX_NEEDED_FROM 4
#define MIN_NEEDED_TO 4
2014-05-01 13:42:40 -07:00
#define ONE_DIRECTION 0
1998-04-13 15:01:09 +00:00
1998-04-20 18:41:05 +00:00
/* First define the conversion function from EUC-TW to UCS4. */
#define MIN_NEEDED_INPUT MIN_NEEDED_FROM
#define MAX_NEEDED_INPUT MAX_NEEDED_FROM
#define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
#define LOOPFCT FROM_LOOP
#define BODY \
{ \
uint32_t ch = *inptr; \
\
if (ch <= 0x7f) \
/* Plain ASCII. */ \
++inptr; \
else if ((ch <= 0xa0 || ch > 0xfe) && ch != 0x8e) \
{ \
/* This is illegal. */ \
2002-06-28 21:23:06 +00:00
STANDARD_FROM_LOOP_ERR_HANDLER (1); \
1998-04-20 18:41:05 +00:00
} \
else \
{ \
2001-06-06 12:55:46 +00:00
/* Two or more byte character. First test whether the next byte \
is also available. */ \
1998-04-20 18:41:05 +00:00
uint32_t ch2; \
\
2000-09-05 02:41:25 +00:00
if (inptr + 1 >= inend) \
1998-04-20 18:41:05 +00:00
{ \
2001-06-06 12:55:46 +00:00
/* The second byte is not available. Store the intermediate \
result. */ \
1999-06-16 22:55:47 +00:00
result = __GCONV_INCOMPLETE_INPUT; \
1998-04-20 18:41:05 +00:00
break; \
} \
\
2000-09-05 02:41:25 +00:00
ch2 = *(inptr + 1); \
1998-04-20 18:41:05 +00:00
\
/* All second bytes of a multibyte character must be >= 0xa1. */ \
if (ch2 < 0xa1 || ch2 == 0xff) \
2002-06-28 21:23:06 +00:00
STANDARD_FROM_LOOP_ERR_HANDLER (1); \
1998-04-20 18:41:05 +00:00
\
if (ch == 0x8e) \
{ \
/* This is code set 2: CNS 11643, planes 1 to 16. */ \
const unsigned char *endp = inptr + 1; \
1998-04-20 18:41:05 +00:00
\
2000-06-12 19:47:50 +00:00
ch = cns11643_to_ucs4 (&endp, inend - inptr - 1, 0x80); \
2000-09-05 02:41:25 +00:00
\
if (ch == 0) \
{ \
2001-06-06 12:55:46 +00:00
/* The third or fourth byte is not available. Store \
2000-09-05 02:41:25 +00:00
the intermediate result. */ \
result = __GCONV_INCOMPLETE_INPUT; \
break; \
} \
\
1999-06-16 22:55:47 +00:00
if (ch == __UNKNOWN_10646_CHAR) \
2002-06-28 21:23:06 +00:00
/* Illegal input. */ \
STANDARD_FROM_LOOP_ERR_HANDLER (1); \
1998-04-20 18:41:05 +00:00
\
inptr += 4; \
} \
else \
{ \
/* This is code set 1: CNS 11643, plane 1. */ \
1999-12-29 07:32:44 +00:00
const unsigned char *endp = inptr; \
1998-04-20 18:41:05 +00:00
\
2000-06-12 19:47:50 +00:00
ch = cns11643l1_to_ucs4 (&endp, inend - inptr, 0x80); \
1998-04-20 18:41:05 +00:00
/* Please note that we need not test for the missing input \
characters here anymore. */ \
1999-06-16 22:55:47 +00:00
if (ch == __UNKNOWN_10646_CHAR) \
2002-06-28 21:23:06 +00:00
/* Illegal input. */ \
STANDARD_FROM_LOOP_ERR_HANDLER (2); \
1998-04-20 18:41:05 +00:00
\
inptr += 2; \
} \
} \
\
2000-03-28 17:33:37 +00:00
put32 (outptr, ch); \
outptr += 4; \
1998-04-20 18:41:05 +00:00
}
2000-06-12 19:47:50 +00:00
#define LOOP_NEED_FLAGS
2002-12-02 22:39:58 +00:00
#define ONEBYTE_BODY \
{ \
if (c < 0x80) \
return c; \
else \
return WEOF; \
}
1998-04-20 18:41:05 +00:00
#include <iconv/loop.c>
1998-04-13 15:01:09 +00:00
1998-04-20 18:41:05 +00:00
/* Next, define the other direction. */
#define MIN_NEEDED_INPUT MIN_NEEDED_TO
#define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
#define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
#define LOOPFCT TO_LOOP
#define BODY \
{ \
2000-03-28 17:33:37 +00:00
uint32_t ch = get32 (inptr); \
1998-04-20 18:41:05 +00:00
\
if (ch <= 0x7f) \
/* It's plain ASCII. */ \
*outptr++ = ch; \
else \
{ \
2001-06-06 12:55:46 +00:00
/* Try the CNS 11643 planes. */ \
1998-04-20 18:41:05 +00:00
size_t found; \
\
2000-06-12 19:47:50 +00:00
found = ucs4_to_cns11643l1 (ch, outptr, outend - outptr); \
if (__builtin_expect (found, 1) == 0) \
1998-04-20 18:41:05 +00:00
{ \
/* We ran out of space. */ \
2003-03-26 07:58:49 +00:00
result = __GCONV_FULL_OUTPUT; \
1998-04-20 18:41:05 +00:00
break; \
} \
2000-06-12 19:47:50 +00:00
if (__builtin_expect (found, 1) != __UNKNOWN_10646_CHAR) \
1998-04-20 18:41:05 +00:00
{ \
/* It's a CNS 11643, plane 1 character, adjust it for EUC-TW. */ \
*outptr++ += 0x80; \
*outptr++ += 0x80; \
} \
else \
{ \
/* No CNS 11643, plane 1 character. */ \
\
2000-06-12 19:47:50 +00:00
found = ucs4_to_cns11643 (ch, outptr + 1, outend - outptr - 1); \
if (__builtin_expect (found, 1) == 0) \
1998-04-20 18:41:05 +00:00
{ \
/* We ran out of space. */ \
2003-03-26 07:58:49 +00:00
result = __GCONV_FULL_OUTPUT; \
1998-04-20 18:41:05 +00:00
break; \
} \
2000-06-12 19:47:50 +00:00
if (__builtin_expect (found, 0) == __UNKNOWN_10646_CHAR) \
1998-04-20 18:41:05 +00:00
{ \
2001-06-06 12:55:46 +00:00
UNICODE_TAG_HANDLER (ch, 4); \
\
2000-06-12 19:47:50 +00:00
/* Illegal character. */ \
2002-06-28 21:23:06 +00:00
STANDARD_TO_LOOP_ERR_HANDLER (4); \
1998-04-20 18:41:05 +00:00
} \
\
/* It's a CNS 11643 character, adjust it for EUC-TW. */ \
*outptr++ = '\x8e'; \
*outptr++ += 0xa0; \
*outptr++ += 0x80; \
*outptr++ += 0x80; \
} \
} \
\
inptr += 4; \
}
2000-06-12 19:47:50 +00:00
#define LOOP_NEED_FLAGS
1998-04-20 18:41:05 +00:00
#include <iconv/loop.c>
1998-04-13 15:01:09 +00:00
1998-04-20 18:41:05 +00:00
/* Now define the toplevel functions. */
#include <iconv/skeleton.c>