1 |
#include "../config.h" |
2 |
|
3 |
#include "encoding.h" |
4 |
|
5 |
#include <cstdlib> |
6 |
#include <cstring> |
7 |
|
8 |
const struct n2cs { |
9 |
const char *name; |
10 |
codeset cs; |
11 |
} n2cs[] = { |
12 |
/* first one found is the normalized one */ |
13 |
{ "ISO88591", CS_ISO8859_1 }, |
14 |
{ "ISO8859PRIMARY", CS_ISO8859_1 }, // some stupid fonts use this (hi tigert) |
15 |
{ "ISO88592", CS_ISO8859_2 }, |
16 |
{ "ISO88593", CS_ISO8859_3 }, |
17 |
{ "ISO88594", CS_ISO8859_4 }, |
18 |
{ "ISO88595", CS_ISO8859_5 }, |
19 |
{ "ISO88596", CS_ISO8859_6 }, |
20 |
{ "ISO88597", CS_ISO8859_7 }, |
21 |
{ "ISO88598", CS_ISO8859_8 }, |
22 |
{ "ISO88599", CS_ISO8859_9 }, |
23 |
{ "ISO885910", CS_ISO8859_10 }, |
24 |
{ "ISO885911", CS_ISO8859_11 }, |
25 |
{ "ISO885913", CS_ISO8859_13 }, |
26 |
{ "ISO885914", CS_ISO8859_14 }, |
27 |
{ "ISO885915", CS_ISO8859_15 }, |
28 |
{ "FCD885915", CS_ISO8859_15 }, |
29 |
{ "ISO885916", CS_ISO8859_16 }, |
30 |
|
31 |
{ "TIS620*", CS_ISO8859_11 }, // close enough |
32 |
|
33 |
{ "ISO10646*", CS_UNICODE }, |
34 |
{ "UNICODE", CS_UNICODE }, |
35 |
{ "UTF8", CS_UNICODE }, |
36 |
|
37 |
{ "ASCII", CS_US_ASCII }, |
38 |
{ "USASCII", CS_US_ASCII }, |
39 |
{ "ANSIX341968", CS_US_ASCII }, |
40 |
|
41 |
{ "KOI8R", CS_KOI8_R }, |
42 |
{ "GOST1976874*", CS_KOI8_R }, |
43 |
{ "KOI8RU", CS_KOI8_U }, |
44 |
{ "KOI8U", CS_KOI8_U }, |
45 |
|
46 |
{ "VISCII*", CS_VISCII }, |
47 |
|
48 |
{ "JISX0201*", CS_JIS0201_1976_0 }, |
49 |
{ "JISX0208*", CS_JIS0208_1983_0 }, // also wrongly matches -1990-0 (check Encode::JP) |
50 |
{ "JISX0212*", CS_JIS0212_1990_0 }, |
51 |
{ "JISX0221*", CS_UNICODE }, |
52 |
|
53 |
{ "KSC5601*", CS_KSC5601_1987_0 }, |
54 |
{ "KSX1001*", CS_KSC5601_1987_0 }, |
55 |
{ "KSC5700*", CS_UNICODE }, // unicode plus extensions |
56 |
|
57 |
{ "BIG5P*", CS_BIG5_PLUS }, |
58 |
{ "BIG5ETEN*", CS_BIG5_EXT }, |
59 |
{ "BIG5*", CS_BIG5 }, |
60 |
{ "GB2312*", CS_GB2312_1980_0 }, |
61 |
{ "GB6345*", CS_GB2312_1980_0 }, // slightly different to gb2312?? |
62 |
{ "GB8565*", CS_GB2312_1980_0 }, // a superset of gb2312?? |
63 |
{ "GB13000*", CS_UNICODE }, |
64 |
{ "CNS1164319921", CS_CNS11643_1992_1 }, |
65 |
{ "CNS1164319922", CS_CNS11643_1992_2 }, |
66 |
{ "CNS1164319923", CS_CNS11643_1992_3 }, |
67 |
{ "CNS1164319924", CS_CNS11643_1992_4 }, |
68 |
{ "CNS1164319925", CS_CNS11643_1992_5 }, |
69 |
{ "CNS1164319926", CS_CNS11643_1992_6 }, |
70 |
{ "CNS1164319927", CS_CNS11643_1992_7 }, |
71 |
{ "CNS116431992F", CS_CNS11643_1992_F }, |
72 |
|
73 |
{ 0, CS_UNKNOWN } |
74 |
}; |
75 |
|
76 |
static const char * |
77 |
normalize_name (const char *name) |
78 |
{ |
79 |
static char res[16]; |
80 |
char *r; |
81 |
|
82 |
for (r = res; *name && r < res + 15; name++) |
83 |
if ((*name >= '0' && *name <= '9') |
84 |
|| (*name >= 'A' && *name <= 'Z')) |
85 |
*r++ = *name; |
86 |
else if (*name >= 'a' && *name <= 'z') |
87 |
*r++ = *name - ('a' - 'A'); |
88 |
|
89 |
*r = 0; |
90 |
|
91 |
return res; |
92 |
} |
93 |
|
94 |
codeset |
95 |
codeset_from_name (const char *name) |
96 |
{ |
97 |
if (!name) |
98 |
return CS_UNKNOWN; |
99 |
|
100 |
name = normalize_name (name); |
101 |
|
102 |
const struct n2cs *i = n2cs; |
103 |
|
104 |
do { |
105 |
int len = strlen (i->name); |
106 |
|
107 |
if ((i->name[len - 1] == '*' |
108 |
&& !strncmp (name, i->name, len - 1)) |
109 |
|| !strcmp (name, i->name)) |
110 |
return i->cs; |
111 |
|
112 |
} while ((++i)->name); |
113 |
|
114 |
return CS_UNKNOWN; |
115 |
} |
116 |
|
117 |
struct rxvt_codeset_conv_unknown : rxvt_codeset_conv { |
118 |
uint32_t to_unicode (uint32_t enc) const { return NOCHAR; } |
119 |
uint32_t from_unicode (uint32_t unicode) const { return NOCHAR; } |
120 |
} rxvt_codeset_conv_unknown; |
121 |
|
122 |
struct rxvt_codeset_conv_us_ascii : rxvt_codeset_conv { |
123 |
uint32_t from_unicode (uint32_t unicode) const { return unicode <= 127 ? unicode : NOCHAR; } |
124 |
} rxvt_codeset_conv_us_ascii; |
125 |
|
126 |
struct rxvt_codeset_conv_unicode : rxvt_codeset_conv { |
127 |
/* transparent */ |
128 |
} rxvt_codeset_conv_unicode; |
129 |
|
130 |
struct 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; } |
133 |
} rxvt_codeset_conv_unicode_16; |
134 |
|
135 |
#define ENCODING_DEFAULT |
136 |
|
137 |
#include "table/iso8859_1.h" |
138 |
#include "table/iso8859_15.h" |
139 |
|
140 |
//#define ENCODING_EU |
141 |
|
142 |
#include "table/iso8859_2.h" |
143 |
#include "table/iso8859_3.h" |
144 |
#include "table/iso8859_4.h" |
145 |
#include "table/iso8859_5.h" |
146 |
#include "table/iso8859_6.h" |
147 |
#include "table/iso8859_7.h" |
148 |
#include "table/iso8859_8.h" |
149 |
#include "table/iso8859_9.h" |
150 |
#include "table/iso8859_10.h" |
151 |
#include "table/iso8859_11.h" |
152 |
#include "table/iso8859_13.h" |
153 |
#include "table/iso8859_14.h" |
154 |
#include "table/iso8859_16.h" |
155 |
|
156 |
#include "table/koi8_r.h" |
157 |
#include "table/koi8_u.h" |
158 |
|
159 |
//#define ENCODING_KR |
160 |
|
161 |
#include "table/ksc5601_1987_0.h" |
162 |
|
163 |
//#define ENCODING_CN |
164 |
|
165 |
#include "table/gb2312_1980_0.h" |
166 |
#include "table/big5.h" |
167 |
|
168 |
//#define ENCODING_CN_EXT |
169 |
|
170 |
#include "table/cns11643_1992_1.h" |
171 |
#include "table/cns11643_1992_2.h" |
172 |
#include "table/cns11643_1992_3.h" |
173 |
#include "table/cns11643_1992_4.h" |
174 |
#include "table/cns11643_1992_5.h" |
175 |
#include "table/cns11643_1992_6.h" |
176 |
#include "table/cns11643_1992_7.h" |
177 |
#include "table/cns11643_1992_f.h" |
178 |
#include "table/big5_ext.h" |
179 |
#include "table/big5_plus.h" |
180 |
|
181 |
//#define ENCODING_VN |
182 |
|
183 |
#include "table/viscii.h" |
184 |
|
185 |
//#define ENCODING_JP |
186 |
|
187 |
#include "table/jis0201_1976_0.h" |
188 |
#include "table/jis0208_1983_0.h" |
189 |
#include "table/jis0212_1990_0.h" |
190 |
|
191 |
//#define ENCODING_JP_EXT |
192 |
|
193 |
#include "table/jis0213_1.h" |
194 |
#include "table/jis0213_2.h" |
195 |
|
196 |
// order must match table in encoding.h(!) |
197 |
const rxvt_codeset_conv *rxvt_codeset[NUM_CODESETS] = { |
198 |
&rxvt_codeset_conv_unknown, |
199 |
|
200 |
&rxvt_codeset_conv_us_ascii, |
201 |
|
202 |
&rxvt_codeset_conv_iso8859_1, |
203 |
&rxvt_codeset_conv_iso8859_2, |
204 |
&rxvt_codeset_conv_iso8859_3, |
205 |
&rxvt_codeset_conv_iso8859_4, |
206 |
&rxvt_codeset_conv_iso8859_5, |
207 |
&rxvt_codeset_conv_iso8859_6, |
208 |
&rxvt_codeset_conv_iso8859_7, |
209 |
&rxvt_codeset_conv_iso8859_8, |
210 |
&rxvt_codeset_conv_iso8859_9, |
211 |
&rxvt_codeset_conv_iso8859_10, |
212 |
&rxvt_codeset_conv_iso8859_11, |
213 |
&rxvt_codeset_conv_iso8859_13, |
214 |
&rxvt_codeset_conv_iso8859_14, |
215 |
&rxvt_codeset_conv_iso8859_15, |
216 |
&rxvt_codeset_conv_iso8859_16, |
217 |
|
218 |
&rxvt_codeset_conv_koi8_r, |
219 |
&rxvt_codeset_conv_koi8_u, |
220 |
|
221 |
&rxvt_codeset_conv_jis0201_1976_0, |
222 |
&rxvt_codeset_conv_jis0208_1983_0, |
223 |
&rxvt_codeset_conv_jis0212_1990_0, |
224 |
|
225 |
&rxvt_codeset_conv_jis0213_1, |
226 |
&rxvt_codeset_conv_jis0213_2, |
227 |
|
228 |
&rxvt_codeset_conv_ksc5601_1987_0, |
229 |
|
230 |
&rxvt_codeset_conv_gb2312_1980_0, |
231 |
|
232 |
&rxvt_codeset_conv_cns11643_1992_1, |
233 |
&rxvt_codeset_conv_cns11643_1992_2, |
234 |
&rxvt_codeset_conv_cns11643_1992_3, |
235 |
&rxvt_codeset_conv_cns11643_1992_4, |
236 |
&rxvt_codeset_conv_cns11643_1992_5, |
237 |
&rxvt_codeset_conv_cns11643_1992_6, |
238 |
&rxvt_codeset_conv_cns11643_1992_7, |
239 |
&rxvt_codeset_conv_cns11643_1992_f, |
240 |
&rxvt_codeset_conv_big5, |
241 |
&rxvt_codeset_conv_big5_ext, |
242 |
&rxvt_codeset_conv_big5_plus, |
243 |
|
244 |
&rxvt_codeset_conv_viscii, |
245 |
|
246 |
&rxvt_codeset_conv_unicode_16, |
247 |
&rxvt_codeset_conv_unicode |
248 |
}; |
249 |
|
250 |
#if ENABLE_COMBINING |
251 |
# define ENCODING_COMPOSE |
252 |
#endif |
253 |
|
254 |
#include "table/compose.h" |
255 |
|
256 |
uint32_t |
257 |
rxvt_compose (uint32_t c1, uint32_t c2) |
258 |
{ |
259 |
int l = 0; |
260 |
int r = sizeof (rxvt_compose_table) / sizeof (rxvt_compose_entry) - 1; |
261 |
int m; |
262 |
|
263 |
while (r > l) |
264 |
{ |
265 |
m = (l + r) / 2; |
266 |
rxvt_compose_entry &c = rxvt_compose_table[m]; |
267 |
|
268 |
if (c.c1 < c1 || (c.c1 == c1 && c.c2 < c2)) |
269 |
l = m + 1; |
270 |
else if (c.c1 > c1 || (c.c1 == c1 && c.c2 > c2)) |
271 |
r = m - 1; |
272 |
else |
273 |
return c.r; |
274 |
} |
275 |
|
276 |
return NOCHAR; |
277 |
} |