about summary refs log tree commit diff
path: root/Src/prompt.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2005-10-13 13:19:29 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2005-10-13 13:19:29 +0000
commitcc81bba1e34b4a7a357b6a7e6ec1d4eede4ffa61 (patch)
tree822d9fa5a49b0fda14697073c3687b8641bf7c51 /Src/prompt.c
parentcca66ab341ffa330908aa6ea8da03e991aa6903c (diff)
downloadzsh-cc81bba1e34b4a7a357b6a7e6ec1d4eede4ffa61.tar.gz
zsh-cc81bba1e34b4a7a357b6a7e6ec1d4eede4ffa61.tar.xz
zsh-cc81bba1e34b4a7a357b6a7e6ec1d4eede4ffa61.zip
21870: bad INULL() definition
21869: multibyte characters in %-substitutions, invalid multibyte
characters in completion listings
Diffstat (limited to 'Src/prompt.c')
-rw-r--r--Src/prompt.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/Src/prompt.c b/Src/prompt.c
index 8bd1ad9de..69b76aa24 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -736,6 +736,46 @@ addbufspc(int need)
 void
 stradd(char *d)
 {
+#ifdef ZLE_UNICODE_SUPPORT
+    char *ums, *ups;
+    int upslen;
+    mbstate_t ps;
+
+    memset(&ps, 0, sizeof(ps));
+    ums = ztrdup(d);
+    ups = unmetafy(ums, &upslen);
+
+    /*
+     * We now have a raw string of possibly multibyte characters.
+     * Read each character one by one.
+     */
+    while (upslen > 0) {
+	wchar_t cc;
+	char *pc;
+	int ret = mbrtowc(&cc, ups, upslen, &ps);
+
+	if (ret <= 0)
+	{
+	    /* Bad character.  Take the next byte on its own. */
+	    pc = nicechar(*ups);
+	    ret = 1;
+	} else {
+	    /* Take full wide character in one go */
+	    pc = wcs_nicechar(cc, NULL, NULL);
+	}
+	/* Keep output as metafied string. */
+	addbufspc(strlen(pc));
+
+	upslen -= ret;
+	ups += ret;
+
+	/* Put printed representation into the buffer */
+	while (*pc)
+	    *bp++ = *pc++;
+    }
+
+    free(ums);
+#else
     char *ps, *pc;
     addbufspc(niceztrlen(d));
     /* This loop puts the nice representation of the string into the prompt *
@@ -743,6 +783,7 @@ stradd(char *d)
     for(ps=d; *ps; ps++)
 	for(pc=nicechar(*ps == Meta ? STOUC(*++ps)^32 : STOUC(*ps)); *pc; pc++)
 	    *bp++ = *pc;
+#endif
 }
 
 /* tsetcap(), among other things, can write a termcap string into the buffer. */