/* Mapping tables for UHC handling.
- Copyright (C) 1998 Free Software Foundation, Inc.
+ Copyright (C) 1998-2014 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jungshik Shin <jshin@pantheon.yale.edu>, 1998.
The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ 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.
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
- Library General Public License for more details.
+ Lesser General Public License for more details.
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+#include <dlfcn.h>
#include <stdint.h>
#include <ksc5601.h>
#define MIN_NEEDED_FROM 1
#define MAX_NEEDED_FROM 2
#define MIN_NEEDED_TO 4
+#define ONE_DIRECTION 0
/* First define the conversion function from UHC to UCS4. */
#define MIN_NEEDED_INPUT MIN_NEEDED_FROM
*/ \
if (ch <= 0x7f) \
++inptr; \
- else if (ch <= 0x80 || ch >= 0xfe || ch == 0xc9) \
+ else if (__builtin_expect (ch <= 0x80, 0) \
+ || __builtin_expect (ch >= 0xfe, 0) \
+ || __builtin_expect (ch == 0xc9, 0)) \
{ \
/* This is illegal. */ \
- result = GCONV_ILLEGAL_INPUT; \
- break; \
+ STANDARD_FROM_LOOP_ERR_HANDLER (1); \
} \
else \
{ \
- /* Two-byte character. First test whether the next character \
+ /* Two-byte character. First test whether the next byte \
is also available. */ \
uint32_t ch2; \
\
- if (NEED_LENGTH_TEST && inptr + 1 >= inend) \
+ if (__glibc_unlikely (inptr + 1 >= inend)) \
{ \
/* The second character is not available. Store \
the intermediate result. */ \
- result = GCONV_INCOMPLETE_INPUT; \
+ result = __GCONV_INCOMPLETE_INPUT; \
break; \
} \
\
\
if (ch < 0xa1 || ch2 < 0xa1) \
{ \
- if (ch > 0xc6 || ch2 <0x41 || (ch2 > 0x5a && ch2 < 0x61) \
- || (ch2 > 0x7a && ch2 < 0x81) || (ch == 0xc6 && ch2 > 0x52)) \
+ if (__builtin_expect (ch > 0xc6, 0) \
+ || __builtin_expect (ch2 < 0x41, 0) \
+ || __builtin_expect (ch2 > 0xfe, 0) \
+ || (__builtin_expect (ch2 > 0x5a, 0) && ch2 < 0x61) \
+ || (__builtin_expect (ch2 > 0x7a, 0) && ch2 < 0x81) \
+ || (__builtin_expect (ch == 0xc6, 0) && ch2 > 0x52)) \
{ \
/* This is not legal. */ \
- result = GCONV_ILLEGAL_INPUT; \
- break; \
+ STANDARD_FROM_LOOP_ERR_HANDLER (1); \
} \
\
ch = uhc_extra_to_ucs[ch2 - 0x41 \
? (ch - 0x81) * 178 \
: 5696 + (ch - 0xa1) * 84)]; \
\
- if (ch == 0) \
+ if (__glibc_unlikely (ch == 0)) \
{ \
/* This is an illegal character. */ \
- result = GCONV_ILLEGAL_INPUT; \
- break; \
+ STANDARD_FROM_LOOP_ERR_HANDLER (2); \
} \
\
inptr += 2; \
else \
{ \
ch = ksc5601_to_ucs4 (&inptr, 2, 0x80); \
- if (ch == UNKNOWN_10646_CHAR) \
+ if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0) \
+ || __builtin_expect (ch == 0x327e, 0)) \
{ \
/* Illegal. */ \
- result = GCONV_ILLEGAL_INPUT; \
- break; \
+ STANDARD_FROM_LOOP_ERR_HANDLER (2); \
} \
} \
} \
\
- *((uint32_t *) outptr)++ = ch; \
+ put32 (outptr, ch); \
+ outptr += 4; \
+ }
+#define LOOP_NEED_FLAGS
+#define ONEBYTE_BODY \
+ { \
+ if (c < 0x80) \
+ return c; \
+ else \
+ return WEOF; \
}
#include <iconv/loop.c>
#define LOOPFCT TO_LOOP
#define BODY \
{ \
- uint32_t ch = *((uint32_t *) inptr); \
+ uint32_t ch = get32 (inptr); \
\
- if (ch < 0x7f) \
+ if (ch <= 0x7f) \
/* XXX Think about 0x5c ; '\'. */ \
- *outptr = ch; \
+ *outptr++ = ch; \
else if (ch >= 0xac00 && ch <= 0xd7a3) \
{ \
const char *s = uhc_hangul_from_ucs[ch - 0xac00]; \
\
- if (NEED_LENGTH_TEST && outptr + 2 > outend) \
+ if (__glibc_unlikely (outptr + 2 > outend)) \
{ \
- result = GCONV_FULL_OUTPUT; \
+ result = __GCONV_FULL_OUTPUT; \
break; \
} \
\
*outptr++ = s[0]; \
*outptr++ = s[1]; \
} \
- else if (ch >= 0x4e00 && ch <= 0x9fa5 || ch >= 0xf900 && ch <= 0xfa0b) \
+ else if ((ch >= 0x4e00 && ch <= 0x9fa5) || (ch >= 0xf900 && ch <= 0xfa0b))\
{ \
- size_t written = ucs4_to_ksc5601_hanja (ch, outptr, \
- (NEED_LENGTH_TEST \
- ? outend - outptr : 2)); \
+ size_t written = ucs4_to_ksc5601_hanja (ch, outptr, outend - outptr); \
\
- if (NEED_LENGTH_TEST && written == 0) \
+ if (__glibc_unlikely (written == 0)) \
{ \
- result = GCONV_FULL_OUTPUT; \
+ result = __GCONV_FULL_OUTPUT; \
break; \
} \
- if (written == UNKNOWN_10646_CHAR) \
+ if (__glibc_unlikely (written == __UNKNOWN_10646_CHAR)) \
{ \
- result = GCONV_ILLEGAL_INPUT; \
- break; \
+ STANDARD_TO_LOOP_ERR_HANDLER (4); \
} \
\
*outptr++ |= 0x80; \
*/ \
else \
{ \
- size_t written = ucs4_to_ksc5601_sym (ch, outptr, \
- (NEED_LENGTH_TEST \
- ? outend - outptr : 2)); \
+ size_t written = ucs4_to_ksc5601_sym (ch, outptr, outend - outptr); \
\
- if (NEED_LENGTH_TEST && written == 0) \
+ if (__builtin_expect (ch == 0x327e, 0) \
+ || __builtin_expect (written == __UNKNOWN_10646_CHAR, 0)) \
{ \
- result = GCONV_FULL_OUTPUT; \
- break; \
+ UNICODE_TAG_HANDLER (ch, 4); \
+ STANDARD_TO_LOOP_ERR_HANDLER (4); \
} \
- if (written == UNKNOWN_10646_CHAR) \
+ if (__glibc_unlikely (written == 0)) \
{ \
- result = GCONV_ILLEGAL_INPUT; \
+ result = __GCONV_FULL_OUTPUT; \
break; \
} \
\
\
inptr += 4; \
}
+#define LOOP_NEED_FLAGS
#include <iconv/loop.c>