Update.
[glibc.git] / iconvdata / 8bit-gap.c
blob2ddc49eb64dfd8d1353e8b43c41cca3abb8988e2
1 /* Generic conversion to and from 8bit charsets,
2 converting from UCS using gaps.
3 Copyright (C) 1997-1999, 2000-2002 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #include <dlfcn.h>
23 #include <stdint.h>
25 struct gap
27 uint16_t start;
28 uint16_t end;
29 int32_t idx;
32 /* Now we can include the tables. */
33 #include TABLES
36 #define FROM_LOOP from_gap
37 #define TO_LOOP to_gap
38 #define DEFINE_INIT 1
39 #define DEFINE_FINI 1
40 #define MIN_NEEDED_FROM 1
41 #define MIN_NEEDED_TO 4
44 /* First define the conversion function from the 8bit charset to UCS4. */
45 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
46 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
47 #define LOOPFCT FROM_LOOP
48 #define BODY \
49 { \
50 uint32_t ch = to_ucs4[*inptr]; \
52 if (HAS_HOLES && __builtin_expect (ch, L'\1') == L'\0' && *inptr != '\0') \
53 { \
54 /* This is an illegal character. */ \
55 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
56 } \
57 else \
58 { \
59 put32 (outptr, ch); \
60 outptr += 4; \
61 } \
63 ++inptr; \
65 #define LOOP_NEED_FLAGS
66 #include <iconv/loop.c>
69 /* Next, define the other direction. */
70 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
71 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
72 #define LOOPFCT TO_LOOP
73 #define BODY \
74 { \
75 const struct gap *rp = from_idx; \
76 uint32_t ch = get32 (inptr); \
77 unsigned char res; \
79 if (__builtin_expect (ch >= 0xffff, 0)) \
80 { \
81 UNICODE_TAG_HANDLER (ch, 4); \
82 rp = NULL; \
83 } \
84 else \
85 while (ch > rp->end) \
86 ++rp; \
87 if (__builtin_expect (rp == NULL, 0) \
88 || __builtin_expect (ch < rp->start, 0) \
89 || (res = from_ucs4[ch + rp->idx], \
90 __builtin_expect (res, '\1') == '\0' && ch != 0)) \
91 { \
92 /* This is an illegal character. */ \
93 STANDARD_TO_LOOP_ERR_HANDLER (4); \
94 } \
96 *outptr++ = res; \
97 inptr += 4; \
99 #define LOOP_NEED_FLAGS
100 #include <iconv/loop.c>
103 /* Now define the toplevel functions. */
104 #include <iconv/skeleton.c>