xref: /titanic_50/usr/src/ucblib/libcurses/overlay.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate 
6*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
7*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
8*7c478bd9Sstevel@tonic-gate 
9*7c478bd9Sstevel@tonic-gate /*
10*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
11*7c478bd9Sstevel@tonic-gate  * All rights reserved.  The Berkeley software License Agreement
12*7c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
13*7c478bd9Sstevel@tonic-gate  */
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
18*7c478bd9Sstevel@tonic-gate 
19*7c478bd9Sstevel@tonic-gate #ifndef lint
20*7c478bd9Sstevel@tonic-gate static char
21*7c478bd9Sstevel@tonic-gate sccsid[] = "@(#)overlay.c 1.9 89/07/13 SMI"; /* from UCB 5.2 86/02/12 */
22*7c478bd9Sstevel@tonic-gate #endif /* not lint */
23*7c478bd9Sstevel@tonic-gate 
24*7c478bd9Sstevel@tonic-gate #include	"curses.ext"
25*7c478bd9Sstevel@tonic-gate #include	<ctype.h>
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #define	min(a, b)	((a) < (b) ? (a) : (b))
28*7c478bd9Sstevel@tonic-gate #define	max(a, b)	((a) > (b) ? (a) : (b))
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  *	This routine writes win1 on win2 non-destructively.
32*7c478bd9Sstevel@tonic-gate  */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate int
overlay(WINDOW * win1,WINDOW * win2)35*7c478bd9Sstevel@tonic-gate overlay(WINDOW *win1, WINDOW *win2)
36*7c478bd9Sstevel@tonic-gate {
37*7c478bd9Sstevel@tonic-gate 	char	*sp, *end;
38*7c478bd9Sstevel@tonic-gate 	int	x, y, endy, endx, starty, startx;
39*7c478bd9Sstevel@tonic-gate 	int 	y1, y2;
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
42*7c478bd9Sstevel@tonic-gate 	fprintf(outf, "OVERLAY(%0.2o, %0.2o);\n", win1, win2);
43*7c478bd9Sstevel@tonic-gate #endif
44*7c478bd9Sstevel@tonic-gate 	starty = max(win1->_begy, win2->_begy);
45*7c478bd9Sstevel@tonic-gate 	startx = max(win1->_begx, win2->_begx);
46*7c478bd9Sstevel@tonic-gate 	endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begy);
47*7c478bd9Sstevel@tonic-gate 	endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
48*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
49*7c478bd9Sstevel@tonic-gate 	fprintf(outf, "OVERLAY:from (%d,%d) to (%d,%d)\n",
50*7c478bd9Sstevel@tonic-gate 	    starty, startx, endy, endx);
51*7c478bd9Sstevel@tonic-gate #endif
52*7c478bd9Sstevel@tonic-gate 	if (starty >= endy || startx >= endx)
53*7c478bd9Sstevel@tonic-gate 		return (OK);
54*7c478bd9Sstevel@tonic-gate 	y1 = starty - win1->_begy;
55*7c478bd9Sstevel@tonic-gate 	y2 = starty - win2->_begy;
56*7c478bd9Sstevel@tonic-gate 	for (y = starty; y < endy; y++, y1++, y2++) {
57*7c478bd9Sstevel@tonic-gate 		end = &win1->_y[y1][endx - win1->_begx];
58*7c478bd9Sstevel@tonic-gate 		x = startx - win2->_begx;
59*7c478bd9Sstevel@tonic-gate 		for (sp = &win1->_y[y1][startx - win1->_begx]; sp < end; sp++) {
60*7c478bd9Sstevel@tonic-gate 			if (!isspace(*sp))
61*7c478bd9Sstevel@tonic-gate 				(void) mvwaddch(win2, y2, x, *sp);
62*7c478bd9Sstevel@tonic-gate 			x++;
63*7c478bd9Sstevel@tonic-gate 		}
64*7c478bd9Sstevel@tonic-gate 	}
65*7c478bd9Sstevel@tonic-gate 	return (OK);
66*7c478bd9Sstevel@tonic-gate }
67