Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: zcurses -s



This looks about the neatest way of doing zcurses -s, as long as we
don't have separate character attributes (waddwstr() does the cchar_t
conversion internally).  Otherwise I think you just have to loop over
the setcchar() for each wide character and pass that to
wadd_wchstr()---however, that doesn't advance the cursor so isn't
compatible with the other output routines, for some reason.  So then it
looks like you're stuck with looping over wadd_wch(), too, which
probably isn't a disaster.

Index: configure.ac
===================================================================
RCS file: /cvsroot/zsh/zsh/configure.ac,v
retrieving revision 1.71
diff -u -r1.71 configure.ac
--- configure.ac	12 Oct 2007 10:18:58 -0000	1.71
+++ configure.ac	17 Oct 2007 17:47:17 -0000
@@ -1134,7 +1134,7 @@
 	       brk sbrk \
 	       pathconf sysconf \
 	       tgetent tigetflag tigetnum tigetstr setupterm initscr \
-	       setcchar \
+	       setcchar waddwstr \
 	       pcre_compile pcre_study pcre_exec \
 	       nl_langinfo \
 	       erand48 open_memstream \
Index: Src/Modules/curses.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/curses.c,v
retrieving revision 1.9
diff -u -r1.9 curses.c
--- Src/Modules/curses.c	17 Oct 2007 13:11:11 -0000	1.9
+++ Src/Modules/curses.c	17 Oct 2007 17:47:17 -0000
@@ -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
@@ -279,10 +284,11 @@
 	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);
@@ -293,34 +299,20 @@
 
 	w = (ZCWin)getdata(node);
 
-#ifdef HAVE_SETCCHAR
-	sl = strlen(args[1]);
-
-	if (sl == 0) {
-	    return 0;
-	}
-
-	ws = malloc(sl * sizeof(wchar_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;
+#ifdef HAVE_WADDWSTR
+	mb_metacharinit();
+	wptr = wstr = zhalloc((strlen(str)+1) * sizeof(cchar_t));
+
+	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;


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author