2
* _codecs_hk.c: Codecs collection for encodings from Hong Kong
4
* Written by Hye-Shik Chang <perky@FreeBSD.org>
7
#define USING_IMPORTED_MAPS
10
#include "mappings_hk.h"
16
static const encode_map *big5_encmap = NULL;
17
static const decode_map *big5_decmap = NULL;
21
static int initialized = 0;
23
if (!initialized && IMPORT_MAP(tw, big5, &big5_encmap, &big5_decmap))
30
* There are four possible pair unicode -> big5hkscs maps as in HKSCS 2004:
31
* U+00CA U+0304 -> 8862 (U+00CA alone is mapped to 8866)
32
* U+00CA U+030C -> 8864
33
* U+00EA U+0304 -> 88a3 (U+00EA alone is mapped to 88a7)
34
* U+00EA U+030C -> 88a5
35
* These are handled by not mapping tables but a hand-written code.
37
static const DBCHAR big5hkscs_pairenc_table[4] = {0x8862, 0x8864, 0x88a3, 0x88a5};
41
while (*inpos < inlen) {
48
**outbuf = (unsigned char)c;
57
if (TRYMAP_ENC(big5hkscs_bmp, code, c)) {
60
if (inlen - *inpos >= 2)
65
if (inlen - *inpos >= 2 &&
66
((c & 0xffdf) == 0x00ca) &&
67
((c2 & 0xfff7) == 0x0304)) {
68
code = big5hkscs_pairenc_table[
73
else if (inlen - *inpos < 2 &&
74
!(flags & MBENC_FLUSH))
84
else if (TRYMAP_ENC(big5, code, c))
91
else if (c < 0x30000) {
92
if (TRYMAP_ENC(big5hkscs_nonbmp, code, c & 0xffff))
101
OUTBYTE2(code & 0xFF);
108
#define BH2S(c1, c2) (((c1) - 0x87) * (0xfe - 0x40 + 1) + ((c2) - 0x40))
113
unsigned char c = INBYTE1;
124
if (0xc6 > c || c > 0xc8 || (c < 0xc7 && INBYTE2 < 0xa1)) {
125
if (TRYMAP_DEC(big5, decoded, c, INBYTE2)) {
132
if (TRYMAP_DEC(big5hkscs, decoded, c, INBYTE2))
134
int s = BH2S(c, INBYTE2);
135
const unsigned char *hintbase;
137
assert(0x87 <= c && c <= 0xfe);
138
assert(0x40 <= INBYTE2 && INBYTE2 <= 0xfe);
140
if (BH2S(0x87, 0x40) <= s && s <= BH2S(0xa0, 0xfe)) {
141
hintbase = big5hkscs_phint_0;
142
s -= BH2S(0x87, 0x40);
144
else if (BH2S(0xc6,0xa1) <= s && s <= BH2S(0xc8,0xfe)){
145
hintbase = big5hkscs_phint_12130;
146
s -= BH2S(0xc6, 0xa1);
148
else if (BH2S(0xf9,0xd6) <= s && s <= BH2S(0xfe,0xfe)){
149
hintbase = big5hkscs_phint_21924;
150
s -= BH2S(0xf9, 0xd6);
153
return MBERR_INTERNAL;
155
if (hintbase[s >> 3] & (1 << (s & 7))) {
156
OUTCHAR(decoded | 0x20000);
166
switch ((c << 8) | INBYTE2) {
167
case 0x8862: OUTCHAR2(0x00ca, 0x0304); break;
168
case 0x8864: OUTCHAR2(0x00ca, 0x030c); break;
169
case 0x88a3: OUTCHAR2(0x00ea, 0x0304); break;
170
case 0x88a5: OUTCHAR2(0x00ea, 0x030c); break;
174
NEXT_IN(2); /* all decoded codepoints are pairs, above. */
182
MAPPING_DECONLY(big5hkscs)
183
MAPPING_ENCONLY(big5hkscs_bmp)
184
MAPPING_ENCONLY(big5hkscs_nonbmp)
188
CODEC_STATELESS_WINIT(big5hkscs)
191
I_AM_A_MODULE_FOR(hk)