|
Packit |
6c4009 |
/* Generic conversion to and from 8bit charsets.
|
|
Packit |
6c4009 |
Copyright (C) 1997-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <dlfcn.h>
|
|
Packit |
6c4009 |
#include <stdint.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define FROM_LOOP from_generic
|
|
Packit |
6c4009 |
#define TO_LOOP to_generic
|
|
Packit |
6c4009 |
#define DEFINE_INIT 1
|
|
Packit |
6c4009 |
#define DEFINE_FINI 1
|
|
Packit |
6c4009 |
#define MIN_NEEDED_FROM 1
|
|
Packit |
6c4009 |
#define MIN_NEEDED_TO 4
|
|
Packit |
6c4009 |
#define ONE_DIRECTION 0
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* First define the conversion function from the 8bit charset to UCS4. */
|
|
Packit |
6c4009 |
#define MIN_NEEDED_INPUT MIN_NEEDED_FROM
|
|
Packit |
6c4009 |
#define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
|
|
Packit |
6c4009 |
#define LOOPFCT FROM_LOOP
|
|
Packit |
6c4009 |
#define BODY \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
uint32_t ch = to_ucs4[*inptr]; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && *inptr != '\0') \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
/* This is an illegal character. */ \
|
|
Packit |
6c4009 |
STANDARD_FROM_LOOP_ERR_HANDLER (1); \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
put32 (outptr, ch); \
|
|
Packit |
6c4009 |
outptr += 4; \
|
|
Packit |
6c4009 |
++inptr; \
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#define LOOP_NEED_FLAGS
|
|
Packit |
6c4009 |
#define ONEBYTE_BODY \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
uint32_t ch = to_ucs4[c]; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && c != '\0') \
|
|
Packit |
6c4009 |
return WEOF; \
|
|
Packit |
6c4009 |
else \
|
|
Packit |
6c4009 |
return ch; \
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#include <iconv/loop.c>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Next, define the other direction. */
|
|
Packit |
6c4009 |
#define MIN_NEEDED_INPUT MIN_NEEDED_TO
|
|
Packit |
6c4009 |
#define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
|
|
Packit |
6c4009 |
#define LOOPFCT TO_LOOP
|
|
Packit |
6c4009 |
#define BODY \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
uint32_t ch = get32 (inptr); \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), 0)\
|
|
Packit |
6c4009 |
|| (__builtin_expect (from_ucs4[ch], '\1') == '\0' && ch != 0)) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
UNICODE_TAG_HANDLER (ch, 4); \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
/* This is an illegal character. */ \
|
|
Packit |
6c4009 |
STANDARD_TO_LOOP_ERR_HANDLER (4); \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
*outptr++ = from_ucs4[ch]; \
|
|
Packit |
6c4009 |
inptr += 4; \
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#define LOOP_NEED_FLAGS
|
|
Packit |
6c4009 |
#include <iconv/loop.c>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Now define the toplevel functions. */
|
|
Packit |
6c4009 |
#include <iconv/skeleton.c>
|