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