Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libcurses curses: normalise erase logic with clrtoeol an...
details: https://anonhg.NetBSD.org/src/rev/cd8fb1201054
branches: trunk
changeset: 1008123:cd8fb1201054
user: roy <roy%NetBSD.org@localhost>
date: Thu Mar 12 12:17:15 2020 +0000
description:
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.
diffstat:
lib/libcurses/clrtobot.c | 47 ++++++++++++++++++++++++-----------------------
lib/libcurses/clrtoeol.c | 48 ++++++++++++++++++++++++++----------------------
lib/libcurses/curses.h | 6 ++++--
lib/libcurses/erase.c | 38 ++++++++++++++++++--------------------
4 files changed, 72 insertions(+), 67 deletions(-)
diffs (261 lines):
diff -r 6434f58a40cb -r cd8fb1201054 lib/libcurses/clrtobot.c
--- a/lib/libcurses/clrtobot.c Thu Mar 12 11:38:28 2020 +0000
+++ b/lib/libcurses/clrtobot.c Thu Mar 12 12:17:15 2020 +0000
@@ -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 @@
{
int minx, startx, starty, y;
__LDATA *sp, *end, *maxx;
+ wchar_t bch;
attr_t attr;
#ifdef __GNUC__
@@ -77,6 +78,11 @@
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 @@
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)
diff -r 6434f58a40cb -r cd8fb1201054 lib/libcurses/clrtoeol.c
--- a/lib/libcurses/clrtoeol.c Thu Mar 12 11:38:28 2020 +0000
+++ b/lib/libcurses/clrtoeol.c Thu Mar 12 12:17:15 2020 +0000
@@ -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 @@
{
int minx, x, y;
__LDATA *end, *maxx, *sp;
+ wchar_t bch;
attr_t attr;
y = win->cury;
@@ -82,31 +83,34 @@
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",
diff -r 6434f58a40cb -r cd8fb1201054 lib/libcurses/curses.h
--- a/lib/libcurses/curses.h Thu Mar 12 11:38:28 2020 +0000
+++ b/lib/libcurses/curses.h Thu Mar 12 12:17:15 2020 +0000
@@ -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 @@
#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
diff -r 6434f58a40cb -r cd8fb1201054 lib/libcurses/erase.c
--- a/lib/libcurses/erase.c Thu Mar 12 11:38:28 2020 +0000
+++ b/lib/libcurses/erase.c Thu Mar 12 12:17:15 2020 +0000
@@ -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 @@
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 @@
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
}
}
Home |
Main Index |
Thread Index |
Old Index