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