]> git.ipfire.org Git - thirdparty/glibc.git/blame - iconvdata/8bit-gap.c
Fix bug in previous tcvn5712 commit e64d2de52.
[thirdparty/glibc.git] / iconvdata / 8bit-gap.c
CommitLineData
04be94a8
UD
1/* Generic conversion to and from 8bit charsets,
2 converting from UCS using gaps.
e438a468 3 Copyright (C) 1997-1999, 2000-2002 Free Software Foundation, Inc.
f4017d20
UD
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6
7 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
f4017d20
UD
11
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
41bdb6e2 15 Lesser General Public License for more details.
f4017d20 16
41bdb6e2 17 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
f4017d20 20
55985355 21#include <dlfcn.h>
2aea1d79 22#include <stdint.h>
04be94a8
UD
23
24struct gap
25{
26 uint16_t start;
27 uint16_t end;
9b26f5c4 28 int32_t idx;
04be94a8
UD
29};
30
31/* Now we can include the tables. */
32#include TABLES
33
f9ad060c
UD
34#ifndef NONNUL
35# define NONNUL(c) ((c) != '\0')
36#endif
37
f4017d20 38
8619129f
UD
39#define FROM_LOOP from_gap
40#define TO_LOOP to_gap
41#define DEFINE_INIT 1
42#define DEFINE_FINI 1
43#define MIN_NEEDED_FROM 1
44#define MIN_NEEDED_TO 4
45
46
47/* First define the conversion function from the 8bit charset to UCS4. */
48#define MIN_NEEDED_INPUT MIN_NEEDED_FROM
49#define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
50#define LOOPFCT FROM_LOOP
51#define BODY \
52 { \
53 uint32_t ch = to_ucs4[*inptr]; \
54 \
f9ad060c 55 if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && NONNUL (*inptr)) \
8619129f
UD
56 { \
57 /* This is an illegal character. */ \
e438a468 58 STANDARD_FROM_LOOP_ERR_HANDLER (1); \
85830c4c
UD
59 } \
60 else \
61 { \
62 put32 (outptr, ch); \
63 outptr += 4; \
8619129f
UD
64 } \
65 \
8619129f
UD
66 ++inptr; \
67 }
55985355 68#define LOOP_NEED_FLAGS
f9ad060c
UD
69#define ONEBYTE_BODY \
70 { \
71 uint32_t ch = to_ucs4[c]; \
72 \
73 if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && NONNUL (c)) \
74 return WEOF; \
75 else \
76 return ch; \
77 }
8619129f
UD
78#include <iconv/loop.c>
79
80
81/* Next, define the other direction. */
82#define MIN_NEEDED_INPUT MIN_NEEDED_TO
83#define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
84#define LOOPFCT TO_LOOP
85#define BODY \
86 { \
87 const struct gap *rp = from_idx; \
77e1d15a 88 uint32_t ch = get32 (inptr); \
8619129f
UD
89 unsigned char res; \
90 \
db2d05f9 91 if (__builtin_expect (ch >= 0xffff, 0)) \
601d2942
UD
92 { \
93 UNICODE_TAG_HANDLER (ch, 4); \
94 rp = NULL; \
95 } \
d6204268
UD
96 else \
97 while (ch > rp->end) \
98 ++rp; \
99 if (__builtin_expect (rp == NULL, 0) \
100 || __builtin_expect (ch < rp->start, 0) \
101 || (res = from_ucs4[ch + rp->idx], \
102 __builtin_expect (res, '\1') == '\0' && ch != 0)) \
3cb0cda8
UD
103 { \
104 /* This is an illegal character. */ \
e438a468 105 STANDARD_TO_LOOP_ERR_HANDLER (4); \
8619129f
UD
106 } \
107 \
108 *outptr++ = res; \
109 inptr += 4; \
110 }
55985355 111#define LOOP_NEED_FLAGS
8619129f
UD
112#include <iconv/loop.c>
113
114
115/* Now define the toplevel functions. */
116#include <iconv/skeleton.c>