Module Name:    src
Committed By:   blymn
Date:           Tue Dec 20 04:57:01 UTC 2022

Modified Files:
        src/lib/libcurses: addbytes.c slk.c

Log Message:
Backout change to addnstr that broke other applications as n should be
the number of bytes to add - for multibyte characters n will be > 1.

Fix __slk_draw to pass in the actual length of the label instead of
the default label length because wide characters may make the
actual string length longer than the slk display length.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/lib/libcurses/addbytes.c
cvs rdiff -u -r1.20 -r1.21 src/lib/libcurses/slk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libcurses/addbytes.c
diff -u src/lib/libcurses/addbytes.c:1.67 src/lib/libcurses/addbytes.c:1.68
--- src/lib/libcurses/addbytes.c:1.67	Mon Dec 12 21:14:15 2022
+++ src/lib/libcurses/addbytes.c	Tue Dec 20 04:57:01 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: addbytes.c,v 1.67 2022/12/12 21:14:15 blymn Exp $	*/
+/*	$NetBSD: addbytes.c,v 1.68 2022/12/20 04:57:01 blymn Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)addbytes.c	8.4 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: addbytes.c,v 1.67 2022/12/12 21:14:15 blymn Exp $");
+__RCSID("$NetBSD: addbytes.c,v 1.68 2022/12/20 04:57:01 blymn Exp $");
 #endif
 #endif				/* not lint */
 
@@ -118,7 +118,7 @@ _cursesi_waddbytes(WINDOW *win, const ch
 	int		*py = &win->cury, *px = &win->curx, err;
 	__LINE		*lp;
 #ifdef HAVE_WCHAR
-	int		n, width;
+	int		n;
 	cchar_t		cc;
 	wchar_t		wc;
 	mbstate_t	st;
@@ -170,18 +170,14 @@ _cursesi_waddbytes(WINDOW *win, const ch
 		}
 
 		__CTRACE(__CTRACE_INPUT,
-		    "ADDBYTES WIDE(0x%x [%s], %x) at (%d, %d), ate %d bytes\n",
+		    "ADDBYTES WIDE(0x%04x [%s], %x) at (%d, %d), ate %d bytes\n",
 		    (unsigned)wc, unctrl((unsigned)wc), attr, *py, *px, n);
 		cc.vals[0] = wc;
 		cc.elements = 1;
 		cc.attributes = attr;
 		err = _cursesi_addwchar(win, &lp, py, px, &cc, char_interp);
 		bytes += n;
-
-		width = wcwidth(wc);
-		if (width < 0)
-			width = 1;
-		count -= width;
+		count -= n;
 #endif
 	}
 

Index: src/lib/libcurses/slk.c
diff -u src/lib/libcurses/slk.c:1.20 src/lib/libcurses/slk.c:1.21
--- src/lib/libcurses/slk.c:1.20	Tue Apr 12 07:03:04 2022
+++ src/lib/libcurses/slk.c	Tue Dec 20 04:57:01 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: slk.c,v 1.20 2022/04/12 07:03:04 blymn Exp $	*/
+/*	$NetBSD: slk.c,v 1.21 2022/12/20 04:57:01 blymn Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include <sys/cdefs.h>
 #include <limits.h>
 #ifndef lint
-__RCSID("$NetBSD: slk.c,v 1.20 2022/04/12 07:03:04 blymn Exp $");
+__RCSID("$NetBSD: slk.c,v 1.21 2022/12/20 04:57:01 blymn Exp $");
 #endif				/* not lint */
 
 #include <limits.h>
@@ -819,6 +819,9 @@ __slk_draw(SCREEN *screen, int labnum)
 	wchar_t wc[2];
 #endif
 
+	__CTRACE(__CTRACE_INPUT, "__slk_draw: screen %p, label %d\n", screen,
+	    labnum);
+
 	if (screen->slk_hidden)
 		return OK;
 
@@ -834,7 +837,7 @@ __slk_draw(SCREEN *screen, int labnum)
 		    (screen->slk_window->flags & __SCROLLOK) ||
 		    ((l->x + screen->slk_label_len) < screen->slk_window->maxx)) {
 			retval = mvwaddnstr(screen->slk_window, 0, l->x,
-			    l->label, screen->slk_label_len);
+			    l->label, strlen(l->label));
 		} else {
 			lcnt = 0;
 			tx = 0;

Reply via email to