|
|
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> |
… | |
… | |
44 | { "KOI8U", CS_KOI8_U }, |
66 | { "KOI8U", CS_KOI8_U }, |
45 | |
67 | |
46 | { "VISCII*", CS_VISCII }, |
68 | { "VISCII*", CS_VISCII }, |
47 | |
69 | |
48 | { "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) |
49 | { "JISX0208*", CS_JIS0208_1990_0 }, // also wrongly matches -1987-0? (check Encode::JP) |
72 | { "JISX0208*", CS_JIS0208_1990_0 }, // also wrongly matches -1987-0? (check Encode::JP) |
50 | { "JISX0212*", CS_JIS0212_1990_0 }, |
73 | { "JISX0212*", CS_JIS0212_1990_0 }, |
51 | { "JISX021320001", CS_JIS0213_1 }, |
74 | { "JISX021320001", CS_JIS0213_1 }, |
52 | { "JISX021320002", CS_JIS0213_2 }, |
75 | { "JISX021320002", CS_JIS0213_2 }, |
53 | { "JISX0221*", CS_UNICODE }, // _very_ close |
76 | { "JISX0221*", CS_UNICODE }, // _very_ close |
… | |
… | |
114 | } while ((++i)->name); |
137 | } while ((++i)->name); |
115 | |
138 | |
116 | return CS_UNKNOWN; |
139 | return CS_UNKNOWN; |
117 | } |
140 | } |
118 | |
141 | |
119 | struct rxvt_codeset_conv_unknown : rxvt_codeset_conv { |
|
|
120 | unicode_t to_unicode (uint32_t enc) const { return NOCHAR; } |
142 | static unicode_t cs_unknown_to_unicode (uint32_t enc) { return NOCHAR; } |
121 | uint32_t from_unicode (unicode_t unicode) const { return NOCHAR; } |
143 | static uint32_t cs_unknown_from_unicode (unicode_t unicode) { return NOCHAR; } |
122 | } rxvt_codeset_conv_unknown; |
|
|
123 | |
144 | |
124 | 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 |
125 | uint32_t from_unicode (unicode_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; } |
126 | } rxvt_codeset_conv_us_ascii; |
|
|
127 | |
150 | |
128 | struct rxvt_codeset_conv_unicode : rxvt_codeset_conv { |
151 | #define cs_us_ascii_to_unicode_16 cs_unicode_to_unicode |
129 | /* transparent */ |
|
|
130 | } rxvt_codeset_conv_unicode; |
|
|
131 | |
|
|
132 | struct rxvt_codeset_conv_unicode_16 : rxvt_codeset_conv { |
|
|
133 | unicode_t to_unicode (uint32_t enc) const { return enc; } |
|
|
134 | uint32_t from_unicode (unicode_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; } |
135 | } rxvt_codeset_conv_unicode_16; |
|
|
136 | |
153 | |
137 | #define ENCODING_DEFAULT |
154 | #define ENCODING_DEFAULT |
138 | |
155 | |
139 | #include "table/iso8859_1.h" |
156 | #include "table/iso8859_1.h" |
140 | #include "table/iso8859_15.h" |
157 | #include "table/iso8859_15.h" |
… | |
… | |
193 | //#define ENCODING_JP_EXT |
210 | //#define ENCODING_JP_EXT |
194 | |
211 | |
195 | #include "table/jis0213_1.h" |
212 | #include "table/jis0213_1.h" |
196 | #include "table/jis0213_2.h" |
213 | #include "table/jis0213_2.h" |
197 | |
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 | |
198 | // order must match table in encoding.h(!) |
222 | // order must match table in encoding.h(!) |
199 | const rxvt_codeset_conv *rxvt_codeset[NUM_CODESETS] = { |
223 | const rxvt_codeset_conv rxvt_codeset[NUM_CODESETS] = { |
200 | &rxvt_codeset_conv_unknown, |
224 | ENC (unknown), |
201 | |
225 | |
202 | &rxvt_codeset_conv_us_ascii, |
226 | ENC (us_ascii), |
203 | |
227 | |
204 | &rxvt_codeset_conv_iso8859_1, |
228 | ENC (iso8859_1), |
205 | &rxvt_codeset_conv_iso8859_2, |
229 | ENC (iso8859_2), |
206 | &rxvt_codeset_conv_iso8859_3, |
230 | ENC (iso8859_3), |
207 | &rxvt_codeset_conv_iso8859_4, |
231 | ENC (iso8859_4), |
208 | &rxvt_codeset_conv_iso8859_5, |
232 | ENC (iso8859_5), |
209 | &rxvt_codeset_conv_iso8859_6, |
233 | ENC (iso8859_6), |
210 | &rxvt_codeset_conv_iso8859_7, |
234 | ENC (iso8859_7), |
211 | &rxvt_codeset_conv_iso8859_8, |
235 | ENC (iso8859_8), |
212 | &rxvt_codeset_conv_iso8859_9, |
236 | ENC (iso8859_9), |
213 | &rxvt_codeset_conv_iso8859_10, |
237 | ENC (iso8859_10), |
214 | &rxvt_codeset_conv_iso8859_11, |
238 | ENC (iso8859_11), |
215 | &rxvt_codeset_conv_iso8859_13, |
239 | ENC (iso8859_13), |
216 | &rxvt_codeset_conv_iso8859_14, |
240 | ENC (iso8859_14), |
217 | &rxvt_codeset_conv_iso8859_15, |
241 | ENC (iso8859_15), |
218 | &rxvt_codeset_conv_iso8859_16, |
242 | ENC (iso8859_16), |
219 | |
243 | |
220 | &rxvt_codeset_conv_koi8_r, |
244 | ENC (koi8_r), |
221 | &rxvt_codeset_conv_koi8_u, |
245 | ENC (koi8_u), |
222 | |
246 | |
223 | &rxvt_codeset_conv_jis0201_1976_0, |
247 | ENC (jis0201_1976_0), |
224 | &rxvt_codeset_conv_jis0208_1990_0, |
248 | ENC (jis0208_1990_0), |
225 | &rxvt_codeset_conv_jis0212_1990_0, |
249 | ENC (jis0212_1990_0), |
226 | |
250 | |
227 | &rxvt_codeset_conv_jis0213_1, |
251 | ENC (jis0213_1), |
228 | &rxvt_codeset_conv_jis0213_2, |
252 | ENC (jis0213_2), |
229 | |
253 | |
230 | &rxvt_codeset_conv_ksc5601_1987_0, |
254 | ENC (ksc5601_1987_0), |
231 | |
255 | |
232 | &rxvt_codeset_conv_gb2312_1980_0, |
256 | ENC (gb2312_1980_0), |
233 | |
257 | |
234 | &rxvt_codeset_conv_cns11643_1992_1, |
258 | ENC (cns11643_1992_1), |
235 | &rxvt_codeset_conv_cns11643_1992_2, |
259 | ENC (cns11643_1992_2), |
236 | &rxvt_codeset_conv_cns11643_1992_3, |
260 | ENC (cns11643_1992_3), |
237 | &rxvt_codeset_conv_cns11643_1992_4, |
261 | ENC (cns11643_1992_4), |
238 | &rxvt_codeset_conv_cns11643_1992_5, |
262 | ENC (cns11643_1992_5), |
239 | &rxvt_codeset_conv_cns11643_1992_6, |
263 | ENC (cns11643_1992_6), |
240 | &rxvt_codeset_conv_cns11643_1992_7, |
264 | ENC (cns11643_1992_7), |
241 | &rxvt_codeset_conv_cns11643_1992_f, |
265 | ENC (cns11643_1992_f), |
242 | &rxvt_codeset_conv_big5, |
266 | ENC (big5), |
243 | &rxvt_codeset_conv_big5_ext, |
267 | ENC (big5_ext), |
244 | &rxvt_codeset_conv_big5_plus, |
268 | ENC (big5_plus), |
245 | |
269 | |
246 | &rxvt_codeset_conv_viscii, |
270 | ENC (viscii), |
247 | |
271 | |
248 | &rxvt_codeset_conv_unicode_16, |
272 | ENC (unicode_16), |
249 | &rxvt_codeset_conv_unicode |
273 | ENC (unicode), |
250 | }; |
274 | }; |
251 | |
275 | |
252 | #if ENABLE_COMBINING |
276 | #if ENABLE_COMBINING |
253 | # define ENCODING_COMPOSE |
277 | # define ENCODING_COMPOSE |
254 | #endif |
278 | #endif |