new version from arnold
[unix-history] / usr / src / lib / libcurses / overlay.c
CommitLineData
421683f2 1# include "curses.ext"
d50ec87c
KA
2# include <ctype.h>
3
4# define min(a,b) (a < b ? a : b)
700b1e78 5# define max(a,b) (a > b ? a : b)
d50ec87c
KA
6
7/*
8 * This routine writes win1 on win2 non-destructively.
9 *
52f06ac3 10 * @(#)overlay.c 1.6 (Berkeley) %G%
d50ec87c
KA
11 */
12overlay(win1, win2)
13reg WINDOW *win1, *win2; {
14
15 reg char *sp, *end;
afe690b7 16 reg int x, y, endy, endx, starty, startx;
d50ec87c
KA
17
18# ifdef DEBUG
19 fprintf(outf, "OVERLAY(%0.2o, %0.2o);\n", win1, win2);
20# endif
52f06ac3
JB
21 starty = max(win1->_begy, win2->_begy);
22 startx = max(win1->_begx, win2->_begx);
23 endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx);
24 endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
25# ifdef DEBUG
26 fprintf(outf, "OVERLAY:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx);
27# endif
28 if (starty >= endy || startx >= endx)
29 return;
30 x = endx - startx;
31 for (y = starty; y < endy; y++) {
32 bcopy(&win1->_y[y - win1->_begy][startx - win1->_begx],
33 &win2->_y[y - win2->_begy][startx - win2->_begx], x);
34 touchline(win2, y, startx - win2->_begx, endx - win2->_begx);
35 }
36 for (y = starty; y < endy; y++) {
37 end = &win1->_y[y - win1->_begy][endx - win1->_begx];
38 x = startx - win2->_begx;
39 for (sp = &win1->_y[y][startx - win1->_begx]; sp < end; sp++) {
40 if (!isspace(*sp)) {
41 waddch(win2, y - win2->_begy, x);
42 waddch(win2, *sp);
43 }
d50ec87c
KA
44 x++;
45 }
46 }
47}