341N/A/*
341N/A * Copyright The Open Group
341N/A * Permission to use, copy, modify, distribute, and sell this software and its
341N/A * documentation for any purpose is hereby granted without fee, provided that the
341N/A * above copyright notice appear in all copies and that both that copyright notice
341N/A * and this permission notice appear in supporting documentation.
341N/A
341N/A * The above copyright notice and this permission notice shall be included in all
341N/A * copies or substantial portions of the Software.
341N/A
341N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
341N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
341N/A * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE OPEN GROUP
341N/A * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
341N/A * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
341N/A * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
341N/A
341N/A * Except as contained in this notice, the name of The Open Group shall not be used
341N/A * in advertising or otherwise to promote the sale, use or other dealings in this
341N/A * Software without prior written authorization from The Open Group.
341N/A
341N/A * Portions also covered by other licenses as noted in the above URL.
341N/A */
341N/A
341N/A/*
341N/A * GB18030 two-byte extension
341N/A */
341N/A
341N/Astatic const unsigned short gb18030ext_2uni_pagea9[13] = {
341N/A /* 0xa9 */
341N/A 0x303e, 0x2ff0, 0x2ff1, 0x2ff2, 0x2ff3, 0x2ff4, 0x2ff5, 0x2ff6,
341N/A 0x2ff7, 0x2ff8, 0x2ff9, 0x2ffa, 0x2ffb,
341N/A};
341N/Astatic const unsigned short gb18030ext_2uni_pagefe[95] = {
341N/A /* 0xfe */
341N/A 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
341N/A 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
341N/A 0x2e81, 0xfffd, 0xfffd, 0xfffd, 0x2e84, 0x3473, 0x3447, 0x2e88,
341N/A 0x2e8b, 0xfffd, 0x359e, 0x361a, 0x360e, 0x2e8c, 0x2e97, 0x396e,
341N/A 0x3918, 0xfffd, 0x39cf, 0x39df, 0x3a73, 0x39d0, 0xfffd, 0xfffd,
341N/A 0x3b4e, 0x3c6e, 0x3ce0, 0x2ea7, 0xfffd, 0xfffd, 0x2eaa, 0x4056,
341N/A 0x415f, 0x2eae, 0x4337, 0x2eb3, 0x2eb6, 0x2eb7, 0xfffd, 0x43b1,
341N/A 0x43ac, 0x2ebb, 0x43dd, 0x44d6, 0x4661, 0x464c, 0xfffd, 0x4723,
341N/A 0x4729, 0x477c, 0x478d, 0x2eca, 0x4947, 0x497a, 0x497d, 0x4982,
341N/A 0x4983, 0x4985, 0x4986, 0x499f, 0x499b, 0x49b7, 0x49b6, 0xfffd,
341N/A 0xfffd, 0x4ca3, 0x4c9f, 0x4ca0, 0x4ca1, 0x4c77, 0x4ca2, 0x4d13,
341N/A 0x4d14, 0x4d15, 0x4d16, 0x4d17, 0x4d18, 0x4d19, 0x4dae,
341N/A};
341N/A
341N/Astatic int
341N/Agb18030ext_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
341N/A{
341N/A unsigned char c1 = s[0];
341N/A if ((c1 == 0xa2) || (c1 >= 0xa8 && c1 <= 0xa9) || (c1 == 0xfe)) {
341N/A if (n >= 2) {
341N/A unsigned char c2 = s[1];
341N/A if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0x80 && c2 < 0xff)) {
341N/A unsigned int i = 190 * (c1 - 0x81) + (c2 - (c2 >= 0x80 ? 0x41 : 0x40));
341N/A unsigned short wc = 0xfffd;
341N/A if (i < 7410) {
341N/A if (i == 6432)
341N/A wc = 0x20ac;
341N/A } else if (i < 23750) {
341N/A if (i == 7536)
341N/A wc = 0x01f9;
341N/A else if (i >= 7672 && i < 7685)
341N/A wc = gb18030ext_2uni_pagea9[i-7672];
341N/A } else {
341N/A if (i < 23845)
341N/A wc = gb18030ext_2uni_pagefe[i-23750];
341N/A }
341N/A if (wc != 0xfffd) {
341N/A *pwc = (ucs4_t) wc;
341N/A return 2;
341N/A }
341N/A }
341N/A return RET_ILSEQ;
341N/A }
341N/A return RET_TOOFEW(0);
341N/A }
341N/A return RET_ILSEQ;
341N/A}
341N/A
341N/Astatic const unsigned short gb18030ext_page2e[80] = {
341N/A 0x0000, 0xfe50, 0x0000, 0x0000, 0xfe54, 0x0000, 0x0000, 0x0000, /*0x80-0x87*/
341N/A 0xfe57, 0x0000, 0x0000, 0xfe58, 0xfe5d, 0x0000, 0x0000, 0x0000, /*0x88-0x8f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe5e, /*0x90-0x97*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x98-0x9f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe6b, /*0xa0-0xa7*/
341N/A 0x0000, 0x0000, 0xfe6e, 0x0000, 0x0000, 0x0000, 0xfe71, 0x0000, /*0xa8-0xaf*/
341N/A 0x0000, 0x0000, 0x0000, 0xfe73, 0x0000, 0x0000, 0xfe74, 0xfe75, /*0xb0-0xb7*/
341N/A 0x0000, 0x0000, 0x0000, 0xfe79, 0x0000, 0x0000, 0x0000, 0x0000, /*0xb8-0xbf*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0xc0-0xc7*/
341N/A 0x0000, 0x0000, 0xfe84, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0xc8-0xcf*/
341N/A};
341N/Astatic const unsigned short gb18030ext_page2f[16] = {
341N/A 0xa98a, 0xa98b, 0xa98c, 0xa98d, 0xa98e, 0xa98f, 0xa990, 0xa991, /*0xf0-0xf7*/
341N/A 0xa992, 0xa993, 0xa994, 0xa995, 0x0000, 0x0000, 0x0000, 0x0000, /*0xf8-0xff*/
341N/A};
341N/Astatic const unsigned short gb18030ext_page34[56] = {
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe56, /*0x40-0x47*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x48-0x4f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x50-0x57*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x58-0x5f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x60-0x67*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x68-0x6f*/
341N/A 0x0000, 0x0000, 0x0000, 0xfe55, 0x0000, 0x0000, 0x0000, 0x0000, /*0x70-0x77*/
341N/A};
341N/Astatic const unsigned short gb18030ext_page36[24] = {
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe5c, 0x0000, /*0x08-0x0f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x10-0x17*/
341N/A 0x0000, 0x0000, 0xfe5b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x18-0x1f*/
341N/A};
341N/Astatic const unsigned short gb18030ext_page39[24] = {
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe62, /*0xc8-0xcf*/
341N/A 0xfe65, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0xd0-0xd7*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe63, /*0xd8-0xdf*/
341N/A};
341N/Astatic const unsigned short gb18030ext_page43[56] = {
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0xfe78, 0x0000, 0x0000, 0x0000, /*0xa8-0xaf*/
341N/A 0x0000, 0xfe77, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0xb0-0xb7*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0xb8-0xbf*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0xc0-0xc7*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0xc8-0xcf*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0xd0-0xd7*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe7a, 0x0000, 0x0000, /*0xd8-0xdf*/
341N/A};
341N/Astatic const unsigned short gb18030ext_page46[32] = {
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0xfe7d, 0x0000, 0x0000, 0x0000, /*0x48-0x4f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x50-0x57*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x58-0x5f*/
341N/A 0x0000, 0xfe7c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x60-0x67*/
341N/A};
341N/Astatic const unsigned short gb18030ext_page47_1[16] = {
341N/A 0x0000, 0x0000, 0x0000, 0xfe80, 0x0000, 0x0000, 0x0000, 0x0000, /*0x20-0x27*/
341N/A 0x0000, 0xfe81, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x28-0x2f*/
341N/A};
341N/Astatic const unsigned short gb18030ext_page47_2[24] = {
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0xfe82, 0x0000, 0x0000, 0x0000, /*0x78-0x7f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x80-0x87*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe83, 0x0000, 0x0000, /*0x88-0x8f*/
341N/A};
341N/Astatic const unsigned short gb18030ext_page49[120] = {
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe85, /*0x40-0x47*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x48-0x4f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x50-0x57*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x58-0x5f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x60-0x67*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x68-0x6f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x70-0x77*/
341N/A 0x0000, 0x0000, 0xfe86, 0x0000, 0x0000, 0xfe87, 0x0000, 0x0000, /*0x78-0x7f*/
341N/A 0x0000, 0x0000, 0xfe88, 0xfe89, 0x0000, 0xfe8a, 0xfe8b, 0x0000, /*0x80-0x87*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x88-0x8f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x90-0x97*/
341N/A 0x0000, 0x0000, 0x0000, 0xfe8d, 0x0000, 0x0000, 0x0000, 0xfe8c, /*0x98-0x9f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0xa0-0xa7*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0xa8-0xaf*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe8f, 0xfe8e, /*0xb0-0xb7*/
341N/A};
341N/Astatic const unsigned short gb18030ext_page4c[56] = {
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe96, /*0x70-0x77*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x78-0x7f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x80-0x87*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x88-0x8f*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x90-0x97*/
341N/A 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfe93, /*0x98-0x9f*/
341N/A 0xfe94, 0xfe95, 0xfe97, 0xfe92, 0x0000, 0x0000, 0x0000, 0x0000, /*0xa0-0xa7*/
341N/A};
341N/Astatic const unsigned short gb18030ext_page4d[16] = {
341N/A 0x0000, 0x0000, 0x0000, 0xfe98, 0xfe99, 0xfe9a, 0xfe9b, 0xfe9c, /*0x10-0x17*/
341N/A 0xfe9d, 0xfe9e, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x18-0x1f*/
341N/A};
341N/A
341N/Astatic int
341N/Agb18030ext_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
341N/A{
341N/A if (n >= 2) {
341N/A unsigned short c = 0;
341N/A if (wc == 0x01f9)
341N/A c = 0xa8bf;
341N/A else if (wc == 0x20ac)
341N/A c = 0xa2e3;
341N/A else if (wc >= 0x2e80 && wc < 0x2ed0)
341N/A c = gb18030ext_page2e[wc-0x2e80];
341N/A else if (wc >= 0x2ff0 && wc < 0x3000)
341N/A c = gb18030ext_page2f[wc-0x2ff0];
341N/A else if (wc == 0x303e)
341N/A c = 0xa989;
341N/A else if (wc >= 0x3440 && wc < 0x3478)
341N/A c = gb18030ext_page34[wc-0x3440];
341N/A else if (wc == 0x359e)
341N/A c = 0xfe5a;
341N/A else if (wc >= 0x3608 && wc < 0x3620)
341N/A c = gb18030ext_page36[wc-0x3608];
341N/A else if (wc == 0x3918)
341N/A c = 0xfe60;
341N/A else if (wc == 0x396e)
341N/A c = 0xfe5f;
341N/A else if (wc >= 0x39c8 && wc < 0x39e0)
341N/A c = gb18030ext_page39[wc-0x39c8];
341N/A else if (wc == 0x3a73)
341N/A c = 0xfe64;
341N/A else if (wc == 0x3b4e)
341N/A c = 0xfe68;
341N/A else if (wc == 0x3c6e)
341N/A c = 0xfe69;
341N/A else if (wc == 0x3ce0)
341N/A c = 0xfe6a;
341N/A else if (wc == 0x4056)
341N/A c = 0xfe6f;
341N/A else if (wc == 0x415f)
341N/A c = 0xfe70;
341N/A else if (wc == 0x4337)
341N/A c = 0xfe72;
341N/A else if (wc >= 0x43a8 && wc < 0x43e0)
341N/A c = gb18030ext_page43[wc-0x43a8];
341N/A else if (wc == 0x44d6)
341N/A c = 0xfe7b;
341N/A else if (wc >= 0x4648 && wc < 0x4668)
341N/A c = gb18030ext_page46[wc-0x4648];
341N/A else if (wc >= 0x4720 && wc < 0x4730)
341N/A c = gb18030ext_page47_1[wc-0x4720];
341N/A else if (wc >= 0x4778 && wc < 0x4790)
341N/A c = gb18030ext_page47_2[wc-0x4778];
341N/A else if (wc >= 0x4940 && wc < 0x49b8)
341N/A c = gb18030ext_page49[wc-0x4940];
341N/A else if (wc >= 0x4c70 && wc < 0x4ca8)
341N/A c = gb18030ext_page4c[wc-0x4c70];
341N/A else if (wc >= 0x4d10 && wc < 0x4d20)
341N/A c = gb18030ext_page4d[wc-0x4d10];
341N/A else if (wc == 0x4dae)
341N/A c = 0xfe9f;
341N/A if (c != 0) {
341N/A r[0] = (c >> 8); r[1] = (c & 0xff);
341N/A return 2;
341N/A }
341N/A return RET_ILSEQ;
341N/A }
341N/A return RET_TOOSMALL;
341N/A}