zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: zcurses -s
@ 2007-10-17 17:52 Peter Stephenson
  2007-10-17 18:14 ` Clint Adams
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2007-10-17 17:52 UTC (permalink / raw)
  To: Zsh hackers list

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@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: zcurses -s
  2007-10-17 17:52 PATCH: zcurses -s Peter Stephenson
@ 2007-10-17 18:14 ` Clint Adams
  2007-10-18  8:25   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Clint Adams @ 2007-10-17 18:14 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Wed, Oct 17, 2007 at 06:52:30PM +0100, Peter Stephenson wrote:
> 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

I am confused by this; why does setcchar(3ncurses) talk about arrays and
strings if it can't handle an entire wchar_t* string?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: zcurses -s
  2007-10-17 18:14 ` Clint Adams
@ 2007-10-18  8:25   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2007-10-18  8:25 UTC (permalink / raw)
  To: Zsh hackers list

On Wed, 17 Oct 2007 14:14:35 -0400
Clint Adams <clint@zsh.org> wrote:
> On Wed, Oct 17, 2007 at 06:52:30PM +0100, Peter Stephenson wrote:
> > 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
> 
> I am confused by this; why does setcchar(3ncurses) talk about arrays and
> strings if it can't handle an entire wchar_t* string?

            The string must be
            L'\0' terminated, contain at most one character with strictly pos-
            itive width, which must be the first, and contain no characters of
            negative width.

I think it's trying to take account of combining characters (which zsh
doesn't handle at all yet and which, not coincidentally, I haven't got a
clue about).

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-10-18  8:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-17 17:52 PATCH: zcurses -s Peter Stephenson
2007-10-17 18:14 ` Clint Adams
2007-10-18  8:25   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).