|
|
1.1 ! root 1: /* ! 2: * make the current screen look like "win" over the area coverd by ! 3: * win. ! 4: * ! 5: * 5/12/83 (Berkeley) @(#)refresh.c 1.8 ! 6: */ ! 7: ! 8: # include "curses.ext" ! 9: ! 10: # ifdef DEBUG ! 11: # define STATIC ! 12: # else ! 13: # define STATIC static ! 14: # endif ! 15: ! 16: STATIC short ly, lx; ! 17: ! 18: STATIC bool curwin; ! 19: ! 20: WINDOW *_win = NULL; ! 21: ! 22: wrefresh(win) ! 23: reg WINDOW *win; ! 24: { ! 25: reg short wy; ! 26: reg int retval; ! 27: ! 28: /* ! 29: * make sure were in visual state ! 30: */ ! 31: if (_endwin) { ! 32: _puts(VS); ! 33: _puts(TI); ! 34: _endwin = FALSE; ! 35: } ! 36: ! 37: /* ! 38: * initialize loop parameters ! 39: */ ! 40: ! 41: ly = curscr->_cury; ! 42: lx = curscr->_curx; ! 43: wy = 0; ! 44: _win = win; ! 45: curwin = (win == curscr); ! 46: ! 47: if (win->_clear || curscr->_clear || curwin) { ! 48: if ((win->_flags & _FULLWIN) || curscr->_clear) { ! 49: _puts(CL); ! 50: ly = 0; ! 51: lx = 0; ! 52: if (!curwin) { ! 53: curscr->_clear = FALSE; ! 54: curscr->_cury = 0; ! 55: curscr->_curx = 0; ! 56: werase(curscr); ! 57: } ! 58: touchwin(win); ! 59: } ! 60: win->_clear = FALSE; ! 61: } ! 62: if (!CA) { ! 63: if (win->_curx != 0) ! 64: putchar('\n'); ! 65: if (!curwin) ! 66: werase(curscr); ! 67: } ! 68: # ifdef DEBUG ! 69: fprintf(outf, "REFRESH(%0.2o): curwin = %d\n", win, curwin); ! 70: fprintf(outf, "REFRESH:\n\tfirstch\tlastch\n"); ! 71: # endif ! 72: for (wy = 0; wy < win->_maxy; wy++) { ! 73: # ifdef DEBUG ! 74: fprintf(outf, "%d\t%d\t%d\n", wy, win->_firstch[wy], win->_lastch[wy]); ! 75: # endif ! 76: if (win->_firstch[wy] != _NOCHANGE) ! 77: if (makech(win, wy) == ERR) ! 78: return ERR; ! 79: else ! 80: win->_firstch[wy] = _NOCHANGE; ! 81: } ! 82: if (win == curscr) ! 83: domvcur(ly, lx, win->_cury, win->_curx); ! 84: else if (win->_leave) { ! 85: curscr->_cury = ly; ! 86: curscr->_curx = lx; ! 87: ly -= win->_begy; ! 88: lx -= win->_begx; ! 89: if (ly >= 0 && ly < win->_maxy && lx >= 0 && lx < win->_maxx) { ! 90: win->_cury = ly; ! 91: win->_curx = lx; ! 92: } ! 93: else ! 94: win->_cury = win->_curx = 0; ! 95: } ! 96: else { ! 97: domvcur(ly, lx, win->_cury+win->_begy, win->_curx+win->_begx); ! 98: curscr->_cury = win->_cury + win->_begy; ! 99: curscr->_curx = win->_curx + win->_begx; ! 100: } ! 101: retval = OK; ! 102: ret: ! 103: _win = NULL; ! 104: fflush(stdout); ! 105: return retval; ! 106: } ! 107: ! 108: /* ! 109: * make a change on the screen ! 110: */ ! 111: STATIC ! 112: makech(win, wy) ! 113: reg WINDOW *win; ! 114: short wy; ! 115: { ! 116: reg char *nsp, *csp, *ce; ! 117: reg short wx, lch, y; ! 118: reg int nlsp, clsp; /* last space in lines */ ! 119: ! 120: wx = win->_firstch[wy]; ! 121: y = wy + win->_begy; ! 122: lch = win->_lastch[wy]; ! 123: if (curwin) ! 124: csp = " "; ! 125: else ! 126: csp = &curscr->_y[wy + win->_begy][wx + win->_begx]; ! 127: nsp = &win->_y[wy][wx]; ! 128: if (CE && !curwin) { ! 129: for (ce = &win->_y[wy][win->_maxx - 1]; *ce == ' '; ce--) ! 130: if (ce <= win->_y[wy]) ! 131: break; ! 132: nlsp = ce - win->_y[wy]; ! 133: } ! 134: if (!curwin) ! 135: ce = CE; ! 136: else ! 137: ce = NULL; ! 138: while (wx <= lch) { ! 139: if (*nsp != *csp) { ! 140: domvcur(ly, lx, y, wx + win->_begx); ! 141: # ifdef DEBUG ! 142: fprintf(outf, "MAKECH: 1: wx = %d, lx = %d\n", wx, lx); ! 143: # endif ! 144: ly = y; ! 145: lx = wx + win->_begx; ! 146: while (*nsp != *csp && wx <= lch) { ! 147: if (ce != NULL && wx >= nlsp && *nsp == ' ') { ! 148: /* ! 149: * check for clear to end-of-line ! 150: */ ! 151: ce = &curscr->_y[ly][COLS - 1]; ! 152: while (*ce == ' ') ! 153: if (ce-- <= csp) ! 154: break; ! 155: clsp = ce - curscr->_y[ly] - win->_begx; ! 156: # ifdef DEBUG ! 157: fprintf(outf, "MAKECH: clsp = %d, nlsp = %d\n", clsp, nlsp); ! 158: # endif ! 159: if (clsp - nlsp >= strlen(CE) ! 160: && clsp < win->_maxx) { ! 161: # ifdef DEBUG ! 162: fprintf(outf, "MAKECH: using CE\n"); ! 163: # endif ! 164: _puts(CE); ! 165: lx = wx + win->_begx; ! 166: while (wx++ <= clsp) ! 167: *csp++ = ' '; ! 168: goto ret; ! 169: } ! 170: ce = NULL; ! 171: } ! 172: /* ! 173: * enter/exit standout mode as appropriate ! 174: */ ! 175: if (SO && (*nsp&_STANDOUT) != (curscr->_flags&_STANDOUT)) { ! 176: if (*nsp & _STANDOUT) { ! 177: _puts(SO); ! 178: curscr->_flags |= _STANDOUT; ! 179: } ! 180: else { ! 181: _puts(SE); ! 182: curscr->_flags &= ~_STANDOUT; ! 183: } ! 184: } ! 185: wx++; ! 186: if (wx >= win->_maxx && wy == win->_maxy - 1) ! 187: if (win->_scroll) { ! 188: if ((curscr->_flags&_STANDOUT) && ! 189: (win->_flags & _ENDLINE)) ! 190: if (!MS) { ! 191: _puts(SE); ! 192: curscr->_flags &= ~_STANDOUT; ! 193: } ! 194: if (!curwin) ! 195: putchar((*csp = *nsp) & 0177); ! 196: else ! 197: putchar(*nsp & 0177); ! 198: scroll(win); ! 199: if (win->_flags&_FULLWIN && !curwin) ! 200: scroll(curscr); ! 201: ly = win->_begy+win->_cury; ! 202: lx = win->_begx+win->_curx; ! 203: return OK; ! 204: } ! 205: else if (win->_flags&_SCROLLWIN) { ! 206: lx = --wx; ! 207: return ERR; ! 208: } ! 209: if (!curwin) ! 210: putchar((*csp++ = *nsp) & 0177); ! 211: else ! 212: putchar(*nsp & 0177); ! 213: if (UC && (*nsp & _STANDOUT)) { ! 214: putchar('\b'); ! 215: _puts(UC); ! 216: } ! 217: nsp++; ! 218: } ! 219: # ifdef DEBUG ! 220: fprintf(outf, "MAKECH: 2: wx = %d, lx = %d\n", wx, lx); ! 221: # endif ! 222: if (lx == wx + win->_begx) /* if no change */ ! 223: break; ! 224: lx = wx + win->_begx; ! 225: } ! 226: else if (wx < lch) ! 227: while (*nsp == *csp) { ! 228: nsp++; ! 229: if (!curwin) ! 230: csp++; ! 231: ++wx; ! 232: } ! 233: else ! 234: break; ! 235: # ifdef DEBUG ! 236: fprintf(outf, "MAKECH: 3: wx = %d, lx = %d\n", wx, lx); ! 237: # endif ! 238: } ! 239: ret: ! 240: return OK; ! 241: } ! 242: ! 243: /* ! 244: * perform a mvcur, leaving standout mode if necessary ! 245: */ ! 246: static ! 247: domvcur(oy, ox, ny, nx) ! 248: int oy, ox, ny, nx; { ! 249: ! 250: if (curscr->_flags & _STANDOUT && !MS) { ! 251: _puts(SE); ! 252: curscr->_flags &= ~_STANDOUT; ! 253: } ! 254: mvcur(oy, ox, ny, nx); ! 255: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.