summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2007-10-18 08:29:33 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2007-10-18 08:29:33 +0000
commit5128de28f272b5dd00e3dc99f9051ec19c97a311 (patch)
tree01cb86ca56d747b64c3f14d2f6c4b4fc226845a9
parent4138a4c24c51af46deccd40afbd65aee7d716f21 (diff)
downloadzsh-5128de28f272b5dd00e3dc99f9051ec19c97a311.tar.gz
zsh-5128de28f272b5dd00e3dc99f9051ec19c97a311.tar.xz
zsh-5128de28f272b5dd00e3dc99f9051ec19c97a311.zip
23978: zcurses -s with wide characters: use waddwstr()
-rw-r--r--ChangeLog5
-rw-r--r--Src/Modules/curses.c48
-rw-r--r--configure.ac2
3 files changed, 26 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index 74ca80143..a5a18ba04 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-10-18  Peter Stephenson  <pws@csr.com>
+
+	* 23978: configure.ac, Src/Modules/curses.c: use waddwstr() to
+	get zcurses -s to work with wide characters.
+
 2007-10-17  Clint Adams  <clint@zsh.org>
 
 	* 23982: Doc/Zsh/mod_curses.yo: documentation for zcurses -A.
diff --git a/Src/Modules/curses.c b/Src/Modules/curses.c
index d27bdcdc4..ffe5d674d 100644
--- a/Src/Modules/curses.c
+++ b/Src/Modules/curses.c
@@ -30,6 +30,11 @@
 #define _XOPEN_SOURCE_EXTENDED 1
 
 #include <ncurses.h>
+#ifndef MULTIBYTE_SUPPORT
+# undef HAVE_SETCCHAR
+# undef HAVE_WADDWSTR
+#endif
+
 #ifdef HAVE_SETCCHAR
 # include <wchar.h>
 #endif
@@ -322,10 +327,11 @@ bin_zcurses(char *nam, char **args, Options ops, UNUSED(int func))
 	LinkNode node;
 	ZCWin w;
 
-#ifdef HAVE_SETCCHAR
-	wchar_t *ws;
-	cchar_t *wcc;
-	size_t sl;
+#ifdef HAVE_WADDWSTR
+	int clen;
+	wint_t wc;
+	wchar_t *wstr, *wptr;
+	char *str = args[1];
 #endif
 
 	node = zcurses_validate_window(args[0], ZCURSES_USED);
@@ -336,34 +342,20 @@ bin_zcurses(char *nam, char **args, Options ops, UNUSED(int func))
 
 	w = (ZCWin)getdata(node);
 
-#ifdef HAVE_SETCCHAR
-	sl = strlen(args[1]);
-
-	if (sl == 0) {
-	    return 0;
-	}
-
-	ws = malloc(sl * sizeof(wchar_t));
+#ifdef HAVE_WADDWSTR
+	mb_metacharinit();
+	wptr = wstr = zhalloc((strlen(str)+1) * sizeof(cchar_t));
 
-	if (mbstowcs(ws, args[1], sl) < 1) {
-	    free(ws);
-	    return 1;
-	}
-
-	wcc = malloc(wcslen(ws) * sizeof(cchar_t));
-
-	if (setcchar(wcc, ws, A_NORMAL, 0, NULL)==ERR) {
-	    return 1;
+	while (*str && (clen = mb_metacharlenconv(str, &wc))) {
+	    str += clen;
+	    if (wc == WEOF) /* TODO: replace with space? nicen? */
+		continue;
+	    *wptr++ = wc;
 	}
-
-	free(ws);
-
-	if (wadd_wchstr(w->win, wcc)!=OK) {
-	    free(wcc);
+	*wptr++ = L'\0';
+	if (waddwstr(w->win, wstr)!=OK) {
 	    return 1;
 	}
-
-	free(wcc);
 #else
 	if (waddstr(w->win, args[1])!=OK)
 	    return 1;
diff --git a/configure.ac b/configure.ac
index f5ceeae62..e79060d20 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1134,7 +1134,7 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \
 	       brk sbrk \
 	       pathconf sysconf \
 	       tgetent tigetflag tigetnum tigetstr setupterm initscr \
-	       setcchar \
+	       setcchar waddwstr \
 	       pcre_compile pcre_study pcre_exec \
 	       nl_langinfo \
 	       erand48 open_memstream \