예제 #1
0
int
wdelch(WINDOW *win)
{
	chtype	*temp1, *temp2;
	chtype	*end;
	int	cury = win->_cury;
	short	curx = win->_curx;
	chtype	*cp;
	int	s;

	end = &win->_y[cury][win->_maxx - 1];
	temp2 = &win->_y[cury][curx + 1];
	temp1 = temp2 - 1;

	s = 1;
	win->_nbyte = -1;
	if (_scrmax > 1) {
		if (ISMBIT(*temp1)) {
			win->_insmode = TRUE;
			if (_mbvalid(win) == ERR)
				return (ERR);
			curx = win->_curx;
			temp1 = &win->_y[cury][curx];
		}
		if (ISMBIT(*end)) {
			for (cp = end; cp >= temp1; --cp)
				if (!ISCBIT(*cp))
					break;
			if (cp + _curs_scrwidth[TYPE(*cp)] > end+1)
				end = cp - 1;
		}
		if (ISMBIT(*temp1))
			s = _curs_scrwidth[TYPE(RBYTE(*temp1))];
		end -= s - 1;
		temp2 = &win->_y[cury][curx+s];
	}

	while (temp1 < end)
		*temp1++ = *temp2++;

	while (s--)
		*temp1++ = win->_bkgd;

#ifdef	_VR3_COMPAT_CODE
	if (_y16update)
		(*_y16update)(win, 1, win->_maxx - curx, cury, curx);
#endif	/* _VR3_COMPAT_CODE */

	win->_lastch[cury] = win->_maxx - 1;
	if (win->_firstch[cury] > curx)
		win->_firstch[cury] = curx;

	win->_flags |= _WINCHANGED;

	if (win->_sync)
		wsyncup(win);

	return (win->_immed ? wrefresh(win) : OK);
}
예제 #2
0
int
winwstr(WINDOW *win, wchar_t *wstr)
{
	int	counter = 0;
	int	cy = win->_cury;
	chtype	*ptr = &(win->_y[cy][win->_curx]),
		*pmax = &(win->_y[cy][win->_maxx]);
	chtype	*p1st = &(win->_y[cy][0]);
	wchar_t	wc;
	int	sw, s;
	char	*cp, cbuf[CSMAX+1];

	while (ISCBIT(*ptr) && (p1st < ptr))
		ptr--;

	while (ptr < pmax) {
		wc = RBYTE(*ptr);
		sw = mbscrw((int)wc);
		(void) mbeucw((int)wc);

		cp = cbuf;
		for (s = 0; s < sw; s++, ptr++) {
			if ((wc = RBYTE(*ptr)) == MBIT)
				continue;
			/* LINTED */
			*cp++ = (char) wc;
			if ((wc = LBYTE(*ptr) | MBIT) == MBIT)
				continue;
			/* LINTED */
			*cp++ = (char) wc;
		}
		*cp = '\0';

		if (_curs_mbtowc(&wc, cbuf, CSMAX) <= 0)
			break;

		*wstr++ = wc;
	}

	*wstr = (wchar_t)0;

	return (counter);
}
예제 #3
0
/*
 * Add ncols worth of data to win, using string as input.
 * Return the number of chtypes copied.
 * Note: chtype contains 32/16 bit process code.
 */
