Module Name:    src
Committed By:   uwe
Date:           Wed Jul  1 02:57:02 UTC 2020

Modified Files:
        src/lib/libcurses: line.c

Log Message:
hline, vline - don't lose attributes when using default character.

Make default (wide) and non-wide behavior match.  If the character
argument has (only) attributes set, use them with the default line
character.

In the wide case don't do the fallback in hline - it just calls
hline_set that needs to do it anyway.  Fix the latter to check the
wcwidth of the right character and avoid division by zero.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libcurses/line.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/line.c
diff -u src/lib/libcurses/line.c:1.15 src/lib/libcurses/line.c:1.16
--- src/lib/libcurses/line.c:1.15	Wed Jul  1 02:14:41 2020
+++ src/lib/libcurses/line.c	Wed Jul  1 02:57:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: line.c,v 1.15 2020/07/01 02:14:41 uwe Exp $	*/
+/*	$NetBSD: line.c,v 1.16 2020/07/01 02:57:01 uwe Exp $	*/
 
 /*-
  * Copyright (c) 1998-1999 Brett Lymn
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: line.c,v 1.15 2020/07/01 02:14:41 uwe Exp $");
+__RCSID("$NetBSD: line.c,v 1.16 2020/07/01 02:57:01 uwe Exp $");
 #endif				/* not lint */
 
 #include <string.h>
@@ -101,15 +101,10 @@ whline(WINDOW *win, chtype ch, int count
 	wmove(win, ocury, ocurx);
 	return OK;
 #else
-	cchar_t cch, *cchp;
+	cchar_t cch;
 
-	if (ch & __CHARTEXT) {
-		__cursesi_chtype_to_cchar(ch, &cch);
-		cchp = & cch;
-	} else
-		cchp = WACS_HLINE;
-
-	return whline_set(win, cchp, count);
+	__cursesi_chtype_to_cchar(ch, &cch);
+	return whline_set(win, &cch, count);
 #endif
 }
 
@@ -174,15 +169,10 @@ wvline(WINDOW *win, chtype ch, int count
 	wmove(win, ocury, ocurx);
 	return OK;
 #else
-	cchar_t cch, *cchp;
-
-	if (ch & __CHARTEXT) {
-		__cursesi_chtype_to_cchar(ch, &cch);
-		cchp = & cch;
-	} else
-		cchp = WACS_VLINE;
+	cchar_t cch;
 
-	return wvline_set(win, cchp, count);
+	__cursesi_chtype_to_cchar(ch, &cch);
+	return wvline_set(win, &cch, count);
 #endif
 }
 
@@ -224,8 +214,14 @@ int whline_set(WINDOW *win, const cchar_
 	int ocury, ocurx, wcn, i, cw;
 	cchar_t cc;
 
-	cw = wcwidth( wch->vals[ 0 ]);
-	if (cw < 0)
+	cc = *wch;
+	if (!cc.vals[0]) {
+		cc.vals[0] = WACS_HLINE->vals[0];
+		cc.attributes |= WACS_HLINE->attributes;
+	}
+
+	cw = wcwidth(cc.vals[0]);
+	if (cw <= 0)
 		cw = 1;
 	if ( ( win->maxx - win->curx ) < cw )
 		return ERR;
@@ -236,9 +232,6 @@ int whline_set(WINDOW *win, const cchar_
 	ocury = win->cury;
 	ocurx = win->curx;
 
-	memcpy( &cc, wch, sizeof( cchar_t ));
-	if (!(wch->vals[ 0 ]))
-		cc.vals[ 0 ] |= WACS_HLINE->vals[0];
 	for (i = 0; i < wcn; i++ ) {
 #ifdef DEBUG
 		__CTRACE(__CTRACE_LINE, "whline_set: (%d,%d)\n",
@@ -298,9 +291,11 @@ int wvline_set(WINDOW *win, const cchar_
 	ocury = win->cury;
 	ocurx = win->curx;
 
-	memcpy(&cc, wch, sizeof(cchar_t));
-	if (!(wch->vals[0]))
-		cc.vals[0] |= WACS_VLINE->vals[0];
+	cc = *wch;
+	if (!cc.vals[0]) {
+		cc.vals[0] = WACS_VLINE->vals[0];
+		cc.attributes |= WACS_VLINE->attributes;
+	}
 	for (i = 0; i < wcn; i++) {
 		mvwadd_wch(win, ocury + i, ocurx, &cc);
 #ifdef DEBUG

Reply via email to