xref: /csrg-svn/lib/libcurses/overwrite.c (revision 22678)
1*22678Sdist /*
2*22678Sdist  * Copyright (c) 1980 Regents of the University of California.
3*22678Sdist  * All rights reserved.  The Berkeley software License Agreement
4*22678Sdist  * specifies the terms and conditions for redistribution.
5*22678Sdist  */
6*22678Sdist 
7*22678Sdist #ifndef lint
8*22678Sdist static char sccsid[] = "@(#)overwrite.c	5.1 (Berkeley) 06/07/85";
9*22678Sdist #endif not lint
10*22678Sdist 
115866Sarnold # include	"curses.ext"
1219890Sbloom # include	<ctype.h>
132259Sarnold 
142259Sarnold # define	min(a,b)	(a < b ? a : b)
1519890Sbloom # define	max(a,b)	(a > b ? a : b)
162259Sarnold 
172259Sarnold /*
182259Sarnold  *	This routine writes win1 on win2 destructively.
192259Sarnold  *
202259Sarnold  */
212259Sarnold overwrite(win1, win2)
222259Sarnold reg WINDOW	*win1, *win2; {
232259Sarnold 
2419890Sbloom 	reg char	*sp, *end;
2519890Sbloom 	reg int		x, y, endy, endx, starty, startx;
262259Sarnold 
272259Sarnold # ifdef DEBUG
2819890Sbloom 	fprintf(outf, "OVERWRITE(%0.2o, %0.2o);\n", win1, win2);
292259Sarnold # endif
3019890Sbloom 	starty = max(win1->_begy, win2->_begy);
3119890Sbloom 	startx = max(win1->_begx, win2->_begx);
3219890Sbloom 	endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx);
3319890Sbloom 	endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
3419890Sbloom 	if (starty >= endy || startx >= endx)
3519890Sbloom 		return;
362259Sarnold # ifdef DEBUG
3719890Sbloom 	fprintf(outf, "OVERWRITE:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx);
382259Sarnold # endif
3919890Sbloom 	x = endx - startx;
4019890Sbloom 	for (y = starty; y < endy; y++) {
4119890Sbloom 		bcopy(&win1->_y[y - win1->_begy][startx - win1->_begx],
4219890Sbloom 		      &win2->_y[y - win2->_begy][startx - win2->_begx], x);
4319890Sbloom 		touchline(win2, y, startx - win2->_begx, endx - win2->_begx);
4419890Sbloom 	}
452259Sarnold }
46