int
waddwchnstr(WINDOW *win, chtype *string, int ncols)
{
	int		my_x = win->_curx;
	int		my_y = win->_cury;
	short		my_maxx;
	int		counter;
	chtype		*ptr = &(win->_y[my_y][my_x]);
	chtype		*sptr = ptr;
	char		mbbuf[CSMAX+1];
	int		mp, s, scrw;
	chtype		rawc;
	chtype		attr;
	short		my_x1 = win->_curx;


	while (ISCBIT(*ptr)) {
		ptr--;
		my_x1--;
	}
	while (ptr < sptr)
		*ptr++ = win->_bkgd;

	if (ncols == -1)
		ncols = MAXINT;

	counter = win->_maxx - my_x;
	while ((ncols > 0) && (*string) && (counter > 0)) {
		attr = *string & A_WATTRIBUTES;
		rawc = *string & A_WCHARTEXT;

		/* conver wchar_t to mbuti byte string */
		for (mp = 0; mp < sizeof (mbbuf); mp++)
			mbbuf[mp] = '\0';
		if (_curs_wctomb(mbbuf, rawc) <= 0)
			goto out;

		/* if there are no cols on screen, end */
		if ((scrw = wcscrw(rawc)) > counter)
			goto out;

		if (rawc & WCHAR_CSMASK) {
			/* store multi-byte string into chtype */
			for (s = 0, mp = 0; s < scrw; s++, mp += 2) {
				*ptr = _CHAR(RBYTE(mbbuf[mp]) |
				    RBYTE(mbbuf[mp + 1]) << 8) | CBIT;
				SETMBIT(*ptr);
				if (mp > 0)
					SETCBIT(*ptr);
				else
					CLRCBIT(*ptr);
				*ptr |= attr;
				ptr++;
			}
		} else {
		/* store single-byte string into chtype */
			*ptr = mbbuf[0];
			*ptr |= attr;
			ptr++;
		}

		ncols--;
		string++;
		counter -= scrw;
	}
out :

	while (ISCBIT(*ptr))
		*ptr++ = win->_bkgd;

	/* LINTED */
	my_maxx = (short) (ptr - sptr + my_x);

	if (my_x1 < win->_firstch[my_y])
		win->_firstch[my_y] = my_x1;

	if (my_maxx > win->_lastch[my_y])
		win->_lastch[my_y] = my_maxx;

	win->_flags |= _WINCHANGED;

	/* sync with ancestor structures */
	if (win->_sync)
		wsyncup(win);

	return (win->_immed ? wrefresh(win) : OK);
}
예제 #4
0
파일: wbkgd.c 프로젝트: andreiw/polaris
int
wbkgd(WINDOW *win, chtype nbkgd)
{
	short	maxx;
	int	x, y;
	chtype	*wcp, obkgda, obkgdc, nbkgda,
		nbkgdc, acolor, c;
	short	*begch, *endch;

	/* if 'nbkgd' contains color information, but this is not a color   */
	/* terminal, erase that information.				*/

	if ((nbkgd & A_COLOR) && (cur_term->_pairs_tbl == NULL))
		nbkgd &= ~A_COLOR;

	if (nbkgd == win->_bkgd)
		return (OK);

	obkgdc = _CHAR(win->_bkgd);
	obkgda = _ATTR(win->_bkgd);

	nbkgdc = _CHAR(nbkgd);
	nbkgda = _ATTR(nbkgd);

	/* switch byte order if necessary */
	if (ISCBIT(nbkgdc))
		nbkgdc = _CHAR((RBYTE(nbkgdc) << 8) | (LBYTE(nbkgdc)|MBIT)) |
		    CBIT;
	c = RBYTE(nbkgdc);
	if ((nbkgdc < ' ' || nbkgdc == _CTRL('?')) ||
	    _curs_scrwidth[TYPE(c)] > 1)
		nbkgdc = obkgdc;
	nbkgd = (nbkgdc & ~CBIT) | nbkgda;

	win->_bkgd = nbkgd;

	/* delete the old background from the attribute field and replace    */
	/* it with the new background.  Note: if the same attribute was	*/
	/* first set by wbkgd() and then by wattron(), or vice versa, it */
	/* will be deleted, so the effect of wattron() will be lost.	 */
	/* This applies to both video and color attributes.		 */

	if ((acolor = (win->_attrs & A_COLOR)) != 0) {
		if (acolor == (obkgda & A_COLOR)) {
			win->_attrs = _ATTR((win->_attrs & ~obkgda) | nbkgda);
		} else {
			win->_attrs = _ATTR((win->_attrs &
			    (~obkgda | A_COLOR)) | (nbkgda & ~A_COLOR));
		}
	} else
		win->_attrs = _ATTR((win->_attrs & ~obkgda) | nbkgda);

	maxx = win->_maxx - 1;
	begch = win->_firstch;
	endch = win->_lastch;
	for (y = win->_maxy-1; y >= 0; --y, ++begch, ++endch) {
		for (x = maxx, wcp = win->_y[y]; x-- >= 0; ++wcp) {
			if ((c = _CHAR(*wcp)) == obkgdc)
				c = nbkgdc;
			if ((acolor = (*wcp & A_COLOR)) != 0) {
				if (acolor == (obkgda & A_COLOR))
					*wcp = c | _ATTR((*wcp & ~obkgda) |
					    nbkgda);
				else
					*wcp = c | _ATTR((*wcp & (~obkgda |
					    A_COLOR)) | (nbkgda & ~A_COLOR));
			} else
				*wcp = c | _ATTR((*wcp & ~obkgda) | nbkgda);
		}
		*begch = 0;
		*endch = maxx;
	}

	win->_flags |= _WINCHANGED;
	if (win->_sync)
		wsyncup(win);

	return (win->_immed ? wrefresh(win) : OK);
}
예제 #5
0
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];

	/* easy case */
	if (!redraw && (_virtscr->_lastch[wy] == _BLANK) && (begns >= scrco))
		return;

	/* line images */
	wcp = magic_cookie_glitch <= 0 ? _virtscr->_y[wy] : _shove(wy);
	scp = curscr->_y[wy];

	/* the interval to be updated */
	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;
	}

	/* skip equal parts */
	if (!redraw) {
		/* skip the starting equal part */
		wp = wcp + wx;
		sp = scp + wx;
		for (; wx < lastx; ++wx)
			if (*wp++ != *sp++)
				break;
		if (wx >= lastx)
			return;

		/* start update at an entire character */
		for (sp = scp+wx, wp = wcp+wx; wp > wcp; --wp, --sp, --wx)
			if (!ISCBIT(*wp) && !ISCBIT(*sp))
				break;

		/* skip the ending equal part */
		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;
	}

	/* place to do clear-eol */
	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;
		}

	/* on cookie terminals, we may need to do more work */
	if (marks) {
		/* video_attrx = color_attrx = scrco; */
		video_attrx = color_attrx = (lastx >= scrco) ? lastx - 1 :
		    lastx;

		/* find the last video attribute on the line	*/

		wp = wcp + video_attrx;
		for (; video_attrx >= wx; --video_attrx, --wp)
			if (_VIDEO(*wp) != A_NORMAL)
				break;

		/* find the last color attribute on the line	*/

		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;
	}

	/* place for insert/delete chars */
