1/*
2 * Copyright (C) 1999-2010 Free Software Foundation, Inc.
3 * This file is part of the GNU LIBICONV Library.
4 *
5 * The GNU LIBICONV Library is free software; you can redistribute it
6 * and/or modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * The GNU LIBICONV Library is distributed in the hope that it will be
11 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with the GNU LIBICONV Library; see the file COPYING.LIB.
17 * If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
18 * Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21/*
22 * HKSCS:2008
23 */
24
25static const unsigned short hkscs2008_2uni_page87[126] = {
26  /* 0x87 */
27  0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd,
28  0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd,
29  0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd,
30  0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd,
31  0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd,
32  0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd,
33  0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd, 0x22fd,
34  0x22fd, 0x22fd, 0x0175, 0x2453, 0x299e, 0x2d21, 0x03ec, 0x2bde,
35  0x02f5, 0x16fc, 0x2197, 0x2a61, 0x300d, 0x26ea, 0x238a, 0x275e,
36  0x060a, 0x1884, 0x2196, 0x1f2f, 0x0930, 0x1a13, 0x0d96, 0x204a,
37  0x1e18, 0x15d0, 0x1632, 0x0f60, 0x1129, 0x1b9d, 0x144c, 0x17c5,
38  0x1082, 0x162c, 0x0a4f, 0x1d46, 0x00e6, 0x13c4, 0x2cb9, 0x14c6,
39  0x21c7, 0x0cb3, 0x092f, 0x0b4c, 0x0531, 0x298e, 0x0d18, 0x1672,
40  0x2f65, 0x1c8f, 0x08ae, 0x2e88, 0x0581, 0x2c99, 0x17ae, 0x25bc,
41  0x21c8, 0x25c1, 0x25c9, 0x25cc, 0x21c9, 0x1904, 0x28bb, 0x04b4,
42  0x21ca, 0x07e1, 0x31ff, 0x0ec1, 0x126e, 0x21cb,
43};
44
45static const ucs4_t hkscs2008_2uni_upages[50] = {
46  0x03400, 0x03800, 0x03a00, 0x03e00, 0x04000, 0x04100, 0x04300, 0x04400,
47  0x04600, 0x04900, 0x05200, 0x05400, 0x05700, 0x05800, 0x06200, 0x06600,
48  0x06700, 0x06a00, 0x07000, 0x07300, 0x07400, 0x07900, 0x07a00, 0x07b00,
49  0x08400, 0x08500, 0x08600, 0x08800, 0x08b00, 0x09000, 0x09200, 0x09400,
50  0x09700, 0x09f00, 0x0ff00, 0x20a00, 0x21d00, 0x22400, 0x23100, 0x23200,
51  0x23500, 0x23600, 0x24100, 0x25800, 0x25d00, 0x26000, 0x26e00, 0x27b00,
52  0x28900, 0x2ad00,
53};
54
55static int
56hkscs2008_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
57{
58  unsigned char c1 = s[0];
59  if ((c1 == 0x87)) {
60    if (n >= 2) {
61      unsigned char c2 = s[1];
62      if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0xa1 && c2 < 0xff)) {
63        unsigned int i = 157 * (c1 - 0x80) + (c2 - (c2 >= 0xa1 ? 0x62 : 0x40));
64        ucs4_t wc = 0xfffd;
65        unsigned short swc;
66        {
67          if (i < 1225)
68            swc = hkscs2008_2uni_page87[i-1099],
69            wc = hkscs2008_2uni_upages[swc>>8] | (swc & 0xff);
70        }
71        if (wc != 0xfffd) {
72          *pwc = wc;
73          return 2;
74        }
75      }
76      return RET_ILSEQ;
77    }
78    return RET_TOOFEW(0);
79  }
80  return RET_ILSEQ;
81}
82
83static const unsigned short hkscs2008_2charset[68] = {
84  0x87be, 0x877a, 0x87a2, 0x877e, 0x87d9, 0x87c6, 0x87ce, 0x87aa,
85  0x87db, 0x87cc, 0x87c4, 0x87ae, 0x87bc, 0x87c5, 0x87c3, 0x87c8,
86  0x87b0, 0x87dd, 0x87b5, 0x87ba, 0x87b6, 0x87de, 0x87bf, 0x87b8,
87  0x87c1, 0x87b3, 0x87bb, 0x87b4, 0x87c9, 0x87a3, 0x87d0, 0x87b9,
88  0x87ab, 0x87d7, 0x87af, 0x87b7, 0x87cb, 0x87bd, 0x87b2, 0x87ad,
89  0x87b1, 0x87ac, 0x87a4, 0x87c2, 0x87d2, 0x87d6, 0x87da, 0x87df,
90  0x87a8, 0x877b, 0x87d1, 0x87d3, 0x87d4, 0x87d5, 0x87a7, 0x87a9,
91  0x87d8, 0x87c7, 0x877c, 0x87a5, 0x87a1, 0x87cf, 0x87c0, 0x877d,
92  0x87cd, 0x87ca, 0x87a6, 0x87dc,
93};
94
95static const Summary16 hkscs2008_uni2indx_page34[15] = {
96  /* 0x3400 */
97  {    0, 0x0000 }, {    0, 0x0000 }, {    0, 0x0000 }, {    0, 0x0000 },
98  {    0, 0x0000 }, {    0, 0x0000 }, {    0, 0x0000 }, {    0, 0x0000 },
99  {    0, 0x0000 }, {    0, 0x0000 }, {    0, 0x0000 }, {    0, 0x0000 },
100  {    0, 0x0000 }, {    0, 0x0000 }, {    0, 0x0040 },
101};
102static const Summary16 hkscs2008_uni2indx_page38[8] = {
103  /* 0x3800 */
104  {    1, 0x0000 }, {    1, 0x0000 }, {    1, 0x0000 }, {    1, 0x0000 },
105  {    1, 0x0000 }, {    1, 0x0000 }, {    1, 0x0000 }, {    1, 0x0020 },
106};
107static const Summary16 hkscs2008_uni2indx_page3a[16] = {
108  /* 0x3a00 */
109  {    2, 0x0000 }, {    2, 0x0000 }, {    2, 0x0000 }, {    2, 0x0000 },
110  {    2, 0x0000 }, {    2, 0x0000 }, {    2, 0x0000 }, {    2, 0x0000 },
111  {    2, 0x0000 }, {    2, 0x0000 }, {    2, 0x0000 }, {    2, 0x0000 },
112  {    2, 0x0000 }, {    2, 0x0000 }, {    2, 0x0000 }, {    2, 0x0020 },
113};
114static const Summary16 hkscs2008_uni2indx_page3e[15] = {
115  /* 0x3e00 */
116  {    3, 0x0000 }, {    3, 0x0000 }, {    3, 0x0000 }, {    3, 0x0000 },
117  {    3, 0x0000 }, {    3, 0x0000 }, {    3, 0x0000 }, {    3, 0x0000 },
118  {    3, 0x0000 }, {    3, 0x0000 }, {    3, 0x0000 }, {    3, 0x0000 },
119  {    3, 0x0000 }, {    3, 0x0000 }, {    3, 0x1000 },
120};
121static const Summary16 hkscs2008_uni2indx_page40[25] = {
122  /* 0x4000 */
123  {    4, 0x0000 }, {    4, 0x0000 }, {    4, 0x0000 }, {    4, 0x0000 },
124  {    4, 0x0000 }, {    4, 0x0000 }, {    4, 0x0000 }, {    4, 0x0000 },
125  {    4, 0x0000 }, {    4, 0x0000 }, {    4, 0x0000 }, {    4, 0x0010 },
126  {    5, 0x0000 }, {    5, 0x0000 }, {    5, 0x0000 }, {    5, 0x0000 },
127  /* 0x4100 */
128  {    5, 0x0000 }, {    5, 0x0000 }, {    5, 0x0000 }, {    5, 0x0002 },
129  {    6, 0x0000 }, {    6, 0x0000 }, {    6, 0x0000 }, {    6, 0x0000 },
130  {    6, 0x0002 },
131};
132static const Summary16 hkscs2008_uni2indx_page43[31] = {
133  /* 0x4300 */
134  {    7, 0x0400 }, {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 },
135  {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 },
136  {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 },
137  {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 },
138  /* 0x4400 */
139  {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 },
140  {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 },
141  {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0000 },
142  {    8, 0x0000 }, {    8, 0x0000 }, {    8, 0x0002 },
143};
144static const Summary16 hkscs2008_uni2indx_page46[11] = {
145  /* 0x4600 */
146  {    9, 0x0000 }, {    9, 0x0000 }, {    9, 0x0000 }, {    9, 0x0000 },
147  {    9, 0x0000 }, {    9, 0x0000 }, {    9, 0x0000 }, {    9, 0x0000 },
148  {    9, 0x0000 }, {    9, 0x0000 }, {    9, 0x4000 },
149};
150static const Summary16 hkscs2008_uni2indx_page49[4] = {
151  /* 0x4900 */
152  {   10, 0x0000 }, {   10, 0x0000 }, {   10, 0x8000 }, {   11, 0x0001 },
153};
154static const Summary16 hkscs2008_uni2indx_page52[5] = {
155  /* 0x5200 */
156  {   12, 0x0000 }, {   12, 0x0000 }, {   12, 0x0000 }, {   12, 0x0000 },
157  {   12, 0x8000 },
158};
159static const Summary16 hkscs2008_uni2indx_page54[5] = {
160  /* 0x5400 */
161  {   13, 0x0000 }, {   13, 0x0000 }, {   13, 0x0000 }, {   13, 0x0000 },
162  {   13, 0x1000 },
163};
164static const Summary16 hkscs2008_uni2indx_page57[26] = {
165  /* 0x5700 */
166  {   14, 0x0000 }, {   14, 0x0000 }, {   14, 0x0000 }, {   14, 0x0000 },
167  {   14, 0x0000 }, {   14, 0x0000 }, {   14, 0x0000 }, {   14, 0x0000 },
168  {   14, 0x0000 }, {   14, 0x0000 }, {   14, 0x0000 }, {   14, 0x0008 },
169  {   15, 0x0000 }, {   15, 0x0000 }, {   15, 0x0000 }, {   15, 0x0000 },
170  /* 0x5800 */
171  {   15, 0x0000 }, {   15, 0x0100 }, {   16, 0x0000 }, {   16, 0x0000 },
172  {   16, 0x0000 }, {   16, 0x0000 }, {   16, 0x0000 }, {   16, 0x0000 },
173  {   16, 0x0000 }, {   16, 0x0040 },
174};
175static const Summary16 hkscs2008_uni2indx_page62[13] = {
176  /* 0x6200 */
177  {   17, 0x0000 }, {   17, 0x0000 }, {   17, 0x0000 }, {   17, 0x0000 },
178  {   17, 0x0000 }, {   17, 0x0000 }, {   17, 0x0000 }, {   17, 0x0000 },
179  {   17, 0x0000 }, {   17, 0x0000 }, {   17, 0x0000 }, {   17, 0x0000 },
180  {   17, 0x0002 },
181};
182static const Summary16 hkscs2008_uni2indx_page66[25] = {
183  /* 0x6600 */
184  {   18, 0x0000 }, {   18, 0x0000 }, {   18, 0x0000 }, {   18, 0x0000 },
185  {   18, 0x0000 }, {   18, 0x0000 }, {   18, 0x0001 }, {   19, 0x0000 },
186  {   19, 0x0000 }, {   19, 0x0000 }, {   19, 0x0000 }, {   19, 0x0000 },
187  {   19, 0x0000 }, {   19, 0x0000 }, {   19, 0x0000 }, {   19, 0x0000 },
188  /* 0x6700 */
189  {   19, 0x0000 }, {   19, 0x0000 }, {   19, 0x0000 }, {   19, 0x0000 },
190  {   19, 0x0000 }, {   19, 0x0000 }, {   19, 0x0000 }, {   19, 0x0000 },
191  {   19, 0x0004 },
192};
193static const Summary16 hkscs2008_uni2indx_page6a[3] = {
194  /* 0x6a00 */
195  {   20, 0x0000 }, {   20, 0x0000 }, {   20, 0x0200 },
196};
197static const Summary16 hkscs2008_uni2indx_page70[7] = {
198  /* 0x7000 */
199  {   21, 0x0000 }, {   21, 0x0000 }, {   21, 0x0000 }, {   21, 0x0000 },
200  {   21, 0x0000 }, {   21, 0x0000 }, {   21, 0x4000 },
201};
202static const Summary16 hkscs2008_uni2indx_page73[29] = {
203  /* 0x7300 */
204  {   22, 0x0000 }, {   22, 0x0000 }, {   22, 0x0000 }, {   22, 0x0000 },
205  {   22, 0x0000 }, {   22, 0x0000 }, {   22, 0x0000 }, {   22, 0x0000 },
206  {   22, 0x0000 }, {   22, 0x0000 }, {   22, 0x0000 }, {   22, 0x0000 },
207  {   22, 0x0010 }, {   23, 0x0000 }, {   23, 0x0000 }, {   23, 0x0000 },
208  /* 0x7400 */
209  {   23, 0x0000 }, {   23, 0x0000 }, {   23, 0x0000 }, {   23, 0x0000 },
210  {   23, 0x1000 }, {   24, 0x0000 }, {   24, 0x0000 }, {   24, 0x0000 },
211  {   24, 0x0000 }, {   24, 0x0000 }, {   24, 0x0000 }, {   24, 0x0000 },
212  {   24, 0x0040 },
213};
214static const Summary16 hkscs2008_uni2indx_page79[45] = {
215  /* 0x7900 */
216  {   25, 0x0000 }, {   25, 0x0000 }, {   25, 0x0000 }, {   25, 0x0000 },
217  {   25, 0x0000 }, {   25, 0x0000 }, {   25, 0x0000 }, {   25, 0x0000 },
218  {   25, 0x0000 }, {   25, 0x0000 }, {   25, 0x0000 }, {   25, 0x0000 },
219  {   25, 0x0000 }, {   25, 0x0001 }, {   26, 0x0000 }, {   26, 0x0000 },
220  /* 0x7a00 */
221  {   26, 0x0000 }, {   26, 0x0000 }, {   26, 0x1000 }, {   27, 0x0004 },
222  {   28, 0x0000 }, {   28, 0x0000 }, {   28, 0x0000 }, {   28, 0x0004 },
223  {   29, 0x0000 }, {   29, 0x0000 }, {   29, 0x0000 }, {   29, 0x0000 },
224  {   29, 0x0000 }, {   29, 0x0000 }, {   29, 0x0000 }, {   29, 0x1000 },
225  /* 0x7b00 */
226  {   30, 0x0000 }, {   30, 0x0000 }, {   30, 0x0000 }, {   30, 0x0000 },
227  {   30, 0x0000 }, {   30, 0x0000 }, {   30, 0x0000 }, {   30, 0x0000 },
228  {   30, 0x0000 }, {   30, 0x0000 }, {   30, 0x4000 }, {   31, 0x0000 },
229  {   31, 0x0020 },
230};
231static const Summary16 hkscs2008_uni2indx_page84[34] = {
232  /* 0x8400 */
233  {   32, 0x0000 }, {   32, 0x0000 }, {   32, 0x0000 }, {   32, 0x0000 },
234  {   32, 0x0000 }, {   32, 0x0000 }, {   32, 0x0000 }, {   32, 0x0000 },
235  {   32, 0x0010 }, {   33, 0x0000 }, {   33, 0x0000 }, {   33, 0x0000 },
236  {   33, 0x0000 }, {   33, 0x0000 }, {   33, 0x0000 }, {   33, 0x0000 },
237  /* 0x8500 */
238  {   33, 0x0010 }, {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 },
239  {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 },
240  {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 },
241  {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 },
242  /* 0x8600 */
243  {   34, 0x0000 }, {   34, 0x0008 },
244};
245static const Summary16 hkscs2008_uni2indx_page88[10] = {
246  /* 0x8800 */
247  {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 },
248  {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 },
249  {   35, 0x0000 }, {   35, 0x2000 },
250};
251static const Summary16 hkscs2008_uni2indx_page8b[9] = {
252  /* 0x8b00 */
253  {   36, 0x0000 }, {   36, 0x0000 }, {   36, 0x0000 }, {   36, 0x0000 },
254  {   36, 0x0000 }, {   36, 0x0000 }, {   36, 0x0000 }, {   36, 0x0000 },
255  {   36, 0x8000 },
256};
257static const Summary16 hkscs2008_uni2indx_page90[5] = {
258  /* 0x9000 */
259  {   37, 0x0000 }, {   37, 0x0000 }, {   37, 0x0000 }, {   37, 0x0000 },
260  {   37, 0x0040 },
261};
262static const Summary16 hkscs2008_uni2indx_page92[2] = {
263  /* 0x9200 */
264  {   38, 0x0000 }, {   38, 0x0100 },
265};
266static const Summary16 hkscs2008_uni2indx_page94[3] = {
267  /* 0x9400 */
268  {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x8000 },
269};
270static const Summary16 hkscs2008_uni2indx_page97[5] = {
271  /* 0x9700 */
272  {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0000 },
273  {   40, 0x0400 },
274};
275static const Summary16 hkscs2008_uni2indx_page9f[13] = {
276  /* 0x9f00 */
277  {   41, 0x0000 }, {   41, 0x0000 }, {   41, 0x0000 }, {   41, 0x0000 },
278  {   41, 0x0000 }, {   41, 0x0000 }, {   41, 0x0000 }, {   41, 0x0000 },
279  {   41, 0x0000 }, {   41, 0x00c0 }, {   43, 0x0000 }, {   43, 0x0000 },
280  {   43, 0x0f80 },
281};
282static const Summary16 hkscs2008_uni2indx_page20a[9] = {
283  /* 0x20a00 */
284  {   48, 0x0000 }, {   48, 0x0000 }, {   48, 0x0000 }, {   48, 0x0000 },
285  {   48, 0x0000 }, {   48, 0x0000 }, {   48, 0x0000 }, {   48, 0x0000 },
286  {   48, 0x0400 },
287};
288static const Summary16 hkscs2008_uni2indx_page21d[6] = {
289  /* 0x21d00 */
290  {   49, 0x0000 }, {   49, 0x0000 }, {   49, 0x0000 }, {   49, 0x0000 },
291  {   49, 0x0000 }, {   49, 0x0008 },
292};
293static const Summary16 hkscs2008_uni2indx_page224[13] = {
294  /* 0x22400 */
295  {   50, 0x0000 }, {   50, 0x0000 }, {   50, 0x0000 }, {   50, 0x0000 },
296  {   50, 0x0000 }, {   50, 0x0000 }, {   50, 0x0000 }, {   50, 0x0000 },
297  {   50, 0x0000 }, {   50, 0x0000 }, {   50, 0x0000 }, {   50, 0x1000 },
298  {   51, 0x1202 },
299};
300static const Summary16 hkscs2008_uni2indx_page231[22] = {
301  /* 0x23100 */
302  {   54, 0x0000 }, {   54, 0x0000 }, {   54, 0x0000 }, {   54, 0x0000 },
303  {   54, 0x0000 }, {   54, 0x0000 }, {   54, 0x0000 }, {   54, 0x0000 },
304  {   54, 0x0000 }, {   54, 0x0000 }, {   54, 0x0000 }, {   54, 0x0000 },
305  {   54, 0x0000 }, {   54, 0x0000 }, {   54, 0x0400 }, {   55, 0x0000 },
306  /* 0x23200 */
307  {   55, 0x0000 }, {   55, 0x0000 }, {   55, 0x0000 }, {   55, 0x0000 },
308  {   55, 0x0000 }, {   55, 0x4000 },
309};
310static const Summary16 hkscs2008_uni2indx_page235[26] = {
311  /* 0x23500 */
312  {   56, 0x0000 }, {   56, 0x0000 }, {   56, 0x0000 }, {   56, 0x0000 },
313  {   56, 0x0000 }, {   56, 0x0000 }, {   56, 0x0000 }, {   56, 0x0000 },
314  {   56, 0x0000 }, {   56, 0x0000 }, {   56, 0x0000 }, {   56, 0x0800 },
315  {   57, 0x0000 }, {   57, 0x0000 }, {   57, 0x0000 }, {   57, 0x0000 },
316  /* 0x23600 */
317  {   57, 0x0000 }, {   57, 0x0000 }, {   57, 0x0000 }, {   57, 0x0000 },
318  {   57, 0x0000 }, {   57, 0x0000 }, {   57, 0x0000 }, {   57, 0x0000 },
319  {   57, 0x4000 }, {   58, 0x4000 },
320};
321static const Summary16 hkscs2008_uni2indx_page241[7] = {
322  /* 0x24100 */
323  {   59, 0x0000 }, {   59, 0x0000 }, {   59, 0x0000 }, {   59, 0x0000 },
324  {   59, 0x0000 }, {   59, 0x0000 }, {   59, 0x0002 },
325};
326static const Summary16 hkscs2008_uni2indx_page258[14] = {
327  /* 0x25800 */
328  {   60, 0x0000 }, {   60, 0x0000 }, {   60, 0x0000 }, {   60, 0x0000 },
329  {   60, 0x0000 }, {   60, 0x0000 }, {   60, 0x0000 }, {   60, 0x0000 },
330  {   60, 0x0000 }, {   60, 0x0000 }, {   60, 0x0000 }, {   60, 0x0000 },
331  {   60, 0x0000 }, {   60, 0x4000 },
332};
333static const Summary16 hkscs2008_uni2indx_page25d[12] = {
334  /* 0x25d00 */
335  {   61, 0x0000 }, {   61, 0x0000 }, {   61, 0x0000 }, {   61, 0x0000 },
336  {   61, 0x0000 }, {   61, 0x0000 }, {   61, 0x0000 }, {   61, 0x0000 },
337  {   61, 0x0000 }, {   61, 0x0200 }, {   62, 0x0000 }, {   62, 0x0200 },
338};
339static const Summary16 hkscs2008_uni2indx_page260[3] = {
340  /* 0x26000 */
341  {   63, 0x0000 }, {   63, 0x0000 }, {   63, 0x0002 },
342};
343static const Summary16 hkscs2008_uni2indx_page26e[9] = {
344  /* 0x26e00 */
345  {   64, 0x0000 }, {   64, 0x0000 }, {   64, 0x0000 }, {   64, 0x0000 },
346  {   64, 0x0000 }, {   64, 0x0000 }, {   64, 0x0000 }, {   64, 0x0000 },
347  {   64, 0x0100 },
348};
349static const Summary16 hkscs2008_uni2indx_page27b[7] = {
350  /* 0x27b00 */
351  {   65, 0x0000 }, {   65, 0x0000 }, {   65, 0x0000 }, {   65, 0x0000 },
352  {   65, 0x0000 }, {   65, 0x0000 }, {   65, 0x0020 },
353};
354static const Summary16 hkscs2008_uni2indx_page289[1] = {
355  /* 0x28900 */
356  {   66, 0x2000 },
357};
358static const Summary16 hkscs2008_uni2indx_page2ad[16] = {
359  /* 0x2ad00 */
360  {   67, 0x0000 }, {   67, 0x0000 }, {   67, 0x0000 }, {   67, 0x0000 },
361  {   67, 0x0000 }, {   67, 0x0000 }, {   67, 0x0000 }, {   67, 0x0000 },
362  {   67, 0x0000 }, {   67, 0x0000 }, {   67, 0x0000 }, {   67, 0x0000 },
363  {   67, 0x0000 }, {   67, 0x0000 }, {   67, 0x0000 }, {   67, 0x8000 },
364};
365
366static int
367hkscs2008_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
368{
369  if (n >= 2) {
370    const Summary16 *summary = NULL;
371    if (wc >= 0x3400 && wc < 0x34f0)
372      summary = &hkscs2008_uni2indx_page34[(wc>>4)-0x340];
373    else if (wc >= 0x3800 && wc < 0x3880)
374      summary = &hkscs2008_uni2indx_page38[(wc>>4)-0x380];
375    else if (wc >= 0x3a00 && wc < 0x3b00)
376      summary = &hkscs2008_uni2indx_page3a[(wc>>4)-0x3a0];
377    else if (wc >= 0x3e00 && wc < 0x3ef0)
378      summary = &hkscs2008_uni2indx_page3e[(wc>>4)-0x3e0];
379    else if (wc >= 0x4000 && wc < 0x4190)
380      summary = &hkscs2008_uni2indx_page40[(wc>>4)-0x400];
381    else if (wc >= 0x4300 && wc < 0x44f0)
382      summary = &hkscs2008_uni2indx_page43[(wc>>4)-0x430];
383    else if (wc >= 0x4600 && wc < 0x46b0)
384      summary = &hkscs2008_uni2indx_page46[(wc>>4)-0x460];
385    else if (wc >= 0x4900 && wc < 0x4940)
386      summary = &hkscs2008_uni2indx_page49[(wc>>4)-0x490];
387    else if (wc >= 0x5200 && wc < 0x5250)
388      summary = &hkscs2008_uni2indx_page52[(wc>>4)-0x520];
389    else if (wc >= 0x5400 && wc < 0x5450)
390      summary = &hkscs2008_uni2indx_page54[(wc>>4)-0x540];
391    else if (wc >= 0x5700 && wc < 0x58a0)
392      summary = &hkscs2008_uni2indx_page57[(wc>>4)-0x570];
393    else if (wc >= 0x6200 && wc < 0x62d0)
394      summary = &hkscs2008_uni2indx_page62[(wc>>4)-0x620];
395    else if (wc >= 0x6600 && wc < 0x6790)
396      summary = &hkscs2008_uni2indx_page66[(wc>>4)-0x660];
397    else if (wc >= 0x6a00 && wc < 0x6a30)
398      summary = &hkscs2008_uni2indx_page6a[(wc>>4)-0x6a0];
399    else if (wc >= 0x7000 && wc < 0x7070)
400      summary = &hkscs2008_uni2indx_page70[(wc>>4)-0x700];
401    else if (wc >= 0x7300 && wc < 0x74d0)
402      summary = &hkscs2008_uni2indx_page73[(wc>>4)-0x730];
403    else if (wc >= 0x7900 && wc < 0x7bd0)
404      summary = &hkscs2008_uni2indx_page79[(wc>>4)-0x790];
405    else if (wc >= 0x8400 && wc < 0x8620)
406      summary = &hkscs2008_uni2indx_page84[(wc>>4)-0x840];
407    else if (wc >= 0x8800 && wc < 0x88a0)
408      summary = &hkscs2008_uni2indx_page88[(wc>>4)-0x880];
409    else if (wc >= 0x8b00 && wc < 0x8b90)
410      summary = &hkscs2008_uni2indx_page8b[(wc>>4)-0x8b0];
411    else if (wc >= 0x9000 && wc < 0x9050)
412      summary = &hkscs2008_uni2indx_page90[(wc>>4)-0x900];
413    else if (wc >= 0x9200 && wc < 0x9220)
414      summary = &hkscs2008_uni2indx_page92[(wc>>4)-0x920];
415    else if (wc >= 0x9400 && wc < 0x9430)
416      summary = &hkscs2008_uni2indx_page94[(wc>>4)-0x940];
417    else if (wc >= 0x9700 && wc < 0x9750)
418      summary = &hkscs2008_uni2indx_page97[(wc>>4)-0x970];
419    else if (wc >= 0x9f00 && wc < 0x9fd0)
420      summary = &hkscs2008_uni2indx_page9f[(wc>>4)-0x9f0];
421    else if (wc >= 0x20a00 && wc < 0x20a90)
422      summary = &hkscs2008_uni2indx_page20a[(wc>>4)-0x20a0];
423    else if (wc >= 0x21d00 && wc < 0x21d60)
424      summary = &hkscs2008_uni2indx_page21d[(wc>>4)-0x21d0];
425    else if (wc >= 0x22400 && wc < 0x224d0)
426      summary = &hkscs2008_uni2indx_page224[(wc>>4)-0x2240];
427    else if (wc >= 0x23100 && wc < 0x23260)
428      summary = &hkscs2008_uni2indx_page231[(wc>>4)-0x2310];
429    else if (wc >= 0x23500 && wc < 0x236a0)
430      summary = &hkscs2008_uni2indx_page235[(wc>>4)-0x2350];
431    else if (wc >= 0x24100 && wc < 0x24170)
432      summary = &hkscs2008_uni2indx_page241[(wc>>4)-0x2410];
433    else if (wc >= 0x25800 && wc < 0x258e0)
434      summary = &hkscs2008_uni2indx_page258[(wc>>4)-0x2580];
435    else if (wc >= 0x25d00 && wc < 0x25dc0)
436      summary = &hkscs2008_uni2indx_page25d[(wc>>4)-0x25d0];
437    else if (wc >= 0x26000 && wc < 0x26030)
438      summary = &hkscs2008_uni2indx_page260[(wc>>4)-0x2600];
439    else if (wc >= 0x26e00 && wc < 0x26e90)
440      summary = &hkscs2008_uni2indx_page26e[(wc>>4)-0x26e0];
441    else if (wc >= 0x27b00 && wc < 0x27b70)
442      summary = &hkscs2008_uni2indx_page27b[(wc>>4)-0x27b0];
443    else if (wc >= 0x28900 && wc < 0x28910)
444      summary = &hkscs2008_uni2indx_page289[(wc>>4)-0x2890];
445    else if (wc >= 0x2ad00 && wc < 0x2ae00)
446      summary = &hkscs2008_uni2indx_page2ad[(wc>>4)-0x2ad0];
447    if (summary) {
448      unsigned short used = summary->used;
449      unsigned int i = wc & 0x0f;
450      if (used & ((unsigned short) 1 << i)) {
451        unsigned short c;
452        /* Keep in `used' only the bits 0..i-1. */
453        used &= ((unsigned short) 1 << i) - 1;
454        /* Add `summary->indx' and the number of bits set in `used'. */
455        used = (used & 0x5555) + ((used & 0xaaaa) >> 1);
456        used = (used & 0x3333) + ((used & 0xcccc) >> 2);
457        used = (used & 0x0f0f) + ((used & 0xf0f0) >> 4);
458        used = (used & 0x00ff) + (used >> 8);
459        c = hkscs2008_2charset[summary->indx + used];
460        r[0] = (c >> 8); r[1] = (c & 0xff);
461        return 2;
462      }
463    }
464    return RET_ILUNI;
465  }
466  return RET_TOOSMALL;
467}
468