ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/encoding.C
(Generate patch)

Comparing rxvt-unicode/src/encoding.C (file contents):
Revision 1.17 by root, Mon Jun 21 18:19:28 2004 UTC vs.
Revision 1.31 by root, Mon Feb 21 07:41:00 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines