Update.
[glibc.git] / iconvdata / euccn.c
blob89b8f48ebb81d5d7d5867bd6d7bbf0b65de1b661
1 /* Mapping tables for EUC-CN handling.
2 Copyright (C) 1998 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
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. */
21 #include <gb2312.h>
22 #include <stdint.h>
24 /* Definitions used in the body of the `gconv' function. */
25 #define CHARSET_NAME "EUC-CN//"
26 #define FROM_LOOP from_euc_cn
27 #define TO_LOOP to_euc_cn
28 #define DEFINE_INIT 1
29 #define DEFINE_FINI 1
30 #define MIN_NEEDED_FROM 1
31 #define MAX_NEEDED_FROM 2
32 #define MIN_NEEDED_TO 4
35 /* First define the conversion function from ISO 8859-1 to UCS4. */
36 #define MIN_NEEDED_INPUT MIN_NEEDED_FROM
37 #define MAX_NEEDED_INPUT MAX_NEEDED_FROM
38 #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
39 #define LOOPFCT FROM_LOOP
40 #define BODY \
41 { \
42 uint32_t ch = *inptr; \
44 if (ch <= 0x7f) \
45 ++inptr; \
46 else \
47 if ((ch <= 0xa0 || ch > 0xfe) && ch != 0x8e && ch != 0x8f) \
48 { \
49 /* This is illegal. */ \
50 result = GCONV_ILLEGAL_INPUT; \
51 break; \
52 } \
53 else \
54 { \
55 /* Two or more byte character. First test whether the \
56 next character is also available. */ \
57 const unsigned char *endp; \
59 if (NEED_LENGTH_TEST && inptr + 1 >= inend) \
60 { \
61 /* The second character is not available. Store \
62 the intermediate result. */ \
63 result = GCONV_INCOMPLETE_INPUT; \
64 break; \
65 } \
67 ch = inptr[1]; \
69 /* All second bytes of a multibyte character must be >= 0xa1. */ \
70 if (ch < 0xa1) \
71 { \
72 /* This is an illegal character. */ \
73 result = GCONV_ILLEGAL_INPUT; \
74 break; \
75 } \
77 /* This is code set 1: GB 2312-80. */ \
78 endp = inptr; \
80 ch = gb2312_to_ucs4 (&endp, 2, 0x80); \
81 if (ch == UNKNOWN_10646_CHAR) \
82 { \
83 /* This is an illegal character. */ \
84 result = GCONV_ILLEGAL_INPUT; \
85 break; \
86 } \
88 inptr += 2; \
89 } \
91 *((uint32_t *) outptr)++ = ch; \
93 #include <iconv/loop.c>
96 /* Next, define the other direction. */
97 #define MIN_NEEDED_INPUT MIN_NEEDED_TO
98 #define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
99 #define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
100 #define LOOPFCT TO_LOOP
101 #define BODY \
103 uint32_t ch = *((uint32_t *) inptr); \
105 if (ch <= L'\x7f') \
106 /* It's plain ASCII. */ \
107 *outptr++ = (unsigned char) ch; \
108 else \
110 size_t found; \
112 found = ucs4_to_gb2312 (ch, outptr, \
113 (NEED_LENGTH_TEST \
114 ? outend - outptr : MAX_NEEDED_OUTPUT)); \
115 if (!NEED_LENGTH_TEST || found != 0) \
117 if (found == UNKNOWN_10646_CHAR) \
119 /* Illegal character. */ \
120 result = GCONV_ILLEGAL_INPUT; \
121 break; \
124 /* It's a GB 2312 character, adjust it for EUC-CN. */ \
125 *outptr++ += 0x80; \
126 *outptr++ += 0x80; \
128 else \
130 /* We ran out of space. */ \
131 result = GCONV_FULL_OUTPUT; \
132 break; \
135 inptr += 4; \
137 #include <iconv/loop.c>
140 /* Now define the toplevel functions. */
141 #include <iconv/skeleton.c>