xref: /titanic_50/usr/src/lib/iconv_modules/inc/unicode_viscii.h (revision 880d797826457b77414b37d531cc3e1aa166ecbe)
1*880d7978SAlexander Pyhalov /*
2*880d7978SAlexander Pyhalov  * CDDL HEADER START
3*880d7978SAlexander Pyhalov  *
4*880d7978SAlexander Pyhalov  * The contents of this file are subject to the terms of the
5*880d7978SAlexander Pyhalov  * Common Development and Distribution License (the "License").
6*880d7978SAlexander Pyhalov  * You may not use this file except in compliance with the License.
7*880d7978SAlexander Pyhalov  *
8*880d7978SAlexander Pyhalov  * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
9*880d7978SAlexander Pyhalov  * or http://www.opensolaris.org/os/licensing.
10*880d7978SAlexander Pyhalov  * See the License for the specific language governing permissions
11*880d7978SAlexander Pyhalov  * and limitations under the License.
12*880d7978SAlexander Pyhalov  *
13*880d7978SAlexander Pyhalov  * When distributing Covered Code, include this CDDL HEADER in each
14*880d7978SAlexander Pyhalov  * file and include the License file at src/OPENSOLARIS.LICENSE.
15*880d7978SAlexander Pyhalov  * If applicable, add the following below this CDDL HEADER, with the
16*880d7978SAlexander Pyhalov  * fields enclosed by brackets "[]" replaced with your own identifying
17*880d7978SAlexander Pyhalov  * information: Portions Copyright [yyyy] [name of copyright owner]
18*880d7978SAlexander Pyhalov  *
19*880d7978SAlexander Pyhalov  * CDDL HEADER END
20*880d7978SAlexander Pyhalov  */
21*880d7978SAlexander Pyhalov /*
22*880d7978SAlexander Pyhalov  * COPYRIGHT AND PERMISSION NOTICE
23*880d7978SAlexander Pyhalov  *
24*880d7978SAlexander Pyhalov  * Copyright (c) 1991-2005 Unicode, Inc. All rights reserved. Distributed
25*880d7978SAlexander Pyhalov  *  under the Terms of Use in http://www.unicode.org/copyright.html.
26*880d7978SAlexander Pyhalov  *
27*880d7978SAlexander Pyhalov  * This file has been modified by Sun Microsystems, Inc.
28*880d7978SAlexander Pyhalov  *
29*880d7978SAlexander Pyhalov */
30*880d7978SAlexander Pyhalov /*
31*880d7978SAlexander Pyhalov  * Copyright(c) 2008 Sun Microsystems, Inc.
32*880d7978SAlexander Pyhalov  * All rights reserved.
33*880d7978SAlexander Pyhalov  */
34*880d7978SAlexander Pyhalov 
35*880d7978SAlexander Pyhalov #ifndef _UNICODE_VISCII_H_
36*880d7978SAlexander Pyhalov #define _UNICODE_VISCII_H_
37*880d7978SAlexander Pyhalov 
38*880d7978SAlexander Pyhalov #include <public_struc.h>
39*880d7978SAlexander Pyhalov 
40*880d7978SAlexander Pyhalov 
41*880d7978SAlexander Pyhalov static const unsigned long viscii2uni_1[32] = {
42*880d7978SAlexander Pyhalov     /*
43*880d7978SAlexander Pyhalov     * 0x00 - Ox1f
44*880d7978SAlexander Pyhalov     */
45*880d7978SAlexander Pyhalov     0x0000,  0x0001,  0x1EB2,  0x0003,  0x0004,  0x1EB4,  0x1EAA,  0x0007,
46*880d7978SAlexander Pyhalov     0x0008,  0x0009,  0x000A,  0x000B,  0x000C,  0x000D,  0x000E,  0x000F,
47*880d7978SAlexander Pyhalov     0x0010,  0x0011,  0x0012,  0x0013,  0x1EF6,  0x0015,  0x0016,  0x0017,
48*880d7978SAlexander Pyhalov     0x0018,  0x1EF8,  0x001A,  0x001B,  0x001C,  0x001D,  0x1EF4,  0x001F,
49*880d7978SAlexander Pyhalov };
50*880d7978SAlexander Pyhalov 
51*880d7978SAlexander Pyhalov static const unsigned long viscii2uni_2[128] = {
52*880d7978SAlexander Pyhalov     /*
53*880d7978SAlexander Pyhalov     * 0x80 - Oxff
54*880d7978SAlexander Pyhalov     */
55*880d7978SAlexander Pyhalov     0x1EA0,  0x1EAE,  0x1EB0,  0x1EB6,  0x1EA4,  0x1EA6,  0x1EA8,  0x1EAC,
56*880d7978SAlexander Pyhalov     0x1EBC,  0x1EB8,  0x1EBE,  0x1EC0,  0x1EC2,  0x1EC4,  0x1EC6,  0x1ED0,
57*880d7978SAlexander Pyhalov     0x1ED2,  0x1ED4,  0x1ED6,  0x1ED8,  0x1EE2,  0x1EDA,  0x1EDC,  0x1EDE,
58*880d7978SAlexander Pyhalov     0x1ECA,  0x1ECE,  0x1ECC,  0x1EC8,  0x1EE6,  0x0168,  0x1EE4,  0x1EF2,
59*880d7978SAlexander Pyhalov     0x00D5,  0x1EAF,  0x1EB1,  0x1EB7,  0x1EA5,  0x1EA7,  0x1EA9,  0x1EAD,
60*880d7978SAlexander Pyhalov     0x1EBD,  0x1EB9,  0x1EBF,  0x1EC1,  0x1EC3,  0x1EC5,  0x1EC7,  0x1ED1,
61*880d7978SAlexander Pyhalov     0x1ED3,  0x1ED5,  0x1ED7,  0x1EE0,  0x01A0,  0x1ED9,  0x1EDD,  0x1EDF,
62*880d7978SAlexander Pyhalov     0x1ECB,  0x1EF0,  0x1EE8,  0x1EEA,  0x1EEC,  0x01A1,  0x1EDB,  0x01AF,
63*880d7978SAlexander Pyhalov     0x00C0,  0x00C1,  0x00C2,  0x00C3,  0x1EA2,  0x0102,  0x1EB3,  0x1EB5,
64*880d7978SAlexander Pyhalov     0x00C8,  0x00C9,  0x00CA,  0x1EBA,  0x00CC,  0x00CD,  0x0128,  0x1EF3,
65*880d7978SAlexander Pyhalov     0x0110,  0x1EE9,  0x00D2,  0x00D3,  0x00D4,  0x1EA1,  0x1EF7,  0x1EEB,
66*880d7978SAlexander Pyhalov     0x1EED,  0x00D9,  0x00DA,  0x1EF9,  0x1EF5,  0x00DD,  0x1EE1,  0x01B0,
67*880d7978SAlexander Pyhalov     0x00E0,  0x00E1,  0x00E2,  0x00E3,  0x1EA3,  0x0103,  0x1EEF,  0x1EAB,
68*880d7978SAlexander Pyhalov     0x00E8,  0x00E9,  0x00EA,  0x1EBB,  0x00EC,  0x00ED,  0x0129,  0x1EC9,
69*880d7978SAlexander Pyhalov     0x0111,  0x1EF1,  0x00F2,  0x00F3,  0x00F4,  0x00F5,  0x1ECF,  0x1ECD,
70*880d7978SAlexander Pyhalov     0x1EE5,  0x00F9,  0x00FA,  0x0169,  0x1EE7,  0x00FD,  0x1EE3,  0x1EEE,
71*880d7978SAlexander Pyhalov };
72*880d7978SAlexander Pyhalov 
73*880d7978SAlexander Pyhalov #ifdef __NEED_VISCII_2_UNI__
viscii_2_uni(const unsigned char * in,unsigned long * out)74*880d7978SAlexander Pyhalov static int viscii_2_uni(const unsigned char *in, unsigned long *out )
75*880d7978SAlexander Pyhalov {
76*880d7978SAlexander Pyhalov     unsigned char c = *in;
77*880d7978SAlexander Pyhalov     if (c < 0x20)
78*880d7978SAlexander Pyhalov         *out = (unsigned long) viscii2uni_1[c];
79*880d7978SAlexander Pyhalov     else if (c < 0x80)
80*880d7978SAlexander Pyhalov         *out = (unsigned long) c;
81*880d7978SAlexander Pyhalov     else
82*880d7978SAlexander Pyhalov         *out = (unsigned long) viscii2uni_2[c-0x80];
83*880d7978SAlexander Pyhalov     return 1;
84*880d7978SAlexander Pyhalov }
85*880d7978SAlexander Pyhalov #endif /* __NEED_VISCII_2_UNI__ */
86*880d7978SAlexander Pyhalov 
87*880d7978SAlexander Pyhalov static const unsigned char uni2viscii_1[248] = {
88*880d7978SAlexander Pyhalov     0xc0, 0xc1, 0xc2, 0xc3, 0x00, 0x00, 0x00, 0x00,
89*880d7978SAlexander Pyhalov     0xc8, 0xc9, 0xca, 0x00, 0xcc, 0xcd, 0x00, 0x00,
90*880d7978SAlexander Pyhalov     0x00, 0x00, 0xd2, 0xd3, 0xd4, 0xa0, 0x00, 0x00,
91*880d7978SAlexander Pyhalov     0x00, 0xd9, 0xda, 0x00, 0x00, 0xdd, 0x00, 0x00,
92*880d7978SAlexander Pyhalov     0xe0, 0xe1, 0xe2, 0xe3, 0x00, 0x00, 0x00, 0x00,
93*880d7978SAlexander Pyhalov     0xe8, 0xe9, 0xea, 0x00, 0xec, 0xed, 0x00, 0x00,
94*880d7978SAlexander Pyhalov     0x00, 0x00, 0xf2, 0xf3, 0xf4, 0xf5, 0x00, 0x00,
95*880d7978SAlexander Pyhalov     0x00, 0xf9, 0xfa, 0x00, 0x00, 0xfd, 0x00, 0x00,
96*880d7978SAlexander Pyhalov     0x00, 0x00, 0xc5, 0xe5, 0x00, 0x00, 0x00, 0x00,
97*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98*880d7978SAlexander Pyhalov     0xd0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
99*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101*880d7978SAlexander Pyhalov     0xce, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
102*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
104*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
105*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
107*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
108*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
109*880d7978SAlexander Pyhalov     0x9d, 0xfb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
110*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
111*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
112*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
113*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
114*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
115*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116*880d7978SAlexander Pyhalov     0xb4, 0xbd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
117*880d7978SAlexander Pyhalov     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbf,
118*880d7978SAlexander Pyhalov     0xdf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
119*880d7978SAlexander Pyhalov };
120*880d7978SAlexander Pyhalov static const unsigned char uni2viscii_2[96] = {
121*880d7978SAlexander Pyhalov     /*
122*880d7978SAlexander Pyhalov     * From 0x1EA0 to 0x1EF9.
123*880d7978SAlexander Pyhalov     */
124*880d7978SAlexander Pyhalov     0x80, 0xd5, 0xc4, 0xe4, 0x84, 0xa4, 0x85, 0xa5,
125*880d7978SAlexander Pyhalov     0x86, 0xa6, 0x06, 0xe7, 0x87, 0xa7, 0x81, 0xa1,
126*880d7978SAlexander Pyhalov     0x82, 0xa2, 0x02, 0xc6, 0x05, 0xc7, 0x83, 0xa3,
127*880d7978SAlexander Pyhalov     0x89, 0xa9, 0xcb, 0xeb, 0x88, 0xa8, 0x8a, 0xaa,
128*880d7978SAlexander Pyhalov     0x8b, 0xab, 0x8c, 0xac, 0x8d, 0xad, 0x8e, 0xae,
129*880d7978SAlexander Pyhalov     0x9b, 0xef, 0x98, 0xb8, 0x9a, 0xf7, 0x99, 0xf6,
130*880d7978SAlexander Pyhalov     0x8f, 0xaf, 0x90, 0xb0, 0x91, 0xb1, 0x92, 0xb2,
131*880d7978SAlexander Pyhalov     0x93, 0xb5, 0x95, 0xbe, 0x96, 0xb6, 0x97, 0xb7,
132*880d7978SAlexander Pyhalov     0xb3, 0xde, 0x94, 0xfe, 0x9e, 0xf8, 0x9c, 0xfc,
133*880d7978SAlexander Pyhalov     0xba, 0xd1, 0xbb, 0xd7, 0xbc, 0xd8, 0xff, 0xe6,
134*880d7978SAlexander Pyhalov     0xb9, 0xf1, 0x9f, 0xcf, 0x1e, 0xdc, 0x14, 0xd6,
135*880d7978SAlexander Pyhalov     0x19, 0xdb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136*880d7978SAlexander Pyhalov };
137*880d7978SAlexander Pyhalov 
138*880d7978SAlexander Pyhalov #ifdef __NEED_UNI_2_VISCII__
uni_2_viscii(unsigned long in,unsigned char * out)139*880d7978SAlexander Pyhalov static int uni_2_viscii (unsigned long in,  unsigned char *out)
140*880d7978SAlexander Pyhalov {
141*880d7978SAlexander Pyhalov     unsigned char c = 0;
142*880d7978SAlexander Pyhalov 
143*880d7978SAlexander Pyhalov     if (in < 0x0080 && (in >= 0x0020 || (0xBDEFFF9B & (1 << in)) ) ) {
144*880d7978SAlexander Pyhalov         /* Bit mask from right to left, 0 means no code point:
145*880d7978SAlexander Pyhalov          * 1011 1101 1110 1111 1111 1111 1001 1011
146*880d7978SAlexander Pyhalov          */
147*880d7978SAlexander Pyhalov         *out = in;
148*880d7978SAlexander Pyhalov         return 1;
149*880d7978SAlexander Pyhalov     } else if (in >= 0x00c0 && in < 0x01b8)
150*880d7978SAlexander Pyhalov         c = uni2viscii_1[in-0x00c0];
151*880d7978SAlexander Pyhalov     else if (in >= 0x1ea0 && in < 0x1f00)
152*880d7978SAlexander Pyhalov         c = uni2viscii_2[in-0x1ea0];
153*880d7978SAlexander Pyhalov 
154*880d7978SAlexander Pyhalov     if (c != 0) {
155*880d7978SAlexander Pyhalov         *out = c;
156*880d7978SAlexander Pyhalov         return 1;
157*880d7978SAlexander Pyhalov     }
158*880d7978SAlexander Pyhalov 
159*880d7978SAlexander Pyhalov     return 0;
160*880d7978SAlexander Pyhalov }
161*880d7978SAlexander Pyhalov #endif
162*880d7978SAlexander Pyhalov 
163*880d7978SAlexander Pyhalov #endif
164