From 4b831f02df13e71460b2327607ae3bc4d3ae04d8 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Wed, 11 Jan 2006 20:12:09 +0000 Subject: Tweaked the code to handle mbrtowc() converting '\0' the same way as the other callers do. Also, changed the variable name to 'cnt'. --- Src/Zle/complist.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c index 973df8ed4..5afd78115 100644 --- a/Src/Zle/complist.c +++ b/Src/Zle/complist.c @@ -589,31 +589,40 @@ clnicezputs(Listcols colors, char *s, int ml) initiscol(colors); while (umleft > 0) { - size_t ret = mbrtowc(&cc, uptr, umleft, &ps); + size_t cnt = mbrtowc(&cc, uptr, umleft, &ps); - if (ret == 0 || ret == (size_t)-1 || ret == (size_t)-2) { - /* This handles a '\0' in the input (which is a real char - * to us, not a terminator) and byte values that aren't - * valid wide-character sequences. */ + switch (cnt) { + case (size_t)-2: + case (size_t)-1: + /* This handles byte values that aren't valid wide-character + * sequences. */ sptr = nicechar(STOUC(*uptr)); /* everything here is ASCII... */ width = strlen(sptr); wptr = sptr + width; - ret = 1; - /* Get ps out of its undefined state when ret < 0. */ + cnt = 1; + /* Get ps out of its undefined state. */ memset(&ps, 0, sizeof ps); - } else + break; + case 0: + /* This handles a '\0' in the input (which is a real char + * to us, not a terminator). */ + cnt = 1; + /* FALL THROUGH */ + default: sptr = wcs_nicechar(cc, &width, &wptr); + break; + } - umleft -= ret; - uptr += ret; + umleft -= cnt; + uptr += cnt; if (colors) { /* * The code for the colo[u]ri[s/z]ation is obscure (surprised?) * but if we do it for every input character, as we do in * the simple case, we shouldn't go too far wrong. */ - while (ret--) + while (cnt--) doiscol(colors, i++); } -- cgit 1.4.1