Module Name:    src
Committed By:   roy
Date:           Thu Mar 12 12:17:15 UTC 2020

Modified Files:
        src/lib/libcurses: clrtobot.c clrtoeol.c curses.h erase.c

Log Message:
curses: normalise erase logic with clrtoeol and clrtobot

Define WA_ATTRIBUTES as 0 for the non wide case just to make our code
easier to write.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/libcurses/clrtobot.c
cvs rdiff -u -r1.28 -r1.29 src/lib/libcurses/clrtoeol.c
cvs rdiff -u -r1.126 -r1.127 src/lib/libcurses/curses.h
cvs rdiff -u -r1.29 -r1.30 src/lib/libcurses/erase.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/clrtobot.c
diff -u src/lib/libcurses/clrtobot.c:1.24 src/lib/libcurses/clrtobot.c:1.25
--- src/lib/libcurses/clrtobot.c:1.24	Fri Jan  6 13:53:18 2017
+++ src/lib/libcurses/clrtobot.c	Thu Mar 12 12:17:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: clrtobot.c,v 1.24 2017/01/06 13:53:18 roy Exp $	*/
+/*	$NetBSD: clrtobot.c,v 1.25 2020/03/12 12:17:15 roy Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)clrtobot.c	8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: clrtobot.c,v 1.24 2017/01/06 13:53:18 roy Exp $");
+__RCSID("$NetBSD: clrtobot.c,v 1.25 2020/03/12 12:17:15 roy Exp $");
 #endif
 #endif				/* not lint */
 
@@ -65,6 +65,7 @@ wclrtobot(WINDOW *win)
 {
 	int	 minx, startx, starty, y;
 	__LDATA	*sp, *end, *maxx;
+	wchar_t bch;
 	attr_t	attr;
 
 #ifdef __GNUC__
@@ -77,6 +78,11 @@ wclrtobot(WINDOW *win)
 		starty = win->cury;
 		startx = win->curx;
 	}
+#ifdef HAVE_WCHAR
+	bch = (wchar_t)btowc((int)win->bch);
+#else
+	bch = win->bch;
+#endif
 	if (win != curscr)
 		attr = win->battr & __ATTRIBUTES;
 	else
