From 855997623d252428978a05def30ca93bfd11b7a9 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Wed, 8 Nov 2006 15:19:29 +0000 Subject: [PATCH] Fixed display bug with new charset and unreadable UTF-8 chars in ISO term --- src/common/util.c | 34 ++++++++++++++++++++++++++-------- weechat/src/common/util.c | 34 ++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/common/util.c b/src/common/util.c index 595952b59..aea6b03ea 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -25,6 +25,7 @@ #endif #include +#include #include #include @@ -200,9 +201,10 @@ weechat_iconv (char *from_code, char *to_code, char *string) #ifdef HAVE_ICONV iconv_t cd; char *inbuf; + int done; ICONV_CONST char *ptr_inbuf; char *ptr_outbuf; - size_t inbytesleft, outbytesleft; + size_t err, inbytesleft, outbytesleft; if (from_code && from_code[0] && to_code && to_code[0] && (ascii_strcasecmp(from_code, to_code) != 0)) @@ -218,14 +220,30 @@ weechat_iconv (char *from_code, char *to_code, char *string) outbytesleft = inbytesleft * 4; outbuf = (char *) malloc (outbytesleft + 2); ptr_outbuf = outbuf; - iconv (cd, &ptr_inbuf, &inbytesleft, &ptr_outbuf, &outbytesleft); - if (inbytesleft != 0) + done = 0; + while (!done) { - free (outbuf); - outbuf = strdup (string); + err = iconv (cd, &ptr_inbuf, &inbytesleft, + &ptr_outbuf, &outbytesleft); + if (err == (size_t)(-1)) + { + switch (errno) + { + case EINVAL: + done = 1; + break; + case E2BIG: + done = 1; + break; + case EILSEQ: + ptr_inbuf[0] = '?'; + break; + } + } + else + done = 1; } - else - ptr_outbuf[0] = '\0'; + ptr_outbuf[0] = '\0'; free (inbuf); iconv_close (cd); } @@ -278,7 +296,7 @@ char * weechat_iconv_from_internal (char *charset, char *string) { char *input, *output; - + input = strdup (string); if (input) { diff --git a/weechat/src/common/util.c b/weechat/src/common/util.c index 595952b59..aea6b03ea 100644 --- a/weechat/src/common/util.c +++ b/weechat/src/common/util.c @@ -25,6 +25,7 @@ #endif #include +#include #include #include @@ -200,9 +201,10 @@ weechat_iconv (char *from_code, char *to_code, char *string) #ifdef HAVE_ICONV iconv_t cd; char *inbuf; + int done; ICONV_CONST char *ptr_inbuf; char *ptr_outbuf; - size_t inbytesleft, outbytesleft; + size_t err, inbytesleft, outbytesleft; if (from_code && from_code[0] && to_code && to_code[0] && (ascii_strcasecmp(from_code, to_code) != 0)) @@ -218,14 +220,30 @@ weechat_iconv (char *from_code, char *to_code, char *string) outbytesleft = inbytesleft * 4; outbuf = (char *) malloc (outbytesleft + 2); ptr_outbuf = outbuf; - iconv (cd, &ptr_inbuf, &inbytesleft, &ptr_outbuf, &outbytesleft); - if (inbytesleft != 0) + done = 0; + while (!done) { - free (outbuf); - outbuf = strdup (string); + err = iconv (cd, &ptr_inbuf, &inbytesleft, + &ptr_outbuf, &outbytesleft); + if (err == (size_t)(-1)) + { + switch (errno) + { + case EINVAL: + done = 1; + break; + case E2BIG: + done = 1; + break; + case EILSEQ: + ptr_inbuf[0] = '?'; + break; + } + } + else + done = 1; } - else - ptr_outbuf[0] = '\0'; + ptr_outbuf[0] = '\0'; free (inbuf); iconv_close (cd); } @@ -278,7 +296,7 @@ char * weechat_iconv_from_internal (char *charset, char *string) { char *input, *output; - + input = strdup (string); if (input) {