Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libcurses curses: wrap the erase logic in a macro
details: https://anonhg.NetBSD.org/src/rev/6bcc917366a6
branches: trunk
changeset: 1008146:6bcc917366a6
user: roy <roy%NetBSD.org@localhost>
date: Fri Mar 13 02:57:26 2020 +0000
description:
curses: wrap the erase logic in a macro
Easier to use, it's in one place and now hopefully everyone is happy.
X
diffstat:
lib/libcurses/clrtobot.c | 12 +++++-------
lib/libcurses/clrtoeol.c | 13 +++++--------
lib/libcurses/curses.h | 6 ++----
lib/libcurses/curses_private.h | 14 +++++++++++++-
lib/libcurses/erase.c | 12 ++++--------
5 files changed, 29 insertions(+), 28 deletions(-)
diffs (173 lines):
diff -r bd2e61f8d38d -r 6bcc917366a6 lib/libcurses/clrtobot.c
--- a/lib/libcurses/clrtobot.c Fri Mar 13 02:43:31 2020 +0000
+++ b/lib/libcurses/clrtobot.c Fri Mar 13 02:57:26 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clrtobot.c,v 1.25 2020/03/12 12:17:15 roy Exp $ */
+/* $NetBSD: clrtobot.c,v 1.26 2020/03/13 02:57:26 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.25 2020/03/12 12:17:15 roy Exp $");
+__RCSID("$NetBSD: clrtobot.c,v 1.26 2020/03/13 02:57:26 roy Exp $");
#endif
#endif /* not lint */
@@ -87,15 +87,12 @@
attr = win->battr & __ATTRIBUTES;
else
attr = 0;
+
for (y = starty; y < win->maxy; y++) {
minx = -1;
end = &win->alines[y]->line[win->maxx];
for (sp = &win->alines[y]->line[startx]; sp < end; sp++) {
- if (sp->ch == bch &&
-#ifdef HAVE_WCHAR
- sp->nsp == NULL && WCOL(*sp) >= 0 &&
-#endif
- (sp->attr & WA_ATTRIBUTES) == attr)
+ if (!(__NEED_ERASE(sp, bch, attr)))
continue;
maxx = sp;
@@ -115,6 +112,7 @@
(int)(maxx - win->alines[y]->line));
startx = 0;
}
+
__sync(win);
return OK;
}
diff -r bd2e61f8d38d -r 6bcc917366a6 lib/libcurses/clrtoeol.c
--- a/lib/libcurses/clrtoeol.c Fri Mar 13 02:43:31 2020 +0000
+++ b/lib/libcurses/clrtoeol.c Fri Mar 13 02:57:26 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clrtoeol.c,v 1.29 2020/03/12 12:17:15 roy Exp $ */
+/* $NetBSD: clrtoeol.c,v 1.30 2020/03/13 02:57:26 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.29 2020/03/12 12:17:15 roy Exp $");
+__RCSID("$NetBSD: clrtoeol.c,v 1.30 2020/03/13 02:57:26 roy Exp $");
#endif
#endif /* not lint */
@@ -92,14 +92,10 @@
attr = win->battr & __ATTRIBUTES;
else
attr = 0;
+
for (sp = maxx; sp < end; sp++) {
- if (sp->ch == bch &&
-#ifdef HAVE_WCHAR
- sp->nsp == NULL && WCOL(*sp) >= 0 &&
-#endif
- (sp->attr & WA_ATTRIBUTES) == attr)
+ if (!(__NEED_ERASE(sp, bch, attr)))
continue;
-
maxx = sp;
if (minx == -1)
minx = (int)(sp - win->alines[y]->line);
@@ -111,6 +107,7 @@
SET_WCOL(*sp, 1);
#endif
}
+
#ifdef DEBUG
__CTRACE(__CTRACE_ERASE, "CLRTOEOL: y = %d, minx = %d, maxx = %d, "
"firstch = %d, lastch = %d\n",
diff -r bd2e61f8d38d -r 6bcc917366a6 lib/libcurses/curses.h
--- a/lib/libcurses/curses.h Fri Mar 13 02:43:31 2020 +0000
+++ b/lib/libcurses/curses.h Fri Mar 13 02:57:26 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: curses.h,v 1.127 2020/03/12 12:17:15 roy Exp $ */
+/* $NetBSD: curses.h,v 1.128 2020/03/13 02:57:26 roy Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -275,9 +275,7 @@
#define WA_VERTICAL 0x00000010 /* Vertical highlight */
#define WA_LEFT 0x00000020 /* Left highlight */
#define WA_RIGHT 0x00000040 /* Right highlight */
-#else /* HAVE_WCHAR */
-#define WA_ATTRIBUTES 0 /* Just to make our code easier */
-#endif /* !HAVE_WCHAR */
+#endif /* HAVE_WCHAR */
/*
* Alternate character set definitions
diff -r bd2e61f8d38d -r 6bcc917366a6 lib/libcurses/curses_private.h
--- a/lib/libcurses/curses_private.h Fri Mar 13 02:43:31 2020 +0000
+++ b/lib/libcurses/curses_private.h Fri Mar 13 02:57:26 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: curses_private.h,v 1.71 2019/06/09 07:40:14 blymn Exp $ */
+/* $NetBSD: curses_private.h,v 1.72 2020/03/13 02:57:26 roy Exp $ */
/*-
* Copyright (c) 1998-2000 Brett Lymn
@@ -337,6 +337,18 @@
void __CTRACE(int, const char *, ...) __attribute__((__format__(__printf__, 2, 3)));
#endif
+/* Common erase logic */
+#ifdef HAVE_WCHAR
+#define __NEED_ERASE(sp, bch, attr) \
+ ((sp)->ch != (bch) || \
+ ((sp)->attr & WA_ATTRIBUTES) != (attr) || \
+ (sp)->nsp != NULL || \
+ WCOL(*sp) < 0)
+#else
+#define __NEED_ERASE(sp, bch, attr) \
+ ((sp)->ch != (bch) || (sp)->attr != (attr))
+#endif
+
/* Private functions. */
int __cputchar_args(int, void *);
void _cursesi_free_keymap(keymap_t *);
diff -r bd2e61f8d38d -r 6bcc917366a6 lib/libcurses/erase.c
--- a/lib/libcurses/erase.c Fri Mar 13 02:43:31 2020 +0000
+++ b/lib/libcurses/erase.c Fri Mar 13 02:57:26 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: erase.c,v 1.30 2020/03/12 12:17:15 roy Exp $ */
+/* $NetBSD: erase.c,v 1.31 2020/03/13 02:57:26 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.30 2020/03/12 12:17:15 roy Exp $");
+__RCSID("$NetBSD: erase.c,v 1.31 2020/03/13 02:57:26 roy Exp $");
#endif
#endif /* not lint */
@@ -81,17 +81,13 @@
attr = win->battr & __ATTRIBUTES;
else
attr = 0;
+
for (y = 0; y < win->maxy; y++) {
start = win->alines[y]->line;
end = &start[win->maxx];
for (sp = start; sp < end; sp++) {
- if (sp->ch == bch &&
-#ifdef HAVE_WCHAR
- sp->nsp == NULL && WCOL(*sp) >= 0 &&
-#endif
- (sp->attr & WA_ATTRIBUTES) == attr)
+ if (!(__NEED_ERASE(sp, bch, attr)))
continue;
-
sp->attr = attr | (sp->attr & __ALTCHARSET);
sp->ch = bch;
#ifdef HAVE_WCHAR
Home |
Main Index |
Thread Index |
Old Index