/* Conversion module for ISO-2022-JP-3.
- Copyright (C) 1998-1999, 2000-2002 Free Software Foundation, Inc.
+ Copyright (C) 1998-2015 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998,
and Bruno Haible <bruno@clisp.org>, 2002.
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
+ <http://www.gnu.org/licenses/>. */
#include <assert.h>
#include <dlfcn.h>
#define TO_LOOP to_iso2022jp3_loop
#define DEFINE_INIT 1
#define DEFINE_FINI 1
+#define ONE_DIRECTION 0
#define FROM_LOOP_MIN_NEEDED_FROM 1
#define FROM_LOOP_MAX_NEEDED_FROM 4
#define FROM_LOOP_MIN_NEEDED_TO 4
JISX0208_1983_set = 2 << 3, /* Esc $ B */
JISX0201_Roman_set = 3 << 3, /* Esc ( J */
JISX0201_Kana_set = 4 << 3, /* Esc ( I */
- JISX0213_1_set = 5 << 3, /* Esc $ ( O */
+ JISX0213_1_2000_set = 5 << 3, /* Esc $ ( O */
JISX0213_2_set = 6 << 3, /* Esc $ ( P */
+ JISX0213_1_2004_set = 7 << 3, /* Esc $ ( Q */
CURRENT_SEL_MASK = 7 << 3
};
+ ((data->__statep->__count & CURRENT_SEL_MASK) != ASCII_set \
? 3 : 0); \
\
- if (__builtin_expect (outbuf + need > outend, 0)) \
+ if (__glibc_unlikely (outbuf + need > outend)) \
/* We don't have enough room in the output buffer. */ \
status = __GCONV_FULL_OUTPUT; \
else \
uint32_t ch = *inptr; \
\
/* Recognize escape sequences. */ \
- if (__builtin_expect (ch == ESC, 0)) \
+ if (__glibc_unlikely (ch == ESC)) \
{ \
/* We now must be prepared to read two to three more bytes. \
If we have a match in the first byte but then the input buffer \
} \
else if (inptr[2] == '(') \
{ \
- if (inptr[3] == 'O') \
+ if (inptr[3] == 'O' || inptr[3] == 'Q') \
{ \
/* JIS X 0213 plane 1 selected. */ \
- set = JISX0213_1_set; \
+ /* In this direction we don't need to distinguish the \
+ versions from 2000 and 2004. */ \
+ set = JISX0213_1_2004_set; \
inptr += 4; \
continue; \
} \
{ \
/* Use the JIS X 0201 table. */ \
ch = jisx0201_to_ucs4 (ch); \
- if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0)) \
+ if (__glibc_unlikely (ch == __UNKNOWN_10646_CHAR)) \
{ \
STANDARD_FROM_LOOP_ERR_HANDLER (1); \
} \
{ \
/* Use the JIS X 0201 table. */ \
ch = jisx0201_to_ucs4 (ch + 0x80); \
- if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0)) \
+ if (__glibc_unlikely (ch == __UNKNOWN_10646_CHAR)) \
{ \
STANDARD_FROM_LOOP_ERR_HANDLER (1); \
} \
provide the appropriate tables. */ \
ch = jisx0208_to_ucs4 (&inptr, inend - inptr, 0); \
\
- if (__builtin_expect (ch == 0, 0)) \
+ if (__glibc_unlikely (ch == 0)) \
{ \
result = __GCONV_INCOMPLETE_INPUT; \
break; \
} \
- else if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0)) \
+ else if (__glibc_unlikely (ch == __UNKNOWN_10646_CHAR)) \
{ \
STANDARD_FROM_LOOP_ERR_HANDLER (1); \
} \
} \
- else /* (set == JISX0213_1_set || set == JISX0213_2_set) */ \
+ else /* (set == JISX0213_1_2004_set || set == JISX0213_2_set) */ \
{ \
- if (__builtin_expect (inptr + 1 >= inend, 0)) \
+ if (__glibc_unlikely (inptr + 1 >= inend)) \
{ \
result = __GCONV_INCOMPLETE_INPUT; \
break; \
} \
\
- ch = jisx0213_to_ucs4 (((set - JISX0213_1_set + (1 << 3)) << 5) + ch, \
- inptr[1]); \
+ ch = jisx0213_to_ucs4 ( \
+ ((JISX0213_1_2004_set - set + (1 << 3)) << 5) + ch, \
+ inptr[1]); \
if (ch == 0) \
STANDARD_FROM_LOOP_ERR_HANDLER (1); \
\
/* We know the combined character is in JISX0213 plane 1, \
but the buffered character may have been in JISX0208 or in \
JISX0213 plane 1. */ \
- size_t need = (lasttwo >> 16 || set != JISX0213_1_set ? 4 : 0); \
+ size_t need = \
+ (lasttwo >> 16 \
+ || (set != JISX0213_1_2000_set && set != JISX0213_1_2004_set) \
+ ? 4 : 0); \
\
- if (__builtin_expect (outptr + need + 2 > outend, 0)) \
+ if (__glibc_unlikely (outptr + need + 2 > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
*outptr++ = '$'; \
*outptr++ = '('; \
*outptr++ = 'O'; \
- set = JISX0213_1_set; \
+ set = JISX0213_1_2000_set; \
} \
lasttwo = comp_table_data[idx].composed; \
*outptr++ = (lasttwo >> 8) & 0xff; \
{ \
size_t need = (lasttwo >> 16 ? 3 : 0); \
\
- if (__builtin_expect (outptr + need + 2 > outend, 0)) \
+ if (__glibc_unlikely (outptr + need + 2 > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
inptr += 4; \
continue; \
} \
- if (__builtin_expect (written == 0, 0)) \
+ if (__glibc_unlikely (written == 0)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
} \
else \
{ \
- /* (set == JISX0213_1_set || set == JISX0213_2_set) */ \
+ /* (set == JISX0213_1_2000_set || set == JISX0213_1_2004_set \
+ || set == JISX0213_2_set) */ \
uint32_t jch = ucs4_to_jisx0213 (ch); \
\
if (jch != 0 \
- && (set == (jch & 0x8000 ? JISX0213_2_set : JISX0213_1_set))) \
+ && (jch & 0x8000 \
+ ? set == JISX0213_2_set \
+ : (set == JISX0213_1_2004_set \
+ || (set == JISX0213_1_2000_set \
+ && !jisx0213_added_in_2004_p (jch))))) \
{ \
if (jch & 0x0080) \
{ \
continue; \
} \
\
- if (__builtin_expect (outptr + 1 >= outend, 0)) \
+ if (__glibc_unlikely (outptr + 1 >= outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
{ \
/* We must encode using ASCII. First write out the escape \
sequence. */ \
- if (__builtin_expect (outptr + 3 > outend, 0)) \
+ if (__glibc_unlikely (outptr + 3 > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
*outptr++ = 'B'; \
set = ASCII_set; \
\
- if (__builtin_expect (outptr >= outend, 0)) \
+ if (__glibc_unlikely (outptr >= outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
{ \
if (set != JISX0201_Roman_set) \
{ \
- if (__builtin_expect (outptr + 3 > outend, 0)) \
+ if (__glibc_unlikely (outptr + 3 > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
set = JISX0201_Roman_set; \
} \
\
- if (__builtin_expect (outptr >= outend, 0)) \
+ if (__glibc_unlikely (outptr >= outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
\
if (set != JISX0208_1983_set) \
{ \
- if (__builtin_expect (outptr + 3 > outend, 0)) \
+ if (__glibc_unlikely (outptr + 3 > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
set = JISX0208_1983_set; \
} \
\
- if (__builtin_expect (outptr + 2 > outend, 0)) \
+ if (__glibc_unlikely (outptr + 2 > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
if (jch != 0) \
{ \
int new_set = \
- (jch & 0x8000 ? JISX0213_2_set : JISX0213_1_set); \
+ (jch & 0x8000 \
+ ? JISX0213_2_set \
+ : jisx0213_added_in_2004_p (jch) \
+ ? JISX0213_1_2004_set \
+ : JISX0213_1_2000_set); \
\
if (set != new_set) \
{ \
- if (__builtin_expect (outptr + 4 > outend, 0)) \
+ if (__glibc_unlikely (outptr + 4 > outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
*outptr++ = ESC; \
*outptr++ = '$'; \
*outptr++ = '('; \
- *outptr++ = ((new_set - JISX0213_1_set) >> 3) + 'O'; \
+ *outptr++ = \
+ ((new_set - JISX0213_1_2000_set) >> 3) + 'O'; \
set = new_set; \
} \
\
continue; \
} \
\
- if (__builtin_expect (outptr + 1 >= outend, 0)) \
+ if (__glibc_unlikely (outptr + 1 >= outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
set = JISX0201_Kana_set; \
} \
\
- if (__builtin_expect (outptr >= outend, 0)) \
+ if (__glibc_unlikely (outptr >= outend)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
#define EXTRA_LOOP_DECLS , int *statep
#define INIT_PARAMS int set = *statep & CURRENT_SEL_MASK; \
uint32_t lasttwo = *statep >> 6
+#define REINIT_PARAMS do \
+ { \
+ set = *statep & CURRENT_SEL_MASK; \
+ lasttwo = *statep >> 6; \
+ } \
+ while (0)
#define UPDATE_PARAMS *statep = set | (lasttwo << 6)
#include <iconv/loop.c>