about summary refs log tree commit diff
path: root/Src/Zle/complist.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/complist.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/complist.c')
-rw-r--r--Src/Zle/complist.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 5afd78115..9e633e64f 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -572,14 +572,14 @@ clnicezputs(Listcols colors, char *s, int ml)
      * umlen is the full length of the unmetafied string
      * width is the full printing width of a prettified character,
      *  including both ASCII prettification and the wide character itself.
-     * ps is the shift state of the conversion to wide characters.
+     * mbs is the shift state of the conversion to wide characters.
      */
     char *ums, *uptr, *sptr, *wptr;
-    int umleft, umlen;
+    int umleft, umlen, eol = 0;
     size_t width;
-    mbstate_t ps;
+    mbstate_t mbs;
 
-    memset(&ps, 0, sizeof(ps));
+    memset(&mbs, 0, sizeof mbs);
     ums = ztrdup(s);
     untokenize(ums);
     uptr = unmetafy(ums, &umlen);
@@ -589,11 +589,13 @@ clnicezputs(Listcols colors, char *s, int ml)
 	initiscol(colors);
 
     while (umleft > 0) {
-	size_t cnt = mbrtowc(&cc, uptr, umleft, &ps);
+	size_t cnt = eol ? MB_INVALID : mbrtowc(&cc, uptr, umleft, &mbs);
 
 	switch (cnt) {
-	case (size_t)-2:
-	case (size_t)-1:
+	case MB_INCOMPLETE:
+	    eol = 1;
+	    /* FALL THROUGH */
+	case MB_INVALID:
 	    /* This handles byte values that aren't valid wide-character
 	     * sequences. */
 	    sptr = nicechar(STOUC(*uptr));
@@ -601,8 +603,8 @@ clnicezputs(Listcols colors, char *s, int ml)
 	    width = strlen(sptr);
 	    wptr = sptr + width;
 	    cnt = 1;
-	    /* Get ps out of its undefined state. */
-	    memset(&ps, 0, sizeof ps);
+	    /* Get mbs out of its undefined state. */
+	    memset(&mbs, 0, sizeof mbs);
 	    break;
 	case 0:
 	    /* This handles a '\0' in the input (which is a real char