@@ -85,28 +91,23 @@ wclrtobot(WINDOW *win)
 		minx = -1;
 		end = &win->alines[y]->line[win->maxx];
 		for (sp = &win->alines[y]->line[startx]; sp < end; sp++) {
-#ifndef HAVE_WCHAR
-			if (sp->ch != win->bch || sp->attr != attr) {
-#else
-			if (sp->ch != (wchar_t)btowc((int)win->bch) ||
-			    (sp->attr & WA_ATTRIBUTES) != attr || sp->nsp) {
-#endif /* HAVE_WCHAR */
-				maxx = sp;
-				if (minx == -1)
-					minx = (int)(sp - win->alines[y]->line);
-				if (sp->attr & __ALTCHARSET)
-					sp->attr = attr | __ALTCHARSET;
-				else
-					sp->attr = attr;
+			if (sp->ch == bch &&
 #ifdef HAVE_WCHAR
-				sp->ch = (wchar_t)btowc((int)win->bch);
-				if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
-					return ERR;
-				SET_WCOL(*sp, 1);
-#else
-				sp->ch = win->bch;
-#endif /* HAVE_WCHAR */
-			}
+			    sp->nsp == NULL && WCOL(*sp) >= 0 &&
+#endif
+			    (sp->attr & WA_ATTRIBUTES) == attr)
+				continue;
+
+			maxx = sp;
+			if (minx == -1)
+				minx = (int)(sp - win->alines[y]->line);
+			sp->attr = attr | (sp->attr & __ALTCHARSET);
+			sp->ch = bch;
+#ifdef HAVE_WCHAR
+			if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
+				return ERR;
+			SET_WCOL(*sp, 1);
+#endif
 		}
 
 		if (minx != -1)

Index: src/lib/libcurses/clrtoeol.c
diff -u src/lib/libcurses/clrtoeol.c:1.28 src/lib/libcurses/clrtoeol.c:1.29
--- src/lib/libcurses/clrtoeol.c:1.28	Fri Jan  6 13:53:18 2017
+++ src/lib/libcurses/clrtoeol.c	Thu Mar 12 12:17:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: clrtoeol.c,v 1.28 2017/01/06 13:53:18 roy Exp $	*/
+/*	$NetBSD: clrtoeol.c,v 1.29 2020/03/12 12:17:15 roy Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)clrtoeol.c	8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: clrtoeol.c,v 1.28 2017/01/06 13:53:18 roy Exp $");
+__RCSID("$NetBSD: clrtoeol.c,v 1.29 2020/03/12 12:17:15 roy Exp $");
 #endif
 #endif				/* not lint */
 
@@ -65,6 +65,7 @@ wclrtoeol(WINDOW *win)
 {
 	int     minx, x, y;
 	__LDATA *end, *maxx, *sp;
+	wchar_t bch;
 	attr_t	attr;
 
 	y = win->cury;
@@ -82,31 +83,34 @@ wclrtoeol(WINDOW *win)
 	end = &win->alines[y]->line[win->maxx];
 	minx = -1;
 	maxx = &win->alines[y]->line[x];
+#ifdef HAVE_WCHAR
+	bch = (wchar_t)btowc((int)win->bch);
+#else
+	bch = win->bch;
+#endif
 	if (win != curscr)
 		attr = win->battr & __ATTRIBUTES;
 	else
 		attr = 0;
-	for (sp = maxx; sp < end; sp++)
-#ifndef HAVE_WCHAR
-		if (sp->ch != win->bch || sp->attr != attr) {
-#else
-		if (sp->ch != (wchar_t)btowc((int) win->bch ) ||
-		    (sp->attr & WA_ATTRIBUTES) != attr || sp->nsp
-		    || (WCOL(*sp) < 0)) {
-#endif /* HAVE_WCHAR */
-			maxx = sp;
-			if (minx == -1)
-				minx = (int) (sp - win->alines[y]->line);
-			sp->attr = attr | (sp->attr & __ALTCHARSET);
+	for (sp = maxx; sp < end; sp++) {
+		if (sp->ch == bch &&
 #ifdef HAVE_WCHAR
-			sp->ch = (wchar_t)btowc((int) win->bch);
-			if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
-				return ERR;
-			SET_WCOL(*sp, 1);
-#else
-			sp->ch = win->bch;
-#endif /* HAVE_WCHAR */
-		}
+		    sp->nsp == NULL && WCOL(*sp) >= 0 &&
+#endif
+		    (sp->attr & WA_ATTRIBUTES) == attr)
+			continue;
+
+		maxx = sp;
+		if (minx == -1)
+			minx = (int)(sp - win->alines[y]->line);
+		sp->attr = attr | (sp->attr & __ALTCHARSET);
+		sp->ch = bch;
+#ifdef HAVE_WCHAR
+		if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
+			return ERR;
+		SET_WCOL(*sp, 1);
+#endif
+	}
 #ifdef DEBUG
 	__CTRACE(__CTRACE_ERASE, "CLRTOEOL: y = %d, minx = %d, maxx = %d, "
 	    "firstch = %d, lastch = %d\n",

Index: src/lib/libcurses/curses.h
diff -u src/lib/libcurses/curses.h:1.126 src/lib/libcurses/curses.h:1.127
--- src/lib/libcurses/curses.h:1.126	Tue Sep  3 13:43:34 2019
+++ src/lib/libcurses/curses.h	Thu Mar 12 12:17:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: curses.h,v 1.126 2019/09/03 13:43:34 roy Exp $	*/
+/*	$NetBSD: curses.h,v 1.127 2020/03/12 12:17:15 roy Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -275,7 +275,9 @@ typedef struct __screen SCREEN;
 #define WA_VERTICAL	0x00000010	/* Vertical highlight */
 #define WA_LEFT		0x00000020	/* Left highlight */
 #define WA_RIGHT	0x00000040	/* Right highlight */
-#endif /* HAVE_WCHAR */
+#else /* HAVE_WCHAR */
+#define WA_ATTRIBUTES	0		/* Just to make our code easier */
+#endif /* !HAVE_WCHAR */
 
 /*
  * Alternate character set definitions

Index: src/lib/libcurses/erase.c
diff -u src/lib/libcurses/erase.c:1.29 src/lib/libcurses/erase.c:1.30
--- src/lib/libcurses/erase.c:1.29	Wed Mar 11 23:47:40 2020
+++ src/lib/libcurses/erase.c	Thu Mar 12 12:17:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: erase.c,v 1.29 2020/03/11 23:47:40 roy Exp $	*/
+/*	$NetBSD: erase.c,v 1.30 2020/03/12 12:17:15 roy Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)erase.c	8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: erase.c,v 1.29 2020/03/11 23:47:40 roy Exp $");
+__RCSID("$NetBSD: erase.c,v 1.30 2020/03/12 12:17:15 roy Exp $");
 #endif
 #endif				/* not lint */
 
@@ -64,14 +64,19 @@ erase(void)
 int
 werase(WINDOW *win)
 {
-
 	int     y;
 	__LDATA *sp, *end, *start;
+	wchar_t	bch;
 	attr_t	attr;
 
 #ifdef DEBUG
 	__CTRACE(__CTRACE_ERASE, "werase: (%p)\n", win);
 #endif
+#ifdef HAVE_WCHAR
+	bch = (wchar_t)btowc((int)win->bch);
+#else
+	bch = win->bch;
+#endif
 	if (win != curscr)
 		attr = win->battr & __ATTRIBUTES;
 	else
@@ -80,27 +85,20 @@ werase(WINDOW *win)
 		start = win->alines[y]->line;
 		end = &start[win->maxx];
 		for (sp = start; sp < end; sp++) {
-#ifndef HAVE_WCHAR
-			if (sp->ch == win->bch && sp->attr == 0)
-				continue;
-#else
-			if (sp->ch == (wchar_t)btowc((int)win->bch) &&
-			    sp->attr == 0 &&
-			    sp->nsp == NULL)
-				continue;
+			if (sp->ch == bch &&
+#ifdef HAVE_WCHAR
+			    sp->nsp == NULL && WCOL(*sp) >= 0 &&
 #endif
-			if (sp->attr & __ALTCHARSET)
-				sp->attr = attr | __ALTCHARSET;
-			else
-				sp->attr = attr;
-#ifndef HAVE_WCHAR
-			sp->ch = win->bch;
-#else
-			sp->ch = (wchar_t)btowc((int)win->bch);
+			    (sp->attr & WA_ATTRIBUTES) == attr)
+				continue;
+
+			sp->attr = attr | (sp->attr & __ALTCHARSET);
+			sp->ch = bch;
+#ifdef HAVE_WCHAR
 			if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
 				return ERR;
 			SET_WCOL(*sp, 1);
-#endif /* HAVE_WCHAR */
+#endif
 		}
 	}
 

Reply via email to