From 72f72d64a422d6628c4796f5c0bf2e508f134214 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Wed, 4 May 2011 16:05:14 +0900 Subject: Adding upstream version 0.5.1 --- symbol.c | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 symbol.c (limited to 'symbol.c') diff --git a/symbol.c b/symbol.c new file mode 100644 index 0000000..9a482b3 --- /dev/null +++ b/symbol.c @@ -0,0 +1,168 @@ + +#include "fm.h" + +#include "Symbols/alt.sym" +#include "Symbols/graph.sym" +#ifdef USE_M17N +#include "Symbols/eucjp.sym" +#include "Symbols/euckr.sym" +#include "Symbols/euccn.sym" +#include "Symbols/euctw.sym" +#include "Symbols/big5.sym" +#ifdef USE_UNICODE +#include "Symbols/utf8.sym" +#endif +#include "Symbols/cp850.sym" + +typedef struct { + wc_ces ces; + char width; + char **item; + char encode; +} symbol_set; + +typedef struct { + wc_ces charset; + symbol_set *symbol; +} charset_symbol_set; + +/* *INDENT-OFF* */ +static symbol_set alt_symbol_set = { WC_CES_US_ASCII, 1, alt_symbol, 1 }; +static symbol_set alt2_symbol_set = { WC_CES_US_ASCII, 2, alt2_symbol, 1 }; +static symbol_set eucjp_symbol_set = { WC_CES_EUC_JP, 2, eucjp_symbol, 0 }; +static symbol_set euckr_symbol_set = { WC_CES_EUC_KR, 2, euckr_symbol, 0 }; +static symbol_set euccn_symbol_set = { WC_CES_EUC_CN, 2, euccn_symbol, 0 }; +static symbol_set euctw_symbol_set = { WC_CES_EUC_TW, 2, euctw_symbol, 0 }; +static symbol_set big5_symbol_set = { WC_CES_BIG5, 2, big5_symbol, 0 }; +#ifdef USE_UNICODE +static symbol_set utf8_symbol_set = { WC_CES_UTF_8, 1, utf8_symbol, 0 }; +#endif +static symbol_set cp850_symbol_set = { WC_CES_CP850, 1, cp850_symbol, 0 }; + +static charset_symbol_set charset_symbol_list[] = { + { WC_CES_EUC_JP, &eucjp_symbol_set }, + { WC_CES_SHIFT_JIS, &eucjp_symbol_set }, + { WC_CES_ISO_2022_JP, &eucjp_symbol_set }, + { WC_CES_ISO_2022_JP_2, &eucjp_symbol_set }, + { WC_CES_ISO_2022_JP_3, &eucjp_symbol_set }, + { WC_CES_EUC_KR, &euckr_symbol_set }, + { WC_CES_ISO_2022_KR, &euckr_symbol_set }, + { WC_CES_JOHAB, &euckr_symbol_set }, + { WC_CES_UHC, &euckr_symbol_set }, + { WC_CES_EUC_CN, &euccn_symbol_set }, + { WC_CES_GBK, &euccn_symbol_set }, + { WC_CES_GB18030, &euccn_symbol_set }, + { WC_CES_HZ_GB_2312, &euccn_symbol_set }, + { WC_CES_ISO_2022_CN, &euccn_symbol_set }, + { WC_CES_EUC_TW, &euctw_symbol_set }, + { WC_CES_BIG5, &big5_symbol_set }, + { WC_CES_HKSCS, &big5_symbol_set }, +#ifdef USE_UNICODE + { WC_CES_UTF_8, &utf8_symbol_set }, +#endif + { WC_CES_CP850, &cp850_symbol_set }, + { 0, NULL }, +}; +/* *INDENT-ON* */ + +static wc_ces save_charset = 0; +static symbol_set *save_symbol = NULL; + +static void +encode_symbol(symbol_set * s) +{ + int i; + + for (i = 0; s->item[i]; i++) { + if (*(s->item[i])) + s->item[i] = wc_conv(s->item[i], s->ces, InnerCharset)->ptr; + } + s->encode = 1; +} + +char ** +get_symbol(wc_ces charset, int *width) +{ + charset_symbol_set *p; + symbol_set *s = NULL; + + if (charset == save_charset && save_symbol != NULL && + *width == save_symbol->width) { + *width = save_symbol->width; + return save_symbol->item; + } + save_charset = charset; + for (p = charset_symbol_list; p->charset; p++) { + if (charset == p->charset && + (*width == 0 || *width == p->symbol->width)) { + s = p->symbol; + break; + } + } + if (s == NULL) + s = (*width == 2) ? &alt2_symbol_set : &alt_symbol_set; + if (s != save_symbol) { + if (!s->encode) + encode_symbol(s); + save_symbol = s; + } + *width = s->width; + return s->item; +} + +char ** +set_symbol(int width) +{ + static char **symbol_buf = NULL; + static int save_width = -1; + symbol_set *s = &alt_symbol_set; + int i; + Str tmp; + + if (width == save_width) + return symbol_buf; + if (symbol_buf == NULL) { + for (i = 0; s->item[i]; i++) ; + symbol_buf = New_N(char *, i); + } + for (i = 0; s->item[i]; i++) { + tmp = Strnew_size(4); + if (width == 2) + wtf_push(tmp, WC_CCS_SPECIAL_W, (wc_uint32) (SYMBOL_BASE + i)); + else + wtf_push(tmp, WC_CCS_SPECIAL, (wc_uint32) (SYMBOL_BASE + i)); + symbol_buf[i] = tmp->ptr; + } + save_width = width; + return symbol_buf; +} + +#else + +char ** +get_symbol(void) +{ + return alt_symbol; +} +#endif + +void +push_symbol(Str str, char symbol, int width, int n) +{ + char buf[2], *p; + int i; + +#ifdef USE_M17N + if (width == 2) + p = alt2_symbol[(int)symbol]; + else +#endif + p = alt_symbol[(int)symbol]; + for (i = 0; i < 2 && *p; i++, p++) + buf[i] = (*p == ' ') ? NBSP_CODE : *p; + + Strcat(str, Sprintf("<_SYMBOL TYPE=%d>", symbol)); + for (; n > 0; n--) + Strcat_charp_n(str, buf, i); + Strcat_charp(str, ""); +} -- cgit v1.2.3 From 5397d09e585a1938fb64bc9c5cd5daed1959eb90 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Wed, 4 May 2011 16:41:45 +0900 Subject: Adding upstream version 0.5.3 --- symbol.c | 80 +++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 29 deletions(-) (limited to 'symbol.c') diff --git a/symbol.c b/symbol.c index 9a482b3..50475ae 100644 --- a/symbol.c +++ b/symbol.c @@ -18,7 +18,7 @@ typedef struct { wc_ces ces; char width; char **item; - char encode; + char **conved_item; } symbol_set; typedef struct { @@ -27,17 +27,17 @@ typedef struct { } charset_symbol_set; /* *INDENT-OFF* */ -static symbol_set alt_symbol_set = { WC_CES_US_ASCII, 1, alt_symbol, 1 }; -static symbol_set alt2_symbol_set = { WC_CES_US_ASCII, 2, alt2_symbol, 1 }; -static symbol_set eucjp_symbol_set = { WC_CES_EUC_JP, 2, eucjp_symbol, 0 }; -static symbol_set euckr_symbol_set = { WC_CES_EUC_KR, 2, euckr_symbol, 0 }; -static symbol_set euccn_symbol_set = { WC_CES_EUC_CN, 2, euccn_symbol, 0 }; -static symbol_set euctw_symbol_set = { WC_CES_EUC_TW, 2, euctw_symbol, 0 }; -static symbol_set big5_symbol_set = { WC_CES_BIG5, 2, big5_symbol, 0 }; +static symbol_set alt_symbol_set = { WC_CES_US_ASCII, 1, alt_symbol, alt_symbol }; +static symbol_set alt2_symbol_set = { WC_CES_US_ASCII, 2, alt2_symbol, alt2_symbol }; +static symbol_set eucjp_symbol_set = { WC_CES_EUC_JP, 2, eucjp_symbol, NULL }; +static symbol_set euckr_symbol_set = { WC_CES_EUC_KR, 2, euckr_symbol, NULL }; +static symbol_set euccn_symbol_set = { WC_CES_EUC_CN, 2, euccn_symbol, NULL }; +static symbol_set euctw_symbol_set = { WC_CES_EUC_TW, 2, euctw_symbol, NULL }; +static symbol_set big5_symbol_set = { WC_CES_BIG5, 2, big5_symbol, NULL }; #ifdef USE_UNICODE -static symbol_set utf8_symbol_set = { WC_CES_UTF_8, 1, utf8_symbol, 0 }; +static symbol_set utf8_symbol_set = { WC_CES_UTF_8, 1, utf8_symbol, NULL }; #endif -static symbol_set cp850_symbol_set = { WC_CES_CP850, 1, cp850_symbol, 0 }; +static symbol_set cp850_symbol_set = { WC_CES_CP850, 1, cp850_symbol, NULL }; static charset_symbol_set charset_symbol_list[] = { { WC_CES_EUC_JP, &eucjp_symbol_set }, @@ -73,11 +73,12 @@ encode_symbol(symbol_set * s) { int i; + for (i = 0; s->item[i]; i++) ; + s->conved_item = New_N(char *, i); for (i = 0; s->item[i]; i++) { if (*(s->item[i])) - s->item[i] = wc_conv(s->item[i], s->ces, InnerCharset)->ptr; + s->conved_item[i] = wc_conv(s->item[i], s->ces, InnerCharset)->ptr; } - s->encode = 1; } char ** @@ -86,28 +87,34 @@ get_symbol(wc_ces charset, int *width) charset_symbol_set *p; symbol_set *s = NULL; - if (charset == save_charset && save_symbol != NULL && - *width == save_symbol->width) { - *width = save_symbol->width; - return save_symbol->item; - } - save_charset = charset; - for (p = charset_symbol_list; p->charset; p++) { - if (charset == p->charset && - (*width == 0 || *width == p->symbol->width)) { - s = p->symbol; - break; + if (UseGraphicChar != GRAPHIC_CHAR_ASCII) { + if (charset == save_charset && save_symbol != NULL && + *width == save_symbol->width) { + return save_symbol->conved_item; } - } - if (s == NULL) + save_charset = charset; + for (p = charset_symbol_list; p->charset; p++) { + if (charset == p->charset && + (*width == 0 || *width == p->symbol->width)) { + s = p->symbol; + break; + } + } + if (s == NULL) + s = (*width == 2) ? &alt2_symbol_set : &alt_symbol_set; + if (s != save_symbol) { + if (!s->conved_item) + encode_symbol(s); + save_symbol = s; + } + } else { + if (save_symbol != NULL && *width == save_symbol->width) + return save_symbol->conved_item; s = (*width == 2) ? &alt2_symbol_set : &alt_symbol_set; - if (s != save_symbol) { - if (!s->encode) - encode_symbol(s); save_symbol = s; } *width = s->width; - return s->item; + return s->conved_item; } char ** @@ -137,6 +144,21 @@ set_symbol(int width) return symbol_buf; } +#ifdef USE_UNICODE +void +update_utf8_symbol(void) +{ + charset_symbol_set *p; + utf8_symbol_set.width = WcOption.east_asian_width ? 2 : 1; + for (p = charset_symbol_list; p->charset; p++) { + if (p->charset == WC_CES_UTF_8) { + encode_symbol(p->symbol); + break; + } + } +} +#endif + #else char ** -- cgit v1.2.3 From 1d0ba25a660483da1272a31dd077ed94441e3d9f Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Sat, 2 Jan 2021 09:20:37 +0900 Subject: New upstream version 0.5.3+git20210102 --- symbol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'symbol.c') diff --git a/symbol.c b/symbol.c index 50475ae..c047c56 100644 --- a/symbol.c +++ b/symbol.c @@ -176,10 +176,10 @@ push_symbol(Str str, char symbol, int width, int n) #ifdef USE_M17N if (width == 2) - p = alt2_symbol[(int)symbol]; + p = alt2_symbol[(unsigned char)symbol % N_SYMBOL]; else #endif - p = alt_symbol[(int)symbol]; + p = alt_symbol[(unsigned char)symbol % N_SYMBOL]; for (i = 0; i < 2 && *p; i++, p++) buf[i] = (*p == ' ') ? NBSP_CODE : *p; -- cgit v1.2.3