Annotation of embedaddon/libiconv/lib/cp950ext.h, revision 1.1.1.2

1.1       misho       1: /*
1.1.1.2 ! misho       2:  * Copyright (C) 1999-2001, 2012, 2016 Free Software Foundation, Inc.
1.1       misho       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.
1.1.1.2 ! misho      17:  * If not, see <https://www.gnu.org/licenses/>.
1.1       misho      18:  */
                     19: 
                     20: /*
                     21:  * CP950 extensions
                     22:  */
                     23: 
                     24: static const unsigned short cp950ext_2uni_pagef9[157-116] = {
                     25:   /* 0xf9 */
                     26:                                   0x7881, 0x92b9, 0x88cf, 0x58bb,
                     27:   0x6052, 0x7ca7, 0x5afa, 0x2554, 0x2566, 0x2557, 0x2560, 0x256c,
                     28:   0x2563, 0x255a, 0x2569, 0x255d, 0x2552, 0x2564, 0x2555, 0x255e,
                     29:   0x256a, 0x2561, 0x2558, 0x2567, 0x255b, 0x2553, 0x2565, 0x2556,
                     30:   0x255f, 0x256b, 0x2562, 0x2559, 0x2568, 0x255c, 0x2551, 0x2550,
                     31:   0x256d, 0x256e, 0x2570, 0x256f, 0x2593,
                     32: };
                     33: 
                     34: static int
1.1.1.2 ! misho      35: cp950ext_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, size_t n)
1.1       misho      36: {
                     37:   unsigned char c1 = s[0];
                     38:   if ((c1 == 0xf9)) {
                     39:     if (n >= 2) {
                     40:       unsigned char c2 = s[1];
                     41:       if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0xa1 && c2 < 0xff)) {
                     42:         unsigned int i = 157 * (c1 - 0xa1) + (c2 - (c2 >= 0xa1 ? 0x62 : 0x40));
                     43:         unsigned short wc = 0xfffd;
                     44:         {
                     45:           if (i >= 13932 && i < 13973)
                     46:             wc = cp950ext_2uni_pagef9[i-13932];
                     47:         }
                     48:         if (wc != 0xfffd) {
                     49:           *pwc = (ucs4_t) wc;
                     50:           return 2;
                     51:         }
                     52:       }
                     53:       return RET_ILSEQ;
                     54:     }
                     55:     return RET_TOOFEW(0);
                     56:   }
                     57:   return RET_ILSEQ;
                     58: }
                     59: 
                     60: static const unsigned short cp950ext_2charset[41] = {
                     61:   0xf9f9, 0xf9f8, 0xf9e6, 0xf9ef, 0xf9dd, 0xf9e8, 0xf9f1, 0xf9df,
                     62:   0xf9ec, 0xf9f5, 0xf9e3, 0xf9ee, 0xf9f7, 0xf9e5, 0xf9e9, 0xf9f2,
                     63:   0xf9e0, 0xf9eb, 0xf9f4, 0xf9e2, 0xf9e7, 0xf9f0, 0xf9de, 0xf9ed,
                     64:   0xf9f6, 0xf9e4, 0xf9ea, 0xf9f3, 0xf9e1, 0xf9fa, 0xf9fb, 0xf9fd,
                     65:   0xf9fc, 0xf9fe, 0xf9d9, 0xf9dc, 0xf9da, 0xf9d6, 0xf9db, 0xf9d8,
                     66:   0xf9d7,
                     67: };
                     68: 
                     69: static const Summary16 cp950ext_uni2indx_page25[10] = {
                     70:   /* 0x2500 */
                     71:   {    0, 0x0000 }, {    0, 0x0000 }, {    0, 0x0000 }, {    0, 0x0000 },
                     72:   {    0, 0x0000 }, {    0, 0xffff }, {   16, 0xffff }, {   32, 0x0001 },
                     73:   {   33, 0x0000 }, {   33, 0x0008 },
                     74: };
                     75: static const Summary16 cp950ext_uni2indx_page58[12] = {
                     76:   /* 0x5800 */
                     77:   {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 },
                     78:   {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 },
                     79:   {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0800 },
                     80: };
                     81: static const Summary16 cp950ext_uni2indx_page5a[16] = {
                     82:   /* 0x5a00 */
                     83:   {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 },
                     84:   {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 },
                     85:   {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 },
                     86:   {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0400 },
                     87: };
                     88: static const Summary16 cp950ext_uni2indx_page60[6] = {
                     89:   /* 0x6000 */
                     90:   {   36, 0x0000 }, {   36, 0x0000 }, {   36, 0x0000 }, {   36, 0x0000 },
                     91:   {   36, 0x0000 }, {   36, 0x0004 },
                     92: };
                     93: static const Summary16 cp950ext_uni2indx_page78[9] = {
                     94:   /* 0x7800 */
                     95:   {   37, 0x0000 }, {   37, 0x0000 }, {   37, 0x0000 }, {   37, 0x0000 },
                     96:   {   37, 0x0000 }, {   37, 0x0000 }, {   37, 0x0000 }, {   37, 0x0000 },
                     97:   {   37, 0x0002 },
                     98: };
                     99: static const Summary16 cp950ext_uni2indx_page7c[11] = {
                    100:   /* 0x7c00 */
                    101:   {   38, 0x0000 }, {   38, 0x0000 }, {   38, 0x0000 }, {   38, 0x0000 },
                    102:   {   38, 0x0000 }, {   38, 0x0000 }, {   38, 0x0000 }, {   38, 0x0000 },
                    103:   {   38, 0x0000 }, {   38, 0x0000 }, {   38, 0x0080 },
                    104: };
                    105: static const Summary16 cp950ext_uni2indx_page88[13] = {
                    106:   /* 0x8800 */
                    107:   {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x0000 },
                    108:   {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x0000 },
                    109:   {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x0000 },
                    110:   {   39, 0x8000 },
                    111: };
                    112: static const Summary16 cp950ext_uni2indx_page92[12] = {
                    113:   /* 0x9200 */
                    114:   {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0000 },
                    115:   {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0000 },
                    116:   {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0200 },
                    117: };
                    118: 
                    119: static int
