1 /* Conversion from and to IBM933.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Masahide Washizawa <washi@yamato.ibm.co.jp>, 2000.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
27 /* The shift sequences for this charset (it does not use ESC). */
28 #define SI 0x0F /* Shift In, host code to turn DBCS off. */
29 #define SO 0x0E /* Shift Out, host code to turn DBCS on. */
31 /* Definitions used in the body of the `gconv' function. */
32 #define CHARSET_NAME "IBM933//"
33 #define FROM_LOOP from_ibm933
34 #define TO_LOOP to_ibm933
36 /* Definitions of initialization and destructor function. */
40 #define MIN_NEEDED_FROM 1
41 #define MIN_NEEDED_TO 4
43 /* Current codeset type. */
51 /* First, define the conversion function from IBM-933 to UCS4. */
52 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
53 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
54 #define INIT_PARAMS int curcs = init;
55 #define LOOPFCT FROM_LOOP
58 uint32_t ch = *inptr; \
60 const struct gap *rp1 = __ibm933sb_to_ucs4_idx; \
61 const struct gap *rp2 = __ibm933db_to_ucs4_idx; \
63 if (__builtin_expect (ch, 0) == SO) \
65 if (__builtin_expect (inptr + 1 >= inend, 0)) \
67 result = __GCONV_INCOMPLETE_INPUT; \
71 /* Shift OUT, change to DBCS converter. */ \
74 result = __GCONV_ILLEGAL_INPUT; \
81 else if (__builtin_expect (ch, 0) == SI) \
83 if (__builtin_expect (inptr + 1 >= inend, 0)) \
85 result = __GCONV_INCOMPLETE_INPUT; \
89 /* Shift IN, change to SBCS converter. */ \
92 result = __GCONV_ILLEGAL_INPUT; \
100 if (curcs == sb || curcs == init) \
102 /* Use the IBM933 table for single byte. */ \
103 while (ch > rp1->end) \
106 if (__builtin_expect (rp1 == NULL, 0) \
107 || __builtin_expect (ch < rp1->start, 0) \
108 || (res = __ibm933sb_to_ucs4[ch + rp1->idx], \
109 __builtin_expect (res, L'\1') == L'\0' && ch != '\0')) \
111 /* This is an illegal character. */ \
112 if (! ignore_errors_p ()) \
114 result = __GCONV_ILLEGAL_INPUT; \
123 put32 (outptr, res); \
128 else if (curcs == db) \
130 /* Use the IBM933 table for double byte. */ \
131 if (__builtin_expect (inptr + 1 >= inend, 0)) \
133 /* The second character is not available. Store the \
134 intermediate result. */ \
135 result = __GCONV_INCOMPLETE_INPUT; \
139 ch = (ch * 0x100) + inptr[1]; \
140 while (ch > rp2->end) \
143 if (__builtin_expect (rp2 == NULL, 0) \
144 || __builtin_expect (ch < rp2->start, 0) \
145 || (res = __ibm933db_to_ucs4[ch + rp2->idx], \
146 __builtin_expect (res, L'\1') == L'\0' && ch != '\0')) \
148 /* This is an illegal character. */ \
149 if (! ignore_errors_p ()) \
151 result = __GCONV_ILLEGAL_INPUT; \
160 put32 (outptr, res); \
166 #define LOOP_NEED_FLAGS
167 #include <iconv/loop.c>
169 /* Next, define the other direction. */
170 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
171 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
172 #define INIT_PARAMS int curcs = init;
173 #define LOOPFCT TO_LOOP
176 uint32_t ch = get32 (inptr); \
177 const struct gap *rp1 = __ucs4_to_ibm933sb_idx; \
178 const struct gap *rp2 = __ucs4_to_ibm933db_idx; \
181 if (__builtin_expect (ch, 0) >= 0xffff) \
187 while (ch > rp1->end) \
190 /* Use the UCS4 table for single byte. */ \
191 if (__builtin_expect (rp1 == NULL, 0) \
192 || __builtin_expect (ch < rp1->start, 0) \
193 || (cp = __ucs4_to_ibm933sb[ch + rp1->idx], \
194 __builtin_expect (cp[0], L'\1') == L'\0' && ch != '\0')) \
196 /* Use the UCS4 table for double byte. */ \
197 while (ch > rp2->end) \
200 if (__builtin_expect (rp2 == NULL, 0) \
201 || __builtin_expect (ch < rp2->start, 0) \
202 || (cp = __ucs4_to_ibm933db[ch + rp2->idx], \
203 __builtin_expect (cp[0], L'\1')==L'\0' && ch != '\0')) \
205 /* This is an illegal character. */ \
206 if (! ignore_errors_p ()) \
208 result = __GCONV_ILLEGAL_INPUT; \
215 if (curcs == init || curcs == sb) \
217 if (__builtin_expect (outptr+1 > outend, 0)) \
219 result = __GCONV_FULL_OUTPUT; \
226 if (__builtin_expect (outptr + 2 > outend, 0)) \
228 result = __GCONV_FULL_OUTPUT; \
239 if (__builtin_expect (outptr + 1 > outend, 0)) \
241 result = __GCONV_FULL_OUTPUT; \
247 if (__builtin_expect (outptr + 1 > outend, 0)) \
249 result = __GCONV_FULL_OUTPUT; \
256 /* Now that we wrote the output increment the input pointer. */ \
259 #define LOOP_NEED_FLAGS
260 #include <iconv/loop.c>
262 /* Now define the toplevel functions. */
263 #include <iconv/skeleton.c>