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