Files
glibc/iconvdata/euc-kr.c
T

160 lines
4.9 KiB
C
Raw Normal View History

1998-03-27 22:57:26 +00:00
/* Mapping tables for EUC-KR handling.
Copyright (C) 1998-2026 Free Software Foundation, Inc.
1998-03-27 22:57:26 +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-03-27 22:57:26 +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-03-27 22:57:26 +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-03-27 22:57:26 +00:00
2000-06-12 19:47:50 +00:00
#include <dlfcn.h>
1998-04-13 09:17:55 +00:00
#include <stdint.h>
1998-03-27 22:57:26 +00:00
#include <ksc5601.h>
static inline void
2003-06-11 21:57:23 +00:00
__attribute ((always_inline))
1998-04-20 18:41:05 +00:00
euckr_from_ucs4 (uint32_t ch, unsigned char *cp)
1998-03-27 22:57:26 +00:00
{
2000-07-07 06:41:18 +00:00
if (ch > 0x9f)
1998-03-27 22:57:26 +00:00
{
2000-10-04 23:52:14 +00:00
if (__builtin_expect (ch, 0) == 0x20a9)
{
2000-11-08 08:08:09 +00:00
/* Half-width Korean Currency WON sign. There is no
equivalent in EUC-KR. Some mappings use \x5c because
this is what some old Korean ASCII variants used but this
is causing problems. We map it to the FULL WIDTH WON SIGN. */
cp[0] = '\xa3';
cp[1] = '\xdc';
2000-10-04 23:52:14 +00:00
}
else if (__builtin_expect (ucs4_to_ksc5601 (ch, cp, 2), 0)
2000-06-06 16:53:06 +00:00
!= __UNKNOWN_10646_CHAR)
1998-04-26 10:28:28 +00:00
{
cp[0] |= 0x80;
cp[1] |= 0x80;
}
1999-07-25 15:03:25 +00:00
else
cp[0] = cp[1] = '\0';
1998-03-27 22:57:26 +00:00
}
else
{
2000-10-04 23:52:14 +00:00
/* There is no mapping for U005c but we nevertheless map it to
\x5c. */
1998-04-20 18:41:05 +00:00
cp[0] = (unsigned char) ch;
cp[1] = '\0';
1998-03-27 22:57:26 +00:00
}
}
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-KR//"
1998-04-20 18:41:05 +00:00
#define FROM_LOOP from_euc_kr
#define TO_LOOP to_euc_kr
#define DEFINE_INIT 1
#define DEFINE_FINI 1
#define MIN_NEEDED_FROM 1
#define MAX_NEEDED_FROM 2
#define MIN_NEEDED_TO 4
2014-05-01 13:42:40 -07:00
#define ONE_DIRECTION 0
1998-03-27 22:57:26 +00:00
1998-04-20 18:41:05 +00:00
/* First define the conversion function from EUC-KR 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; \
\
2000-07-07 06:41:18 +00:00
if (ch <= 0x9f) \
2000-11-08 08:08:09 +00:00
++inptr; \
else if (__glibc_unlikely (ch == 0xa0)) \
1998-04-20 18:41:05 +00:00
{ \
/* 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 \
{ \
2002-12-02 22:39:58 +00:00
/* Two-byte character. First test whether the next byte \
1998-04-20 18:41:05 +00:00
is also available. */ \
2000-08-29 21:14:05 +00:00
ch = ksc5601_to_ucs4 (&inptr, inend - inptr, 0x80); \
2014-02-10 14:45:42 +01:00
if (__glibc_unlikely (ch == 0)) \
1998-04-20 18:41:05 +00:00
{ \
2002-06-28 21:23:06 +00:00
/* The second byte is not available. */ \
1999-06-16 22:55:47 +00:00
result = __GCONV_INCOMPLETE_INPUT; \
1998-04-20 18:41:05 +00:00
break; \
} \
2014-02-10 14:45:42 +01:00
if (__glibc_unlikely (ch == __UNKNOWN_10646_CHAR)) \
2002-06-28 21:23:06 +00:00
/* This is an illegal character. */ \
STANDARD_FROM_LOOP_ERR_HANDLER (2); \
1998-04-20 18:41:05 +00:00
} \
\
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 <= 0x9f) \
return c; \
else \
return WEOF; \
}
1998-04-20 18:41:05 +00:00
#include <iconv/loop.c>
1998-03-27 22:57:26 +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
unsigned char cp[2]; \
\
/* Decomposing Hangul syllables not available in KS C 5601 into \
Jamos should be considered either here or in euckr_from_ucs4() */ \
2001-06-06 12:55:46 +00:00
euckr_from_ucs4 (ch, cp); \
1998-04-20 18:41:05 +00:00
\
2000-06-06 16:53:06 +00:00
if (__builtin_expect (cp[0], '\1') == '\0' && ch != 0) \
1998-04-20 18:41:05 +00:00
{ \
2001-06-06 12:55:46 +00:00
UNICODE_TAG_HANDLER (ch, 4); \
\
1998-04-20 18:41:05 +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
} \
\
*outptr++ = cp[0]; \
/* Now test for a possible second byte and write this if possible. */ \
if (cp[1] != '\0') \
{ \
2014-02-10 14:45:42 +01:00
if (__glibc_unlikely (outptr >= outend)) \
1998-04-20 18:41:05 +00:00
{ \
/* The result does not fit into the buffer. */ \
--outptr; \
1999-06-16 22:55:47 +00:00
result = __GCONV_FULL_OUTPUT; \
1998-04-20 18:41:05 +00:00
break; \
} \
*outptr++ = cp[1]; \
} \
\
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-03-27 22:57:26 +00:00
1998-04-20 18:41:05 +00:00
/* Now define the toplevel functions. */
#include <iconv/skeleton.c>