2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A/*
2N/A * University Copyright- Copyright (c) 1982, 1986, 1988
2N/A * The Regents of the University of California
2N/A * All Rights Reserved
2N/A *
2N/A * University Acknowledgment- Portions of this document are derived from
2N/A * software developed by the University of California, Berkeley, and its
2N/A * contributors.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A/*
2N/A * This routine writes parts of Srcwin onto Dstwin,
2N/A * either non-destructively (over_lay = TRUE) or destructively
2N/A * (over_lay = FALSE).
2N/A */
2N/A
2N/A#include <string.h>
2N/A#include <sys/types.h>
2N/A#include "curses_inc.h"
2N/A
2N/Aint
2N/Acopywin(WINDOW *Srcwin, WINDOW *Dstwin,
2N/A int minRowSrc, int minColSrc, int minRowDst,
2N/A int minColDst, int maxRowDst, int maxColDst,
2N/A int over_lay)
2N/A{
2N/A int ySrc, yDst, which_copy, t;
2N/A int height = (maxRowDst - minRowDst) + 1,
2N/A width = (maxColDst - minColDst) + 1;
2N/A chtype **_yDst = Dstwin->_y, **_ySrc = Srcwin->_y,
2N/A bkSrc = Srcwin->_bkgd, atDst = Dstwin->_attrs,
2N/A *spSrc, *spDst, *epSrc, *epDst, *savepS,
2N/A *savepD, width_bytes, numcopied;
2N/A
2N/A#ifdef DEBUG
2N/A if (outf)
2N/A fprintf(outf, "copywin(%0.2o, %0.2o);\n", Srcwin, Dstwin);
2N/A#endif /* DEBUG */
2N/A
2N/A /*
2N/A * If we are going to be copying from curscr,
2N/A * first offset into curscr the offset the Dstwin knows about.
2N/A */
2N/A if (Srcwin == curscr)
2N/A minRowSrc += Dstwin->_yoffset;
2N/A
2N/A /*
2N/A * There are three types of copy.
2N/A * 0 - Straight memcpy allowed
2N/A * 1 - We have to first check to see if the source character is a blank
2N/A * 2 - Dstwin has attributes or bkgd that must changed
2N/A * on a char-by-char basis.
2N/A */
2N/A if ((which_copy = (over_lay) ? 1 :
2N/A (2 * ((Dstwin->_attrs != A_NORMAL) ||
2N/A (Dstwin->_bkgd != _BLNKCHAR)))) == 0)
2N/A width_bytes = width * (int)sizeof (chtype);
2N/A
2N/A /* for each Row */
2N/A for (ySrc = minRowSrc, yDst = minRowDst; height-- > 0; ySrc++, yDst++) {
2N/A if (which_copy) {
2N/A spSrc = &_ySrc[ySrc][minColSrc];
2N/A spDst = &_yDst[yDst][minColDst];
2N/A numcopied = width;
2N/A
2N/A epSrc = savepS = &_ySrc[ySrc][maxColDst];
2N/A epDst = savepD = &_yDst[yDst][maxColDst];
2N/A /* only copy into an area bounded by whole characters */
2N/A for (; spDst <= epDst; spSrc++, spDst++)
2N/A if (!ISCBIT(*spDst))
2N/A break;
2N/A if (spDst > epDst)
2N/A continue;
2N/A for (; epDst >= spDst; --epDst, --epSrc)
2N/A if (!ISCBIT(*epDst))
2N/A break;
2N/A t = _curs_scrwidth[TYPE(RBYTE(*epDst))] - 1;
2N/A if (epDst+t <= savepD)
2N/A epDst += t, epSrc += t;
2N/A else
2N/A epDst -= 1, epSrc -= 1;
2N/A if (epDst < spDst)
2N/A continue;
2N/A /* don't copy partial characters */
2N/A for (; spSrc <= epSrc; ++spSrc, ++spDst)
2N/A if (!ISCBIT(*spSrc))
2N/A break;
2N/A if (spSrc > epSrc)
2N/A continue;
2N/A for (; epSrc >= spSrc; --epSrc, --epDst)
2N/A if (!ISCBIT(*epSrc))
2N/A break;
2N/A t = _curs_scrwidth[TYPE(RBYTE(*epSrc))] - 1;
2N/A if (epSrc+t <= savepS)
2N/A epSrc += t, epDst += t;
2N/A else
2N/A epSrc -= 1, epDst -= 1;
2N/A if (epSrc < spSrc)
2N/A continue;
2N/A /* make sure that the copied-to place is clean */
2N/A if (ISCBIT(*spDst))
2N/A (void) _mbclrch(Dstwin, minRowDst,
2N/A /*LINTED*/
2N/A (intptr_t)(spDst - *_yDst[yDst]));
2N/A if (ISCBIT(*epDst))
2N/A (void) _mbclrch(Dstwin, minRowDst,
2N/A /*LINTED*/
2N/A (intptr_t)(epDst - *_yDst[yDst]));
2N/A /*LINTED*/
2N/A numcopied = (chtype) (epDst - spDst + 1);
2N/A
2N/A if (which_copy == 1) { /* overlay */
2N/A for (; numcopied-- > 0; spSrc++, spDst++)
2N/A /* Check to see if the char is a "blank/bkgd". */
2N/A if (*spSrc != bkSrc)
2N/A *spDst = *spSrc | atDst;
2N/A } else {
2N/A for (; numcopied-- > 0; spSrc++, spDst++)
2N/A *spDst = *spSrc | atDst;
2N/A }
2N/A } else {
2N/A /* ... copy all chtypes */
2N/A (void) memcpy((char *)&_yDst[yDst][minColDst],
2N/A (char *)&_ySrc[ySrc][minColSrc], width_bytes);
2N/A }
2N/A
2N/A /* note that the line has changed */
2N/A if (minColDst < Dstwin->_firstch[yDst])
2N/A /*LINTED*/
2N/A Dstwin->_firstch[yDst] = (short)minColDst;
2N/A if (maxColDst > Dstwin->_lastch[yDst])
2N/A /*LINTED*/
2N/A Dstwin->_lastch[yDst] = (short)maxColDst;
2N/A }
2N/A
2N/A#ifdef _VR3_COMPAT_CODE
2N/A if (_y16update) {
2N/A (*_y16update)(Dstwin, (maxRowDst - minRowDst) + 1,
2N/A (maxColDst - minColDst) + 1, minRowDst, minColDst);
2N/A }
2N/A#endif /* _VR3_COMPAT_CODE */
2N/A
2N/A /* note that something in Dstwin has changed */
2N/A Dstwin->_flags |= _WINCHANGED;
2N/A
2N/A if (Dstwin->_sync)
2N/A wsyncup(Dstwin);
2N/A
2N/A return (Dstwin->_immed ? wrefresh(Dstwin) : OK);
2N/A}