xref: /titanic_51/usr/src/lib/libcurses/screen/idlok.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 #include	<stdlib.h>
45*7c478bd9Sstevel@tonic-gate #include	"curses_inc.h"
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /* Functions to make use of insert/delete line caps */
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #define	scrco	COLS
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate typedef	struct
53*7c478bd9Sstevel@tonic-gate 	{
54*7c478bd9Sstevel@tonic-gate 	    int		_wy,	/* matching lines */
55*7c478bd9Sstevel@tonic-gate 			_sy;
56*7c478bd9Sstevel@tonic-gate 	} IDST;
57*7c478bd9Sstevel@tonic-gate static	IDST	*sid, *eid;		/* list of idln actions */
58*7c478bd9Sstevel@tonic-gate static	int	scrli,			/* screen dimensions */
59*7c478bd9Sstevel@tonic-gate 		cy, cx;			/* current cursor positions */
60*7c478bd9Sstevel@tonic-gate static	bool	didcsr;			/* scrolling region was used */
61*7c478bd9Sstevel@tonic-gate static	int	_use_idln(void), _set_idln(void);
62*7c478bd9Sstevel@tonic-gate static	void	_do_idln(int, int, int, int);
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate /* Set insert/delete line mode for win */
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate int
67*7c478bd9Sstevel@tonic-gate idlok(WINDOW *win, bool bf)
68*7c478bd9Sstevel@tonic-gate {
69*7c478bd9Sstevel@tonic-gate 	_useidln = _use_idln;
70*7c478bd9Sstevel@tonic-gate 	_setidln = _set_idln;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	SP->yesidln = (delete_line || parm_delete_line ||
73*7c478bd9Sstevel@tonic-gate 	    (change_scroll_region && (parm_index || scroll_forward))) &&
74*7c478bd9Sstevel@tonic-gate 	    (insert_line || parm_insert_line ||
75*7c478bd9Sstevel@tonic-gate 	    (change_scroll_region && (parm_rindex || scroll_reverse)));
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate 	win->_use_idl = bf;
78*7c478bd9Sstevel@tonic-gate 	return (OK);
79*7c478bd9Sstevel@tonic-gate }
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate /*
82*7c478bd9Sstevel@tonic-gate  * Set the places to do insert/delete lines
83*7c478bd9Sstevel@tonic-gate  * Return the start line for such action.
84*7c478bd9Sstevel@tonic-gate  */
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate static int
87*7c478bd9Sstevel@tonic-gate _set_idln(void)
88*7c478bd9Sstevel@tonic-gate {
89*7c478bd9Sstevel@tonic-gate 	/*
90*7c478bd9Sstevel@tonic-gate 	 * The value we want to return is the lower line
91*7c478bd9Sstevel@tonic-gate 	 * number of the top-most range.
92*7c478bd9Sstevel@tonic-gate 	 *
93*7c478bd9Sstevel@tonic-gate 	 * If there is more than one range of lines on which
94*7c478bd9Sstevel@tonic-gate 	 * we're operating, _find_idln will get called more
95*7c478bd9Sstevel@tonic-gate 	 * then once; we need to search all the IDST for the
96*7c478bd9Sstevel@tonic-gate 	 * desired return value.
97*7c478bd9Sstevel@tonic-gate 	 */
98*7c478bd9Sstevel@tonic-gate 	{
99*7c478bd9Sstevel@tonic-gate 		IDST *idp;
100*7c478bd9Sstevel@tonic-gate 		int rval = scrli;
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 		for (idp = sid; idp != eid; idp++) {
103*7c478bd9Sstevel@tonic-gate 			int tmp;
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate 			if ((tmp = _MIN(idp->_wy, idp->_sy)) < rval)
106*7c478bd9Sstevel@tonic-gate 				rval = tmp;
107*7c478bd9Sstevel@tonic-gate 		}
108*7c478bd9Sstevel@tonic-gate 		return (rval);
109*7c478bd9Sstevel@tonic-gate 	}
110*7c478bd9Sstevel@tonic-gate }
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate /* Use hardware line delete/insert */
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate static int
115*7c478bd9Sstevel@tonic-gate _use_idln(void)
116*7c478bd9Sstevel@tonic-gate {
117*7c478bd9Sstevel@tonic-gate 	int	tsy, bsy, idn, dir, nomore;
118*7c478bd9Sstevel@tonic-gate 	IDST	*ip, *ep, *eip;
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 	cy = curscr->_cury;
121*7c478bd9Sstevel@tonic-gate 	cx = curscr->_curx;
122*7c478bd9Sstevel@tonic-gate 	didcsr = FALSE;
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate 	/* first cycle do deletions, second cycle do insertions */
125*7c478bd9Sstevel@tonic-gate 	for (dir = 1; dir > -2; dir -= 2) {
126*7c478bd9Sstevel@tonic-gate 		if (dir > 0) {
127*7c478bd9Sstevel@tonic-gate 			ip = sid;
128*7c478bd9Sstevel@tonic-gate 			eip = eid;
129*7c478bd9Sstevel@tonic-gate 		} else {
130*7c478bd9Sstevel@tonic-gate 			ip = eid - 1;
131*7c478bd9Sstevel@tonic-gate 			eip = sid - 1;
132*7c478bd9Sstevel@tonic-gate 		}
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate 		nomore = TRUE;
135*7c478bd9Sstevel@tonic-gate 		while (ip != eip) {
136*7c478bd9Sstevel@tonic-gate 			/* skip deletions or insertions */
137*7c478bd9Sstevel@tonic-gate 			if ((dir > 0 && ip->_wy > ip->_sy) ||
138*7c478bd9Sstevel@tonic-gate 			    (dir < 0 && ip->_wy < ip->_sy)) {
139*7c478bd9Sstevel@tonic-gate 				nomore = FALSE;
140*7c478bd9Sstevel@tonic-gate 				ip += dir;
141*7c478bd9Sstevel@tonic-gate 				continue;
142*7c478bd9Sstevel@tonic-gate 			}
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate 			/* find a contiguous block */
145*7c478bd9Sstevel@tonic-gate 			for (ep = ip+dir; ep != eip; ep += dir)
146*7c478bd9Sstevel@tonic-gate 				if (ep->_wy != (ep - dir)->_wy + dir ||
147*7c478bd9Sstevel@tonic-gate 				    ep->_sy != (ep - dir)->_sy + dir) {
148*7c478bd9Sstevel@tonic-gate 				    break;
149*7c478bd9Sstevel@tonic-gate 			}
150*7c478bd9Sstevel@tonic-gate 			ep -= dir;
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate 			/* top and bottom lines of the affected region */
153*7c478bd9Sstevel@tonic-gate 			if (dir > 0) {
154*7c478bd9Sstevel@tonic-gate 				tsy = _MIN(ip->_wy, ip->_sy);
155*7c478bd9Sstevel@tonic-gate 				bsy = _MAX(ep->_wy, ep->_sy) + 1;
156*7c478bd9Sstevel@tonic-gate 			} else {
157*7c478bd9Sstevel@tonic-gate 				tsy = _MIN(ep->_wy, ep->_sy);
158*7c478bd9Sstevel@tonic-gate 				bsy = _MAX(ip->_wy, ip->_sy) + 1;
159*7c478bd9Sstevel@tonic-gate 			}
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 			/* amount to insert/delete */
162*7c478bd9Sstevel@tonic-gate 			if ((idn = ip->_wy - ip->_sy) < 0)
163*7c478bd9Sstevel@tonic-gate 				idn = -idn;
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 			/* do the actual output */
166*7c478bd9Sstevel@tonic-gate 			_do_idln(tsy, bsy, idn, dir == -1);
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 			/* update change structure */
169*7c478bd9Sstevel@tonic-gate 			(void) wtouchln(_virtscr, tsy, bsy - tsy, -1);
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate 			/* update screen image */
172*7c478bd9Sstevel@tonic-gate 			/*LINTED*/
173*7c478bd9Sstevel@tonic-gate 			curscr->_tmarg = (short)tsy;
174*7c478bd9Sstevel@tonic-gate 			curscr->_bmarg = bsy - 1;
175*7c478bd9Sstevel@tonic-gate 			/*LINTED*/
176*7c478bd9Sstevel@tonic-gate 			curscr->_cury = (short)tsy;
177*7c478bd9Sstevel@tonic-gate 			(void) winsdelln(curscr, dir > 0 ? -idn : idn);
178*7c478bd9Sstevel@tonic-gate 			curscr->_tmarg = 0;
179*7c478bd9Sstevel@tonic-gate 			curscr->_bmarg = scrli - 1;
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate 			/* for next while cycle */
182*7c478bd9Sstevel@tonic-gate 			ip = ep + dir;
183*7c478bd9Sstevel@tonic-gate 		}
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate 		if (nomore)
186*7c478bd9Sstevel@tonic-gate 			break;
187*7c478bd9Sstevel@tonic-gate 	}
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate 	/* reset scrolling region */
190*7c478bd9Sstevel@tonic-gate 	if (didcsr) {
191*7c478bd9Sstevel@tonic-gate 		_PUTS(tparm_p2(change_scroll_region, 0, scrli - 1), scrli);
192*7c478bd9Sstevel@tonic-gate 		cy = cx = -1;
193*7c478bd9Sstevel@tonic-gate 	}
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 	/*LINTED*/
196*7c478bd9Sstevel@tonic-gate 	curscr->_cury = (short)cy;
197*7c478bd9Sstevel@tonic-gate 	/*LINTED*/
198*7c478bd9Sstevel@tonic-gate 	curscr->_curx = (short)cx;
199*7c478bd9Sstevel@tonic-gate 	return (OK);
200*7c478bd9Sstevel@tonic-gate }
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate /* Do the actual insert/delete lines */
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate static void
205*7c478bd9Sstevel@tonic-gate _do_idln(int tsy, int bsy, int idn, int doinsert)
206*7c478bd9Sstevel@tonic-gate {
207*7c478bd9Sstevel@tonic-gate 	int	y, usecsr, yesscrl;
208*7c478bd9Sstevel@tonic-gate 	short	*begns;
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate 	/* change scrolling region */
211*7c478bd9Sstevel@tonic-gate 	yesscrl = usecsr = FALSE;
212*7c478bd9Sstevel@tonic-gate 	if (tsy > 0 || bsy < scrli) {
213*7c478bd9Sstevel@tonic-gate 		if (change_scroll_region) {
214*7c478bd9Sstevel@tonic-gate 		    _PUTS(tparm_p2(change_scroll_region, tsy, bsy - 1),
215*7c478bd9Sstevel@tonic-gate 			bsy - tsy);
216*7c478bd9Sstevel@tonic-gate 		    cy = cx = -1;
217*7c478bd9Sstevel@tonic-gate 		    yesscrl = usecsr = didcsr = TRUE;
218*7c478bd9Sstevel@tonic-gate 		}
219*7c478bd9Sstevel@tonic-gate 	} else {
220*7c478bd9Sstevel@tonic-gate 		if (didcsr) {
221*7c478bd9Sstevel@tonic-gate 		    _PUTS(tparm_p2(change_scroll_region, 0, scrli - 1), scrli);
222*7c478bd9Sstevel@tonic-gate 		    cy = cx = -1;
223*7c478bd9Sstevel@tonic-gate 		    didcsr = FALSE;
224*7c478bd9Sstevel@tonic-gate 		}
225*7c478bd9Sstevel@tonic-gate 		yesscrl = TRUE;
226*7c478bd9Sstevel@tonic-gate 	}
227*7c478bd9Sstevel@tonic-gate 
228*7c478bd9Sstevel@tonic-gate 	if (doinsert) {
229*7c478bd9Sstevel@tonic-gate 		/* memory below, clobber it now */
230*7c478bd9Sstevel@tonic-gate 		if (memory_below && clr_eol &&
231*7c478bd9Sstevel@tonic-gate 		    ((usecsr && non_dest_scroll_region) || bsy == scrli)) {
232*7c478bd9Sstevel@tonic-gate 			for (y = bsy - idn, begns = _BEGNS + y;
233*7c478bd9Sstevel@tonic-gate 			    y < bsy; ++y, ++begns)
234*7c478bd9Sstevel@tonic-gate 				if (*begns < scrco) {
235*7c478bd9Sstevel@tonic-gate 					(void) mvcur(cy, cx, y, 0);
236*7c478bd9Sstevel@tonic-gate 					cy = y;
237*7c478bd9Sstevel@tonic-gate 					cx = 0;
238*7c478bd9Sstevel@tonic-gate 					_PUTS(clr_eol, 1);
239*7c478bd9Sstevel@tonic-gate 				}
240*7c478bd9Sstevel@tonic-gate 		}
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate 		/* if not change_scroll_region, delete, then insert */
243*7c478bd9Sstevel@tonic-gate 		if (!usecsr && bsy < scrli) {
244*7c478bd9Sstevel@tonic-gate 			/* delete appropriate number of lines */
245*7c478bd9Sstevel@tonic-gate 			(void) mvcur(cy, cx, bsy - idn, 0);
246*7c478bd9Sstevel@tonic-gate 			cy = bsy - idn;
247*7c478bd9Sstevel@tonic-gate 			cx = 0;
248*7c478bd9Sstevel@tonic-gate 			if (parm_delete_line && (idn > 1 || !delete_line))
249*7c478bd9Sstevel@tonic-gate 				_PUTS(tparm_p1(parm_delete_line, idn),
250*7c478bd9Sstevel@tonic-gate 				    scrli - cy);
251*7c478bd9Sstevel@tonic-gate 			else
252*7c478bd9Sstevel@tonic-gate 				for (y = 0; y < idn; ++y)
253*7c478bd9Sstevel@tonic-gate 			_PUTS(delete_line, scrli - cy);
254*7c478bd9Sstevel@tonic-gate 		}
255*7c478bd9Sstevel@tonic-gate 
256*7c478bd9Sstevel@tonic-gate 		/* now do insert */
257*7c478bd9Sstevel@tonic-gate 		(void) mvcur(cy, cx, tsy, 0);
258*7c478bd9Sstevel@tonic-gate 		cy = tsy;
259*7c478bd9Sstevel@tonic-gate 		cx = 0;
260*7c478bd9Sstevel@tonic-gate 		if (yesscrl) {
261*7c478bd9Sstevel@tonic-gate 			if (!parm_rindex && (!scroll_reverse ||
262*7c478bd9Sstevel@tonic-gate 			    (parm_insert_line && idn > 1))) {
263*7c478bd9Sstevel@tonic-gate 				goto hardinsert;
264*7c478bd9Sstevel@tonic-gate 			}
265*7c478bd9Sstevel@tonic-gate 			if (parm_rindex && (idn > 1 || !scroll_reverse))
266*7c478bd9Sstevel@tonic-gate 				_PUTS(tparm_p1(parm_rindex, idn), scrli - cy);
267*7c478bd9Sstevel@tonic-gate 			else
268*7c478bd9Sstevel@tonic-gate 				for (y = 0; y < idn; ++y)
269*7c478bd9Sstevel@tonic-gate 					_PUTS(scroll_reverse, scrli - cy);
270*7c478bd9Sstevel@tonic-gate 		} else {
271*7c478bd9Sstevel@tonic-gate hardinsert:
272*7c478bd9Sstevel@tonic-gate 			if (parm_insert_line && (idn > 1 || !insert_line))
273*7c478bd9Sstevel@tonic-gate 				_PUTS(tparm_p1(parm_insert_line, idn),
274*7c478bd9Sstevel@tonic-gate 				    scrli - cy);
275*7c478bd9Sstevel@tonic-gate 			else
276*7c478bd9Sstevel@tonic-gate 				for (y = 0; y < idn; ++y)
277*7c478bd9Sstevel@tonic-gate 					_PUTS(insert_line, scrli - cy);
278*7c478bd9Sstevel@tonic-gate 		}
279*7c478bd9Sstevel@tonic-gate 	} else {
280*7c478bd9Sstevel@tonic-gate 		/* doing deletion */
281*7c478bd9Sstevel@tonic-gate 		/* memory above, clobber it now */
282*7c478bd9Sstevel@tonic-gate 		if (memory_above && clr_eol &&
283*7c478bd9Sstevel@tonic-gate 		    ((usecsr && non_dest_scroll_region) || tsy == 0)) {
284*7c478bd9Sstevel@tonic-gate 			for (y = 0, begns = _BEGNS + y + tsy;
285*7c478bd9Sstevel@tonic-gate 			    y < idn; ++y, ++begns)
286*7c478bd9Sstevel@tonic-gate 				if (*begns < scrco) {
287*7c478bd9Sstevel@tonic-gate 					(void) mvcur(cy, cx, tsy + y, 0);
288*7c478bd9Sstevel@tonic-gate 					cy = tsy + y;
289*7c478bd9Sstevel@tonic-gate 					cx = 0;
290*7c478bd9Sstevel@tonic-gate 					_PUTS(clr_eol, 1);
291*7c478bd9Sstevel@tonic-gate 				}
292*7c478bd9Sstevel@tonic-gate 		}
293*7c478bd9Sstevel@tonic-gate 
294*7c478bd9Sstevel@tonic-gate 		if (yesscrl) {
295*7c478bd9Sstevel@tonic-gate 			if (!parm_index && (!scroll_forward ||
296*7c478bd9Sstevel@tonic-gate 			    (parm_delete_line && idn > 1))) {
297*7c478bd9Sstevel@tonic-gate 				goto harddelete;
298*7c478bd9Sstevel@tonic-gate 			}
299*7c478bd9Sstevel@tonic-gate 			(void) mvcur(cy, cx, bsy - 1, 0);
300*7c478bd9Sstevel@tonic-gate 			cy = bsy - 1;
301*7c478bd9Sstevel@tonic-gate 			cx = 0;
302*7c478bd9Sstevel@tonic-gate 			if (parm_index && (idn > 1 || !scroll_forward))
303*7c478bd9Sstevel@tonic-gate 				_PUTS(tparm_p1(parm_index, idn), scrli - cy);
304*7c478bd9Sstevel@tonic-gate 			else
305*7c478bd9Sstevel@tonic-gate 				for (y = 0; y < idn; ++y)
306*7c478bd9Sstevel@tonic-gate 					_PUTS(scroll_forward, scrli - cy);
307*7c478bd9Sstevel@tonic-gate 		} else {
308*7c478bd9Sstevel@tonic-gate harddelete:
309*7c478bd9Sstevel@tonic-gate 			/* do deletion */
310*7c478bd9Sstevel@tonic-gate 			(void) mvcur(cy, cx, tsy, 0);
311*7c478bd9Sstevel@tonic-gate 			cy = tsy;
312*7c478bd9Sstevel@tonic-gate 			cx = 0;
313*7c478bd9Sstevel@tonic-gate 			if (parm_delete_line && (idn > 1 || !delete_line))
314*7c478bd9Sstevel@tonic-gate 				_PUTS(tparm_p1(parm_delete_line, idn),
315*7c478bd9Sstevel@tonic-gate 				    scrli - cy);
316*7c478bd9Sstevel@tonic-gate 			else
317*7c478bd9Sstevel@tonic-gate 				for (y = 0; y < idn; ++y)
318*7c478bd9Sstevel@tonic-gate 				    _PUTS(delete_line, scrli - cy);
319*7c478bd9Sstevel@tonic-gate 		}
320*7c478bd9Sstevel@tonic-gate 
321*7c478bd9Sstevel@tonic-gate 		/* if not change_scroll_region, do insert to restore bottom */
322*7c478bd9Sstevel@tonic-gate 		if (!usecsr && bsy < scrli) {
323*7c478bd9Sstevel@tonic-gate 			y = scrli - 1;
324*7c478bd9Sstevel@tonic-gate 			begns = _BEGNS + y;
325*7c478bd9Sstevel@tonic-gate 			for (; y >= bsy; --y, --begns)
326*7c478bd9Sstevel@tonic-gate 				if (*begns < scrco)
327*7c478bd9Sstevel@tonic-gate 					break;
328*7c478bd9Sstevel@tonic-gate 			if (y >= bsy) {
329*7c478bd9Sstevel@tonic-gate 				(void) mvcur(cy, cx, bsy - idn, 0);
330*7c478bd9Sstevel@tonic-gate 				cy = bsy - idn;
331*7c478bd9Sstevel@tonic-gate 				cx = 0;
332*7c478bd9Sstevel@tonic-gate 				if (parm_insert_line &&
333*7c478bd9Sstevel@tonic-gate 				    (idn > 1 || !insert_line))
334*7c478bd9Sstevel@tonic-gate 					_PUTS(tparm_p1(parm_insert_line, idn),
335*7c478bd9Sstevel@tonic-gate 					    scrli - cy);
336*7c478bd9Sstevel@tonic-gate 				else
337*7c478bd9Sstevel@tonic-gate 					for (y = 0; y < idn; ++y)
338*7c478bd9Sstevel@tonic-gate 						_PUTS(insert_line, scrli - cy);
339*7c478bd9Sstevel@tonic-gate 			}
340*7c478bd9Sstevel@tonic-gate 		}
341*7c478bd9Sstevel@tonic-gate 	}
342*7c478bd9Sstevel@tonic-gate }
343