|
|
1 | /*--------------------------------*-C-*---------------------------------* |
|
|
2 | * File: encoding.C |
|
|
3 | *----------------------------------------------------------------------* |
|
|
4 | * |
|
|
5 | * All portions of code are copyright by their respective author/s. |
|
|
6 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
|
|
7 | * |
|
|
8 | * This program is free software; you can redistribute it and/or modify |
|
|
9 | * it under the terms of the GNU General Public License as published by |
|
|
10 | * the Free Software Foundation; either version 2 of the License, or |
|
|
11 | * (at your option) any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, |
|
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
16 | * GNU General Public License for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the GNU General Public License |
|
|
19 | * along with this program; if not, write to the Free Software |
|
|
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | *----------------------------------------------------------------------*/ |
|
|
22 | |
1 | #include "../config.h" |
23 | #include "../config.h" |
2 | |
24 | |
3 | #include "encoding.h" |
25 | #include "encoding.h" |
4 | |
26 | |
5 | #include <cstdlib> |
27 | #include <cstdlib> |
… | |
… | |
26 | { "ISO885914", CS_ISO8859_14 }, |
48 | { "ISO885914", CS_ISO8859_14 }, |
27 | { "ISO885915", CS_ISO8859_15 }, |
49 | { "ISO885915", CS_ISO8859_15 }, |
28 | { "FCD885915", CS_ISO8859_15 }, |
50 | { "FCD885915", CS_ISO8859_15 }, |
29 | { "ISO885916", CS_ISO8859_16 }, |
51 | { "ISO885916", CS_ISO8859_16 }, |
30 | |
52 | |
|
|
53 | { "TIS620*", CS_ISO8859_11 }, // close enough |
|
|
54 | |
31 | { "ISO10646*", CS_UNICODE }, |
55 | { "ISO10646*", CS_UNICODE }, |
32 | { "UNICODE", CS_UNICODE }, |
56 | { "UNICODE", CS_UNICODE }, |
33 | { "UTF8", CS_UNICODE }, |
57 | { "UTF8", CS_UNICODE }, |
34 | |
58 | |
35 | { "ASCII", CS_US_ASCII }, |
59 | { "ASCII", CS_US_ASCII }, |
… | |
… | |
40 | { "GOST1976874*", CS_KOI8_R }, |
64 | { "GOST1976874*", CS_KOI8_R }, |
41 | { "KOI8RU", CS_KOI8_U }, |
65 | { "KOI8RU", CS_KOI8_U }, |
42 | { "KOI8U", CS_KOI8_U }, |
66 | { "KOI8U", CS_KOI8_U }, |
43 | |
67 | |
44 | { "VISCII*", CS_VISCII }, |
68 | { "VISCII*", CS_VISCII }, |
45 | { "TIS62025291", CS_VISCII }, // close enough |
|
|
46 | |
69 | |
47 | { "JISX0201*", CS_JIS0201_1976_0 }, |
70 | { "JISX0201*", CS_JIS0201_1976_0 }, |
|
|
71 | { "JISC6226*", CS_JIS0208_1990_0 }, // also wrongly matches -1987-0? (check Encode::JP) |
48 | { "JISX0208*", CS_JIS0208_1983_0 }, // also wrongly matches -1990-0 (check Encode::JP) |
72 | { "JISX0208*", CS_JIS0208_1990_0 }, // also wrongly matches -1987-0? (check Encode::JP) |
49 | { "JISX0212*", CS_JIS0212_1990_0 }, |
73 | { "JISX0212*", CS_JIS0212_1990_0 }, |
|
|
74 | { "JISX021320001", CS_JIS0213_1 }, |
|
|
75 | { "JISX021320002", CS_JIS0213_2 }, |
50 | { "JISX0221*", CS_UNICODE }, |
76 | { "JISX0221*", CS_UNICODE }, // _very_ close |
51 | |
77 | |
52 | { "KSC5601*", CS_KSC5601_1987_0 }, |
78 | { "KSC5601*", CS_KSC5601_1987_0 }, |
53 | { "KSX1001*", CS_KSC5601_1987_0 }, |
79 | { "KSX1001*", CS_KSC5601_1987_0 }, |
54 | { "KSC5700*", CS_UNICODE }, // unicode plus extensions |
80 | { "KSC5700*", CS_UNICODE }, // unicode plus extensions |
55 | |
81 | |
… | |
… | |
111 | } while ((++i)->name); |
137 | } while ((++i)->name); |
112 | |
138 | |
113 | return CS_UNKNOWN; |
139 | return CS_UNKNOWN; |
114 | } |
140 | } |
115 | |
141 | |
116 | struct rxvt_codeset_conv_unknown : rxvt_codeset_conv { |
142 | static unicode_t cs_unknown_to_unicode (uint32_t enc) { return NOCHAR; } |
117 | uint32_t to_unicode (uint32_t enc) const { return NOCHAR; } |
|
|
118 | uint32_t from_unicode (uint32_t unicode) const { return NOCHAR; } |
143 | static uint32_t cs_unknown_from_unicode (unicode_t unicode) { return NOCHAR; } |
119 | } rxvt_codeset_conv_unknown; |
|
|
120 | |
144 | |
121 | struct rxvt_codeset_conv_us_ascii : rxvt_codeset_conv { |
145 | static unicode_t cs_unicode_to_unicode (uint32_t enc) { return enc; } |
|
|
146 | static uint32_t cs_unicode_from_unicode (unicode_t unicode) { return unicode; } |
|
|
147 | |
|
|
148 | #define cs_us_ascii_to_unicode cs_unicode_to_unicode |
122 | uint32_t from_unicode (uint32_t unicode) const { return unicode <= 127 ? unicode : NOCHAR; } |
149 | static uint32_t cs_us_ascii_from_unicode (unicode_t unicode) { return unicode <= 127 ? unicode : NOCHAR; } |
123 | } rxvt_codeset_conv_us_ascii; |
|
|
124 | |
150 | |
125 | struct rxvt_codeset_conv_unicode : rxvt_codeset_conv { |
151 | #define cs_us_ascii_to_unicode_16 cs_unicode_to_unicode |
126 | /* transparent */ |
|
|
127 | } rxvt_codeset_conv_unicode; |
|
|
128 | |
|
|
129 | struct rxvt_codeset_conv_unicode_16 : rxvt_codeset_conv { |
|
|
130 | uint32_t to_unicode (uint32_t enc) const { return enc; } |
|
|
131 | uint32_t from_unicode (uint32_t unicode) const { return unicode <= 65535 ? unicode : NOCHAR; } |
152 | static uint32_t cs_unicode_16_from_unicode (unicode_t unicode) { return unicode <= 65535 ? unicode : NOCHAR; } |
132 | } rxvt_codeset_conv_unicode_16; |
|
|
133 | |
|
|
134 | /* block character set, must conform to the dec special pseudofont in defaultfont.C */ |
|
|
135 | struct rxvt_codeset_conv_special : rxvt_codeset_conv { |
|
|
136 | uint32_t to_unicode (uint32_t enc) const { |
|
|
137 | return enc; |
|
|
138 | } |
|
|
139 | |
|
|
140 | uint32_t from_unicode (uint32_t unicode) const { |
|
|
141 | return unicode; |
|
|
142 | } |
|
|
143 | } rxvt_codeset_conv_special; |
|
|
144 | |
153 | |
145 | #define ENCODING_DEFAULT |
154 | #define ENCODING_DEFAULT |
146 | |
155 | |
147 | #include "table/iso8859_1.h" |
156 | #include "table/iso8859_1.h" |
148 | #include "table/iso8859_15.h" |
157 | #include "table/iso8859_15.h" |
… | |
… | |
168 | |
177 | |
169 | //#define ENCODING_KR |
178 | //#define ENCODING_KR |
170 | |
179 | |
171 | #include "table/ksc5601_1987_0.h" |
180 | #include "table/ksc5601_1987_0.h" |
172 | |
181 | |
173 | //#define ENCODING_CN |
182 | //#define ENCODING_ZH |
174 | |
183 | |
175 | #include "table/gb2312_1980_0.h" |
184 | #include "table/gb2312_1980_0.h" |
176 | #include "table/big5.h" |
185 | #include "table/big5.h" |
177 | |
186 | |
178 | //#define ENCODING_CN_EXT |
187 | //#define ENCODING_ZH_EXT |
179 | |
188 | |
180 | #include "table/cns11643_1992_1.h" |
189 | #include "table/cns11643_1992_1.h" |
181 | #include "table/cns11643_1992_2.h" |
190 | #include "table/cns11643_1992_2.h" |
182 | #include "table/cns11643_1992_3.h" |
191 | #include "table/cns11643_1992_3.h" |
183 | #include "table/cns11643_1992_4.h" |
192 | #include "table/cns11643_1992_4.h" |
… | |
… | |
193 | #include "table/viscii.h" |
202 | #include "table/viscii.h" |
194 | |
203 | |
195 | //#define ENCODING_JP |
204 | //#define ENCODING_JP |
196 | |
205 | |
197 | #include "table/jis0201_1976_0.h" |
206 | #include "table/jis0201_1976_0.h" |
198 | #include "table/jis0208_1983_0.h" |
207 | #include "table/jis0208_1990_0.h" |
199 | #include "table/jis0212_1990_0.h" |
208 | #include "table/jis0212_1990_0.h" |
200 | |
209 | |
201 | //#define ENCODING_JP_EXT |
210 | //#define ENCODING_JP_EXT |
202 | |
211 | |
203 | #include "table/jis0213_1.h" |
212 | #include "table/jis0213_1.h" |
204 | #include "table/jis0213_2.h" |
213 | #include "table/jis0213_2.h" |
205 | |
214 | |
|
|
215 | #if ENCODING_TO_UNICODE |
|
|
216 | # define ENC(base) { cs_ ## base ## _from_unicode, cs_ ## base ## _to_unicode } |
|
|
217 | #else |
|
|
218 | # define ENC(base) { cs_ ## base ## _from_unicode } |
|
|
219 | #endif |
|
|
220 | |
|
|
221 | |
206 | // order must match table in encoding.h(!) |
222 | // order must match table in encoding.h(!) |
207 | const rxvt_codeset_conv *rxvt_codeset[NUM_CODESETS] = { |
223 | const rxvt_codeset_conv rxvt_codeset[NUM_CODESETS] = { |
208 | &rxvt_codeset_conv_unknown, |
224 | ENC (unknown), |
209 | &rxvt_codeset_conv_special, |
|
|
210 | |
225 | |
211 | &rxvt_codeset_conv_us_ascii, |
226 | ENC (us_ascii), |
212 | |
227 | |
213 | &rxvt_codeset_conv_iso8859_1, |
228 | ENC (iso8859_1), |
214 | &rxvt_codeset_conv_iso8859_2, |
229 | ENC (iso8859_2), |
215 | &rxvt_codeset_conv_iso8859_3, |
230 | ENC (iso8859_3), |
216 | &rxvt_codeset_conv_iso8859_4, |
231 | ENC (iso8859_4), |
217 | &rxvt_codeset_conv_iso8859_5, |
232 | ENC (iso8859_5), |
218 | &rxvt_codeset_conv_iso8859_6, |
233 | ENC (iso8859_6), |
219 | &rxvt_codeset_conv_iso8859_7, |
234 | ENC (iso8859_7), |
220 | &rxvt_codeset_conv_iso8859_8, |
235 | ENC (iso8859_8), |
221 | &rxvt_codeset_conv_iso8859_9, |
236 | ENC (iso8859_9), |
222 | &rxvt_codeset_conv_iso8859_10, |
237 | ENC (iso8859_10), |
223 | &rxvt_codeset_conv_iso8859_11, |
238 | ENC (iso8859_11), |
224 | &rxvt_codeset_conv_iso8859_13, |
239 | ENC (iso8859_13), |
225 | &rxvt_codeset_conv_iso8859_14, |
240 | ENC (iso8859_14), |
226 | &rxvt_codeset_conv_iso8859_15, |
241 | ENC (iso8859_15), |
227 | &rxvt_codeset_conv_iso8859_16, |
242 | ENC (iso8859_16), |
228 | |
243 | |
229 | &rxvt_codeset_conv_koi8_r, |
244 | ENC (koi8_r), |
230 | &rxvt_codeset_conv_koi8_u, |
245 | ENC (koi8_u), |
231 | |
246 | |
232 | &rxvt_codeset_conv_jis0201_1976_0, |
247 | ENC (jis0201_1976_0), |
233 | &rxvt_codeset_conv_jis0208_1983_0, |
248 | ENC (jis0208_1990_0), |
234 | &rxvt_codeset_conv_jis0212_1990_0, |
249 | ENC (jis0212_1990_0), |
235 | |
250 | |
236 | &rxvt_codeset_conv_jis0213_1, |
251 | ENC (jis0213_1), |
237 | &rxvt_codeset_conv_jis0213_2, |
252 | ENC (jis0213_2), |
238 | |
253 | |
239 | &rxvt_codeset_conv_ksc5601_1987_0, |
254 | ENC (ksc5601_1987_0), |
240 | |
255 | |
241 | &rxvt_codeset_conv_gb2312_1980_0, |
256 | ENC (gb2312_1980_0), |
242 | |
257 | |
243 | &rxvt_codeset_conv_cns11643_1992_1, |
258 | ENC (cns11643_1992_1), |
244 | &rxvt_codeset_conv_cns11643_1992_2, |
259 | ENC (cns11643_1992_2), |
245 | &rxvt_codeset_conv_cns11643_1992_3, |
260 | ENC (cns11643_1992_3), |
246 | &rxvt_codeset_conv_cns11643_1992_4, |
261 | ENC (cns11643_1992_4), |
247 | &rxvt_codeset_conv_cns11643_1992_5, |
262 | ENC (cns11643_1992_5), |
248 | &rxvt_codeset_conv_cns11643_1992_6, |
263 | ENC (cns11643_1992_6), |
249 | &rxvt_codeset_conv_cns11643_1992_7, |
264 | ENC (cns11643_1992_7), |
250 | &rxvt_codeset_conv_cns11643_1992_f, |
265 | ENC (cns11643_1992_f), |
251 | &rxvt_codeset_conv_big5, |
266 | ENC (big5), |
252 | &rxvt_codeset_conv_big5_ext, |
267 | ENC (big5_ext), |
253 | &rxvt_codeset_conv_big5_plus, |
268 | ENC (big5_plus), |
254 | |
269 | |
255 | &rxvt_codeset_conv_viscii, |
270 | ENC (viscii), |
256 | |
271 | |
257 | &rxvt_codeset_conv_unicode_16, |
272 | ENC (unicode_16), |
258 | &rxvt_codeset_conv_unicode |
273 | ENC (unicode), |
259 | }; |
274 | }; |
260 | |
275 | |
|
|
276 | #if ENABLE_COMBINING |
|
|
277 | # define ENCODING_COMPOSE |
|
|
278 | #endif |
|
|
279 | |
|
|
280 | #include "table/compose.h" |
|
|
281 | |
|
|
282 | unicode_t |
|
|
283 | rxvt_compose (unicode_t c1, unicode_t c2) |
|
|
284 | { |
|
|
285 | int l = 0; |
|
|
286 | int r = sizeof (rxvt_compose_table) / sizeof (rxvt_compose_entry) - 1; |
|
|
287 | int m; |
|
|
288 | |
|
|
289 | while (r > l) |
|
|
290 | { |
|
|
291 | m = (l + r) / 2; |
|
|
292 | rxvt_compose_entry &c = rxvt_compose_table[m]; |
|
|
293 | |
|
|
294 | if (c.c1 < c1 || (c.c1 == c1 && c.c2 < c2)) |
|
|
295 | l = m + 1; |
|
|
296 | else if (c.c1 > c1 || (c.c1 == c1 && c.c2 > c2)) |
|
|
297 | r = m - 1; |
|
|
298 | else |
|
|
299 | return c.r; |
|
|
300 | } |
|
|
301 | |
|
|
302 | return NOCHAR; |
|
|
303 | } |
|
|
304 | |
|
|
305 | #include "table/category.h" |
|
|
306 | |
|
|
307 | bool unicode::is_space (unicode_t c) |
|
|
308 | { |
|
|
309 | return IS_SPACE (c) |
|
|
310 | || c == 0x09; // exclude tabs, too, as we store them in the buffer |
|
|
311 | } |