/* Conversion from and to IBM943.
- Copyright (C) 2000-2002 Free Software Foundation, Inc.
+ Copyright (C) 2000-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Masahide Washizawa <washi@jp.ibm.com>, 2000.
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
#include <dlfcn.h>
#include <stdint.h>
+#include <stdbool.h>
#include "ibm943.h"
-#ifndef TRUE
-#define TRUE 1
-#define FALSE 0
-#endif
-
#define FROM 0
#define TO 1
#define CHARSET_NAME "IBM943//"
#define FROM_LOOP from_ibm943
#define TO_LOOP to_ibm943
+#define ONE_DIRECTION 0
/* Definitions of initialization and destructor function. */
#define DEFINE_INIT 1
#define LOOPFCT FROM_LOOP
#define BODY \
{ \
- const struct gap *rp1 = __ibm943sb_to_ucs4_idx; \
const struct gap *rp2 = __ibm943db_to_ucs4_idx; \
uint32_t ch = *inptr; \
uint32_t res; \
\
- if (__builtin_expect (ch >= 0xffff, 0)) \
- { \
- rp1 = NULL; \
- rp2 = NULL; \
- } \
- else if (__builtin_expect (ch, 0) == 0x80 \
- || __builtin_expect (ch, 0) == 0xa0 \
- || __builtin_expect (ch, 0) == 0xfd \
- || __builtin_expect (ch, 0) == 0xfe \
- || __builtin_expect (ch, 0) == 0xff) \
+ if (__builtin_expect (ch == 0x80, 0) \
+ || __builtin_expect (ch == 0xa0, 0) \
+ || __builtin_expect (ch == 0xfd, 0) \
+ || __builtin_expect (ch == 0xfe, 0) \
+ || __builtin_expect (ch == 0xff, 0)) \
{ \
/* This is an illegal character. */ \
STANDARD_FROM_LOOP_ERR_HANDLER (1); \
- } \
- else \
- { \
- while (ch > rp1->end) \
- ++rp1; \
} \
\
/* Use the IBM943 table for single byte. */ \
- if (__builtin_expect (rp1 == NULL, 0) \
- || __builtin_expect (ch < rp1->start, 0) \
- || (res = __ibm943sb_to_ucs4[ch + rp1->idx], \
- __builtin_expect (res, '\1') == 0 && ch != 0)) \
+ if (__builtin_expect (ch > 0xdf, 0) \
+ || (res = __ibm943sb_to_ucs4[ch], \
+ __builtin_expect (res == 0, 0) && ch != 0)) \
{ \
- \
/* Use the IBM943 table for double byte. */ \
- if (__builtin_expect (inptr + 1 >= inend, 0)) \
+ if (__glibc_unlikely (inptr + 1 >= inend)) \
{ \
/* The second character is not available. \
Store the intermediate result. */ \
} \
\
ch = (ch * 0x100) + inptr[1]; \
+ /* ch was less than 0xfd. */ \
+ assert (ch < 0xfd00); \
while (ch > rp2->end) \
++rp2; \
\
- if (__builtin_expect (rp2 == NULL, 0) \
- || __builtin_expect (ch < rp2->start, 0) \
+ if (__builtin_expect (ch < rp2->start, 0) \
|| (res = __ibm943db_to_ucs4[ch + rp2->idx], \
__builtin_expect (res, '\1') == 0 && ch !=0)) \
{ \
} \
else \
{ \
- if (res == 0x1c) \
- res = 0x1a; \
- else if (res == 0x7f) \
- res = 0x1c; \
- else if (res == 0xa5) \
+ if (res == 0xa5) \
res = 0x5c; \
else if (res == 0x203e) \
res = 0x7e; \
- else if (res == 0x1a) \
- res = 0x7f; \
put32 (outptr, res); \
outptr += 4; \
inptr++; \
} \
}
#define LOOP_NEED_FLAGS
+#define ONEBYTE_BODY \
+ { \
+ if (c == 0x80 || c == 0xa0 || c >= 0xe0) \
+ return WEOF; \
+ uint32_t res = __ibm943sb_to_ucs4[c]; \
+ if (res == 0 && c != 0) \
+ return WEOF; \
+ if (res == 0xa5) \
+ res = 0x5c; \
+ else if (res == 0x203e) \
+ res = 0x7e; \
+ return res; \
+ }
#include <iconv/loop.c>
/* Next, define the other direction. */
const struct gap *rp = __ucs4_to_ibm943sb_idx; \
unsigned char sc; \
uint32_t ch = get32(inptr); \
- uint16_t found = TRUE; \
+ bool found = true; \
uint32_t i; \
uint32_t low; \
uint32_t high; \
uint16_t pccode; \
\
- if (__builtin_expect (ch >= 0xffff, 0)) \
+ if (__glibc_unlikely (ch >= 0xffff)) \
{ \
UNICODE_TAG_HANDLER (ch, 4); \
rp = NULL; \
{ \
\
/* Use the UCS4 table for double byte. */ \
- found = FALSE; \
+ found = false; \
low = 0; \
high = (sizeof (__ucs4_to_ibm943db) >> 1) \
/ sizeof (__ucs4_to_ibm943db[0][FROM]); \
pccode = ch; \
- while (low <= high) \
- { \
- i = (low + high) >> 1; \
- if (pccode < __ucs4_to_ibm943db[i][FROM]) \
- high = i - 1; \
- else if (pccode > __ucs4_to_ibm943db[i][FROM]) \
- low = i + 1; \
- else \
- { \
- pccode = __ucs4_to_ibm943db[i][TO]; \
- found = TRUE; \
- break; \
- } \
- } \
+ if (__glibc_likely (rp != NULL)) \
+ while (low < high) \
+ { \
+ i = (low + high) >> 1; \
+ if (pccode < __ucs4_to_ibm943db[i][FROM]) \
+ high = i; \
+ else if (pccode > __ucs4_to_ibm943db[i][FROM]) \
+ low = i + 1; \
+ else \
+ { \
+ pccode = __ucs4_to_ibm943db[i][TO]; \
+ found = true; \
+ break; \
+ } \
+ } \
if (found) \
{ \
- if (__builtin_expect (outptr + 2 > outend, 0)) \
+ if (__glibc_unlikely (outptr + 2 > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
} \
else \
{ \
- if (__builtin_expect (outptr + 1 > outend, 0)) \
+ if (__glibc_unlikely (outptr + 1 > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \