1: /* 2: * Copyright (c) 1980 Regents of the University of California. 3: * All rights reserved. The Berkeley software License Agreement 4: * specifies the terms and conditions for redistribution. 5: */ 6: 7: #ifndef lint 8: static char sccsid[] = "@(#)refresh.c 5.1 (Berkeley) 6/7/85"; 9: #endif not lint 10: 11: /* 12: * make the current screen look like "win" over the area coverd by 13: * win. 14: */ 15: 16: # include "curses.ext" 17: 18: # ifdef DEBUG 19: # define STATIC 20: # else 21: # define STATIC static 22: # endif 23: 24: STATIC short ly, lx; 25: 26: STATIC bool curwin; 27: 28: WINDOW *_win = NULL; 29: 30: wrefresh(win) 31: reg WINDOW *win; 32: { 33: reg short wy; 34: reg int retval; 35: reg WINDOW *orig; 36: 37: /* 38: * make sure were in visual state 39: */ 40: if (_endwin) { 41: _puts(VS); 42: _puts(TI); 43: _endwin = FALSE; 44: } 45: 46: /* 47: * initialize loop parameters 48: */ 49: 50: ly = curscr->_cury; 51: lx = curscr->_curx; 52: wy = 0; 53: _win = win; 54: curwin = (win == curscr); 55: 56: if (win->_clear || curscr->_clear || curwin) { 57: if ((win->_flags & _FULLWIN) || curscr->_clear) { 58: _puts(CL); 59: ly = 0; 60: lx = 0; 61: if (!curwin) { 62: curscr->_clear = FALSE; 63: curscr->_cury = 0; 64: curscr->_curx = 0; 65: werase(curscr); 66: } 67: touchwin(win); 68: } 69: win->_clear = FALSE; 70: } 71: if (!CA) { 72: if (win->_curx != 0) 73: _putchar('\n'); 74: if (!curwin) 75: werase(curscr); 76: } 77: # ifdef DEBUG 78: fprintf(outf, "REFRESH(%0.2o): curwin = %d\n", win, curwin); 79: fprintf(outf, "REFRESH:\n\tfirstch\tlastch\n"); 80: # endif 81: for (wy = 0; wy < win->_maxy; wy++) { 82: # ifdef DEBUG 83: fprintf(outf, "%d\t%d\t%d\n", wy, win->_firstch[wy], 84: win->_lastch[wy]); 85: # endif 86: if (win->_firstch[wy] != _NOCHANGE) 87: if (makech(win, wy) == ERR) 88: return ERR; 89: else { 90: if (win->_firstch[wy] >= win->_ch_off) 91: win->_firstch[wy] = win->_maxx + 92: win->_ch_off; 93: if (win->_lastch[wy] < win->_maxx + 94: win->_ch_off) 95: win->_lastch[wy] = win->_ch_off; 96: if (win->_lastch[wy] < win->_firstch[wy]) 97: win->_firstch[wy] = _NOCHANGE; 98: } 99: # ifdef DEBUG 100: fprintf(outf, "\t%d\t%d\n", win->_firstch[wy], 101: win->_lastch[wy]); 102: # endif 103: } 104: 105: if (win == curscr) 106: domvcur(ly, lx, win->_cury, win->_curx); 107: else { 108: if (win->_leave) { 109: curscr->_cury = ly; 110: curscr->_curx = lx; 111: ly -= win->_begy; 112: lx -= win->_begx; 113: if (ly >= 0 && ly < win->_maxy && lx >= 0 && 114: lx < win->_maxx) { 115: win->_cury = ly; 116: win->_curx = lx; 117: } 118: else 119: win->_cury = win->_curx = 0; 120: } 121: else { 122: domvcur(ly, lx, win->_cury + win->_begy, 123: win->_curx + win->_begx); 124: curscr->_cury = win->_cury + win->_begy; 125: curscr->_curx = win->_curx + win->_begx; 126: } 127: } 128: retval = OK; 129: ret: 130: _win = NULL; 131: fflush(stdout); 132: return retval; 133: } 134: 135: /* 136: * make a change on the screen 137: */ 138: STATIC 139: makech(win, wy) 140: reg WINDOW *win; 141: short wy; 142: { 143: reg char *nsp, *csp, *ce; 144: reg short wx, lch, y; 145: reg int nlsp, clsp; /* last space in lines */ 146: 147: wx = win->_firstch[wy] - win->_ch_off; 148: if (wx >= win->_maxx) 149: return OK; 150: else if (wx < 0) 151: wx = 0; 152: lch = win->_lastch[wy] - win->_ch_off; 153: if (lch < 0) 154: return OK; 155: else if (lch >= win->_maxx) 156: lch = win->_maxx - 1;; 157: y = wy + win->_begy; 158: 159: if (curwin) 160: csp = " "; 161: else 162: csp = &curscr->_y[wy + win->_begy][wx + win->_begx]; 163: 164: nsp = &win->_y[wy][wx]; 165: if (CE && !curwin) { 166: for (ce = &win->_y[wy][win->_maxx - 1]; *ce == ' '; ce--) 167: if (ce <= win->_y[wy]) 168: break; 169: nlsp = ce - win->_y[wy]; 170: } 171: 172: if (!curwin) 173: ce = CE; 174: else 175: ce = NULL; 176: 177: while (wx <= lch) { 178: if (*nsp != *csp) { 179: domvcur(ly, lx, y, wx + win->_begx); 180: # ifdef DEBUG 181: fprintf(outf, "MAKECH: 1: wx = %d, lx = %d\n", wx, lx); 182: # endif 183: ly = y; 184: lx = wx + win->_begx; 185: while (*nsp != *csp && wx <= lch) { 186: if (ce != NULL && wx >= nlsp && *nsp == ' ') { 187: /* 188: * check for clear to end-of-line 189: */ 190: ce = &curscr->_y[ly][COLS - 1]; 191: while (*ce == ' ') 192: if (ce-- <= csp) 193: break; 194: clsp = ce - curscr->_y[ly] - win->_begx; 195: # ifdef DEBUG 196: fprintf(outf, "MAKECH: clsp = %d, nlsp = %d\n", clsp, nlsp); 197: # endif 198: if (clsp - nlsp >= strlen(CE) 199: && clsp < win->_maxx) { 200: # ifdef DEBUG 201: fprintf(outf, "MAKECH: using CE\n"); 202: # endif 203: _puts(CE); 204: lx = wx + win->_begx; 205: while (wx++ <= clsp) 206: *csp++ = ' '; 207: return OK; 208: } 209: ce = NULL; 210: } 211: /* 212: * enter/exit standout mode as appropriate 213: */ 214: if (SO && (*nsp&_STANDOUT) != (curscr->_flags&_STANDOUT)) { 215: if (*nsp & _STANDOUT) { 216: _puts(SO); 217: curscr->_flags |= _STANDOUT; 218: } 219: else { 220: _puts(SE); 221: curscr->_flags &= ~_STANDOUT; 222: } 223: } 224: wx++; 225: if (wx >= win->_maxx && wy == win->_maxy - 1) 226: if (win->_scroll) { 227: if ((curscr->_flags&_STANDOUT) && 228: (win->_flags & _ENDLINE)) 229: if (!MS) { 230: _puts(SE); 231: curscr->_flags &= ~_STANDOUT; 232: } 233: if (!curwin) 234: _putchar((*csp = *nsp) & 0177); 235: else 236: _putchar(*nsp & 0177); 237: if (win->_flags&_FULLWIN && !curwin) 238: scroll(curscr); 239: ly = win->_begy+win->_cury; 240: lx = win->_begx+win->_curx; 241: return OK; 242: } 243: else if (win->_flags&_SCROLLWIN) { 244: lx = --wx; 245: return ERR; 246: } 247: if (!curwin) 248: _putchar((*csp++ = *nsp) & 0177); 249: else 250: _putchar(*nsp & 0177); 251: # ifdef FULLDEBUG 252: fprintf(outf, 253: "MAKECH:putchar(%c)\n", *nsp & 0177); 254: # endif 255: if (UC && (*nsp & _STANDOUT)) { 256: _putchar('\b'); 257: _puts(UC); 258: } 259: nsp++; 260: } 261: # ifdef DEBUG 262: fprintf(outf, "MAKECH: 2: wx = %d, lx = %d\n", wx, lx); 263: # endif 264: if (lx == wx + win->_begx) /* if no change */ 265: break; 266: lx = wx + win->_begx; 267: if (lx >= COLS && AM) { 268: lx = 0; 269: ly++; 270: /* 271: * xn glitch: chomps a newline after auto-wrap. 272: * we just feed it now and forget about it. 273: */ 274: if (XN) { 275: _putchar('\n'); 276: _putchar('\r'); 277: } 278: } 279: } 280: else if (wx <= lch) 281: while (*nsp == *csp && wx <= lch) { 282: nsp++; 283: if (!curwin) 284: csp++; 285: ++wx; 286: } 287: else 288: break; 289: # ifdef DEBUG 290: fprintf(outf, "MAKECH: 3: wx = %d, lx = %d\n", wx, lx); 291: # endif 292: } 293: return OK; 294: } 295: 296: /* 297: * perform a mvcur, leaving standout mode if necessary 298: */ 299: STATIC 300: domvcur(oy, ox, ny, nx) 301: int oy, ox, ny, nx; { 302: 303: if (curscr->_flags & _STANDOUT && !MS) { 304: _puts(SE); 305: curscr->_flags &= ~_STANDOUT; 306: } 307: mvcur(oy, ox, ny, nx); 308: }