#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 {
			/* on cookie term, only do idch where no attrs */
			/* are used */
			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;

	/* max amount of insert allow */
	if (idcx == scrco || !SP->ichok)
		maxi = 0;
	else
		if (lastx == scrco)
			maxi = scrco;
		else
			maxi = lastx - (endns + 1);

	/* go */
	wcp += wx;
	scp += wx;
	didvideo = changed = FALSE;
	didcolor = (color_marks) ? FALSE : TRUE;

	while (wx < lastx) {
		/* skip things that are already right */
		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;
			}
		}

		/* try clear-bol, we'll assume exclusive clr_bol */
		if (!changed && !marks && clr_bol && blnkx > wx &&
		    begns >= wx) {
			for (x = wx, wp = wcp; x < lastx; ++x, ++wp)
				if (_DARKCHAR(*wp))
					break;
			/* clearing only whole screen characters */
			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);
				/* MORE?: colors - mvcur will shuts of */
				/* colors when msgr is not defined */

/* SS: colors */
				if (back_color_erase)
					_turn_off_background();

				_PUTS(clr_bol, 1);
				/* LINTED */
				cy = (short) wy;
				/* LINTED */
				cx = (short) x;

				mtch = x - wx;
				(void) memcpy((char *) scp, (char *) wcp,
				    (mtch * sizeof (chtype)));
				wcp += mtch;
				scp += mtch;
				wx = x;
			}
		}

		/* screen image is changing */
		changed = TRUE;

		/* move to the point to start refresh */
		if (cy != wy || cx != wx)
			(void) mvcur(cy, cx, wy, wx);
		/* LINTED */
		cy = (short) wy;
		/* LINTED */
		cx = (short) wx;

		/* update screen image */
		while (wx < lastx) {
			wc = *wcp;
			sc = *scp;

			if (!redraw && !multi_col && wc == sc)
				break;

			/* real video attributes */
			if (marks)
				curscr->_attrs = _ATTR(sc);

			/* blanks only */
			if (wx > blnkx) {
/* SS: colors */
				if (back_color_erase)
					_turn_off_background();

				_PUTS(clr_eol, 1);
				/* LINTED */
				curscr->_curx = (short) wx;
		 		/* LINTED */
				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;
			}

			/* try insert/delete chars */
			if (wx > idcx && !ISCBIT(*scp) &&
			    (mtch = _useidch(wcp, scp, lastx - wx,
			    maxi, &idch))) {
				maxi -= idch;
				wx += mtch;
				scp += mtch;
				wcp += mtch;
				break;
			}

			/* about to output chars, make sure insert */
			/* mode is off */
			if (SP->phys_irm)
				_OFFINSERT();

			/* color and video attributes */
			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;

				/* the following may occurs when, for */
				/* example the application */
				/* is written for color terminal and then */
				/* run on a monocrome  */

				if (marks && !video_change && !color_change)
					goto no_change;

				/* prevent spilling out of line */
				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);
				/*
				 * sc = _COLOR(curscr->_y[wy][color_attrx]);
				 *_VIDS(sc, (~sc & A_COLOR));
				*/
					_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);

			/* on cookie terminals mark the interval */
			if (video_change)
				_setmark1(wy, wx, scp);
			if (color_change)
				_setmark2(wy, wx, scp);
		}

		/* end-of-line */
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);
		}

		/* put out the character */
		(void) _outwch(tilde_glitch && _CHAR(wc) == '~' ? '`' : wc);

		*scp++ = wc;
		wcp++;
		wx++;
		cx++;
		/* output entire multi-byte chars */
		while (wx < lastx && ISCBIT(*wcp)) {
			(void) _outwch(*wcp);
			*scp++ = *wcp++;
			wx++;
			cx++;




		}
		}
	}

