#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "curses_inc.h"
extern int outchcount;
static void _updateln(int), _turn_off_background(void),
_setmark1(int, int, chtype *),
_setmark2(int, int, chtype *), _rmargin(int),
_useceod(int, int);
static int _useidch(chtype *, chtype *, int, int, int *),
_prefix(chtype *, chtype *, int, int, int *),
_getceod(int, int);
static short cy, cx,
scrli,
scrco;
static char **marks;
static char **color_marks;
#define _ISMARK1(y, x) (marks[y][x / BITSPERBYTE] & (1 << (x % BITSPERBYTE)))
#define _ISMARK2(y, x) (color_marks ? (color_marks[y][x / BITSPERBYTE] & \
(1 << (x % BITSPERBYTE))) : FALSE)
#define _VIDEO(c) ((c) & A_ATTRIBUTES & ~A_COLOR)
#define _COLOR(c) ((c) & A_COLOR)
#ifdef _VR2_COMPAT_CODE
extern char _endwin;
#endif
int
wrefresh(WINDOW *win)
{
short *bnsch, *ensch;
SLK_MAP *slk;
int wx, wy, nc, boty, clby, idby, *hs, curwin;
curwin = (win == curscr);
if (curwin && curscr->_sync)
return (OK);
if (!curwin && (win != _virtscr))
(void) wnoutrefresh(win);
if ((_INPUTPENDING = _chkinput()) == TRUE) {
if (curwin)
curscr->_clear = TRUE;
return (OK);
}
if (curwin || curscr->_clear)
_virtscr->_clear = TRUE;
cy = curscr->_cury;
cx = curscr->_curx;
marks = _MARKS;
color_marks = _COLOR_MARKS;
scrli = curscr->_maxy;
scrco = curscr->_maxx;
slk = SP->slk;
outchcount = 0;
if (SP->fl_endwin) {
if (SP->fl_endwin == TRUE) {
(void) reset_prog_mode();
if (SP->kp_state)
(void) tputs(keypad_xmit, 1, _outch);
if (slk)
(*_do_slk_tch)();
if (SP->fl_meta)
(void) tputs(meta_on, 1, _outch);
if (cur_term->_cursorstate != 1)
_PUTS(cur_term->cursor_seq[cur_term->
_cursorstate], 0);
}
_PUTS(enter_ca_mode, 1);
(void) tputs(ena_acs, 1, _outch);
if (exit_attribute_mode)
_PUTS(tparm_p0(exit_attribute_mode), 1);
else
vidupdate(A_NORMAL, (A_ALTCHARSET | A_STANDOUT |
A_UNDERLINE), _outch);
SP->fl_endwin = FALSE;
#ifdef _VR2_COMPAT_CODE
_endwin = (char)FALSE;
#endif
}
if (_virtscr->_clear) {
if (back_color_erase)
_turn_off_background();
_PUTS(clear_screen, scrli);
cy = cx = curscr->_curx = curscr->_cury = 0;
if (!curscr->_sync)
(void) werase(curscr);
else {
nc = scrco / BITSPERBYTE - (scrco %
BITSPERBYTE ? 0 : 1);
wy = scrli - 1;
bnsch = _BEGNS; ensch = _ENDNS;
hs = _CURHASH;
for (; wy >= 0; --wy) {
*bnsch++ = scrco;
*ensch++ = -1;
*hs++ = 0;
if (marks)
for (wx = nc; wx >= 0; --wx)
marks[wy][wx] = 0;
}
}
_virtscr->_clear = curscr->_sync = curscr->_clear = FALSE;
if (slk)
(*_do_slk_tch)();
(void) wtouchln(_virtscr, 0, scrli, -1);
_VIRTTOP = 0;
_VIRTBOT = scrli - 1;
clby = idby = scrli;
} else
clby = idby = -1;
if (slk && slk->_win && (slk->_changed == TRUE))
(*_do_slk_noref)();
_virtscr->_clear = FALSE;
wy = _VIRTTOP;
boty = _VIRTBOT + 1;
bnsch = _virtscr->_firstch + wy;
ensch = _virtscr->_lastch + wy;
for (; wy < boty; ++wy, ++bnsch, ++ensch) {
if (*bnsch >= scrco)
goto next;
if (!curwin && (_INPUTPENDING = _chkinput()) == TRUE) {
_VIRTTOP = (short)wy;
goto done;
}
if (clby < 0) {
clby = _getceod(wy, boty);
if (_virtscr->_use_idl)
idby = (*_setidln)();
}
if (wy == clby)
_useceod(wy, boty);
if (wy == idby) {
curscr->_cury = cy;
curscr->_curx = cx;
(*_useidln)();
cy = curscr->_cury;
cx = curscr->_curx;
}
if (*bnsch < scrco)
_updateln(wy);
next:
*bnsch = _INFINITY;
*ensch = -1;
}
if (slk && (slk->_changed == TRUE) && !(slk->_win))
(*_do_slk_ref)();
wy = _virtscr->_cury;
wx = _virtscr->_curx;
if (wy != cy || wx != cx) {
(void) mvcur(cy, cx, wy, wx);
cy = (short)wy;
cx = (short)wx;
}
curscr->_clear = FALSE;
_virtscr->_use_idl = FALSE;
_virtscr->_use_idc = TRUE;
_INPUTPENDING = FALSE;
_VIRTTOP = scrli;
_VIRTBOT = -1;
done :
curscr->_cury = cy;
curscr->_curx = cx;
(void) fflush(SP->term_file);
return (outchcount);
}
static chtype *
_shove(int wy)
{
chtype *wcp, *cp, prev;
short curx;
int x, cury, didshift;
static chtype *line;
static int length;
if (length < scrco) {
free(line);
line = (chtype *) malloc(scrco * sizeof (chtype));
length = line ? scrco : 0;
}
if (!line)
return (_virtscr->_y[wy]);
prev = A_NORMAL;
cp = line;
wcp = _virtscr->_y[wy];
curx = _virtscr->_curx;
cury = _virtscr->_cury;
didshift = FALSE;
for (x = 0; x < scrco; ++x, ++wcp, ++cp) {
if (_ATTR(*wcp) != prev) {
if (_CHAR(*wcp) == ' ')
*cp = ' ' | _ATTR(*(wcp + 1));
else
if ((x > 0) && _CHAR(*(cp - 1)) == ' ') {
*(cp - 1) = ' ' | _ATTR(*wcp);
*cp = *wcp;
} else {
if ((curx >= x) && (cury == wy))
++curx;
*cp = ' ' | _ATTR(*wcp);
--wcp;
didshift = TRUE;
}
prev = _ATTR(*cp);
} else
*cp = *wcp;
}
cp = line + scrco - 1;
if (didshift || (_ATTR(*cp) != A_NORMAL) ||
((wy == scrli - 1) && (_ATTR(*(cp - 1)) != A_NORMAL))) {
*cp = didshift ? ' ' : _CHAR(*cp);
if (wy == scrli - 1)
*(cp - 1) = didshift ? ' ' : _CHAR(*(cp - 1));
}
if (wy == cury)
_virtscr->_curx = curx >= scrco ? scrco - 1 : curx;
return (line);
}
static void
_updateln(int wy)
{
chtype *wcp, *scp, *wp, *sp, wc, sc;
int wx, lastx, x, mtch, idch, blnkx, idcx, video_attrx,
color_attrx, maxi, endns, begns, wx_sav, multi_col;
bool redraw, changed, didcolor, didvideo;
redraw = (_virtscr->_firstch[wy] == _REDRAW);
endns = _ENDNS[wy];
begns = _BEGNS[wy];
if (!redraw && (_virtscr->_lastch[wy] == _BLANK) && (begns >= scrco))
return;
wcp = magic_cookie_glitch <= 0 ? _virtscr->_y[wy] : _shove(wy);
scp = curscr->_y[wy];
if (redraw || magic_cookie_glitch >= 0) {
wx = 0;
lastx = scrco;
} else {
wx = _virtscr->_firstch[wy];
lastx = _virtscr->_lastch[wy] == _BLANK ? scrco :
_virtscr->_lastch[wy] + 1;
}
if (!redraw) {
wp = wcp + wx;
sp = scp + wx;
for (; wx < lastx; ++wx)
if (*wp++ != *sp++)
break;
if (wx >= lastx)
return;
for (sp = scp+wx, wp = wcp+wx; wp > wcp; --wp, --sp, --wx)
if (!ISCBIT(*wp) && !ISCBIT(*sp))
break;
wp = wcp + lastx - 1;
sp = scp + lastx - 1;
for (; lastx > wx; --lastx)
if (*wp-- != *sp--)
break;
++wp;
++wp;
++sp;
++sp;
for (; lastx < scrco; ++wp, ++sp, ++lastx)
if (!ISCBIT(*wp) && !ISCBIT(*sp))
break;
}
if (!clr_eol || endns >= lastx)
blnkx = scrco;
else
if (_virtscr->_lastch[wy] == _BLANK)
blnkx = -1;
else {
for (blnkx = lastx - 1, wp = wcp + blnkx;
blnkx >= wx; --blnkx, --wp)
if (_DARKCHAR(*wp))
break;
for (sp = scp + blnkx + 1; blnkx < scrco - 1;
++sp, ++blnkx)
if (!ISCBIT(*sp))
break;
if (blnkx + _COST(Clr_eol) >= lastx)
blnkx = scrco;
}
if (marks) {
video_attrx = color_attrx = (lastx >= scrco) ? lastx - 1 :
lastx;
wp = wcp + video_attrx;
for (; video_attrx >= wx; --video_attrx, --wp)
if (_VIDEO(*wp) != A_NORMAL)
break;
if (color_marks) {
wp = wcp + color_attrx;
for (; color_attrx >= wx; --color_attrx, --wp)
if (_COLOR(*wp) != A_NORMAL)
break;
if (color_attrx < lastx)
color_attrx++;
}
if (video_attrx < lastx)
video_attrx++;
if (video_attrx >= scrco)
--video_attrx;
if (color_marks && color_attrx >= scrco)
--color_attrx;
if (magic_cookie_glitch > 0 && wy == scrli - 1 &&
video_attrx == scrco - 1)
--video_attrx;
if (color_marks && magic_cookie_glitch > 0 &&
wy == scrli - 1 && color_attrx == scrco - 1)
--color_attrx;
for (wp = wcp+video_attrx; wp >= wcp+wx; --wp)
if (!ISCBIT(*wp))
break;
}
#define SLACK 4
if (redraw || (!SP->dchok && !SP->ichok) || !(_virtscr->_use_idc) ||
endns < wx || (endns >= lastx && (scrco - lastx) > SLACK)) {
idcx = scrco;
} else
if (!marks)
idcx = -1;
else {
for (idcx = scrco - 1, wp = wcp + idcx; idcx >= wx;
--idcx, --wp)
if (_ATTR(*wp) || _ISMARK1(wy, idcx) ||
_ISMARK2(wy, idcx))
break;
if (idcx >= scrco - SLACK)
idcx = scrco;
}
if (idcx < lastx && endns >= lastx)
lastx = scrco;
if (idcx == scrco || !SP->ichok)
maxi = 0;
else
if (lastx == scrco)
maxi = scrco;
else
maxi = lastx - (endns + 1);
wcp += wx;
scp += wx;
didvideo = changed = FALSE;
didcolor = (color_marks) ? FALSE : TRUE;
while (wx < lastx) {
if (!redraw) {
multi_col = 0;
wx_sav = wx;
for (; wx < lastx; ++wx, ++wcp, ++scp)
if (*wcp != *scp)
break;
if (wx >= lastx)
goto done;
for (; wx > wx_sav; --wx, --wcp, --scp) {
if (!ISCBIT(*wcp) && !ISCBIT(*scp))
break;
multi_col = 1;
}
}
if (!changed && !marks && clr_bol && blnkx > wx &&
begns >= wx) {
for (x = wx, wp = wcp; x < lastx; ++x, ++wp)
if (_DARKCHAR(*wp))
break;
for (sp = scp+(x-wx); x >= wx; --x, --sp)
if (!ISCBIT(*sp))
break;
x -= 1;
if ((x - (redraw ? 0 : begns)) > _COST(Clr_bol)) {
(void) mvcur(cy, cx, wy, x);
if (back_color_erase)
_turn_off_background();
_PUTS(clr_bol, 1);
cy = (short)wy;
cx = (short)x;
mtch = x - wx;
(void) memcpy(scp, wcp,
(mtch * sizeof (chtype)));
wcp += mtch;
scp += mtch;
wx = x;
}
}
changed = TRUE;
if (cy != wy || cx != wx)
(void) mvcur(cy, cx, wy, wx);
cy = (short)wy;
cx = (short)wx;
while (wx < lastx) {
wc = *wcp;
sc = *scp;
if (!redraw && !multi_col && wc == sc)
break;
if (marks)
curscr->_attrs = _ATTR(sc);
if (wx > blnkx) {
if (back_color_erase)
_turn_off_background();
_PUTS(clr_eol, 1);
curscr->_curx = (short)wx;
curscr->_cury = (short)wy;
(void) wclrtoeol(curscr);
if (marks && wx > 0 && _ATTR(*(scp - 1)) !=
A_NORMAL) {
_VIDS(A_NORMAL, _ATTR(*(scp - 1)));
if (_VIDEO(*scp - 1))
_setmark1(wy, wx, NULL);
if (_COLOR(*scp - 1))
_setmark2(wy, wx, NULL);
}
goto done;
}
if (wx > idcx && !ISCBIT(*scp) &&
(mtch = _useidch(wcp, scp, lastx - wx,
maxi, &idch))) {
maxi -= idch;
wx += mtch;
scp += mtch;
wcp += mtch;
break;
}
if (SP->phys_irm)
_OFFINSERT();
if (_ATTR(wc) != curscr->_attrs) {
bool color_change = FALSE;
bool video_change = FALSE;
if (marks) {
if (_VIDEO(wc) !=
_VIDEO(curscr->_attrs)) {
video_change = TRUE;
}
}
if (color_marks) {
if (_COLOR(wc) !=
_COLOR(curscr->_attrs)) {
color_change = TRUE;
}
}
if (marks && !video_change && !color_change)
goto no_change;
if (marks && !(didcolor && didvideo)) {
if ((video_change && !_ISMARK1(wy,
video_attrx)) || (color_change &&
!_ISMARK2(wy, color_attrx))) {
int tempx;
chtype sa = curscr->_attrs;
bool first = FALSE;
bool second = FALSE;
if (!didvideo && video_change &&
!_ISMARK1(wy, video_attrx)) {
didvideo = TRUE;
(void) mvcur(wy, wx,
wy, video_attrx);
_VIDS(_VIDEO(_virtscr->_y[wy]
[video_attrx]),
_VIDEO(_virtscr->_y[wy]
[video_attrx-1]));
_setmark1(wy, video_attrx,
NULL);
first = TRUE;
}
if (!didcolor && color_change &&
!_ISMARK2(wy, color_attrx)) {
didcolor = TRUE;
tempx = first ? video_attrx : wx;
if (tempx != color_attrx)
(void) mvcur(wy, tempx, wy,
color_attrx);
_VIDS(_COLOR(_virtscr->_y[wy]
[color_attrx]),
_COLOR(_virtscr->_y[wy]
[color_attrx-1]));
_setmark2(wy, color_attrx, NULL);
second = TRUE;
}
(void) mvcur(wy, (second ? color_attrx :
video_attrx), wy, wx);
curscr->_attrs = sa;
}
}
_VIDS(_ATTR(wc), curscr->_attrs);
if (video_change)
_setmark1(wy, wx, scp);
if (color_change)
_setmark2(wy, wx, scp);
}
no_change:
x = 1;
if (_scrmax > 1)
x = _curs_scrwidth[TYPE(RBYTE(wc))];
if (wx == scrco - x) {
_rmargin(wx);
goto done;
}
if (transparent_underline && erase_overstrike &&
_CHAR(wc) == '_') {
(void) _outch(' ');
(void) mvcur(wy, wx + 1, wy, wx);
}
(void) _outwch(tilde_glitch && _CHAR(wc) == '~' ? '`' : wc);
*scp++ = wc;
wcp++;
wx++;
cx++;
while (wx < lastx && ISCBIT(*wcp)) {
(void) _outwch(*wcp);
*scp++ = *wcp++;
wx++;
cx++;
}
}
}
done:
if (changed) {
for (wx = 0, scp = curscr->_y[wy]; wx < scrco; ++wx, ++scp)
if (_DARKCHAR(*scp))
break;
_BEGNS[wy] = (short)wx;
if (wx == scrco)
_ENDNS[wy] = -1;
else {
wx = scrco - 1;
scp = curscr->_y[wy] + wx;
for (; wx >= 0; --wx, --scp)
if (_DARKCHAR(*scp))
break;
_ENDNS[wy] = (short)wx;
}
_CURHASH[wy] = _BEGNS[wy] < scrco ? _NOHASH : 0;
}
}
static int
_useidch(chtype *wcp, chtype *scp, int length, int maxi, int *id)
{
int x1, x2, blnk, idch, cost, cost_ich1, match;
chtype wc;
if (SP->dchok && _CHAR(*wcp) != ' ') {
if ((match = _prefix(wcp, scp, length, length / 2, &idch)) > 0)
cost = _COST(dcfixed) + (parm_dch ? _COST(Parm_dch) :
_COST(Delete_character) * idch);
else
cost = _INFINITY;
if (match >= cost) {
if (back_color_erase)
_turn_off_background();
if (SP->dmode) {
if (SP->sid_equal) {
if (!(SP->phys_irm))
_ONINSERT();
} else {
if (SP->phys_irm)
_OFFINSERT();
_PUTS(enter_delete_mode, 1);
}
}
if (parm_dch)
_PUTS(tparm_p1(parm_dch, idch), 1);
else
for (x1 = 0; x1 < idch; ++x1)
_PUTS(delete_character, 1);
if (SP->dmode) {
if (SP->eid_equal)
SP->phys_irm = FALSE;
_PUTS(exit_delete_mode, 1);
}
for (x1 = 0, x2 = idch; x2 < length; ++x1, ++x2)
scp[x1] = scp[x2];
for (; x1 < length; ++x1)
scp[x1] = ' ';
*id = -idch;
return (match);
}
}
if (!(SP->ichok) || _CHAR(*scp) == ' ')
return (0);
maxi = (idch = length / 2) < maxi ? idch : maxi;
if ((match = _prefix(scp, wcp, length, maxi, &idch)) <= 0)
return (0);
for (blnk = 0; blnk < idch; ++blnk)
if (wcp[blnk] != ' ') {
blnk = 0;
break;
}
cost_ich1 = idch * _COST(Insert_character);
if (SP->imode) {
cost = SP->phys_irm ? 0 : _COST(icfixed);
if (blnk > _COST(Parm_ich) && _COST(Parm_ich) < cost_ich1)
cost += _COST(Parm_ich);
else
if (insert_character)
cost += cost_ich1;
} else {
if (parm_ich && _COST(Parm_ich) < cost_ich1)
cost = _COST(Parm_ich);
else
cost = cost_ich1;
}
if ((cost - blnk) > match)
return (0);
if (back_color_erase)
_turn_off_background();
if (SP->imode) {
if (!SP->phys_irm)
_ONINSERT();
if (blnk > _COST(Parm_ich) && _COST(Parm_ich) < cost_ich1)
_PUTS(tparm_p1(parm_ich, idch), 1);
else
if (insert_character)
goto do_insert_char;
else
blnk = 0;
} else {
if (parm_ich && _COST(Parm_ich) < cost_ich1)
_PUTS(tparm_p1(parm_ich, idch), 1);
else {
do_insert_char:
for (x1 = 0; x1 < idch; ++x1)
_PUTS(insert_character, 1);
}
}
if (!blnk)
for (x1 = 0; x1 < idch; ++x1) {
wc = wcp[x1];
if (_ATTR(wc) != curscr->_attrs)
_VIDS(_ATTR(wc), curscr->_attrs);
(void) _outwch(_CHAR(wc) == '~' &&
tilde_glitch ? '`' : wc);
++cx;
}
for (x1 = length - 1, x2 = length - idch - 1; x2 >= 0; --x1, --x2)
scp[x1] = scp[x2];
(void) memcpy(scp, wcp, idch * sizeof (chtype));
*id = idch;
return (match + idch);
}
static int
_prefix(chtype *s1, chtype *s2, int length, int maxs, int *begm)
{
int m, n, k;
n = 0;
for (m = 1; m <= maxs; ++m)
if (s1[0] == s2[m] && s1[m] != s2[m]) {
for (k = 2 * m - 1; k > m; --k)
if (s1[k - m] != s2[k])
break;
if (k == m) {
*begm = m;
s2 += m;
length -= m;
for (n = m; n < length; ++n)
if (s1[n] != s2[n])
break;
goto done;
}
}
done:
return (n);
}
static void
_setmark1(int y, int x, chtype *s)
{
long a;
marks[y][x / BITSPERBYTE] |= (1 << (x % BITSPERBYTE));
if (s) {
a = _VIDEO(curscr->_attrs);
*s = _CHAR(*s) | _COLOR(*s) | a;
for (x += 1, s += 1; x < scrco; ++x, ++s)
if (_ISMARK1(y, x))
break;
else
*s = _CHAR(*s) | _COLOR(*s) | a;
}
}
static void
_setmark2(int y, int x, chtype *s)
{
long a;
color_marks[y][x / BITSPERBYTE] |= (1 << (x % BITSPERBYTE));
if (s) {
a = _COLOR(curscr->_attrs);
*s = _CHAR(*s) | _VIDEO(*s) | a;
for (x += 1, s += 1; x < scrco; ++x, ++s)
if (_ISMARK2(y, x))
break;
else
*s = _CHAR(*s) | _VIDEO(*s) | a;
}
}
static void
_rmargin(int wx)
{
int x, w, ix;
chtype sc;
chtype *wcp = _virtscr->_y[cy];
if (cy == scrli - 1) {
if (!SP->ichok)
return;
w = _curs_scrwidth[TYPE(RBYTE(wcp[wx]))];
for (x = wx - 1; x > 0; --x)
if (!ISCBIT(wcp[x]))
break;
sc = curscr->_y[cy][x];
(void) mvcur(cy, cx, cy, x);
if (_ATTR(wcp[wx]) != curscr->_attrs)
_VIDS(_ATTR(wcp[wx]), curscr->_attrs);
(void) _outwch(tilde_glitch &&
_CHAR(wcp[wx]) == '~' ? '`' : wcp[wx]);
for (ix = wx + 1; ix < scrco; ++ix) {
(void) _outwch(wcp[ix]);
}
(void) mvcur(cy, x+w, cy, x);
if (back_color_erase)
_turn_off_background();
if (SP->imode && !SP->phys_irm)
_ONINSERT();
w = _curs_scrwidth[TYPE(RBYTE(curscr->_y[cy][x]))];
if (insert_character)
for (ix = 0; ix < w; ++ix)
_PUTS(insert_character, 1);
else
if (parm_ich && !SP->imode)
_PUTS(tparm_p1(parm_ich, w), 1);
if (_ATTR(sc) != curscr->_attrs)
_VIDS(_ATTR(sc), curscr->_attrs);
for (ix = x; w > 0; --w, ++ix)
(void) _outwch(curscr->_y[cy][ix]);
if (marks && (_ATTR(sc) || _ATTR(wcp[wx])))
_VIDS(_ATTR(wcp[wx]), ~_ATTR(sc));
cx = (short)wx;
curscr->_y[cy][wx] = wcp[wx];
for (x = wx + 1; x < scrco; ++x) {
(void) _outwch(wcp[x]);
curscr->_y[cy][x] = wcp[x];
}
return;
}
(void) _outwch(tilde_glitch && _CHAR(wcp[wx]) == '~' ? '`' : wcp[wx]);
curscr->_y[cy][wx] = wcp[wx];
for (x = wx + 1; x < scrco; ++x) {
(void) _outwch(wcp[x]);
curscr->_y[cy][x] = wcp[x];
}
if (!auto_right_margin || eat_newline_glitch) {
(void) _outch('\r');
(void) _outch('\n');
}
cx = 0;
++cy;
}
static int
_getceod(int topy, int boty)
{
chtype *wcp, *ecp;
int wy;
short *begch, *endch, *begns;
if ((topy + 1) >= boty)
return (boty);
wy = boty - 1;
begch = _virtscr->_firstch + wy;
endch = _virtscr->_lastch + wy;
begns = _BEGNS + wy;
for (; wy >= topy; --wy, --begch, --endch, --begns) {
if (*endch == _BLANK || (*begch >= scrco && *begns >= scrco))
continue;
wcp = _virtscr->_y[wy];
ecp = wcp + scrco;
for (; wcp < ecp; ++wcp)
if (_DARKCHAR(*wcp))
break;
if (wcp != ecp)
break;
*endch = _BLANK;
}
return (wy + 1);
}
static void
_useceod(int topy, int boty)
{
short *begns, *begch;
begch = _virtscr->_firstch + topy;
begns = _BEGNS + topy;
for (; topy < boty; ++topy, ++begns, ++begch)
if (*begns < scrco || *begch == _REDRAW)
break;
else
*begch = _INFINITY;
if (topy + 1 >= boty)
return;
for (begns = _BEGNS + boty; boty < scrli; ++boty, ++begns)
if (*begns < scrco)
return;
if (topy == 0) {
if (back_color_erase)
_turn_off_background();
_PUTS(clear_screen, scrli);
cy = 0; cx = 0;
(void) werase(curscr);
} else {
if (clr_eos || (parm_delete_line && !memory_below)) {
(void) mvcur(cy, cx, topy, 0);
cy = (short)topy;
cx = 0;
if (back_color_erase)
_turn_off_background();
_PUTS(clr_eos ? clr_eos : tparm_p1(parm_delete_line,
scrli - topy), scrli - topy);
curscr->_cury = (short)topy;
curscr->_curx = 0;
(void) wclrtobot(curscr);
} else {
return;
}
}
(void) wtouchln(_virtscr, topy, scrli, FALSE);
}
static void
_turn_off_background(void)
{
if (set_background && cur_term->_cur_pair.background > 0) {
_PUTS(orig_pair, 1);
cur_term->_cur_pair.foreground = -1;
cur_term->_cur_pair.background = -1;
curscr->_attrs &= ~A_COLOR;
}
}