1.1.1.2 ! misho     120: cp950ext_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, size_t n)
1.1       misho     121: {
                    122:   if (n >= 2) {
                    123:     const Summary16 *summary = NULL;
                    124:     if (wc >= 0x2500 && wc < 0x25a0)
                    125:       summary = &cp950ext_uni2indx_page25[(wc>>4)-0x250];
                    126:     else if (wc >= 0x5800 && wc < 0x58c0)
                    127:       summary = &cp950ext_uni2indx_page58[(wc>>4)-0x580];
                    128:     else if (wc >= 0x5a00 && wc < 0x5b00)
                    129:       summary = &cp950ext_uni2indx_page5a[(wc>>4)-0x5a0];
                    130:     else if (wc >= 0x6000 && wc < 0x6060)
                    131:       summary = &cp950ext_uni2indx_page60[(wc>>4)-0x600];
                    132:     else if (wc >= 0x7800 && wc < 0x7890)
                    133:       summary = &cp950ext_uni2indx_page78[(wc>>4)-0x780];
                    134:     else if (wc >= 0x7c00 && wc < 0x7cb0)
                    135:       summary = &cp950ext_uni2indx_page7c[(wc>>4)-0x7c0];
                    136:     else if (wc >= 0x8800 && wc < 0x88d0)
                    137:       summary = &cp950ext_uni2indx_page88[(wc>>4)-0x880];
                    138:     else if (wc >= 0x9200 && wc < 0x92c0)
                    139:       summary = &cp950ext_uni2indx_page92[(wc>>4)-0x920];
                    140:     if (summary) {
                    141:       unsigned short used = summary->used;
                    142:       unsigned int i = wc & 0x0f;
                    143:       if (used & ((unsigned short) 1 << i)) {
                    144:         unsigned short c;
1.1.1.2 ! misho     145:         /* Keep in 'used' only the bits 0..i-1. */
1.1       misho     146:         used &= ((unsigned short) 1 << i) - 1;
1.1.1.2 ! misho     147:         /* Add 'summary->indx' and the number of bits set in 'used'. */
1.1       misho     148:         used = (used & 0x5555) + ((used & 0xaaaa) >> 1);
                    149:         used = (used & 0x3333) + ((used & 0xcccc) >> 2);
                    150:         used = (used & 0x0f0f) + ((used & 0xf0f0) >> 4);
                    151:         used = (used & 0x00ff) + (used >> 8);
                    152:         c = cp950ext_2charset[summary->indx + used];
                    153:         r[0] = (c >> 8); r[1] = (c & 0xff);
                    154:         return 2;
                    155:       }
                    156:     }
                    157:     return RET_ILUNI;
                    158:   }
                    159:   return RET_TOOSMALL;
                    160: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>