about summary refs log tree commit diff
path: root/Src/Zle/zle_refresh.c
diff options
context:
space:
mode:
authorWayne Davison <wayned@users.sourceforge.net>2006-01-12 00:51:50 +0000
committerWayne Davison <wayned@users.sourceforge.net>2006-01-12 00:51:50 +0000
commit542797377aabd9af067909fd14af08b1081b250c (patch)
tree653d363b018b51c0fdf62723f33a370d53b929f3 /Src/Zle/zle_refresh.c
parente46d08523fd44432448c9c15bcec5977fd817e7d (diff)
downloadzsh-542797377aabd9af067909fd14af08b1081b250c.tar.gz
zsh-542797377aabd9af067909fd14af08b1081b250c.tar.xz
zsh-542797377aabd9af067909fd14af08b1081b250c.zip
- 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).
Diffstat (limited to 'Src/Zle/zle_refresh.c')
-rw-r--r--Src/Zle/zle_refresh.c27
1 files changed, 18 insertions, 9 deletions
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) {