done:
	if (changed) {
		/* update the blank structure */
		for (wx = 0, scp = curscr->_y[wy]; wx < scrco; ++wx, ++scp)
			if (_DARKCHAR(*scp))
				break;
		/* LINTED */
		_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;
			/* LINTED */
			_ENDNS[wy] = (short) wx;
		}

		/* update the hash structure */
		_CURHASH[wy] = _BEGNS[wy] < scrco ? _NOHASH : 0;
	}
}
예제 #6
0
static void
_rmargin(int wx)
{
	int	x, w, ix;
	chtype	sc;
	chtype	*wcp =	_virtscr->_y[cy];

	/* screen may scroll */
	if (cy == scrli - 1) {
		/* can't do anything */
		if (!SP->ichok)
			return;

		/* the width of the new character */
		w = _curs_scrwidth[TYPE(RBYTE(wcp[wx]))];
		/* the place to put it without causing scrolling */
		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]);
		}

		/* insert sc back in and push wcp[wx] right */
		(void) mvcur(cy, x+w, cy, x);

		/* SS: colors */
		if (back_color_erase)
			_turn_off_background();

		if (SP->imode && !SP->phys_irm)
			_ONINSERT();
		/* width of the old character that was overwritten */
		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]);

		/* make sure the video attrs are ok */
		if (marks && (_ATTR(sc) || _ATTR(wcp[wx])))
			_VIDS(_ATTR(wcp[wx]), ~_ATTR(sc));

		/* update screen image */
		/* LINTED */
		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;
	}

	/* put char out and update screen image */
	(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];
	}

	/* make sure that wrap-around happens */
	if (!auto_right_margin || eat_newline_glitch) {
		(void) _outch('\r');
		(void) _outch('\n');
	}
	cx = 0;
	++cy;
}
예제 #7
0
int
copywin(WINDOW *Srcwin, WINDOW *Dstwin,
	int minRowSrc, int minColSrc, int minRowDst,
	int minColDst, int maxRowDst, int maxColDst,
	int over_lay)
{
	int		ySrc, yDst, which_copy, t;
	int		height = (maxRowDst - minRowDst) + 1,
			width = (maxColDst - minColDst) + 1;
	chtype		**_yDst = Dstwin->_y, **_ySrc = Srcwin->_y,
			bkSrc = Srcwin->_bkgd, atDst = Dstwin->_attrs,
			*spSrc, *spDst, *epSrc, *epDst, *savepS,
			*savepD, width_bytes, numcopied;

#ifdef	DEBUG
	if (outf)
		fprintf(outf, "copywin(%0.2o, %0.2o);\n", Srcwin, Dstwin);
#endif	/* DEBUG */

	/*
	 * If we are going to be copying from curscr,
	 * first offset into curscr the offset the Dstwin knows about.
	 */
	if (Srcwin == curscr)
		minRowSrc += Dstwin->_yoffset;

	/*
	 * There are three types of copy.
	 * 0 - Straight memcpy allowed
	 * 1 - We have to first check to see if the source character is a blank
	 * 2 - Dstwin has attributes or bkgd that must changed
	 * on a char-by-char basis.
	 */
	if ((which_copy = (over_lay) ? 1 :
	    (2 * ((Dstwin->_attrs != A_NORMAL) ||
	    (Dstwin->_bkgd != _BLNKCHAR)))) == 0)
		width_bytes = width * (int)sizeof (chtype);

	/* for each Row */
	for (ySrc = minRowSrc, yDst = minRowDst; height-- > 0; ySrc++, yDst++) {
		if (which_copy) {
			spSrc = &_ySrc[ySrc][minColSrc];
			spDst = &_yDst[yDst][minColDst];
			numcopied = width;

			epSrc = savepS = &_ySrc[ySrc][maxColDst];
			epDst = savepD = &_yDst[yDst][maxColDst];
		/* only copy into an area bounded by whole characters */
			for (; spDst <= epDst; spSrc++, spDst++)
				if (!ISCBIT(*spDst))
					break;
			if (spDst > epDst)
				continue;
			for (; epDst >= spDst; --epDst, --epSrc)
				if (!ISCBIT(*epDst))
					break;
			t = _curs_scrwidth[TYPE(RBYTE(*epDst))] - 1;
			if (epDst+t <= savepD)
				epDst += t, epSrc += t;
			else
				epDst -= 1, epSrc -= 1;
			if (epDst < spDst)
				continue;
			/* don't copy partial characters */
			for (; spSrc <= epSrc; ++spSrc, ++spDst)
				if (!ISCBIT(*spSrc))
					break;
			if (spSrc > epSrc)
				continue;
			for (; epSrc >= spSrc; --epSrc, --epDst)
				if (!ISCBIT(*epSrc))
					break;
			t = _curs_scrwidth[TYPE(RBYTE(*epSrc))] - 1;
			if (epSrc+t <= savepS)
				epSrc += t, epDst += t;
			else
				epSrc -= 1, epDst -= 1;
			if (epSrc < spSrc)
				continue;
		/* make sure that the copied-to place is clean */
			if (ISCBIT(*spDst))
				(void) _mbclrch(Dstwin, minRowDst,
				    /*LINTED*/
				    (intptr_t)(spDst - *_yDst[yDst]));
			if (ISCBIT(*epDst))
				(void) _mbclrch(Dstwin, minRowDst,
				    /*LINTED*/
				    (intptr_t)(epDst - *_yDst[yDst]));
			/*LINTED*/
			numcopied = (chtype) (epDst - spDst + 1);

			if (which_copy == 1) {		/* overlay */
				for (; numcopied-- > 0; spSrc++, spDst++)
			/* Check to see if the char is a "blank/bkgd". */
					if (*spSrc != bkSrc)
						*spDst = *spSrc | atDst;
			} else {
				for (; numcopied-- > 0; spSrc++, spDst++)
					*spDst = *spSrc | atDst;
			}
		} else {
			/* ... copy all chtypes */
			(void) memcpy((char *)&_yDst[yDst][minColDst],
			    (char *)&_ySrc[ySrc][minColSrc], width_bytes);
		}

		/* note that the line has changed */
		if (minColDst < Dstwin->_firstch[yDst])
			/*LINTED*/
			Dstwin->_firstch[yDst] = (short)minColDst;
		if (maxColDst > Dstwin->_lastch[yDst])
			/*LINTED*/
			Dstwin->_lastch[yDst] = (short)maxColDst;
	}

#ifdef	_VR3_COMPAT_CODE
	if (_y16update) {
		(*_y16update)(Dstwin, (maxRowDst - minRowDst) + 1,
		    (maxColDst - minColDst) + 1, minRowDst, minColDst);
	}
#endif	/* _VR3_COMPAT_CODE */

	/* note that something in Dstwin has changed */
	Dstwin->_flags |= _WINCHANGED;

	if (Dstwin->_sync)
		wsyncup(Dstwin);

	return (Dstwin->_immed ? wrefresh(Dstwin) : OK);
}
예제 #8
0
static int
_mvright(int cx, int nx, int doit)
{
	chtype	*scp;
	char	*mks;
	int	nt, tx, x, stcost, iscont;

	if (!cursor_right && !parm_right_cursor)
		return (LARGECOST);

	scp = curscr->_y[Newy];
	mks = magic_cookie_glitch >= 0 ? SP->_mks[Newy] : NULL;

	if (cursor_right) {
		/* number of tabs used in stepwise movement */
		nt = tab ? (nx / TABSIZE - cx / TABSIZE) : 0;
		tx = (nt > 0) ? (cx / TABSIZE + nt) * TABSIZE : cx;

		/* calculate stepwise cost */
		stcost = nt * _COST(Tab);
		iscont = 0;
		for (x = tx; x < nx; ++x) {
			if (iscont == 0 && !ISCBIT(scp[x]))
				iscont = 1;
			if ((!ceol_standout_glitch && !mks &&
			    _ATTR(scp[x]) == curscr->_attrs) ||
			    ceol_standout_glitch || (mks && !_ISMARK2(x))) {
				if (!ISMBIT(scp[x]))
					stcost += 1;
				else if (iscont && !(nx - x == 1 && nx <
				    curscr->_maxx && ISCBIT(scp[nx])))
					stcost += 1;
				else
					stcost += _COST(Cursor_right);
			} else
				stcost += _COST(Cursor_right);
		}
	} else
		stcost = LARGECOST;

	if (!doit)
		return ((_COST(Parm_right_cursor) < stcost) ?
		    _COST(Parm_right_cursor) : stcost);

	/* actually move */
	if (_COST(Parm_right_cursor) < stcost)
		_PUTS(tparm_p1(parm_right_cursor, nx-cx), 1);
	else {
		if (SP->phys_irm)
			_OFFINSERT();
		for (; nt > 0; --nt)
			_PUTS(tab, 1);
		iscont = 0;
		for (x = tx; x < nx; ++x) {
			if (iscont == 0 && !ISCBIT(scp[x]))
				iscont = 1;
			if ((!ceol_standout_glitch && !mks &&
			    _ATTR(scp[x]) == curscr->_attrs) ||
			    ceol_standout_glitch || (mks && !_ISMARK2(x))) {
				if (!ISMBIT(scp[x]))
					(void) _outwch(_CHAR(scp[x]));
				else if (iscont && !(nx - x == 1 &&
				    nx < curscr->_maxx && ISCBIT(scp[nx])))
					(void) _outwch(_CHAR(scp[x]));
				else
					_PUTS(cursor_right, 1);
			} else
				_PUTS(cursor_right, 1);
		}
	}

	return (0);
}