[MALLOC_DEBUG]: Keep track of current maximum number of mmaps. n_mmaps_max is the...
[glibc.git] / iconvdata / gb2312.h
blobf5eaaf2224ac163b20f3ec3d1f96cee61d8ec408
1 /* Access functions for GB2312 conversion.
2 Copyright (C) 1998, 1999, 2003 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 Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the 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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef _GB2312_H
22 #define _GB2312_H 1
24 #include <gconv.h>
25 #include <stdint.h>
26 #include <assert.h>
28 /* Conversion table. */
29 extern const uint16_t __gb2312_to_ucs[];
32 static inline uint32_t
33 __attribute ((always_inline))
34 gb2312_to_ucs4 (const unsigned char **s, size_t avail, unsigned char offset)
36 unsigned char ch = *(*s);
37 unsigned char ch2;
38 int idx;
40 if (ch < offset || (ch - offset) <= 0x20 || (ch - offset) > 0x77)
41 return __UNKNOWN_10646_CHAR;
43 if (avail < 2)
44 return 0;
46 ch2 = (*s)[1];
47 if ((ch2 - offset) <= 0x20 || (ch2 - offset) >= 0x7f)
48 return __UNKNOWN_10646_CHAR;
50 idx = (ch - 0x21 - offset) * 94 + (ch2 - 0x21 - offset);
51 if (idx > 0x1ff1)
52 return __UNKNOWN_10646_CHAR;
54 (*s) += 2;
56 return __gb2312_to_ucs[idx] ?: ((*s) -= 2, __UNKNOWN_10646_CHAR);
60 extern const char __gb2312_from_ucs4_tab1[][2];
61 extern const char __gb2312_from_ucs4_tab2[][2];
62 extern const char __gb2312_from_ucs4_tab3[][2];
63 extern const char __gb2312_from_ucs4_tab4[][2];
64 extern const char __gb2312_from_ucs4_tab5[][2];
65 extern const char __gb2312_from_ucs4_tab6[][2];
66 extern const char __gb2312_from_ucs4_tab7[][2];
67 extern const char __gb2312_from_ucs4_tab8[][2];
68 extern const char __gb2312_from_ucs4_tab9[][2];
70 static inline size_t
71 __attribute ((always_inline))
72 ucs4_to_gb2312 (uint32_t wch, unsigned char *s, size_t avail)
74 unsigned int ch = (unsigned int) wch;
75 char buf[2];
76 const char *cp = buf;
78 switch (ch)
80 case 0xa4 ... 0x101:
81 cp = __gb2312_from_ucs4_tab1[ch - 0xa4];
82 break;
83 case 0x113:
84 cp = "\x28\x25";
85 break;
86 case 0x11b:
87 cp = "\x28\x27";
88 break;
89 case 0x12b:
90 cp = "\x28\x29";
91 break;
92 case 0x14d:
93 cp = "\x28\x2d";
94 break;
95 case 0x16b:
96 cp = "\x28\x31";
97 break;
98 case 0x1ce:
99 cp = "\x28\x23";
100 break;
101 case 0x1d0:
102 cp = "\x28\x2b";
103 break;
104 case 0x1d2:
105 cp = "\x28\x2f";
106 break;
107 case 0x1d4:
108 cp = "\x28\x33";
109 break;
110 case 0x1d6:
111 cp = "\x28\x35";
112 break;
113 case 0x1d8:
114 cp = "\x28\x36";
115 break;
116 case 0x1da:
117 cp = "\x28\x37";
118 break;
119 case 0x1dc:
120 cp = "\x28\x38";
121 break;
122 case 0x2c7:
123 cp = "\x21\x26";
124 break;
125 case 0x2c9:
126 cp = "\x21\x25";
127 break;
128 case 0x391 ... 0x3c9:
129 cp = __gb2312_from_ucs4_tab2[ch - 0x391];
130 break;
131 case 0x401 ... 0x451:
132 cp = __gb2312_from_ucs4_tab3[ch - 0x401];
133 break;
134 case 0x2015 ... 0x203b:
135 cp = __gb2312_from_ucs4_tab4[ch - 0x2015];
136 break;
137 case 0x2103 ... 0x22a5:
138 cp = __gb2312_from_ucs4_tab5[ch - 0x2103];
139 break;
140 case 0x2312:
141 cp = "\x21\x50";
142 break;
143 case 0x2460 ... 0x249b:
144 cp = __gb2312_from_ucs4_tab6[ch - 0x2460];
145 break;
146 case 0x2500 ... 0x254b:
147 buf[0] = '\x29';
148 buf[1] = '\x24' + (ch % 256);
149 break;
150 case 0x25a0:
151 cp = "\x21\x76";
152 break;
153 case 0x25a1:
154 cp = "\x21\x75";
155 break;
156 case 0x25b2:
157 cp = "\x21\x78";
158 break;
159 case 0x25b3:
160 cp = "\x21\x77";
161 break;
162 case 0x25c6:
163 cp = "\x21\x74";
164 break;
165 case 0x25c7:
166 cp = "\x21\x73";
167 break;
168 case 0x25cb:
169 cp = "\x21\x70";
170 break;
171 case 0x25ce:
172 cp = "\x21\x72";
173 break;
174 case 0x25cf:
175 cp = "\x21\x71";
176 break;
177 case 0x2605:
178 cp = "\x21\x6f";
179 break;
180 case 0x2606:
181 cp = "\x21\x6e";
182 break;
183 case 0x2640:
184 cp = "\x21\x62";
185 break;
186 case 0x2642:
187 cp = "\x21\x61";
188 break;
189 case 0x3000 ... 0x3129:
190 cp = __gb2312_from_ucs4_tab7[ch - 0x3000];
191 break;
192 case 0x3220 ... 0x3229:
193 buf[0] = '\x22';
194 buf[1] = '\x65' + (ch - 0x3220);
195 break;
196 case 0x4e00 ... 0x9fa0:
197 cp = __gb2312_from_ucs4_tab8[ch - 0x4e00];
198 break;
199 case 0xff01 ... 0xff5e:
200 cp = __gb2312_from_ucs4_tab9[ch - 0xff01];
201 break;
202 case 0xffe0:
203 cp = "\x21\x69";
204 break;
205 case 0xffe1:
206 cp = "\x21\x6a";
207 break;
208 case 0xffe3:
209 cp = "\x23\x7e";
210 break;
211 case 0xffe5:
212 cp = "\x23\x24";
213 break;
214 default:
215 return __UNKNOWN_10646_CHAR;
218 if (cp[0] == '\0')
219 return __UNKNOWN_10646_CHAR;
221 assert (cp[1] != '\0');
223 if (avail < 2)
224 return 0;
226 s[0] = cp[0];
227 s[1] = cp[1];
229 return 2;
232 #endif /* gb2312.h */