2 * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
15 #pragma ident "%Z%%M% %I% %E% SMI"
21 sccsid
[] = "@(#)refresh.c 1.8 89/08/24 SMI"; /* from UCB 5.1 85/06/07 */
25 * make the current screen look like "win" over the area coverd by
36 #define DEBUGSTATIC static
39 DEBUGSTATIC
short ly
, lx
;
40 DEBUGSTATIC
bool curwin
;
43 /* forward declarations */
44 DEBUGSTATIC
void domvcur(int, int, int, int);
45 DEBUGSTATIC
int makech(WINDOW
*, short);
54 * make sure were in visual state
63 * initialize loop parameters
69 curwin
= (win
== curscr
);
71 if (win
->_clear
|| curscr
->_clear
|| curwin
) {
72 if ((win
->_flags
& _FULLWIN
) || curscr
->_clear
) {
77 curscr
->_clear
= FALSE
;
80 (void) werase(curscr
);
88 (void) _putchar('\n');
90 (void) werase(curscr
);
93 fprintf(outf
, "REFRESH(%0.2o): curwin = %d\n", win
, curwin
);
94 fprintf(outf
, "REFRESH:\n\tfirstch\tlastch\n");
96 for (wy
= 0; wy
< win
->_maxy
; wy
++) {
98 fprintf(outf
, "%d\t%d\t%d\n", wy
, win
->_firstch
[wy
],
101 if (win
->_firstch
[wy
] != _NOCHANGE
)
102 if (makech(win
, wy
) == ERR
)
105 if (win
->_firstch
[wy
] >= win
->_ch_off
)
106 win
->_firstch
[wy
] = win
->_maxx
+
108 if (win
->_lastch
[wy
] < win
->_maxx
+
110 win
->_lastch
[wy
] = win
->_ch_off
;
111 if (win
->_lastch
[wy
] < win
->_firstch
[wy
])
112 win
->_firstch
[wy
] = _NOCHANGE
;
115 fprintf(outf
, "\t%d\t%d\n", win
->_firstch
[wy
],
121 domvcur(ly
, lx
, win
->_cury
, win
->_curx
);
128 if (ly
>= 0 && ly
< win
->_maxy
&& lx
>= 0 &&
134 win
->_cury
= win
->_curx
= 0;
136 domvcur(ly
, lx
, win
->_cury
+ win
->_begy
,
137 win
->_curx
+ win
->_begx
);
138 curscr
->_cury
= win
->_cury
+ win
->_begy
;
139 curscr
->_curx
= win
->_curx
+ win
->_begx
;
145 (void) fflush(stdout
);
150 * make a change on the screen
154 makech(WINDOW
*win
, short wy
)
156 char *nsp
, *csp
, *ce
;
158 intptr_t nlsp
, clsp
; /* last space in lines */
160 wx
= win
->_firstch
[wy
] - win
->_ch_off
;
161 if (wx
>= win
->_maxx
)
165 lch
= win
->_lastch
[wy
] - win
->_ch_off
;
168 else if (lch
>= win
->_maxx
)
169 lch
= win
->_maxx
- 1;
175 csp
= &curscr
->_y
[wy
+ win
->_begy
][wx
+ win
->_begx
];
177 nsp
= &win
->_y
[wy
][wx
];
179 for (ce
= &win
->_y
[wy
][win
->_maxx
- 1]; *ce
== ' '; ce
--)
180 if (ce
<= win
->_y
[wy
])
182 nlsp
= ce
- win
->_y
[wy
];
192 domvcur(ly
, lx
, y
, wx
+ win
->_begx
);
194 fprintf(outf
, "MAKECH: 1: wx = %d, lx = %d\n", wx
, lx
);
197 lx
= wx
+ win
->_begx
;
198 while (wx
<= lch
&& *nsp
!= *csp
) {
199 if (ce
!= NULL
&& wx
>= nlsp
&& *nsp
== ' ') {
201 * check for clear to end-of-line
203 ce
= &curscr
->_y
[ly
][COLS
- 1];
207 clsp
= ce
- curscr
->_y
[ly
] - win
->_begx
;
209 fprintf(outf
, "MAKECH: clsp = %d,"
210 " nlsp = %d\n", clsp
, nlsp
);
212 if (clsp
- nlsp
>= strlen(CE
) &&
215 fprintf(outf
, "MAKECH: using"
219 lx
= wx
+ win
->_begx
;
227 * enter/exit standout mode as appropriate
229 if (SO
&& (*nsp
&_STANDOUT
) !=
230 (curscr
->_flags
&_STANDOUT
)) {
231 if (*nsp
& _STANDOUT
) {
233 curscr
->_flags
|= _STANDOUT
;
236 curscr
->_flags
&= ~_STANDOUT
;
240 if (wx
>= win
->_maxx
&& wy
== win
->_maxy
- 1)
242 if ((curscr
->_flags
&_STANDOUT
) &&
243 (win
->_flags
& _ENDLINE
))
250 (void) _putchar((*csp
= *nsp
) &
253 (void) _putchar(*nsp
& 0177);
254 if (win
->_flags
&_FULLWIN
&& !curwin
)
255 (void) scroll(curscr
);
257 ly
= wy
+ win
->_begy
;
258 lx
= wx
+ win
->_begx
;
260 ly
= win
->_begy
+win
->_cury
;
261 lx
= win
->_begx
+win
->_curx
;
264 } else if (win
->_flags
&_SCROLLWIN
) {
270 (void) _putchar((*csp
++ = *nsp
) & 0177);
272 (void) _putchar(*nsp
& 0177);
275 "MAKECH:putchar(%c)\n", *nsp
& 0177);
277 if (UC
&& (*nsp
& _STANDOUT
)) {
278 (void) _putchar('\b');
284 fprintf(outf
, "MAKECH: 2: wx = %d, lx = %d\n", wx
, lx
);
286 if (lx
== wx
+ win
->_begx
) /* if no change */
288 lx
= wx
+ win
->_begx
;
289 if (lx
>= COLS
&& AM
) {
293 * xn glitch: chomps a newline after auto-wrap.
294 * we just feed it now and forget about it.
297 (void) _putchar('\n');
298 (void) _putchar('\r');
301 } else if (wx
<= lch
)
302 while (wx
<= lch
&& *nsp
== *csp
) {
311 fprintf(outf
, "MAKECH: 3: wx = %d, lx = %d\n", wx
, lx
);
318 * perform a mvcur, leaving standout mode if necessary
322 domvcur(int oy
, int ox
, int ny
, int nx
)
324 if (curscr
->_flags
& _STANDOUT
&& !MS
) {
326 curscr
->_flags
&= ~_STANDOUT
;
328 (void) mvcur(oy
, ox
, ny
, nx
);