Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtudcfonted / libfal / _fallcUTF.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
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 /******************************************************************
26
27               Copyright 1993 by SunSoft, Inc.
28
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.
39
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.
47
48   Author: Hiromu Inukai (inukai@Japan.Sun.COM) SunSoft, inc.
49
50 ******************************************************************/
51 #include "_fallibint.h"
52 #include "_fallcGeneric.h"
53 #include <X11/Xos.h>
54 #include <stdio.h>
55
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 */
60
61 #define         BADMAP  (0xFFFD)
62 #define         ESC     033
63 #define         NRUNE   65536
64 #define         NLATIN  0x6ff
65 #define         LATINMAX 256
66 #define         KUTENMAX 8407
67 #define         KSCMAX  8743
68 #define         GBMAX   8795
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"
81
82 #define emit(x)    *r = (Rune)x;
83
84 typedef enum {
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 */
89 } NormalizeType;
90
91 typedef struct  _UtfDataRec {
92         XlcCharSet              charset;
93         void                    (*initialize)( /* Table Initializer */
94 #if NeedNestedPrototypes
95                                               long *tbl,
96                                               long fallback
97 #endif
98                                                 );
99         long                    *fromtbl;       /* UTF -> CharSet */
100         NormalizeType           type;           /* Normalize type */
101         void                    (*cstorune)(   /* CharSet -> UTF */
102 #if NeedNestedPrototypes
103                                             unsigned char c,
104                                             Rune *r
105 #endif
106                                             );
107         Bool                    already_init;
108         struct _UtfDataRec      *next;          /* next entry     */
109 } UtfDataRec, *UtfData;
110
111 typedef struct _XlcUTFDataRec {
112     char        *name;
113     XlcSide     side;
114     void        (*initialize)();
115     void        (*cstorune)(
116 #if NeedNestedPrototypes
117                             unsigned char c,
118                             Rune *r
119 #endif
120                             );
121     NormalizeType       type;
122     long                fallback_value;
123 } XlcUTFDataRec, *XlcUTFData;
124
125 typedef struct _StateRec {
126     XlcCharSet charset;
127     XlcCharSet GL_charset;
128     XlcCharSet GR_charset;
129 } StateRec, *State;
130
131 #define MAX_UTF_CHARSET (sizeof(default_utf_data)/sizeof(XlcUTFDataRec))
132
133 #define Char1 Runeself
134 #define Rune1 Runeself
135 #define Char21 0xA1
136 #define Rune21 0x0100
137 #define Char22 0xF6
138 #define Rune22 0x4016
139 #define Char3 0xFC
140 #define Rune3 0x10000   /* really 0x38E2E */
141 #define Esc 0xBE
142 #define Bad Runeerror
143
144 #define T1      0x00
145 #define Tx      0x80
146 #define T2      0xC0
147 #define T3      0xE0
148 #define T4      0xF0
149 #define T5      0xF8
150 #define T6      0xFC
151
152 #define Bit1    7
153 #define Bitx    6
154 #define Bit2    5
155 #define Bit3    4
156 #define Bit4    3
157 #define Bit5    2
158 #define Bit6    2
159
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
167
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
173
174 #ifndef EILSEQ
175 #define EILSEQ  123
176 #endif
177
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; \
183 }
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; \
191 }
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))
196