--- rxvt-unicode/src/encoding.C 2004/06/21 18:19:28 1.17 +++ rxvt-unicode/src/encoding.C 2011/02/21 07:41:00 1.31 @@ -1,9 +1,9 @@ -/*--------------------------------*-C-*---------------------------------* +/*----------------------------------------------------------------------* * File: encoding.C *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. - * Copyright (c) 2003-2004 Marc Lehmann + * Copyright (c) 2003-2006 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,11 +23,12 @@ #include "../config.h" #include "encoding.h" +#include "rxvtutil.h" #include #include -const struct n2cs { +static const struct n2cs { const char *name; codeset cs; } n2cs[] = { @@ -49,24 +50,25 @@ { "ISO885915", CS_ISO8859_15 }, { "FCD885915", CS_ISO8859_15 }, { "ISO885916", CS_ISO8859_16 }, - + { "TIS620*", CS_ISO8859_11 }, // close enough { "ISO10646*", CS_UNICODE }, { "UNICODE", CS_UNICODE }, { "UTF8", CS_UNICODE }, - + { "ASCII", CS_US_ASCII }, { "USASCII", CS_US_ASCII }, { "ANSIX341968", CS_US_ASCII }, - - { "KOI8R", CS_KOI8_R }, + { "ISO6461991IRV", CS_US_ASCII }, // older versions used the currency sign + + { "KOI8R*", CS_KOI8_R }, { "GOST1976874*", CS_KOI8_R }, { "KOI8RU", CS_KOI8_U }, { "KOI8U", CS_KOI8_U }, { "VISCII*", CS_VISCII }, - + { "JISX0201*", CS_JIS0201_1976_0 }, { "JISC6226*", CS_JIS0208_1990_0 }, // also wrongly matches -1987-0? (check Encode::JP) { "JISX0208*", CS_JIS0208_1990_0 }, // also wrongly matches -1987-0? (check Encode::JP) @@ -74,15 +76,16 @@ { "JISX021320001", CS_JIS0213_1 }, { "JISX021320002", CS_JIS0213_2 }, { "JISX0221*", CS_UNICODE }, // _very_ close - + { "KSC5601*", CS_KSC5601_1987_0 }, { "KSX1001*", CS_KSC5601_1987_0 }, { "KSC5700*", CS_UNICODE }, // unicode plus extensions - + { "BIG5P*", CS_BIG5_PLUS }, { "BIG5ETEN*", CS_BIG5_EXT }, { "BIG5*", CS_BIG5 }, { "GB2312*", CS_GB2312_1980_0 }, + { "GBK*", CS_GBK_0 }, { "GB6345*", CS_GB2312_1980_0 }, // slightly different to gb2312?? { "GB8565*", CS_GB2312_1980_0 }, // a superset of gb2312?? { "GB13000*", CS_UNICODE }, @@ -139,23 +142,17 @@ return CS_UNKNOWN; } -struct rxvt_codeset_conv_unknown : rxvt_codeset_conv { - unicode_t to_unicode (uint32_t enc) const { return NOCHAR; } - uint32_t from_unicode (unicode_t unicode) const { return NOCHAR; } -} rxvt_codeset_conv_unknown; - -struct rxvt_codeset_conv_us_ascii : rxvt_codeset_conv { - uint32_t from_unicode (unicode_t unicode) const { return unicode <= 127 ? unicode : NOCHAR; } -} rxvt_codeset_conv_us_ascii; - -struct rxvt_codeset_conv_unicode : rxvt_codeset_conv { - /* transparent */ -} rxvt_codeset_conv_unicode; - -struct rxvt_codeset_conv_unicode_16 : rxvt_codeset_conv { - unicode_t to_unicode (uint32_t enc) const { return enc; } - uint32_t from_unicode (unicode_t unicode) const { return unicode <= 65535 ? unicode : NOCHAR; } -} rxvt_codeset_conv_unicode_16; +static unicode_t cs_unknown_to_unicode (uint32_t enc) { return NOCHAR; } +static uint32_t cs_unknown_from_unicode (unicode_t unicode) { return NOCHAR; } + +static unicode_t cs_unicode_to_unicode (uint32_t enc) { return enc; } +static uint32_t cs_unicode_from_unicode (unicode_t unicode) { return unicode; } + +#define cs_us_ascii_to_unicode cs_unicode_to_unicode +static uint32_t cs_us_ascii_from_unicode (unicode_t unicode) { return unicode <= 127 ? unicode : NOCHAR; } + +#define cs_us_ascii_to_unicode_16 cs_unicode_to_unicode +static uint32_t cs_unicode_16_from_unicode (unicode_t unicode) { return unicode <= 65535 ? unicode : NOCHAR; } #define ENCODING_DEFAULT @@ -185,12 +182,13 @@ #include "table/ksc5601_1987_0.h" -//#define ENCODING_CN +//#define ENCODING_ZH -#include "table/gb2312_1980_0.h" #include "table/big5.h" +#include "table/gbk_0.h" +#include "table/gb2312_1980_0.h" -//#define ENCODING_CN_EXT +//#define ENCODING_ZH_EXT #include "table/cns11643_1992_1.h" #include "table/cns11643_1992_2.h" @@ -218,58 +216,66 @@ #include "table/jis0213_1.h" #include "table/jis0213_2.h" +#if ENCODING_TO_UNICODE +# define ENC(base) { cs_ ## base ## _from_unicode, cs_ ## base ## _to_unicode } +#else +# define ENC(base) { cs_ ## base ## _from_unicode } +#endif + + // order must match table in encoding.h(!) -const rxvt_codeset_conv *rxvt_codeset[NUM_CODESETS] = { - &rxvt_codeset_conv_unknown, +const rxvt_codeset_conv rxvt_codeset[NUM_CODESETS] = { + ENC (unknown), - &rxvt_codeset_conv_us_ascii, + ENC (us_ascii), - &rxvt_codeset_conv_iso8859_1, - &rxvt_codeset_conv_iso8859_2, - &rxvt_codeset_conv_iso8859_3, - &rxvt_codeset_conv_iso8859_4, - &rxvt_codeset_conv_iso8859_5, - &rxvt_codeset_conv_iso8859_6, - &rxvt_codeset_conv_iso8859_7, - &rxvt_codeset_conv_iso8859_8, - &rxvt_codeset_conv_iso8859_9, - &rxvt_codeset_conv_iso8859_10, - &rxvt_codeset_conv_iso8859_11, - &rxvt_codeset_conv_iso8859_13, - &rxvt_codeset_conv_iso8859_14, - &rxvt_codeset_conv_iso8859_15, - &rxvt_codeset_conv_iso8859_16, - - &rxvt_codeset_conv_koi8_r, - &rxvt_codeset_conv_koi8_u, - - &rxvt_codeset_conv_jis0201_1976_0, - &rxvt_codeset_conv_jis0208_1990_0, - &rxvt_codeset_conv_jis0212_1990_0, - - &rxvt_codeset_conv_jis0213_1, - &rxvt_codeset_conv_jis0213_2, - - &rxvt_codeset_conv_ksc5601_1987_0, - - &rxvt_codeset_conv_gb2312_1980_0, - - &rxvt_codeset_conv_cns11643_1992_1, - &rxvt_codeset_conv_cns11643_1992_2, - &rxvt_codeset_conv_cns11643_1992_3, - &rxvt_codeset_conv_cns11643_1992_4, - &rxvt_codeset_conv_cns11643_1992_5, - &rxvt_codeset_conv_cns11643_1992_6, - &rxvt_codeset_conv_cns11643_1992_7, - &rxvt_codeset_conv_cns11643_1992_f, - &rxvt_codeset_conv_big5, - &rxvt_codeset_conv_big5_ext, - &rxvt_codeset_conv_big5_plus, + ENC (iso8859_1), + ENC (iso8859_2), + ENC (iso8859_3), + ENC (iso8859_4), + ENC (iso8859_5), + ENC (iso8859_6), + ENC (iso8859_7), + ENC (iso8859_8), + ENC (iso8859_9), + ENC (iso8859_10), + ENC (iso8859_11), + ENC (iso8859_13), + ENC (iso8859_14), + ENC (iso8859_15), + ENC (iso8859_16), + + ENC (koi8_r), + ENC (koi8_u), + + ENC (jis0201_1976_0), + ENC (jis0208_1990_0), + ENC (jis0212_1990_0), + + ENC (jis0213_1), + ENC (jis0213_2), + + ENC (ksc5601_1987_0), + + ENC (gb2312_1980_0), + ENC (gbk_0), + + ENC (cns11643_1992_1), + ENC (cns11643_1992_2), + ENC (cns11643_1992_3), + ENC (cns11643_1992_4), + ENC (cns11643_1992_5), + ENC (cns11643_1992_6), + ENC (cns11643_1992_7), + ENC (cns11643_1992_f), + ENC (big5), + ENC (big5_ext), + ENC (big5_plus), - &rxvt_codeset_conv_viscii, + ENC (viscii), - &rxvt_codeset_conv_unicode_16, - &rxvt_codeset_conv_unicode + ENC (unicode_16), + ENC (unicode), }; #if ENABLE_COMBINING @@ -282,10 +288,10 @@ rxvt_compose (unicode_t c1, unicode_t c2) { int l = 0; - int r = sizeof (rxvt_compose_table) / sizeof (rxvt_compose_entry) - 1; + int r = ARRAY_LENGTH(rxvt_compose_table) - 1; int m; - while (r > l) + while (r >= l) { m = (l + r) / 2; rxvt_compose_entry &c = rxvt_compose_table[m]; @@ -305,5 +311,6 @@ bool unicode::is_space (unicode_t c) { - return IS_SPACE (c); + return IS_SPACE (c) + || c == 0x09; // exclude tabs, too, as we store them in the buffer }