xref: /haiku/src/libs/iconv/cp864.h (revision aef5731f38da6f7b913e0f64acd8a40555491ce5)
1*aef5731fSOliver Tappe /*
2*aef5731fSOliver Tappe  * Copyright (C) 1999-2001 Free Software Foundation, Inc.
3*aef5731fSOliver Tappe  * This file is part of the GNU LIBICONV Library.
4*aef5731fSOliver Tappe  *
5*aef5731fSOliver Tappe  * The GNU LIBICONV Library is free software; you can redistribute it
6*aef5731fSOliver Tappe  * and/or modify it under the terms of the GNU Library General Public
7*aef5731fSOliver Tappe  * License as published by the Free Software Foundation; either version 2
8*aef5731fSOliver Tappe  * of the License, or (at your option) any later version.
9*aef5731fSOliver Tappe  *
10*aef5731fSOliver Tappe  * The GNU LIBICONV Library is distributed in the hope that it will be
11*aef5731fSOliver Tappe  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12*aef5731fSOliver Tappe  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*aef5731fSOliver Tappe  * Library General Public License for more details.
14*aef5731fSOliver Tappe  *
15*aef5731fSOliver Tappe  * You should have received a copy of the GNU Library General Public
16*aef5731fSOliver Tappe  * License along with the GNU LIBICONV Library; see the file COPYING.LIB.
17*aef5731fSOliver Tappe  * If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
18*aef5731fSOliver Tappe  * Fifth Floor, Boston, MA 02110-1301, USA.
19*aef5731fSOliver Tappe  */
20*aef5731fSOliver Tappe 
21*aef5731fSOliver Tappe /*
22*aef5731fSOliver Tappe  * CP864
23*aef5731fSOliver Tappe  */
24*aef5731fSOliver Tappe 
25*aef5731fSOliver Tappe static const unsigned short cp864_2uni_1[16] = {
26*aef5731fSOliver Tappe   /* 0x20 */
27*aef5731fSOliver Tappe   0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x066a, 0x0026, 0x0027,
28*aef5731fSOliver Tappe   0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
29*aef5731fSOliver Tappe };
30*aef5731fSOliver Tappe static const unsigned short cp864_2uni_2[128] = {
31*aef5731fSOliver Tappe   /* 0x80 */
32*aef5731fSOliver Tappe   0x00b0, 0x00b7, 0x2219, 0x221a, 0x2592, 0x2500, 0x2502, 0x253c,
33*aef5731fSOliver Tappe   0x2524, 0x252c, 0x251c, 0x2534, 0x2510, 0x250c, 0x2514, 0x2518,
34*aef5731fSOliver Tappe   /* 0x90 */
35*aef5731fSOliver Tappe   0x03b2, 0x221e, 0x03c6, 0x00b1, 0x00bd, 0x00bc, 0x2248, 0x00ab,
36*aef5731fSOliver Tappe   0x00bb, 0xfef7, 0xfef8, 0xfffd, 0xfffd, 0xfefb, 0xfefc, 0xfffd,
37*aef5731fSOliver Tappe   /* 0xa0 */
38*aef5731fSOliver Tappe   0x00a0, 0x00ad, 0xfe82, 0x00a3, 0x00a4, 0xfe84, 0xfffd, 0xfffd,
39*aef5731fSOliver Tappe   0xfe8e, 0xfe8f, 0xfe95, 0xfe99, 0x060c, 0xfe9d, 0xfea1, 0xfea5,
40*aef5731fSOliver Tappe   /* 0xb0 */
41*aef5731fSOliver Tappe   0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667,
42*aef5731fSOliver Tappe   0x0668, 0x0669, 0xfed1, 0x061b, 0xfeb1, 0xfeb5, 0xfeb9, 0x061f,
43*aef5731fSOliver Tappe   /* 0xc0 */
44*aef5731fSOliver Tappe   0x00a2, 0xfe80, 0xfe81, 0xfe83, 0xfe85, 0xfeca, 0xfe8b, 0xfe8d,
45*aef5731fSOliver Tappe   0xfe91, 0xfe93, 0xfe97, 0xfe9b, 0xfe9f, 0xfea3, 0xfea7, 0xfea9,
46*aef5731fSOliver Tappe   /* 0xd0 */
47*aef5731fSOliver Tappe   0xfeab, 0xfead, 0xfeaf, 0xfeb3, 0xfeb7, 0xfebb, 0xfebf, 0xfec1,
48*aef5731fSOliver Tappe   0xfec5, 0xfecb, 0xfecf, 0x00a6, 0x00ac, 0x00f7, 0x00d7, 0xfec9,
49*aef5731fSOliver Tappe   /* 0xe0 */
50*aef5731fSOliver Tappe   0x0640, 0xfed3, 0xfed7, 0xfedb, 0xfedf, 0xfee3, 0xfee7, 0xfeeb,
51*aef5731fSOliver Tappe   0xfeed, 0xfeef, 0xfef3, 0xfebd, 0xfecc, 0xfece, 0xfecd, 0xfee1,
52*aef5731fSOliver Tappe   /* 0xf0 */
53*aef5731fSOliver Tappe   0xfe7d, 0x0651, 0xfee5, 0xfee9, 0xfeec, 0xfef0, 0xfef2, 0xfed0,
54*aef5731fSOliver Tappe   0xfed5, 0xfef5, 0xfef6, 0xfedd, 0xfed9, 0xfef1, 0x25a0, 0xfffd,
55*aef5731fSOliver Tappe };
56*aef5731fSOliver Tappe 
57*aef5731fSOliver Tappe static int
cp864_mbtowc(conv_t conv,ucs4_t * pwc,const unsigned char * s,int n)58*aef5731fSOliver Tappe cp864_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
59*aef5731fSOliver Tappe {
60*aef5731fSOliver Tappe   unsigned char c = *s;
61*aef5731fSOliver Tappe   if (c < 0x20) {
62*aef5731fSOliver Tappe     *pwc = (ucs4_t) c;
63*aef5731fSOliver Tappe     return 1;
64*aef5731fSOliver Tappe   }
65*aef5731fSOliver Tappe   else if (c < 0x30) {
66*aef5731fSOliver Tappe     *pwc = (ucs4_t) cp864_2uni_1[c-0x20];
67*aef5731fSOliver Tappe     return 1;
68*aef5731fSOliver Tappe   }
69*aef5731fSOliver Tappe   else if (c < 0x80) {
70*aef5731fSOliver Tappe     *pwc = (ucs4_t) c;
71*aef5731fSOliver Tappe     return 1;
72*aef5731fSOliver Tappe   }
73*aef5731fSOliver Tappe   else {
74*aef5731fSOliver Tappe     unsigned short wc = cp864_2uni_2[c-0x80];
75*aef5731fSOliver Tappe     if (wc != 0xfffd) {
76*aef5731fSOliver Tappe       *pwc = (ucs4_t) wc;
77*aef5731fSOliver Tappe       return 1;
78*aef5731fSOliver Tappe     }
79*aef5731fSOliver Tappe   }
80*aef5731fSOliver Tappe   return RET_ILSEQ;
81*aef5731fSOliver Tappe }
82*aef5731fSOliver Tappe 
83*aef5731fSOliver Tappe static const unsigned char cp864_page00[8] = {
84*aef5731fSOliver Tappe   0x20, 0x21, 0x22, 0x23, 0x24, 0x00, 0x26, 0x27, /* 0x20-0x27 */
85*aef5731fSOliver Tappe };
86*aef5731fSOliver Tappe static const unsigned char cp864_page00_1[88] = {
87*aef5731fSOliver Tappe   0xa0, 0x00, 0xc0, 0xa3, 0xa4, 0x00, 0xdb, 0x00, /* 0xa0-0xa7 */
88*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x97, 0xdc, 0xa1, 0x00, 0x00, /* 0xa8-0xaf */
89*aef5731fSOliver Tappe   0x80, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, /* 0xb0-0xb7 */
90*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x98, 0x95, 0x94, 0x00, 0x00, /* 0xb8-0xbf */
91*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
92*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
93*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, /* 0xd0-0xd7 */
94*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
95*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
96*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
97*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdd, /* 0xf0-0xf7 */
98*aef5731fSOliver Tappe };
99*aef5731fSOliver Tappe static const unsigned char cp864_page06[104] = {
100*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00, /* 0x08-0x0f */
101*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
102*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0xbb, 0x00, 0x00, 0x00, 0xbf, /* 0x18-0x1f */
103*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
104*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
105*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
106*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
107*aef5731fSOliver Tappe   0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
108*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
109*aef5731fSOliver Tappe   0x00, 0xf1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
110*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
111*aef5731fSOliver Tappe   0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, /* 0x60-0x67 */
112*aef5731fSOliver Tappe   0xb8, 0xb9, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
113*aef5731fSOliver Tappe };
114*aef5731fSOliver Tappe static const unsigned char cp864_page22[56] = {
115*aef5731fSOliver Tappe   0x00, 0x82, 0x83, 0x00, 0x00, 0x00, 0x91, 0x00, /* 0x18-0x1f */
116*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
117*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
118*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
119*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
120*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
121*aef5731fSOliver Tappe   0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
122*aef5731fSOliver Tappe };
123*aef5731fSOliver Tappe static const unsigned char cp864_page25[64] = {
124*aef5731fSOliver Tappe   0x85, 0x00, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
125*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x8d, 0x00, 0x00, 0x00, /* 0x08-0x0f */
126*aef5731fSOliver Tappe   0x8c, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, 0x00, /* 0x10-0x17 */
127*aef5731fSOliver Tappe   0x8f, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, /* 0x18-0x1f */
128*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, /* 0x20-0x27 */
129*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x89, 0x00, 0x00, 0x00, /* 0x28-0x2f */
130*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, /* 0x30-0x37 */
131*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00, /* 0x38-0x3f */
132*aef5731fSOliver Tappe };
133*aef5731fSOliver Tappe static const unsigned char cp864_pagefe[136] = {
134*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, /* 0x78-0x7f */
135*aef5731fSOliver Tappe   0xc1, 0xc2, 0xa2, 0xc3, 0xa5, 0xc4, 0x00, 0x00, /* 0x80-0x87 */
136*aef5731fSOliver Tappe   0x00, 0x00, 0x00, 0xc6, 0x00, 0xc7, 0xa8, 0xa9, /* 0x88-0x8f */
137*aef5731fSOliver Tappe   0x00, 0xc8, 0x00, 0xc9, 0x00, 0xaa, 0x00, 0xca, /* 0x90-0x97 */
138*aef5731fSOliver Tappe   0x00, 0xab, 0x00, 0xcb, 0x00, 0xad, 0x00, 0xcc, /* 0x98-0x9f */
139*aef5731fSOliver Tappe   0x00, 0xae, 0x00, 0xcd, 0x00, 0xaf, 0x00, 0xce, /* 0xa0-0xa7 */
140*aef5731fSOliver Tappe   0x00, 0xcf, 0x00, 0xd0, 0x00, 0xd1, 0x00, 0xd2, /* 0xa8-0xaf */
141*aef5731fSOliver Tappe   0x00, 0xbc, 0x00, 0xd3, 0x00, 0xbd, 0x00, 0xd4, /* 0xb0-0xb7 */
142*aef5731fSOliver Tappe   0x00, 0xbe, 0x00, 0xd5, 0x00, 0xeb, 0x00, 0xd6, /* 0xb8-0xbf */
143*aef5731fSOliver Tappe   0x00, 0xd7, 0x00, 0x00, 0x00, 0xd8, 0x00, 0x00, /* 0xc0-0xc7 */
144*aef5731fSOliver Tappe   0x00, 0xdf, 0xc5, 0xd9, 0xec, 0xee, 0xed, 0xda, /* 0xc8-0xcf */
145*aef5731fSOliver Tappe   0xf7, 0xba, 0x00, 0xe1, 0x00, 0xf8, 0x00, 0xe2, /* 0xd0-0xd7 */
146*aef5731fSOliver Tappe   0x00, 0xfc, 0x00, 0xe3, 0x00, 0xfb, 0x00, 0xe4, /* 0xd8-0xdf */
147*aef5731fSOliver Tappe   0x00, 0xef, 0x00, 0xe5, 0x00, 0xf2, 0x00, 0xe6, /* 0xe0-0xe7 */
148*aef5731fSOliver Tappe   0x00, 0xf3, 0x00, 0xe7, 0xf4, 0xe8, 0x00, 0xe9, /* 0xe8-0xef */
149*aef5731fSOliver Tappe   0xf5, 0xfd, 0xf6, 0xea, 0x00, 0xf9, 0xfa, 0x99, /* 0xf0-0xf7 */
150*aef5731fSOliver Tappe   0x9a, 0x00, 0x00, 0x9d, 0x9e, 0x00, 0x00, 0x00, /* 0xf8-0xff */
151*aef5731fSOliver Tappe };
152*aef5731fSOliver Tappe 
153*aef5731fSOliver Tappe static int
cp864_wctomb(conv_t conv,unsigned char * r,ucs4_t wc,int n)154*aef5731fSOliver Tappe cp864_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
155*aef5731fSOliver Tappe {
156*aef5731fSOliver Tappe   unsigned char c = 0;
157*aef5731fSOliver Tappe   if (wc < 0x0020) {
158*aef5731fSOliver Tappe     *r = wc;
159*aef5731fSOliver Tappe     return 1;
160*aef5731fSOliver Tappe   }
161*aef5731fSOliver Tappe   else if (wc >= 0x0020 && wc < 0x0028)
162*aef5731fSOliver Tappe     c = cp864_page00[wc-0x0020];
163*aef5731fSOliver Tappe   else if (wc >= 0x0028 && wc < 0x0080)
164*aef5731fSOliver Tappe     c = wc;
165*aef5731fSOliver Tappe   else if (wc >= 0x00a0 && wc < 0x00f8)
166*aef5731fSOliver Tappe     c = cp864_page00_1[wc-0x00a0];
167*aef5731fSOliver Tappe   else if (wc == 0x03b2)
168*aef5731fSOliver Tappe     c = 0x90;
169*aef5731fSOliver Tappe   else if (wc == 0x03c6)
170*aef5731fSOliver Tappe     c = 0x92;
171*aef5731fSOliver Tappe   else if (wc >= 0x0608 && wc < 0x0670)
172*aef5731fSOliver Tappe     c = cp864_page06[wc-0x0608];
173*aef5731fSOliver Tappe   else if (wc >= 0x2218 && wc < 0x2250)
174*aef5731fSOliver Tappe     c = cp864_page22[wc-0x2218];
175*aef5731fSOliver Tappe   else if (wc >= 0x2500 && wc < 0x2540)
176*aef5731fSOliver Tappe     c = cp864_page25[wc-0x2500];
177*aef5731fSOliver Tappe   else if (wc == 0x2592)
178*aef5731fSOliver Tappe     c = 0x84;
179*aef5731fSOliver Tappe   else if (wc == 0x25a0)
180*aef5731fSOliver Tappe     c = 0xfe;
181*aef5731fSOliver Tappe   else if (wc >= 0xfe78 && wc < 0xff00)
182*aef5731fSOliver Tappe     c = cp864_pagefe[wc-0xfe78];
183*aef5731fSOliver Tappe   if (c != 0) {
184*aef5731fSOliver Tappe     *r = c;
185*aef5731fSOliver Tappe     return 1;
186*aef5731fSOliver Tappe   }
187*aef5731fSOliver Tappe   return RET_ILUNI;
188*aef5731fSOliver Tappe }
189