2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* XlcUTF.h 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:06 */
24 /* $XConsortium: _fallcUTF.h /main/1 1996/04/08 15:19:33 cde-fuj $ */
25 /******************************************************************
27 Copyright 1993 by SunSoft, Inc.
29 Permission to use, copy, modify, distribute, and sell this software
30 and its documentation for any purpose is hereby granted without fee,
31 provided that the above copyright notice appear in all copies and
32 that both that copyright notice and this permission notice appear
33 in supporting documentation, and that the name of SunSoft, Inc.
34 not be used in advertising or publicity pertaining to distribution
35 of the software without specific, written prior permission.
36 SunSoft, Inc. makes no representations about the suitability of
37 this software for any purpose. It is provided "as is" without
38 express or implied warranty.
40 SunSoft Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
41 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
42 IN NO EVENT SHALL SunSoft, Inc. BE LIABLE FOR ANY SPECIAL, INDIRECT
43 OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
44 OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
45 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
46 OR PERFORMANCE OF THIS SOFTWARE.
48 Author: Hiromu Inukai (inukai@Japan.Sun.COM) SunSoft, inc.
50 ******************************************************************/
51 #include "_fallibint.h"
52 #include "_fallcGeneric.h"
56 typedef unsigned short Rune; /* 16 bits */
57 #define Runeerror 0x80 /* decoding error in UTF */
58 #define Runeself 0x80 /* rune and UTF sequences are the same (<) */
59 #define UTFmax 3 /* maximum bytes per rune */
61 #define BADMAP (0xFFFD)
69 #define tab8859_1 "tab8859_1"
70 #define tab8859_2 "tab8859_2"
71 #define tab8859_3 "tab8859_3"
72 #define tab8859_4 "tab8859_4"
73 #define tab8859_5 "tab8859_5"
74 #define tab8859_6 "tab8859_6"
75 #define tab8859_7 "tab8859_7"
76 #define tab8859_8 "tab8859_8"
77 #define tab8859_9 "tab8859_9"
78 #define jis0208 "jis0208"
79 #define ksc5601 "ksc5601"
80 #define gb2312 "gb2312"
82 #define emit(x) *r = (Rune)x;
85 N11n_none, /* No need to normalize (1byte) */
86 N11n_ja, /* Normalize for ja */
87 N11n_ko, /* Normalize for ko */
88 N11n_zh /* Normalize for zh */
91 typedef struct _UtfDataRec {
93 void (*initialize)( /* Table Initializer */
94 #if NeedNestedPrototypes
99 long *fromtbl; /* UTF -> CharSet */
100 NormalizeType type; /* Normalize type */
101 void (*cstorune)( /* CharSet -> UTF */
102 #if NeedNestedPrototypes
108 struct _UtfDataRec *next; /* next entry */
109 } UtfDataRec, *UtfData;
111 typedef struct _XlcUTFDataRec {
114 void (*initialize)();
116 #if NeedNestedPrototypes
123 } XlcUTFDataRec, *XlcUTFData;
125 typedef struct _StateRec {
127 XlcCharSet GL_charset;
128 XlcCharSet GR_charset;
131 #define MAX_UTF_CHARSET (sizeof(default_utf_data)/sizeof(XlcUTFDataRec))
133 #define Char1 Runeself
134 #define Rune1 Runeself
136 #define Rune21 0x0100
138 #define Rune22 0x4016
140 #define Rune3 0x10000 /* really 0x38E2E */
142 #define Bad Runeerror
160 #define Mask1 (1<<Bit1)-1
161 #define Maskx (1<<Bitx)-1
162 #define Mask2 (1<<Bit2)-1
163 #define Mask3 (1<<Bit3)-1
164 #define Mask4 (1<<Bit4)-1
165 #define Mask5 (1<<Bit5)-1
166 #define Mask6 (1<<Bit6)-1
168 #define Wchar1 (1<<Bit1)-1
169 #define Wchar2 (1<<(Bit2+Bitx))-1
170 #define Wchar3 (1<<(Bit3+2*Bitx))-1
171 #define Wchar4 (1<<(Bit4+3*Bitx))-1
172 #define Wchar5 (1<<(Bit5+4*Bitx))-1
178 #define J2S(_h, _l) { \
179 /* lower: 21-7e >> 40-9d,9e-fb >> 40-7e,(skip 7f),80-fc */ \
180 if (((_l) += (((_h)-- % 2) ? 0x1f : 0x7d)) > 0x7e) (_l)++; \
181 /* upper: 21-7e >> 81-af >> 81-9f,(skip a0-df),e0-ef */ \
182 if (((_h) = ((_h) / 2 + 0x71)) > 0x9f) (_h) += 0x40; \
184 #define S2J(_h, _l) { \
185 /* lower: 40-7e,80-fc >> 21-5f,61-dd >> 21-7e,7f-dc */ \
186 if (((_l) -= 0x1f) > 0x60) (_l)--; \
187 /* upper: 81-9f,e0-ef >> 00-1e,5f-6e >> 00-2e >> 21-7d */ \
188 if (((_h) -= 0x81) > 0x5e) (_h) -= 0x40; (_h) *= 2, (_h) += 0x21; \
189 /* upper: ,21-7d >> ,22-7e ; lower: ,7f-dc >> ,21-7e */ \
190 if ((_l) > 0x7e) (_h)++, (_l) -= 0x5e; \
192 #define ISJKANA(_b) (0xa0 <= (_b) && (_b) < 0xe0)
193 #define CANS2JH(_h) ((0x81 <= (_h) && (_h) < 0xf0) && !ISJKANA(_h))
194 #define CANS2JL(_l) (0x40 <= (_l) && (_l) < 0xfd && (_l) != 0x7f)
195 #define CANS2J(_h, _l) (CANS2JH(_h) && CANS2JL(_l))