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
))
38 **outbuf
= (unsigned char)c
;
44 insize
= GET_INSIZE(c
);
49 TRYMAP_ENC(big5hkscs_bmp
, code
, c
);
50 else TRYMAP_ENC(big5
, code
, c
);
55 else if (c
< 0x30000) {
56 TRYMAP_ENC(big5hkscs_nonbmp
, code
, c
& 0xffff);
70 #define BH2S(c1, c2) (((c1) - 0x88) * (0xfe - 0x40 + 1) + ((c2) - 0x40))
75 unsigned char c
= IN1
;
88 if (0xc6 <= c
&& c
<= 0xc8 && (c
>= 0xc7 || IN2
>= 0xa1))
91 TRYMAP_DEC(big5
, **outbuf
, c
, IN2
) {
95 hkscsdec
: TRYMAP_DEC(big5hkscs
, decoded
, c
, IN2
) {
97 const unsigned char *hintbase
;
99 assert(0x88 <= c
&& c
<= 0xfe);
100 assert(0x40 <= IN2
&& IN2
<= 0xfe);
102 if (BH2S(0x88, 0x40) <= s
&& s
<= BH2S(0xa0, 0xfe)) {
103 hintbase
= big5hkscs_phint_0
;
104 s
-= BH2S(0x88, 0x40);
106 else if (BH2S(0xc6,0xa1) <= s
&& s
<= BH2S(0xc8,0xfe)){
107 hintbase
= big5hkscs_phint_11939
;
108 s
-= BH2S(0xc6, 0xa1);
110 else if (BH2S(0xf9,0xd6) <= s
&& s
<= BH2S(0xfe,0xfe)){
111 hintbase
= big5hkscs_phint_21733
;
112 s
-= BH2S(0xf9, 0xd6);
115 return MBERR_INTERNAL
;
117 if (hintbase
[s
>> 3] & (1 << (s
& 7))) {
118 WRITEUCS4(decoded
| 0x20000)
134 MAPPING_DECONLY(big5hkscs
)
135 MAPPING_ENCONLY(big5hkscs_bmp
)
136 MAPPING_ENCONLY(big5hkscs_nonbmp
)
140 CODEC_STATELESS_WINIT(big5hkscs
)
143 I_AM_A_MODULE_FOR(hk
)