mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-21 00:01:26 +01:00
23978: zcurses -s with wide characters: use waddwstr()
This commit is contained in:
parent
4138a4c24c
commit
5128de28f2
3 changed files with 26 additions and 29 deletions
|
@ -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.
|
||||
|
|
|
@ -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]);
|
||||
#ifdef HAVE_WADDWSTR
|
||||
mb_metacharinit();
|
||||
wptr = wstr = zhalloc((strlen(str)+1) * sizeof(cchar_t));
|
||||
|
||||
if (sl == 0) {
|
||||
return 0;
|
||||
while (*str && (clen = mb_metacharlenconv(str, &wc))) {
|
||||
str += clen;
|
||||
if (wc == WEOF) /* TODO: replace with space? nicen? */
|
||||
continue;
|
||||
*wptr++ = wc;
|
||||
}
|
||||
|
||||
ws = malloc(sl * sizeof(wchar_t));
|
||||
|
||||
if (mbstowcs(ws, args[1], sl) < 1) {
|
||||
free(ws);
|
||||
*wptr++ = L'\0';
|
||||
if (waddwstr(w->win, wstr)!=OK) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
wcc = malloc(wcslen(ws) * sizeof(cchar_t));
|
||||
|
||||
if (setcchar(wcc, ws, A_NORMAL, 0, NULL)==ERR) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
free(ws);
|
||||
|
||||
if (wadd_wchstr(w->win, wcc)!=OK) {
|
||||
free(wcc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
free(wcc);
|
||||
#else
|
||||
if (waddstr(w->win, args[1])!=OK)
|
||||
return 1;
|
||||
|
|
|
@ -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 \
|
||||
|
|
Loading…
Reference in a new issue