ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/encoding.C
Revision: 1.3
Committed: Wed Mar 3 17:15:49 2004 UTC (20 years, 2 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_1_0
Changes since 1.1: +68 -46 lines
Log Message:
*** empty log message ***

File Contents

# Content
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 { "ISO10646*", CS_UNICODE },
32 { "UNICODE", CS_UNICODE },
33 { "UTF8", CS_UNICODE },
34
35 { "ASCII", CS_US_ASCII },
36 { "USASCII", CS_US_ASCII },
37 { "ANSIX341968", CS_US_ASCII },
38
39 { "KOI8R", CS_KOI8_R },
40 { "GOST1976874*", CS_KOI8_R },
41 { "KOI8RU", CS_KOI8_U },
42 { "KOI8U", CS_KOI8_U },
43
44 { "VISCII*", CS_VISCII },
45 { "TIS62025291", CS_VISCII }, // close enough
46
47 { "JISX0201*", CS_JIS0201_1976_0 },
48 { "JISX0208*", CS_JIS0208_1983_0 }, // also wrongly matches -1990-0 (check Encode::JP)
49 { "JISX0212*", CS_JIS0212_1990_0 },
50 { "JISX0221*", CS_UNICODE },
51
52 { "KSC5601*", CS_KSC5601_1987_0 },
53 { "KSX1001*", CS_KSC5601_1987_0 },
54 { "KSC5700*", CS_UNICODE }, // unicode plus extensions
55
56 { "BIG5P*", CS_BIG5_PLUS },
57 { "BIG5ETEN*", CS_BIG5_EXT },
58 { "BIG5*", CS_BIG5 },
59 { "GB2312*", CS_GB2312_1980_0 },
60 { "GB6345*", CS_GB2312_1980_0 }, // slightly different to gb2312??
61 { "GB8565*", CS_GB2312_1980_0 }, // a superset of gb2312??
62 { "GB13000*", CS_UNICODE },
63 { "CNS1164319921", CS_CNS11643_1992_1 },
64 { "CNS1164319922", CS_CNS11643_1992_2 },
65 { "CNS1164319923", CS_CNS11643_1992_3 },
66 { "CNS1164319924", CS_CNS11643_1992_4 },
67 { "CNS1164319925", CS_CNS11643_1992_5 },
68 { "CNS1164319926", CS_CNS11643_1992_6 },
69 { "CNS1164319927", CS_CNS11643_1992_7 },
70 { "CNS116431992F", CS_CNS11643_1992_F },
71
72 { 0, CS_UNKNOWN }
73 };
74
75 static const char *
76 normalize_name (const char *name)
77 {
78 static char res[16];
79 char *r;
80
81 for (r = res; *name && r < res + 15; name++)
82 if ((*name >= '0' && *name <= '9')
83 || (*name >= 'A' && *name <= 'Z'))
84 *r++ = *name;
85 else if (*name >= 'a' && *name <= 'z')
86 *r++ = *name - ('a' - 'A');
87
88 *r = 0;
89
90 return res;
91 }
92
93 codeset
94 codeset_from_name (const char *name)
95 {
96 if (!name)
97 return CS_UNKNOWN;
98
99 name = normalize_name (name);
100
101 const struct n2cs *i = n2cs;
102
103 do {
104 int len = strlen (i->name);
105
106 if ((i->name[len - 1] == '*'
107 && !strncmp (name, i->name, len - 1))
108 || !strcmp (name, i->name))
109 return i->cs;
110
111 } while ((++i)->name);
112
113 return CS_UNKNOWN;
114 }
115
116 struct rxvt_codeset_conv_unknown : rxvt_codeset_conv {
117 uint32_t to_unicode (uint32_t enc) const { return NOCHAR; }
118 uint32_t from_unicode (uint32_t unicode) const { return NOCHAR; }
119 } rxvt_codeset_conv_unknown;
120
121 struct rxvt_codeset_conv_us_ascii : rxvt_codeset_conv {
122 uint32_t from_unicode (uint32_t unicode) const { return unicode <= 127 ? unicode : NOCHAR; }
123 } rxvt_codeset_conv_us_ascii;
124
125 struct rxvt_codeset_conv_unicode : rxvt_codeset_conv {
126 /* transparent */
127 } rxvt_codeset_conv_unicode;
128
129 struct rxvt_codeset_conv_unicode_16 : rxvt_codeset_conv {
130 uint32_t to_unicode (uint32_t enc) const { return enc; }
131 uint32_t from_unicode (uint32_t unicode) const { return unicode <= 65535 ? unicode : NOCHAR; }
132 } rxvt_codeset_conv_unicode_16;
133
134 /* block character set, must conform to the dec special pseudofont in defaultfont.C */
135 struct rxvt_codeset_conv_special : rxvt_codeset_conv {
136 uint32_t to_unicode (uint32_t enc) const {
137 return enc;
138 }
139
140 uint32_t from_unicode (uint32_t unicode) const {
141 return unicode;
142 }
143 } rxvt_codeset_conv_special;
144
145 #define ENCODING_DEFAULT
146
147 #include "table/iso8859_1.h"
148 #include "table/iso8859_15.h"
149
150 //#define ENCODING_EU
151
152 #include "table/iso8859_2.h"
153 #include "table/iso8859_3.h"
154 #include "table/iso8859_4.h"
155 #include "table/iso8859_5.h"
156 #include "table/iso8859_6.h"
157 #include "table/iso8859_7.h"
158 #include "table/iso8859_8.h"
159 #include "table/iso8859_9.h"
160 #include "table/iso8859_10.h"
161 #include "table/iso8859_11.h"
162 #include "table/iso8859_13.h"
163 #include "table/iso8859_14.h"
164 #include "table/iso8859_16.h"
165
166 #include "table/koi8_r.h"
167 #include "table/koi8_u.h"
168
169 //#define ENCODING_KR
170
171 #include "table/ksc5601_1987_0.h"
172
173 //#define ENCODING_CN
174
175 #include "table/gb2312_1980_0.h"
176 #include "table/big5.h"
177
178 //#define ENCODING_CN_EXT
179
180 #include "table/cns11643_1992_1.h"
181 #include "table/cns11643_1992_2.h"
182 #include "table/cns11643_1992_3.h"
183 #include "table/cns11643_1992_4.h"
184 #include "table/cns11643_1992_5.h"
185 #include "table/cns11643_1992_6.h"
186 #include "table/cns11643_1992_7.h"
187 #include "table/cns11643_1992_f.h"
188 #include "table/big5_ext.h"
189 #include "table/big5_plus.h"
190
191 //#define ENCODING_VN
192
193 #include "table/viscii.h"
194
195 //#define ENCODING_JP
196
197 #include "table/jis0201_1976_0.h"
198 #include "table/jis0208_1983_0.h"
199 #include "table/jis0212_1990_0.h"
200
201 //#define ENCODING_JP_EXT
202
203 #include "table/jis0213_1.h"
204 #include "table/jis0213_2.h"
205
206 // order must match table in encoding.h(!)
207 const rxvt_codeset_conv *rxvt_codeset[NUM_CODESETS] = {
208 &rxvt_codeset_conv_unknown,
209 &rxvt_codeset_conv_special,
210
211 &rxvt_codeset_conv_us_ascii,
212
213 &rxvt_codeset_conv_iso8859_1,
214 &rxvt_codeset_conv_iso8859_2,
215 &rxvt_codeset_conv_iso8859_3,
216 &rxvt_codeset_conv_iso8859_4,
217 &rxvt_codeset_conv_iso8859_5,
218 &rxvt_codeset_conv_iso8859_6,
219 &rxvt_codeset_conv_iso8859_7,
220 &rxvt_codeset_conv_iso8859_8,
221 &rxvt_codeset_conv_iso8859_9,
222 &rxvt_codeset_conv_iso8859_10,
223 &rxvt_codeset_conv_iso8859_11,
224 &rxvt_codeset_conv_iso8859_13,
225 &rxvt_codeset_conv_iso8859_14,
226 &rxvt_codeset_conv_iso8859_15,
227 &rxvt_codeset_conv_iso8859_16,
228
229 &rxvt_codeset_conv_koi8_r,
230 &rxvt_codeset_conv_koi8_u,
231
232 &rxvt_codeset_conv_jis0201_1976_0,
233 &rxvt_codeset_conv_jis0208_1983_0,
234 &rxvt_codeset_conv_jis0212_1990_0,
235
236 &rxvt_codeset_conv_jis0213_1,
237 &rxvt_codeset_conv_jis0213_2,
238
239 &rxvt_codeset_conv_ksc5601_1987_0,
240
241 &rxvt_codeset_conv_gb2312_1980_0,
242
243 &rxvt_codeset_conv_cns11643_1992_1,
244 &rxvt_codeset_conv_cns11643_1992_2,
245 &rxvt_codeset_conv_cns11643_1992_3,
246 &rxvt_codeset_conv_cns11643_1992_4,
247 &rxvt_codeset_conv_cns11643_1992_5,
248 &rxvt_codeset_conv_cns11643_1992_6,
249 &rxvt_codeset_conv_cns11643_1992_7,
250 &rxvt_codeset_conv_cns11643_1992_f,
251 &rxvt_codeset_conv_big5,
252 &rxvt_codeset_conv_big5_ext,
253 &rxvt_codeset_conv_big5_plus,
254
255 &rxvt_codeset_conv_viscii,
256
257 &rxvt_codeset_conv_unicode_16,
258 &rxvt_codeset_conv_unicode
259 };
260