1 | n/a | /* |
---|
2 | n/a | * _codecs_tw.c: Codecs collection for Taiwan's encodings |
---|
3 | n/a | * |
---|
4 | n/a | * Written by Hye-Shik Chang <perky@FreeBSD.org> |
---|
5 | n/a | */ |
---|
6 | n/a | |
---|
7 | n/a | #include "cjkcodecs.h" |
---|
8 | n/a | #include "mappings_tw.h" |
---|
9 | n/a | |
---|
10 | n/a | /* |
---|
11 | n/a | * BIG5 codec |
---|
12 | n/a | */ |
---|
13 | n/a | |
---|
14 | n/a | ENCODER(big5) |
---|
15 | n/a | { |
---|
16 | n/a | while (*inpos < inlen) { |
---|
17 | n/a | Py_UCS4 c = INCHAR1; |
---|
18 | n/a | DBCHAR code; |
---|
19 | n/a | |
---|
20 | n/a | if (c < 0x80) { |
---|
21 | n/a | REQUIRE_OUTBUF(1); |
---|
22 | n/a | **outbuf = (unsigned char)c; |
---|
23 | n/a | NEXT(1, 1); |
---|
24 | n/a | continue; |
---|
25 | n/a | } |
---|
26 | n/a | |
---|
27 | n/a | if (c > 0xFFFF) |
---|
28 | n/a | return 1; |
---|
29 | n/a | |
---|
30 | n/a | REQUIRE_OUTBUF(2); |
---|
31 | n/a | |
---|
32 | n/a | if (TRYMAP_ENC(big5, code, c)) |
---|
33 | n/a | ; |
---|
34 | n/a | else |
---|
35 | n/a | return 1; |
---|
36 | n/a | |
---|
37 | n/a | OUTBYTE1(code >> 8); |
---|
38 | n/a | OUTBYTE2(code & 0xFF); |
---|
39 | n/a | NEXT(1, 2); |
---|
40 | n/a | } |
---|
41 | n/a | |
---|
42 | n/a | return 0; |
---|
43 | n/a | } |
---|
44 | n/a | |
---|
45 | n/a | DECODER(big5) |
---|
46 | n/a | { |
---|
47 | n/a | while (inleft > 0) { |
---|
48 | n/a | unsigned char c = INBYTE1; |
---|
49 | n/a | Py_UCS4 decoded; |
---|
50 | n/a | |
---|
51 | n/a | if (c < 0x80) { |
---|
52 | n/a | OUTCHAR(c); |
---|
53 | n/a | NEXT_IN(1); |
---|
54 | n/a | continue; |
---|
55 | n/a | } |
---|
56 | n/a | |
---|
57 | n/a | REQUIRE_INBUF(2); |
---|
58 | n/a | if (TRYMAP_DEC(big5, decoded, c, INBYTE2)) { |
---|
59 | n/a | OUTCHAR(decoded); |
---|
60 | n/a | NEXT_IN(2); |
---|
61 | n/a | } |
---|
62 | n/a | else return 1; |
---|
63 | n/a | } |
---|
64 | n/a | |
---|
65 | n/a | return 0; |
---|
66 | n/a | } |
---|
67 | n/a | |
---|
68 | n/a | |
---|
69 | n/a | /* |
---|
70 | n/a | * CP950 codec |
---|
71 | n/a | */ |
---|
72 | n/a | |
---|
73 | n/a | ENCODER(cp950) |
---|
74 | n/a | { |
---|
75 | n/a | while (*inpos < inlen) { |
---|
76 | n/a | Py_UCS4 c = INCHAR1; |
---|
77 | n/a | DBCHAR code; |
---|
78 | n/a | |
---|
79 | n/a | if (c < 0x80) { |
---|
80 | n/a | WRITEBYTE1((unsigned char)c); |
---|
81 | n/a | NEXT(1, 1); |
---|
82 | n/a | continue; |
---|
83 | n/a | } |
---|
84 | n/a | |
---|
85 | n/a | if (c > 0xFFFF) |
---|
86 | n/a | return 1; |
---|
87 | n/a | |
---|
88 | n/a | REQUIRE_OUTBUF(2); |
---|
89 | n/a | if (TRYMAP_ENC(cp950ext, code, c)) |
---|
90 | n/a | ; |
---|
91 | n/a | else if (TRYMAP_ENC(big5, code, c)) |
---|
92 | n/a | ; |
---|
93 | n/a | else |
---|
94 | n/a | return 1; |
---|
95 | n/a | |
---|
96 | n/a | OUTBYTE1(code >> 8); |
---|
97 | n/a | OUTBYTE2(code & 0xFF); |
---|
98 | n/a | NEXT(1, 2); |
---|
99 | n/a | } |
---|
100 | n/a | |
---|
101 | n/a | return 0; |
---|
102 | n/a | } |
---|
103 | n/a | |
---|
104 | n/a | DECODER(cp950) |
---|
105 | n/a | { |
---|
106 | n/a | while (inleft > 0) { |
---|
107 | n/a | unsigned char c = INBYTE1; |
---|
108 | n/a | Py_UCS4 decoded; |
---|
109 | n/a | |
---|
110 | n/a | if (c < 0x80) { |
---|
111 | n/a | OUTCHAR(c); |
---|
112 | n/a | NEXT_IN(1); |
---|
113 | n/a | continue; |
---|
114 | n/a | } |
---|
115 | n/a | |
---|
116 | n/a | REQUIRE_INBUF(2); |
---|
117 | n/a | |
---|
118 | n/a | if (TRYMAP_DEC(cp950ext, decoded, c, INBYTE2)) |
---|
119 | n/a | OUTCHAR(decoded); |
---|
120 | n/a | else if (TRYMAP_DEC(big5, decoded, c, INBYTE2)) |
---|
121 | n/a | OUTCHAR(decoded); |
---|
122 | n/a | else |
---|
123 | n/a | return 1; |
---|
124 | n/a | |
---|
125 | n/a | NEXT_IN(2); |
---|
126 | n/a | } |
---|
127 | n/a | |
---|
128 | n/a | return 0; |
---|
129 | n/a | } |
---|
130 | n/a | |
---|
131 | n/a | |
---|
132 | n/a | |
---|
133 | n/a | BEGIN_MAPPINGS_LIST |
---|
134 | n/a | MAPPING_ENCDEC(big5) |
---|
135 | n/a | MAPPING_ENCDEC(cp950ext) |
---|
136 | n/a | END_MAPPINGS_LIST |
---|
137 | n/a | |
---|
138 | n/a | BEGIN_CODECS_LIST |
---|
139 | n/a | CODEC_STATELESS(big5) |
---|
140 | n/a | CODEC_STATELESS(cp950) |
---|
141 | n/a | END_CODECS_LIST |
---|
142 | n/a | |
---|
143 | n/a | I_AM_A_MODULE_FOR(tw) |
---|