diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | Src/Modules/curses.c | 48 | ||||
-rw-r--r-- | configure.ac | 2 |
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 \ |