1 /* 2 * Copyright (c) 1981 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)overlay.c 5.4 (Berkeley) 06/08/88"; 15 #endif /* not lint */ 16 17 # include "curses.ext" 18 # include <ctype.h> 19 20 # define min(a,b) (a < b ? a : b) 21 # define max(a,b) (a > b ? a : b) 22 23 /* 24 * This routine writes win1 on win2 non-destructively. 25 * 26 */ 27 overlay(win1, win2) 28 reg WINDOW *win1, *win2; { 29 30 reg char *sp, *end; 31 reg int x, y, endy, endx, starty, startx; 32 reg int y1,y2; 33 34 # ifdef DEBUG 35 fprintf(outf, "OVERLAY(%0.2o, %0.2o);\n", win1, win2); 36 # endif 37 starty = max(win1->_begy, win2->_begy); 38 startx = max(win1->_begx, win2->_begx); 39 endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx); 40 endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx); 41 # ifdef DEBUG 42 fprintf(outf, "OVERLAY:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx); 43 # endif 44 if (starty >= endy || startx >= endx) 45 return; 46 y1 = starty - win1->_begy; 47 y2 = starty - win2->_begy; 48 for (y = starty; y < endy; y++, y1++, y2++) { 49 end = &win1->_y[y1][endx - win1->_begx]; 50 x = startx - win2->_begx; 51 for (sp = &win1->_y[y1][startx - win1->_begx]; sp < end; sp++) { 52 if (!isspace(*sp)) 53 mvwaddch(win2, y2, x, *sp); 54 x++; 55 } 56 } 57 } 58