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.10 by pcg, Sun Mar 14 17:33:07 2004 UTC vs.
Revision 1.26 by ayin, Wed Oct 31 09:55:23 2007 UTC

1/*----------------------------------------------------------------------*
2 * File: encoding.C
3 *----------------------------------------------------------------------*
4 *
5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2003-2006 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>
25 { "ISO885913", CS_ISO8859_13 }, 47 { "ISO885913", CS_ISO8859_13 },
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
31 { "TIS620*", CS_ISO8859_11 }, // close enough 53 { "TIS620*", CS_ISO8859_11 }, // close enough
32 54
33 { "ISO10646*", CS_UNICODE }, 55 { "ISO10646*", CS_UNICODE },
34 { "UNICODE", CS_UNICODE }, 56 { "UNICODE", CS_UNICODE },
35 { "UTF8", CS_UNICODE }, 57 { "UTF8", CS_UNICODE },
36 58
37 { "ASCII", CS_US_ASCII }, 59 { "ASCII", CS_US_ASCII },
38 { "USASCII", CS_US_ASCII }, 60 { "USASCII", CS_US_ASCII },
39 { "ANSIX341968", CS_US_ASCII }, 61 { "ANSIX341968", CS_US_ASCII },
40 62 { "ISO646.1991-IRV", CS_US_ASCII }, // older versions used the currency sign
63
41 { "KOI8R", CS_KOI8_R }, 64 { "KOI8R*", CS_KOI8_R },
42 { "GOST1976874*", CS_KOI8_R }, 65 { "GOST1976874*", CS_KOI8_R },
43 { "KOI8RU", CS_KOI8_U }, 66 { "KOI8RU", CS_KOI8_U },
44 { "KOI8U", CS_KOI8_U }, 67 { "KOI8U", CS_KOI8_U },
45 68
46 { "VISCII*", CS_VISCII }, 69 { "VISCII*", CS_VISCII },
47 70
48 { "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)
49 { "JISX0208*", CS_JIS0208_1983_0 }, // also wrongly matches -1990-0 (check Encode::JP) 73 { "JISX0208*", CS_JIS0208_1990_0 }, // also wrongly matches -1987-0? (check Encode::JP)
50 { "JISX0212*", CS_JIS0212_1990_0 }, 74 { "JISX0212*", CS_JIS0212_1990_0 },
75 { "JISX021320001", CS_JIS0213_1 },
76 { "JISX021320002", CS_JIS0213_2 },
51 { "JISX0221*", CS_UNICODE }, 77 { "JISX0221*", CS_UNICODE }, // _very_ close
52 78
53 { "KSC5601*", CS_KSC5601_1987_0 }, 79 { "KSC5601*", CS_KSC5601_1987_0 },
54 { "KSX1001*", CS_KSC5601_1987_0 }, 80 { "KSX1001*", CS_KSC5601_1987_0 },
55 { "KSC5700*", CS_UNICODE }, // unicode plus extensions 81 { "KSC5700*", CS_UNICODE }, // unicode plus extensions
56 82
57 { "BIG5P*", CS_BIG5_PLUS }, 83 { "BIG5P*", CS_BIG5_PLUS },
58 { "BIG5ETEN*", CS_BIG5_EXT }, 84 { "BIG5ETEN*", CS_BIG5_EXT },
59 { "BIG5*", CS_BIG5 }, 85 { "BIG5*", CS_BIG5 },
60 { "GB2312*", CS_GB2312_1980_0 }, 86 { "GB2312*", CS_GB2312_1980_0 },
87 { "GBK*", CS_GBK_0 },
61 { "GB6345*", CS_GB2312_1980_0 }, // slightly different to gb2312?? 88 { "GB6345*", CS_GB2312_1980_0 }, // slightly different to gb2312??
62 { "GB8565*", CS_GB2312_1980_0 }, // a superset of gb2312?? 89 { "GB8565*", CS_GB2312_1980_0 }, // a superset of gb2312??
63 { "GB13000*", CS_UNICODE }, 90 { "GB13000*", CS_UNICODE },
64 { "CNS1164319921", CS_CNS11643_1992_1 }, 91 { "CNS1164319921", CS_CNS11643_1992_1 },
65 { "CNS1164319922", CS_CNS11643_1992_2 }, 92 { "CNS1164319922", CS_CNS11643_1992_2 },
112 } while ((++i)->name); 139 } while ((++i)->name);
113 140
114 return CS_UNKNOWN; 141 return CS_UNKNOWN;
115} 142}
116 143
117struct rxvt_codeset_conv_unknown : rxvt_codeset_conv { 144static unicode_t cs_unknown_to_unicode (uint32_t enc) { return NOCHAR; }
118 uint32_t to_unicode (uint32_t enc) const { return NOCHAR; }
119 uint32_t from_unicode (uint32_t unicode) const { return NOCHAR; } 145static uint32_t cs_unknown_from_unicode (unicode_t unicode) { return NOCHAR; }
120} rxvt_codeset_conv_unknown;
121 146
122struct rxvt_codeset_conv_us_ascii : rxvt_codeset_conv { 147static unicode_t cs_unicode_to_unicode (uint32_t enc) { return enc; }
148static uint32_t cs_unicode_from_unicode (unicode_t unicode) { return unicode; }
149
150#define cs_us_ascii_to_unicode cs_unicode_to_unicode
123 uint32_t from_unicode (uint32_t unicode) const { return unicode <= 127 ? unicode : NOCHAR; } 151static uint32_t cs_us_ascii_from_unicode (unicode_t unicode) { return unicode <= 127 ? unicode : NOCHAR; }
124} rxvt_codeset_conv_us_ascii;
125 152
126struct rxvt_codeset_conv_unicode : rxvt_codeset_conv { 153#define cs_us_ascii_to_unicode_16 cs_unicode_to_unicode
127 /* transparent */
128} rxvt_codeset_conv_unicode;
129
130struct rxvt_codeset_conv_unicode_16 : rxvt_codeset_conv {
131 uint32_t to_unicode (uint32_t enc) const { return enc; }
132 uint32_t from_unicode (uint32_t unicode) const { return unicode <= 65535 ? unicode : NOCHAR; } 154static uint32_t cs_unicode_16_from_unicode (unicode_t unicode) { return unicode <= 65535 ? unicode : NOCHAR; }
133} rxvt_codeset_conv_unicode_16;
134 155
135#define ENCODING_DEFAULT 156#define ENCODING_DEFAULT
136 157
137#include "table/iso8859_1.h" 158#include "table/iso8859_1.h"
138#include "table/iso8859_15.h" 159#include "table/iso8859_15.h"
158 179
159//#define ENCODING_KR 180//#define ENCODING_KR
160 181
161#include "table/ksc5601_1987_0.h" 182#include "table/ksc5601_1987_0.h"
162 183
163//#define ENCODING_CN 184//#define ENCODING_ZH
164 185
186#include "table/big5.h"
187#include "table/gbk_0.h"
165#include "table/gb2312_1980_0.h" 188#include "table/gb2312_1980_0.h"
166#include "table/big5.h"
167 189
168//#define ENCODING_CN_EXT 190//#define ENCODING_ZH_EXT
169 191
170#include "table/cns11643_1992_1.h" 192#include "table/cns11643_1992_1.h"
171#include "table/cns11643_1992_2.h" 193#include "table/cns11643_1992_2.h"
172#include "table/cns11643_1992_3.h" 194#include "table/cns11643_1992_3.h"
173#include "table/cns11643_1992_4.h" 195#include "table/cns11643_1992_4.h"
183#include "table/viscii.h" 205#include "table/viscii.h"
184 206
185//#define ENCODING_JP 207//#define ENCODING_JP
186 208
187#include "table/jis0201_1976_0.h" 209#include "table/jis0201_1976_0.h"
188#include "table/jis0208_1983_0.h" 210#include "table/jis0208_1990_0.h"
189#include "table/jis0212_1990_0.h" 211#include "table/jis0212_1990_0.h"
190 212
191//#define ENCODING_JP_EXT 213//#define ENCODING_JP_EXT
192 214
193#include "table/jis0213_1.h" 215#include "table/jis0213_1.h"
194#include "table/jis0213_2.h" 216#include "table/jis0213_2.h"
195 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
196// order must match table in encoding.h(!) 225// order must match table in encoding.h(!)
197const rxvt_codeset_conv *rxvt_codeset[NUM_CODESETS] = { 226const rxvt_codeset_conv rxvt_codeset[NUM_CODESETS] = {
198 &rxvt_codeset_conv_unknown, 227 ENC (unknown),
199 228
200 &rxvt_codeset_conv_us_ascii, 229 ENC (us_ascii),
201 230
202 &rxvt_codeset_conv_iso8859_1, 231 ENC (iso8859_1),
203 &rxvt_codeset_conv_iso8859_2, 232 ENC (iso8859_2),
204 &rxvt_codeset_conv_iso8859_3, 233 ENC (iso8859_3),
205 &rxvt_codeset_conv_iso8859_4, 234 ENC (iso8859_4),
206 &rxvt_codeset_conv_iso8859_5, 235 ENC (iso8859_5),
207 &rxvt_codeset_conv_iso8859_6, 236 ENC (iso8859_6),
208 &rxvt_codeset_conv_iso8859_7, 237 ENC (iso8859_7),
209 &rxvt_codeset_conv_iso8859_8, 238 ENC (iso8859_8),
210 &rxvt_codeset_conv_iso8859_9, 239 ENC (iso8859_9),
211 &rxvt_codeset_conv_iso8859_10, 240 ENC (iso8859_10),
212 &rxvt_codeset_conv_iso8859_11, 241 ENC (iso8859_11),
213 &rxvt_codeset_conv_iso8859_13, 242 ENC (iso8859_13),
214 &rxvt_codeset_conv_iso8859_14, 243 ENC (iso8859_14),
215 &rxvt_codeset_conv_iso8859_15, 244 ENC (iso8859_15),
216 &rxvt_codeset_conv_iso8859_16, 245 ENC (iso8859_16),
217 246
218 &rxvt_codeset_conv_koi8_r, 247 ENC (koi8_r),
219 &rxvt_codeset_conv_koi8_u, 248 ENC (koi8_u),
220 249
221 &rxvt_codeset_conv_jis0201_1976_0, 250 ENC (jis0201_1976_0),
222 &rxvt_codeset_conv_jis0208_1983_0, 251 ENC (jis0208_1990_0),
223 &rxvt_codeset_conv_jis0212_1990_0, 252 ENC (jis0212_1990_0),
224 253
225 &rxvt_codeset_conv_jis0213_1, 254 ENC (jis0213_1),
226 &rxvt_codeset_conv_jis0213_2, 255 ENC (jis0213_2),
227 256
228 &rxvt_codeset_conv_ksc5601_1987_0, 257 ENC (ksc5601_1987_0),
229 258
230 &rxvt_codeset_conv_gb2312_1980_0, 259 ENC (gb2312_1980_0),
260 ENC (gbk_0),
231 261
232 &rxvt_codeset_conv_cns11643_1992_1, 262 ENC (cns11643_1992_1),
233 &rxvt_codeset_conv_cns11643_1992_2, 263 ENC (cns11643_1992_2),
234 &rxvt_codeset_conv_cns11643_1992_3, 264 ENC (cns11643_1992_3),
235 &rxvt_codeset_conv_cns11643_1992_4, 265 ENC (cns11643_1992_4),
236 &rxvt_codeset_conv_cns11643_1992_5, 266 ENC (cns11643_1992_5),
237 &rxvt_codeset_conv_cns11643_1992_6, 267 ENC (cns11643_1992_6),
238 &rxvt_codeset_conv_cns11643_1992_7, 268 ENC (cns11643_1992_7),
239 &rxvt_codeset_conv_cns11643_1992_f, 269 ENC (cns11643_1992_f),
240 &rxvt_codeset_conv_big5, 270 ENC (big5),
241 &rxvt_codeset_conv_big5_ext, 271 ENC (big5_ext),
242 &rxvt_codeset_conv_big5_plus, 272 ENC (big5_plus),
243 273
244 &rxvt_codeset_conv_viscii, 274 ENC (viscii),
245 275
246 &rxvt_codeset_conv_unicode_16, 276 ENC (unicode_16),
247 &rxvt_codeset_conv_unicode 277 ENC (unicode),
248}; 278};
249 279
250#if ENABLE_COMBINING 280#if ENABLE_COMBINING
251# define ENCODING_COMPOSE 281# define ENCODING_COMPOSE
252#endif 282#endif
253 283
254#include "table/compose.h" 284#include "table/compose.h"
255 285
256uint32_t 286unicode_t
257rxvt_compose (uint32_t c1, uint32_t c2) 287rxvt_compose (unicode_t c1, unicode_t c2)
258{ 288{
259 int l = 0; 289 int l = 0;
260 int r = sizeof (rxvt_compose_table) / sizeof (rxvt_compose_entry) - 1; 290 int r = sizeof (rxvt_compose_table) / sizeof (rxvt_compose_entry) - 1;
261 int m; 291 int m;
262 292
273 return c.r; 303 return c.r;
274 } 304 }
275 305
276 return NOCHAR; 306 return NOCHAR;
277} 307}
308
309#include "table/category.h"
310
311bool unicode::is_space (unicode_t c)
312{
313 return IS_SPACE (c)
314 || c == 0x09; // exclude tabs, too, as we store them in the buffer
315}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines