/* Mapping tables for UHC handling.
- Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1998-2019 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
+ <https://www.gnu.org/licenses/>. */
#include <dlfcn.h>
#include <stdint.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 (__builtin_expect (ch, 0x81) <= 0x80 \
- || __builtin_expect (ch, 0x81) >= 0xfe \
- || __builtin_expect (ch, 0x81) == 0xc9) \
+ else if (__builtin_expect (ch <= 0x80, 0) \
+ || __builtin_expect (ch >= 0xfe, 0) \
+ || __builtin_expect (ch == 0xc9, 0)) \
{ \
/* This is illegal. */ \
- if (! ignore_errors_p ()) \
- { \
- /* This is an illegal character. */ \
- result = __GCONV_ILLEGAL_INPUT; \
- break; \
- } \
- \
- ++inptr; \
- ++*irreversible; \
- continue; \
+ 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 (__builtin_expect (inptr + 1 >= inend, 0)) \
+ if (__glibc_unlikely (inptr + 1 >= inend)) \
{ \
/* The second character is not available. Store \
the intermediate result. */ \
\
if (ch < 0xa1 || ch2 < 0xa1) \
{ \
- if (__builtin_expect (ch, 0xc5) > 0xc6 \
- || __builtin_expect (ch2, 0x41) < 0x41 \
- || __builtin_expect (ch2, 0x41) > 0xfe \
- || (__builtin_expect (ch2, 0x41) > 0x5a && ch2 < 0x61) \
- || (__builtin_expect (ch2, 0x41) > 0x7a && ch2 < 0x81) \
- || (__builtin_expect (ch, 0xc5) == 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. */ \
- if (! ignore_errors_p ()) \
- { \
- /* This is an illegal character. */ \
- result = __GCONV_ILLEGAL_INPUT; \
- break; \
- } \
- \
- ++inptr; \
- ++*irreversible; \
- continue; \
+ STANDARD_FROM_LOOP_ERR_HANDLER (1); \
} \
\
ch = uhc_extra_to_ucs[ch2 - 0x41 \
? (ch - 0x81) * 178 \
: 5696 + (ch - 0xa1) * 84)]; \
\
- if (__builtin_expect (ch, 1) == 0) \
+ if (__glibc_unlikely (ch == 0)) \
{ \
/* This is an illegal character. */ \
- if (! ignore_errors_p ()) \
- { \
- /* This is an illegal character. */ \
- result = __GCONV_ILLEGAL_INPUT; \
- break; \
- } \
- \
- inptr += 2; \
- ++*irreversible; \
- continue; \
+ STANDARD_FROM_LOOP_ERR_HANDLER (2); \
} \
\
inptr += 2; \
else \
{ \
ch = ksc5601_to_ucs4 (&inptr, 2, 0x80); \
- if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \
+ if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0) \
+ || __builtin_expect (ch == 0x327e, 0)) \
{ \
/* Illegal. */ \
- if (! ignore_errors_p ()) \
- { \
- /* This is an illegal character. */ \
- result = __GCONV_ILLEGAL_INPUT; \
- break; \
- } \
- \
- inptr += 2; \
- ++*irreversible; \
- continue; \
+ STANDARD_FROM_LOOP_ERR_HANDLER (2); \
} \
} \
} \
outptr += 4; \
}
#define LOOP_NEED_FLAGS
+#define ONEBYTE_BODY \
+ { \
+ if (c < 0x80) \
+ return c; \
+ else \
+ return WEOF; \
+ }
#include <iconv/loop.c>
{ \
const char *s = uhc_hangul_from_ucs[ch - 0xac00]; \
\
- if (__builtin_expect (outptr + 2 > outend, 0)) \
+ if (__glibc_unlikely (outptr + 2 > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
{ \
size_t written = ucs4_to_ksc5601_hanja (ch, outptr, outend - outptr); \
\
- if (__builtin_expect (written, 1) == 0) \
+ if (__glibc_unlikely (written == 0)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
} \
- if (__builtin_expect (written, 0) == __UNKNOWN_10646_CHAR) \
+ if (__glibc_unlikely (written == __UNKNOWN_10646_CHAR)) \
{ \
- STANDARD_ERR_HANDLER (4); \
+ STANDARD_TO_LOOP_ERR_HANDLER (4); \
} \
\
*outptr++ |= 0x80; \
{ \
size_t written = ucs4_to_ksc5601_sym (ch, outptr, outend - outptr); \
\
- if (__builtin_expect (written, 1) == 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 (__builtin_expect (written, 0) == __UNKNOWN_10646_CHAR) \
+ if (__glibc_unlikely (written == 0)) \
{ \
- UNICODE_TAG_HANDLER (ch, 4); \
- STANDARD_ERR_HANDLER (4); \
+ result = __GCONV_FULL_OUTPUT; \
+ break; \
} \
\
*outptr++ |= 0x80; \