From 542797377aabd9af067909fd14af08b1081b250c Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Thu, 12 Jan 2006 00:51:50 +0000 Subject: - When mbrtowc() returns -2 when given all the remaining chars in a string, set an end-of-line flag and avoid calling mbrtowc() again for any of the incomplete characters that remain in the string. - Use "mbs" for the multi-byte state variable name (for consistency). - Use the new MB_INVALID and MB_INCOMPLETE defines for the size_t -1 and -2 values (respectively). --- Src/Zle/zle_refresh.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'Src/Zle/zle_refresh.c') diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c index dad4960cb..a1a2ebb8d 100644 --- a/Src/Zle/zle_refresh.c +++ b/Src/Zle/zle_refresh.c @@ -1446,6 +1446,7 @@ singlerefresh(ZLE_STRING_T tmpline, int tmpll, int tmpcs) refreshop = *obuf; /* pointer to old video buffer */ int t0, /* tmp */ vsiz, /* size of new video buffer */ + eol = 0, /* has mbrtowc() returned -2? */ nvcs = 0; /* new video cursor column */ #ifdef MULTIBYTE_SUPPORT /* @@ -1455,7 +1456,7 @@ singlerefresh(ZLE_STRING_T tmpline, int tmpll, int tmpcs) ZLE_STRING_T lpwbuf, lpwp; char *lpptr, /* pointer into multibyte lprompt */ *lpend; /* end of multibyte lprompt */ - mbstate_t ps; /* shift state */ + mbstate_t mbs; /* shift state */ #endif nlnct = 1; @@ -1490,18 +1491,26 @@ singlerefresh(ZLE_STRING_T tmpline, int tmpll, int tmpcs) lpwp = lpwbuf = (ZLE_STRING_T)zalloc((lpend - lpromptbuf) * sizeof(*lpwbuf)); /* Reset shift state, maybe. */ - memset(&ps, '\0', sizeof(ps)); + memset(&mbs, '\0', sizeof mbs); for (lpptr = lpromptbuf; lpptr < lpend; ) { - size_t cnt = mbrtowc(lpwp, lpptr, lpend - lpptr, &ps); - if (cnt != 0 && cnt != (size_t)-1 && cnt != (size_t)-2) { - /* successfully converted */ - lpptr += cnt; - lpwp++; - } else { + size_t cnt = mbrtowc(lpwp, lpptr, lpend - lpptr, &mbs); + switch (cnt) { + case MB_INCOMPLETE: + eol = 1; + /* FALL THROUGH */ + case MB_INVALID: + memset(&mbs, '\0', sizeof mbs); + /* FALL THROUGH */ + case 0: /* dunno, try to recover */ lpptr++; *lpwp++ = ZWC('?'); - memset(&ps, '\0', sizeof(ps)); + break; + default: + /* successfully converted */ + lpptr += cnt; + lpwp++; + break; } } if (lpwp - lpwbuf < lpromptw) { -- cgit 1.4.1