1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
32*7c478bd9Sstevel@tonic-gate * The Regents of the University of California
33*7c478bd9Sstevel@tonic-gate * All Rights Reserved
34*7c478bd9Sstevel@tonic-gate *
35*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
36*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
37*7c478bd9Sstevel@tonic-gate * contributors.
38*7c478bd9Sstevel@tonic-gate */
39*7c478bd9Sstevel@tonic-gate
40*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
43*7c478bd9Sstevel@tonic-gate
44*7c478bd9Sstevel@tonic-gate /*
45*7c478bd9Sstevel@tonic-gate * This routine writes parts of Srcwin onto Dstwin,
46*7c478bd9Sstevel@tonic-gate * either non-destructively (over_lay = TRUE) or destructively
47*7c478bd9Sstevel@tonic-gate * (over_lay = FALSE).
48*7c478bd9Sstevel@tonic-gate */
49*7c478bd9Sstevel@tonic-gate
50*7c478bd9Sstevel@tonic-gate #include <string.h>
51*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
52*7c478bd9Sstevel@tonic-gate #include "curses_inc.h"
53*7c478bd9Sstevel@tonic-gate
54*7c478bd9Sstevel@tonic-gate int
copywin(WINDOW * Srcwin,WINDOW * Dstwin,int minRowSrc,int minColSrc,int minRowDst,int minColDst,int maxRowDst,int maxColDst,int over_lay)55*7c478bd9Sstevel@tonic-gate copywin(WINDOW *Srcwin, WINDOW *Dstwin,
56*7c478bd9Sstevel@tonic-gate int minRowSrc, int minColSrc, int minRowDst,
57*7c478bd9Sstevel@tonic-gate int minColDst, int maxRowDst, int maxColDst,
58*7c478bd9Sstevel@tonic-gate int over_lay)
59*7c478bd9Sstevel@tonic-gate {
60*7c478bd9Sstevel@tonic-gate int ySrc, yDst, which_copy, t;
61*7c478bd9Sstevel@tonic-gate int height = (maxRowDst - minRowDst) + 1,
62*7c478bd9Sstevel@tonic-gate width = (maxColDst - minColDst) + 1;
63*7c478bd9Sstevel@tonic-gate chtype **_yDst = Dstwin->_y, **_ySrc = Srcwin->_y,
64*7c478bd9Sstevel@tonic-gate bkSrc = Srcwin->_bkgd, atDst = Dstwin->_attrs,
65*7c478bd9Sstevel@tonic-gate *spSrc, *spDst, *epSrc, *epDst, *savepS,
66*7c478bd9Sstevel@tonic-gate *savepD, width_bytes, numcopied;
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
69*7c478bd9Sstevel@tonic-gate if (outf)
70*7c478bd9Sstevel@tonic-gate fprintf(outf, "copywin(%0.2o, %0.2o);\n", Srcwin, Dstwin);
71*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
72*7c478bd9Sstevel@tonic-gate
73*7c478bd9Sstevel@tonic-gate /*
74*7c478bd9Sstevel@tonic-gate * If we are going to be copying from curscr,
75*7c478bd9Sstevel@tonic-gate * first offset into curscr the offset the Dstwin knows about.
76*7c478bd9Sstevel@tonic-gate */
77*7c478bd9Sstevel@tonic-gate if (Srcwin == curscr)
78*7c478bd9Sstevel@tonic-gate minRowSrc += Dstwin->_yoffset;
79*7c478bd9Sstevel@tonic-gate
80*7c478bd9Sstevel@tonic-gate /*
81*7c478bd9Sstevel@tonic-gate * There are three types of copy.
82*7c478bd9Sstevel@tonic-gate * 0 - Straight memcpy allowed
83*7c478bd9Sstevel@tonic-gate * 1 - We have to first check to see if the source character is a blank
84*7c478bd9Sstevel@tonic-gate * 2 - Dstwin has attributes or bkgd that must changed
85*7c478bd9Sstevel@tonic-gate * on a char-by-char basis.
86*7c478bd9Sstevel@tonic-gate */
87*7c478bd9Sstevel@tonic-gate if ((which_copy = (over_lay) ? 1 :
88*7c478bd9Sstevel@tonic-gate (2 * ((Dstwin->_attrs != A_NORMAL) ||
89*7c478bd9Sstevel@tonic-gate (Dstwin->_bkgd != _BLNKCHAR)))) == 0)
90*7c478bd9Sstevel@tonic-gate width_bytes = width * (int)sizeof (chtype);
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate /* for each Row */
93*7c478bd9Sstevel@tonic-gate for (ySrc = minRowSrc, yDst = minRowDst; height-- > 0; ySrc++, yDst++) {
94*7c478bd9Sstevel@tonic-gate if (which_copy) {
95*7c478bd9Sstevel@tonic-gate spSrc = &_ySrc[ySrc][minColSrc];
96*7c478bd9Sstevel@tonic-gate spDst = &_yDst[yDst][minColDst];
97*7c478bd9Sstevel@tonic-gate numcopied = width;
98*7c478bd9Sstevel@tonic-gate
99*7c478bd9Sstevel@tonic-gate epSrc = savepS = &_ySrc[ySrc][maxColDst];
100*7c478bd9Sstevel@tonic-gate epDst = savepD = &_yDst[yDst][maxColDst];
101*7c478bd9Sstevel@tonic-gate /* only copy into an area bounded by whole characters */
102*7c478bd9Sstevel@tonic-gate for (; spDst <= epDst; spSrc++, spDst++)
103*7c478bd9Sstevel@tonic-gate if (!ISCBIT(*spDst))
104*7c478bd9Sstevel@tonic-gate break;
105*7c478bd9Sstevel@tonic-gate if (spDst > epDst)
106*7c478bd9Sstevel@tonic-gate continue;
107*7c478bd9Sstevel@tonic-gate for (; epDst >= spDst; --epDst, --epSrc)
108*7c478bd9Sstevel@tonic-gate if (!ISCBIT(*epDst))
109*7c478bd9Sstevel@tonic-gate break;
110*7c478bd9Sstevel@tonic-gate t = _curs_scrwidth[TYPE(RBYTE(*epDst))] - 1;
111*7c478bd9Sstevel@tonic-gate if (epDst+t <= savepD)
112*7c478bd9Sstevel@tonic-gate epDst += t, epSrc += t;
113*7c478bd9Sstevel@tonic-gate else
114*7c478bd9Sstevel@tonic-gate epDst -= 1, epSrc -= 1;
115*7c478bd9Sstevel@tonic-gate if (epDst < spDst)
116*7c478bd9Sstevel@tonic-gate continue;
117*7c478bd9Sstevel@tonic-gate /* don't copy partial characters */
118*7c478bd9Sstevel@tonic-gate for (; spSrc <= epSrc; ++spSrc, ++spDst)
119*7c478bd9Sstevel@tonic-gate if (!ISCBIT(*spSrc))
120*7c478bd9Sstevel@tonic-gate break;
121*7c478bd9Sstevel@tonic-gate if (spSrc > epSrc)
122*7c478bd9Sstevel@tonic-gate continue;
123*7c478bd9Sstevel@tonic-gate for (; epSrc >= spSrc; --epSrc, --epDst)
124*7c478bd9Sstevel@tonic-gate if (!ISCBIT(*epSrc))
125*7c478bd9Sstevel@tonic-gate break;
126*7c478bd9Sstevel@tonic-gate t = _curs_scrwidth[TYPE(RBYTE(*epSrc))] - 1;
127*7c478bd9Sstevel@tonic-gate if (epSrc+t <= savepS)
128*7c478bd9Sstevel@tonic-gate epSrc += t, epDst += t;
129*7c478bd9Sstevel@tonic-gate else
130*7c478bd9Sstevel@tonic-gate epSrc -= 1, epDst -= 1;
131*7c478bd9Sstevel@tonic-gate if (epSrc < spSrc)
132*7c478bd9Sstevel@tonic-gate continue;
133*7c478bd9Sstevel@tonic-gate /* make sure that the copied-to place is clean */
134*7c478bd9Sstevel@tonic-gate if (ISCBIT(*spDst))
135*7c478bd9Sstevel@tonic-gate (void) _mbclrch(Dstwin, minRowDst,
136*7c478bd9Sstevel@tonic-gate /*LINTED*/
137*7c478bd9Sstevel@tonic-gate (intptr_t)(spDst - *_yDst[yDst]));
138*7c478bd9Sstevel@tonic-gate if (ISCBIT(*epDst))
139*7c478bd9Sstevel@tonic-gate (void) _mbclrch(Dstwin, minRowDst,
140*7c478bd9Sstevel@tonic-gate /*LINTED*/
141*7c478bd9Sstevel@tonic-gate (intptr_t)(epDst - *_yDst[yDst]));
142*7c478bd9Sstevel@tonic-gate /*LINTED*/
143*7c478bd9Sstevel@tonic-gate numcopied = (chtype) (epDst - spDst + 1);
144*7c478bd9Sstevel@tonic-gate
145*7c478bd9Sstevel@tonic-gate if (which_copy == 1) { /* overlay */
146*7c478bd9Sstevel@tonic-gate for (; numcopied-- > 0; spSrc++, spDst++)
147*7c478bd9Sstevel@tonic-gate /* Check to see if the char is a "blank/bkgd". */
148*7c478bd9Sstevel@tonic-gate if (*spSrc != bkSrc)
149*7c478bd9Sstevel@tonic-gate *spDst = *spSrc | atDst;
150*7c478bd9Sstevel@tonic-gate } else {
151*7c478bd9Sstevel@tonic-gate for (; numcopied-- > 0; spSrc++, spDst++)
152*7c478bd9Sstevel@tonic-gate *spDst = *spSrc | atDst;
153*7c478bd9Sstevel@tonic-gate }
154*7c478bd9Sstevel@tonic-gate } else {
155*7c478bd9Sstevel@tonic-gate /* ... copy all chtypes */
156*7c478bd9Sstevel@tonic-gate (void) memcpy((char *)&_yDst[yDst][minColDst],
157*7c478bd9Sstevel@tonic-gate (char *)&_ySrc[ySrc][minColSrc], width_bytes);
158*7c478bd9Sstevel@tonic-gate }
159*7c478bd9Sstevel@tonic-gate
160*7c478bd9Sstevel@tonic-gate /* note that the line has changed */
161*7c478bd9Sstevel@tonic-gate if (minColDst < Dstwin->_firstch[yDst])
162*7c478bd9Sstevel@tonic-gate /*LINTED*/
163*7c478bd9Sstevel@tonic-gate Dstwin->_firstch[yDst] = (short)minColDst;
164*7c478bd9Sstevel@tonic-gate if (maxColDst > Dstwin->_lastch[yDst])
165*7c478bd9Sstevel@tonic-gate /*LINTED*/
166*7c478bd9Sstevel@tonic-gate Dstwin->_lastch[yDst] = (short)maxColDst;
167*7c478bd9Sstevel@tonic-gate }
168*7c478bd9Sstevel@tonic-gate
169*7c478bd9Sstevel@tonic-gate #ifdef _VR3_COMPAT_CODE
170*7c478bd9Sstevel@tonic-gate if (_y16update) {
171*7c478bd9Sstevel@tonic-gate (*_y16update)(Dstwin, (maxRowDst - minRowDst) + 1,
172*7c478bd9Sstevel@tonic-gate (maxColDst - minColDst) + 1, minRowDst, minColDst);
173*7c478bd9Sstevel@tonic-gate }
174*7c478bd9Sstevel@tonic-gate #endif /* _VR3_COMPAT_CODE */
175*7c478bd9Sstevel@tonic-gate
176*7c478bd9Sstevel@tonic-gate /* note that something in Dstwin has changed */
177*7c478bd9Sstevel@tonic-gate Dstwin->_flags |= _WINCHANGED;
178*7c478bd9Sstevel@tonic-gate
179*7c478bd9Sstevel@tonic-gate if (Dstwin->_sync)
180*7c478bd9Sstevel@tonic-gate wsyncup(Dstwin);
181*7c478bd9Sstevel@tonic-gate
182*7c478bd9Sstevel@tonic-gate return (Dstwin->_immed ? wrefresh(Dstwin) : OK);
183*7c478bd9Sstevel@tonic-gate }
184