| 1 |
pcg |
1.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 |
|
|
{ "ISO106461", 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 |
|
|
{ "GOST19768741", CS_KOI8_R }, |
| 41 |
|
|
{ "KOI8U", CS_KOI8_U }, |
| 42 |
|
|
|
| 43 |
|
|
{ "KSC560119870", CS_KSC5601_1987_0 }, |
| 44 |
|
|
{ "KSX100119970", CS_KSC5601_1987_0 }, |
| 45 |
|
|
{ "KSX100119980", CS_KSC5601_1987_0 }, // adds johab |
| 46 |
|
|
|
| 47 |
|
|
{ "GB231219800", CS_GB2312_1980_0 }, |
| 48 |
|
|
|
| 49 |
|
|
{ "VISCII", CS_VISCII }, |
| 50 |
|
|
{ "VISCII111", CS_VISCII }, |
| 51 |
|
|
{ "TIS62025291", CS_VISCII }, /* close enough */ |
| 52 |
|
|
|
| 53 |
|
|
{ "JISX020119760", CS_JIS0201_1976_0 }, |
| 54 |
|
|
{ "JISX020819830", CS_JIS0208_1983_0 }, |
| 55 |
|
|
{ "JISX020819900", CS_JIS0208_1983_0 }, /* ehrm. */ |
| 56 |
|
|
{ "JISX021219900", CS_JIS0212_1990_0 }, |
| 57 |
|
|
|
| 58 |
|
|
{ 0, CS_UNKNOWN } |
| 59 |
|
|
}; |
| 60 |
|
|
|
| 61 |
|
|
static const char * |
| 62 |
|
|
normalize_name (const char *name) |
| 63 |
|
|
{ |
| 64 |
|
|
static char res[16]; |
| 65 |
|
|
char *r; |
| 66 |
|
|
|
| 67 |
|
|
for (r = res; *name && r < res + 15; name++) |
| 68 |
|
|
if ((*name >= '0' && *name <= '9') |
| 69 |
|
|
|| (*name >= 'A' && *name <= 'Z')) |
| 70 |
|
|
*r++ = *name; |
| 71 |
|
|
else if (*name >= 'a' && *name <= 'z') |
| 72 |
|
|
*r++ = *name - ('a' - 'A'); |
| 73 |
|
|
|
| 74 |
|
|
*r = 0; |
| 75 |
|
|
|
| 76 |
|
|
return res; |
| 77 |
|
|
} |
| 78 |
|
|
|
| 79 |
|
|
codeset |
| 80 |
|
|
codeset_from_name (const char *name) |
| 81 |
|
|
{ |
| 82 |
|
|
if (!name) |
| 83 |
|
|
return CS_UNKNOWN; |
| 84 |
|
|
|
| 85 |
|
|
name = normalize_name (name); |
| 86 |
|
|
|
| 87 |
|
|
const struct n2cs *i = n2cs; |
| 88 |
|
|
|
| 89 |
|
|
do { |
| 90 |
|
|
if (!strcmp (name, i->name)) |
| 91 |
|
|
return i->cs; |
| 92 |
|
|
} while ((++i)->name); |
| 93 |
|
|
|
| 94 |
|
|
return CS_UNKNOWN; |
| 95 |
|
|
} |
| 96 |
|
|
|
| 97 |
|
|
struct rxvt_codeset_conv_unknown : rxvt_codeset_conv { |
| 98 |
|
|
uint32_t to_unicode (uint32_t enc) const { return NOCHAR; } |
| 99 |
|
|
uint32_t from_unicode (uint32_t unicode) const { return NOCHAR; } |
| 100 |
|
|
} rxvt_codeset_conv_unknown; |
| 101 |
|
|
|
| 102 |
|
|
struct rxvt_codeset_conv_us_ascii : rxvt_codeset_conv { |
| 103 |
|
|
uint32_t from_unicode (uint32_t unicode) const { return unicode <= 127 ? unicode : NOCHAR; } |
| 104 |
|
|
} rxvt_codeset_conv_us_ascii; |
| 105 |
|
|
|
| 106 |
|
|
struct rxvt_codeset_conv_unicode : rxvt_codeset_conv { |
| 107 |
|
|
/* transparent */ |
| 108 |
|
|
} rxvt_codeset_conv_unicode; |
| 109 |
|
|
|
| 110 |
|
|
struct rxvt_codeset_conv_unicode_16 : rxvt_codeset_conv { |
| 111 |
|
|
uint32_t to_unicode (uint32_t enc) const { return enc; } |
| 112 |
|
|
uint32_t from_unicode (uint32_t unicode) const { return unicode <= 65535 ? unicode : NOCHAR; } |
| 113 |
|
|
} rxvt_codeset_conv_unicode_16; |
| 114 |
|
|
|
| 115 |
|
|
/* block character set, must conform to the dec special pseudofont in defaultfont.C */ |
| 116 |
|
|
struct rxvt_codeset_conv_special : rxvt_codeset_conv { |
| 117 |
|
|
uint32_t to_unicode (uint32_t enc) const { |
| 118 |
|
|
return enc; |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
uint32_t from_unicode (uint32_t unicode) const { |
| 122 |
|
|
return unicode; |
| 123 |
|
|
} |
| 124 |
|
|
} rxvt_codeset_conv_special; |
| 125 |
|
|
|
| 126 |
|
|
#define ENCODING_DEFAULT |
| 127 |
|
|
|
| 128 |
|
|
#include "table/iso8859_1.h" |
| 129 |
|
|
#include "table/iso8859_15.h" |
| 130 |
|
|
|
| 131 |
|
|
//#define ENCODING_EU |
| 132 |
|
|
|
| 133 |
|
|
#include "table/iso8859_2.h" |
| 134 |
|
|
#include "table/iso8859_3.h" |
| 135 |
|
|
#include "table/iso8859_4.h" |
| 136 |
|
|
#include "table/iso8859_5.h" |
| 137 |
|
|
#include "table/iso8859_6.h" |
| 138 |
|
|
#include "table/iso8859_7.h" |
| 139 |
|
|
#include "table/iso8859_8.h" |
| 140 |
|
|
#include "table/iso8859_9.h" |
| 141 |
|
|
#include "table/iso8859_10.h" |
| 142 |
|
|
#include "table/iso8859_11.h" |
| 143 |
|
|
#include "table/iso8859_13.h" |
| 144 |
|
|
#include "table/iso8859_14.h" |
| 145 |
|
|
#include "table/iso8859_16.h" |
| 146 |
|
|
|
| 147 |
|
|
#include "table/koi8_r.h" |
| 148 |
|
|
#include "table/koi8_u.h" |
| 149 |
|
|
|
| 150 |
|
|
//#define ENCODING_KR |
| 151 |
|
|
|
| 152 |
|
|
#include "table/ksc5601_1987_0.h" |
| 153 |
|
|
|
| 154 |
|
|
//#define ENCODING_CN |
| 155 |
|
|
|
| 156 |
|
|
#include "table/gb2312_1980_0.h" |
| 157 |
|
|
|
| 158 |
|
|
//#define ENCODING_CN_EXT |
| 159 |
|
|
|
| 160 |
|
|
#include "table/cns11643_1992_1.h" |
| 161 |
|
|
#include "table/cns11643_1992_2.h" |
| 162 |
|
|
#include "table/cns11643_1992_3.h" |
| 163 |
|
|
#include "table/cns11643_1992_4.h" |
| 164 |
|
|
#include "table/cns11643_1992_5.h" |
| 165 |
|
|
#include "table/cns11643_1992_6.h" |
| 166 |
|
|
#include "table/cns11643_1992_7.h" |
| 167 |
|
|
#include "table/cns11643_1992_f.h" |
| 168 |
|
|
#include "table/big5_ext.h" |
| 169 |
|
|
#include "table/big5_plus.h" |
| 170 |
|
|
|
| 171 |
|
|
//#define ENCODING_VN |
| 172 |
|
|
|
| 173 |
|
|
#include "table/viscii.h" |
| 174 |
|
|
|
| 175 |
|
|
//#define ENCODING_JP |
| 176 |
|
|
|
| 177 |
|
|
#include "table/jis0201_1976_0.h" |
| 178 |
|
|
#include "table/jis0208_1983_0.h" |
| 179 |
|
|
#include "table/jis0212_1990_0.h" |
| 180 |
|
|
|
| 181 |
|
|
//#define ENCODING_JP_EXT |
| 182 |
|
|
|
| 183 |
|
|
#include "table/jis0213_1.h" |
| 184 |
|
|
#include "table/jis0213_2.h" |
| 185 |
|
|
|
| 186 |
|
|
const rxvt_codeset_conv *rxvt_codeset[NUM_CODESETS] = { |
| 187 |
|
|
&rxvt_codeset_conv_unknown, |
| 188 |
|
|
&rxvt_codeset_conv_special, |
| 189 |
|
|
|
| 190 |
|
|
&rxvt_codeset_conv_us_ascii, |
| 191 |
|
|
|
| 192 |
|
|
&rxvt_codeset_conv_iso8859_1, |
| 193 |
|
|
&rxvt_codeset_conv_iso8859_2, |
| 194 |
|
|
&rxvt_codeset_conv_iso8859_3, |
| 195 |
|
|
&rxvt_codeset_conv_iso8859_4, |
| 196 |
|
|
&rxvt_codeset_conv_iso8859_5, |
| 197 |
|
|
&rxvt_codeset_conv_iso8859_6, |
| 198 |
|
|
&rxvt_codeset_conv_iso8859_7, |
| 199 |
|
|
&rxvt_codeset_conv_iso8859_8, |
| 200 |
|
|
&rxvt_codeset_conv_iso8859_9, |
| 201 |
|
|
&rxvt_codeset_conv_iso8859_10, |
| 202 |
|
|
&rxvt_codeset_conv_iso8859_11, |
| 203 |
|
|
&rxvt_codeset_conv_iso8859_13, |
| 204 |
|
|
&rxvt_codeset_conv_iso8859_14, |
| 205 |
|
|
&rxvt_codeset_conv_iso8859_15, |
| 206 |
|
|
&rxvt_codeset_conv_iso8859_16, |
| 207 |
|
|
|
| 208 |
|
|
&rxvt_codeset_conv_koi8_r, |
| 209 |
|
|
&rxvt_codeset_conv_koi8_u, |
| 210 |
|
|
|
| 211 |
|
|
&rxvt_codeset_conv_jis0201_1976_0, |
| 212 |
|
|
&rxvt_codeset_conv_jis0208_1983_0, |
| 213 |
|
|
&rxvt_codeset_conv_jis0212_1990_0, |
| 214 |
|
|
|
| 215 |
|
|
&rxvt_codeset_conv_jis0213_1, |
| 216 |
|
|
&rxvt_codeset_conv_jis0213_2, |
| 217 |
|
|
|
| 218 |
|
|
&rxvt_codeset_conv_ksc5601_1987_0, |
| 219 |
|
|
|
| 220 |
|
|
&rxvt_codeset_conv_gb2312_1980_0, |
| 221 |
|
|
|
| 222 |
|
|
&rxvt_codeset_conv_cns11643_1992_1, |
| 223 |
|
|
&rxvt_codeset_conv_cns11643_1992_2, |
| 224 |
|
|
&rxvt_codeset_conv_cns11643_1992_3, |
| 225 |
|
|
&rxvt_codeset_conv_cns11643_1992_4, |
| 226 |
|
|
&rxvt_codeset_conv_cns11643_1992_5, |
| 227 |
|
|
&rxvt_codeset_conv_cns11643_1992_6, |
| 228 |
|
|
&rxvt_codeset_conv_cns11643_1992_7, |
| 229 |
|
|
&rxvt_codeset_conv_cns11643_1992_f, |
| 230 |
|
|
&rxvt_codeset_conv_big5_ext, |
| 231 |
|
|
&rxvt_codeset_conv_big5_plus, |
| 232 |
|
|
|
| 233 |
|
|
&rxvt_codeset_conv_viscii, |
| 234 |
|
|
|
| 235 |
|
|
&rxvt_codeset_conv_unicode_16, |
| 236 |
|
|
&rxvt_codeset_conv_unicode |
| 237 |
|
|
}; |
| 238 |
|
|
|