diff options
author | Wayne Davison <wayned@users.sourceforge.net> | 2006-01-08 22:57:05 +0000 |
---|---|---|
committer | Wayne Davison <wayned@users.sourceforge.net> | 2006-01-08 22:57:05 +0000 |
commit | 97c34b631cd9294617dac504a36ad2b7cc9c7351 (patch) | |
tree | 5372aa0fbcc7a64006c5eb373036b5218cb5b75d /Src | |
parent | 37c458aa8c24bf1b24969b851533359cd07920b5 (diff) | |
download | zsh-97c34b631cd9294617dac504a36ad2b7cc9c7351.tar.gz zsh-97c34b631cd9294617dac504a36ad2b7cc9c7351.tar.xz zsh-97c34b631cd9294617dac504a36ad2b7cc9c7351.zip |
Changed mb_niceformat() so that it does not truncate a name that
has an invalid character sequence in the current character set, displaying them as \M-... chars. (Improved version of the patch from workers/22140.)
Diffstat (limited to 'Src')
-rw-r--r-- | Src/utils.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/Src/utils.c b/Src/utils.c index 939fa403e..84e2d6848 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -3473,24 +3473,23 @@ mb_niceformat(const char *s, FILE *stream, char **outstrp, int heap) while (umlen > 0) { ret = mbrtowc(&c, ptr, umlen, &ps); - if (ret == (size_t)-1 || ret == (size_t)-2) - { - /* - * We're a bit stuck here. I suppose we could - * just stick with \M-... for the individual bytes. - */ - break; - } - /* - * careful in case converting NULL returned 0: NULLs are real - * characters for us. - */ - if (c == L'\0' && ret == 0) + if (ret != (size_t)-1 && ret != (size_t)-2) { + /* Careful: converting '\0' returns 0, but a '\0' is a + * real character for us, so we should consume 1 byte. */ + if (c == L'\0') + ret = 1; + fmt = wcs_nicechar(c, &newl, NULL); + } else { + /* The byte didn't convert, so output it as a \M-... sequence. */ + fmt = nicechar(STOUC(*ptr)); + newl = strlen(fmt); ret = 1; + /* Get ps out of its undefined state. */ + memset(&ps, 0, sizeof ps); + } + umlen -= ret; ptr += ret; - - fmt = wcs_nicechar(c, &newl, NULL); l += newl; if (stream) |