about summary refs log tree commit diff
path: root/Src/Zle
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2006-08-03 15:37:49 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2006-08-03 15:37:49 +0000
commit48d6402e65f87427d83a516e5296d677735f0022 (patch)
tree8879ee181827627d65ac60f3f822f5294c845778 /Src/Zle
parent07f11ba6bf609797f42c1ac768184b359a4e6ad7 (diff)
downloadzsh-48d6402e65f87427d83a516e5296d677735f0022.tar.gz
zsh-48d6402e65f87427d83a516e5296d677735f0022.tar.xz
zsh-48d6402e65f87427d83a516e5296d677735f0022.zip
rationalise mb<->wc conversions to use restartable form
Diffstat (limited to 'Src/Zle')
-rw-r--r--Src/Zle/complist.c5
-rw-r--r--Src/Zle/zle.h4
-rw-r--r--Src/Zle/zle_tricky.c14
-rw-r--r--Src/Zle/zle_utils.c6
4 files changed, 18 insertions, 11 deletions
diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 0bea231c5..8c6937b4a 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -588,6 +588,7 @@ clnicezputs(Listcols colors, char *s, int ml)
     if (colors)
 	initiscol(colors);
 
+    mb_metacharinit();
     while (umleft > 0) {
 	size_t cnt = eol ? MB_INVALID : mbrtowc(&cc, uptr, umleft, &mbs);
 
@@ -1964,7 +1965,9 @@ msearch(Cmatch **ptr, int ins, int back, int rep, int *wrapp)
 #ifdef MULTIBYTE_SUPPORT
 	if (lastchar_wide_valid)
 	{
-	    int len = wctomb(s, lastchar_wide);
+	    mbstate_t mbs;
+	    memset(&mbs, 0, sizeof(mbs));
+	    int len = wcrtomb(s, lastchar_wide, &mbs);
 	    if (len < 0)
 		len = 0;
 	    s[len] = '\0';
diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h
index f56960734..200804c7d 100644
--- a/Src/Zle/zle.h
+++ b/Src/Zle/zle.h
@@ -71,8 +71,6 @@ typedef wint_t   ZLE_INT_T;
 #define ZC_tolower towlower
 #define ZC_toupper towupper
 
-#define ZC_nicechar(c) wcs_nicechar(c, NULL, NULL)
-
 #define LASTFULLCHAR	lastchar_wide
 
 #else  /* Not MULTIBYTE_SUPPORT: old single-byte code */
@@ -100,8 +98,6 @@ typedef int ZLE_INT_T;
  */
 #define ZMB_nicewidth	niceztrlen
 
-#define ZC_nicechar nicechar
-
 #ifdef __GNUC__
 static inline size_t ZS_strlen(ZLE_STRING_T s)
 { return strlen((char*)s); }
diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index fb0ebad2a..4b7d3126d 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -2464,16 +2464,20 @@ magicspace(char **args)
     ZLE_STRING_T bangq;
     ZLE_CHAR_T zlebangchar[1];
     int ret;
+#ifdef MULTIBYTE_SUPPORT
+    mbstate_t mbs;
+#endif
+
     fixmagicspace();
 
 #ifdef MULTIBYTE_SUPPORT
     /*
-     * TODO: bangchar should really be a multibyte string representing
-     * a single character, since there's no fundamental reason why
-     * it shouldn't be a Unicode character.  In practice this is
-     * very minor, however.
+     * Use mbrtowc() here for consistency and to ensure the
+     * state is initialised properly.  bangchar is unsigned char,
+     * but must be ASCII, so we simply cast the pointer.
      */
-    if (mbtowc(zlebangchar, (char *)&bangchar, 1) < 0)
+    memset(&mbs, 0, sizeof(mbs));
+    if (mbrtowc(zlebangchar, (char *)&bangchar, 1, &mbs) < 0)
 	return selfinsert(args);
 #else
     zlebangchar[0] = bangchar;
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index cce162fa0..6275e74d3 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -135,17 +135,20 @@ zlelineasstring(ZLE_STRING_T instr, int inll, int incs, int *outllp,
     char *s;
     int i, j;
     size_t mb_len = 0;
+    mbstate_t mbs;
 
     s = zalloc(inll * MB_CUR_MAX + 1);
 
     outcs = 0;
+    memset(&mbs, 0, sizeof(mbs));
     for (i=0; i < inll; i++, incs--) {
 	if (incs == 0)
 	    outcs = mb_len;
-	j = wctomb(s + mb_len, instr[i]);
+	j = wcrtomb(s + mb_len, instr[i], &mbs);
 	if (j == -1) {
 	    /* invalid char; what to do? */
 	    s[mb_len++] = ZWC('?');
+	    memset(&mbs, 0, sizeof(mbs));
 	} else {
 	    mb_len += j;
 	}
@@ -780,6 +783,7 @@ showmsg(char const *msg)
     p = unmetafy(umsg, &ulen);
     memset(&mbs, 0, sizeof mbs);
 
+    mb_metacharinit();
     while (ulen > 0) {
 	char const *n;
 	if (*p == '\n') {