1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: encoding.C |
2 | * File: encoding.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
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 |
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 |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
… | |
… | |
47 | { "ISO885913", CS_ISO8859_13 }, |
47 | { "ISO885913", CS_ISO8859_13 }, |
48 | { "ISO885914", CS_ISO8859_14 }, |
48 | { "ISO885914", CS_ISO8859_14 }, |
49 | { "ISO885915", CS_ISO8859_15 }, |
49 | { "ISO885915", CS_ISO8859_15 }, |
50 | { "FCD885915", CS_ISO8859_15 }, |
50 | { "FCD885915", CS_ISO8859_15 }, |
51 | { "ISO885916", CS_ISO8859_16 }, |
51 | { "ISO885916", CS_ISO8859_16 }, |
52 | |
52 | |
53 | { "TIS620*", CS_ISO8859_11 }, // close enough |
53 | { "TIS620*", CS_ISO8859_11 }, // close enough |
54 | |
54 | |
55 | { "ISO10646*", CS_UNICODE }, |
55 | { "ISO10646*", CS_UNICODE }, |
56 | { "UNICODE", CS_UNICODE }, |
56 | { "UNICODE", CS_UNICODE }, |
57 | { "UTF8", CS_UNICODE }, |
57 | { "UTF8", CS_UNICODE }, |
58 | |
58 | |
59 | { "ASCII", CS_US_ASCII }, |
59 | { "ASCII", CS_US_ASCII }, |
60 | { "USASCII", CS_US_ASCII }, |
60 | { "USASCII", CS_US_ASCII }, |
61 | { "ANSIX341968", CS_US_ASCII }, |
61 | { "ANSIX341968", CS_US_ASCII }, |
62 | |
62 | { "ISO6461991IRV", CS_US_ASCII }, // older versions used the currency sign |
|
|
63 | |
63 | { "KOI8R", CS_KOI8_R }, |
64 | { "KOI8R*", CS_KOI8_R }, |
64 | { "GOST1976874*", CS_KOI8_R }, |
65 | { "GOST1976874*", CS_KOI8_R }, |
65 | { "KOI8RU", CS_KOI8_U }, |
66 | { "KOI8RU", CS_KOI8_U }, |
66 | { "KOI8U", CS_KOI8_U }, |
67 | { "KOI8U", CS_KOI8_U }, |
67 | |
68 | |
68 | { "VISCII*", CS_VISCII }, |
69 | { "VISCII*", CS_VISCII }, |
69 | |
70 | |
70 | { "JISX0201*", CS_JIS0201_1976_0 }, |
71 | { "JISX0201*", CS_JIS0201_1976_0 }, |
|
|
72 | { "JISC6226*", CS_JIS0208_1990_0 }, // also wrongly matches -1987-0? (check Encode::JP) |
71 | { "JISX0208*", CS_JIS0208_1990_0 }, // also wrongly matches -1987-0? (check Encode::JP) |
73 | { "JISX0208*", CS_JIS0208_1990_0 }, // also wrongly matches -1987-0? (check Encode::JP) |
72 | { "JISX0212*", CS_JIS0212_1990_0 }, |
74 | { "JISX0212*", CS_JIS0212_1990_0 }, |
73 | { "JISX021320001", CS_JIS0213_1 }, |
75 | { "JISX021320001", CS_JIS0213_1 }, |
74 | { "JISX021320002", CS_JIS0213_2 }, |
76 | { "JISX021320002", CS_JIS0213_2 }, |
75 | { "JISX0221*", CS_UNICODE }, // _very_ close |
77 | { "JISX0221*", CS_UNICODE }, // _very_ close |
76 | |
78 | |
77 | { "KSC5601*", CS_KSC5601_1987_0 }, |
79 | { "KSC5601*", CS_KSC5601_1987_0 }, |
78 | { "KSX1001*", CS_KSC5601_1987_0 }, |
80 | { "KSX1001*", CS_KSC5601_1987_0 }, |
79 | { "KSC5700*", CS_UNICODE }, // unicode plus extensions |
81 | { "KSC5700*", CS_UNICODE }, // unicode plus extensions |
80 | |
82 | |
81 | { "BIG5P*", CS_BIG5_PLUS }, |
83 | { "BIG5P*", CS_BIG5_PLUS }, |
82 | { "BIG5ETEN*", CS_BIG5_EXT }, |
84 | { "BIG5ETEN*", CS_BIG5_EXT }, |
83 | { "BIG5*", CS_BIG5 }, |
85 | { "BIG5*", CS_BIG5 }, |
84 | { "GB2312*", CS_GB2312_1980_0 }, |
86 | { "GB2312*", CS_GB2312_1980_0 }, |
|
|
87 | { "GBK*", CS_GBK_0 }, |
85 | { "GB6345*", CS_GB2312_1980_0 }, // slightly different to gb2312?? |
88 | { "GB6345*", CS_GB2312_1980_0 }, // slightly different to gb2312?? |
86 | { "GB8565*", CS_GB2312_1980_0 }, // a superset of gb2312?? |
89 | { "GB8565*", CS_GB2312_1980_0 }, // a superset of gb2312?? |
87 | { "GB13000*", CS_UNICODE }, |
90 | { "GB13000*", CS_UNICODE }, |
88 | { "CNS1164319921", CS_CNS11643_1992_1 }, |
91 | { "CNS1164319921", CS_CNS11643_1992_1 }, |
89 | { "CNS1164319922", CS_CNS11643_1992_2 }, |
92 | { "CNS1164319922", CS_CNS11643_1992_2 }, |
… | |
… | |
136 | } while ((++i)->name); |
139 | } while ((++i)->name); |
137 | |
140 | |
138 | return CS_UNKNOWN; |
141 | return CS_UNKNOWN; |
139 | } |
142 | } |
140 | |
143 | |
141 | struct rxvt_codeset_conv_unknown : rxvt_codeset_conv { |
|
|
142 | unicode_t to_unicode (uint32_t enc) const { return NOCHAR; } |
144 | static unicode_t cs_unknown_to_unicode (uint32_t enc) { return NOCHAR; } |
143 | uint32_t from_unicode (unicode_t unicode) const { return NOCHAR; } |
145 | static uint32_t cs_unknown_from_unicode (unicode_t unicode) { return NOCHAR; } |
144 | } rxvt_codeset_conv_unknown; |
|
|
145 | |
146 | |
146 | struct rxvt_codeset_conv_us_ascii : rxvt_codeset_conv { |
147 | static unicode_t cs_unicode_to_unicode (uint32_t enc) { return enc; } |
|
|
148 | static uint32_t cs_unicode_from_unicode (unicode_t unicode) { return unicode; } |
|
|
149 | |
|
|
150 | #define cs_us_ascii_to_unicode cs_unicode_to_unicode |
147 | uint32_t from_unicode (unicode_t unicode) const { return unicode <= 127 ? unicode : NOCHAR; } |
151 | static uint32_t cs_us_ascii_from_unicode (unicode_t unicode) { return unicode <= 127 ? unicode : NOCHAR; } |
148 | } rxvt_codeset_conv_us_ascii; |
|
|
149 | |
152 | |
150 | struct rxvt_codeset_conv_unicode : rxvt_codeset_conv { |
153 | #define cs_us_ascii_to_unicode_16 cs_unicode_to_unicode |
151 | /* transparent */ |
|
|
152 | } rxvt_codeset_conv_unicode; |
|
|
153 | |
|
|
154 | struct rxvt_codeset_conv_unicode_16 : rxvt_codeset_conv { |
|
|
155 | unicode_t to_unicode (uint32_t enc) const { return enc; } |
|
|
156 | uint32_t from_unicode (unicode_t unicode) const { return unicode <= 65535 ? unicode : NOCHAR; } |
154 | static uint32_t cs_unicode_16_from_unicode (unicode_t unicode) { return unicode <= 65535 ? unicode : NOCHAR; } |
157 | } rxvt_codeset_conv_unicode_16; |
|
|
158 | |
155 | |
159 | #define ENCODING_DEFAULT |
156 | #define ENCODING_DEFAULT |
160 | |
157 | |
161 | #include "table/iso8859_1.h" |
158 | #include "table/iso8859_1.h" |
162 | #include "table/iso8859_15.h" |
159 | #include "table/iso8859_15.h" |
… | |
… | |
182 | |
179 | |
183 | //#define ENCODING_KR |
180 | //#define ENCODING_KR |
184 | |
181 | |
185 | #include "table/ksc5601_1987_0.h" |
182 | #include "table/ksc5601_1987_0.h" |
186 | |
183 | |
187 | //#define ENCODING_CN |
184 | //#define ENCODING_ZH |
188 | |
185 | |
|
|
186 | #include "table/big5.h" |
|
|
187 | #include "table/gbk_0.h" |
189 | #include "table/gb2312_1980_0.h" |
188 | #include "table/gb2312_1980_0.h" |
190 | #include "table/big5.h" |
|
|
191 | |
189 | |
192 | //#define ENCODING_CN_EXT |
190 | //#define ENCODING_ZH_EXT |
193 | |
191 | |
194 | #include "table/cns11643_1992_1.h" |
192 | #include "table/cns11643_1992_1.h" |
195 | #include "table/cns11643_1992_2.h" |
193 | #include "table/cns11643_1992_2.h" |
196 | #include "table/cns11643_1992_3.h" |
194 | #include "table/cns11643_1992_3.h" |
197 | #include "table/cns11643_1992_4.h" |
195 | #include "table/cns11643_1992_4.h" |
… | |
… | |
215 | //#define ENCODING_JP_EXT |
213 | //#define ENCODING_JP_EXT |
216 | |
214 | |
217 | #include "table/jis0213_1.h" |
215 | #include "table/jis0213_1.h" |
218 | #include "table/jis0213_2.h" |
216 | #include "table/jis0213_2.h" |
219 | |
217 | |
|
|
218 | #if ENCODING_TO_UNICODE |
|
|
219 | # define ENC(base) { cs_ ## base ## _from_unicode, cs_ ## base ## _to_unicode } |
|
|
220 | #else |
|
|
221 | # define ENC(base) { cs_ ## base ## _from_unicode } |
|
|
222 | #endif |
|
|
223 | |
|
|
224 | |
220 | // order must match table in encoding.h(!) |
225 | // order must match table in encoding.h(!) |
221 | const rxvt_codeset_conv *rxvt_codeset[NUM_CODESETS] = { |
226 | const rxvt_codeset_conv rxvt_codeset[NUM_CODESETS] = { |
222 | &rxvt_codeset_conv_unknown, |
227 | ENC (unknown), |
223 | |
228 | |
224 | &rxvt_codeset_conv_us_ascii, |
229 | ENC (us_ascii), |
225 | |
230 | |
226 | &rxvt_codeset_conv_iso8859_1, |
231 | ENC (iso8859_1), |
227 | &rxvt_codeset_conv_iso8859_2, |
232 | ENC (iso8859_2), |
228 | &rxvt_codeset_conv_iso8859_3, |
233 | ENC (iso8859_3), |
229 | &rxvt_codeset_conv_iso8859_4, |
234 | ENC (iso8859_4), |
230 | &rxvt_codeset_conv_iso8859_5, |
235 | ENC (iso8859_5), |
231 | &rxvt_codeset_conv_iso8859_6, |
236 | ENC (iso8859_6), |
232 | &rxvt_codeset_conv_iso8859_7, |
237 | ENC (iso8859_7), |
233 | &rxvt_codeset_conv_iso8859_8, |
238 | ENC (iso8859_8), |
234 | &rxvt_codeset_conv_iso8859_9, |
239 | ENC (iso8859_9), |
235 | &rxvt_codeset_conv_iso8859_10, |
240 | ENC (iso8859_10), |
236 | &rxvt_codeset_conv_iso8859_11, |
241 | ENC (iso8859_11), |
237 | &rxvt_codeset_conv_iso8859_13, |
242 | ENC (iso8859_13), |
238 | &rxvt_codeset_conv_iso8859_14, |
243 | ENC (iso8859_14), |
239 | &rxvt_codeset_conv_iso8859_15, |
244 | ENC (iso8859_15), |
240 | &rxvt_codeset_conv_iso8859_16, |
245 | ENC (iso8859_16), |
241 | |
246 | |
242 | &rxvt_codeset_conv_koi8_r, |
247 | ENC (koi8_r), |
243 | &rxvt_codeset_conv_koi8_u, |
248 | ENC (koi8_u), |
244 | |
249 | |
245 | &rxvt_codeset_conv_jis0201_1976_0, |
250 | ENC (jis0201_1976_0), |
246 | &rxvt_codeset_conv_jis0208_1990_0, |
251 | ENC (jis0208_1990_0), |
247 | &rxvt_codeset_conv_jis0212_1990_0, |
252 | ENC (jis0212_1990_0), |
248 | |
253 | |
249 | &rxvt_codeset_conv_jis0213_1, |
254 | ENC (jis0213_1), |
250 | &rxvt_codeset_conv_jis0213_2, |
255 | ENC (jis0213_2), |
251 | |
256 | |
252 | &rxvt_codeset_conv_ksc5601_1987_0, |
257 | ENC (ksc5601_1987_0), |
253 | |
258 | |
254 | &rxvt_codeset_conv_gb2312_1980_0, |
259 | ENC (gb2312_1980_0), |
|
|
260 | ENC (gbk_0), |
255 | |
261 | |
256 | &rxvt_codeset_conv_cns11643_1992_1, |
262 | ENC (cns11643_1992_1), |
257 | &rxvt_codeset_conv_cns11643_1992_2, |
263 | ENC (cns11643_1992_2), |
258 | &rxvt_codeset_conv_cns11643_1992_3, |
264 | ENC (cns11643_1992_3), |
259 | &rxvt_codeset_conv_cns11643_1992_4, |
265 | ENC (cns11643_1992_4), |
260 | &rxvt_codeset_conv_cns11643_1992_5, |
266 | ENC (cns11643_1992_5), |
261 | &rxvt_codeset_conv_cns11643_1992_6, |
267 | ENC (cns11643_1992_6), |
262 | &rxvt_codeset_conv_cns11643_1992_7, |
268 | ENC (cns11643_1992_7), |
263 | &rxvt_codeset_conv_cns11643_1992_f, |
269 | ENC (cns11643_1992_f), |
264 | &rxvt_codeset_conv_big5, |
270 | ENC (big5), |
265 | &rxvt_codeset_conv_big5_ext, |
271 | ENC (big5_ext), |
266 | &rxvt_codeset_conv_big5_plus, |
272 | ENC (big5_plus), |
267 | |
273 | |
268 | &rxvt_codeset_conv_viscii, |
274 | ENC (viscii), |
269 | |
275 | |
270 | &rxvt_codeset_conv_unicode_16, |
276 | ENC (unicode_16), |
271 | &rxvt_codeset_conv_unicode |
277 | ENC (unicode), |
272 | }; |
278 | }; |
273 | |
279 | |
274 | #if ENABLE_COMBINING |
280 | #if ENABLE_COMBINING |
275 | # define ENCODING_COMPOSE |
281 | # define ENCODING_COMPOSE |
276 | #endif |
282 | #endif |
… | |
… | |
282 | { |
288 | { |
283 | int l = 0; |
289 | int l = 0; |
284 | int r = sizeof (rxvt_compose_table) / sizeof (rxvt_compose_entry) - 1; |
290 | int r = sizeof (rxvt_compose_table) / sizeof (rxvt_compose_entry) - 1; |
285 | int m; |
291 | int m; |
286 | |
292 | |
287 | while (r > l) |
293 | while (r >= l) |
288 | { |
294 | { |
289 | m = (l + r) / 2; |
295 | m = (l + r) / 2; |
290 | rxvt_compose_entry &c = rxvt_compose_table[m]; |
296 | rxvt_compose_entry &c = rxvt_compose_table[m]; |
291 | |
297 | |
292 | if (c.c1 < c1 || (c.c1 == c1 && c.c2 < c2)) |
298 | if (c.c1 < c1 || (c.c1 == c1 && c.c2 < c2)) |
… | |
… | |
302 | |
308 | |
303 | #include "table/category.h" |
309 | #include "table/category.h" |
304 | |
310 | |
305 | bool unicode::is_space (unicode_t c) |
311 | bool unicode::is_space (unicode_t c) |
306 | { |
312 | { |
307 | return IS_SPACE (c); |
313 | return IS_SPACE (c) |
|
|
314 | || c == 0x09; // exclude tabs, too, as we store them in the buffer |
308 | } |
315 | } |