soc/intel/xeon_sp/util: Enhance lock_pam0123
[coreboot2.git] / payloads / libpayload / curses / PDCurses / pdcurses / refresh.c
blobda4bb76edd54ff4da721a223e24ed8e74a4fe6f7
1 /* Public Domain Curses */
3 #include <curspriv.h>
5 RCSID("$Id: refresh.c,v 1.56 2008/07/13 16:08:18 wmcbrine Exp $")
7 /*man-start**************************************************************
9 Name: refresh
11 Synopsis:
12 int refresh(void);
13 int wrefresh(WINDOW *win);
14 int wnoutrefresh(WINDOW *win);
15 int doupdate(void);
16 int redrawwin(WINDOW *win);
17 int wredrawln(WINDOW *win, int beg_line, int num_lines);
19 Description:
20 wrefresh() copies the named window to the physical terminal
21 screen, taking into account what is already there in order to
22 optimize cursor movement. refresh() does the same, using stdscr.
23 These routines must be called to get any output on the terminal,
24 as other routines only manipulate data structures. Unless
25 leaveok() has been enabled, the physical cursor of the terminal
26 is left at the location of the window's cursor.
28 wnoutrefresh() and doupdate() allow multiple updates with more
29 efficiency than wrefresh() alone. wrefresh() works by first
30 calling wnoutrefresh(), which copies the named window to the
31 virtual screen. It then calls doupdate(), which compares the
32 virtual screen to the physical screen and does the actual
33 update. A series of calls to wrefresh() will result in
34 alternating calls to wnoutrefresh() and doupdate(), causing
35 several bursts of output to the screen. By first calling
36 wnoutrefresh() for each window, it is then possible to call
37 doupdate() only once.
39 In PDCurses, redrawwin() is equivalent to touchwin(), and
40 wredrawln() is the same as touchline(). In some other curses
41 implementations, there's a subtle distinction, but it has no
42 meaning in PDCurses.
44 Return Value:
45 All functions return OK on success and ERR on error.
47 Portability X/Open BSD SYS V
48 refresh Y Y Y
49 wrefresh Y Y Y
50 wnoutrefresh Y Y Y
51 doupdate Y Y Y
52 redrawwin Y - 4.0
53 wredrawln Y - 4.0
55 **man-end****************************************************************/
57 #include <string.h>
59 int wnoutrefresh(WINDOW *win)
61 int begy, begx; /* window's place on screen */
62 int i, j;
64 PDC_LOG(("wnoutrefresh() - called: win=%p\n", win));
66 if ( !win || (win->_flags & (_PAD|_SUBPAD)) )
67 return ERR;
69 begy = win->_begy;
70 begx = win->_begx;
72 for (i = 0, j = begy; i < win->_maxy; i++, j++)
74 if (win->_firstch[i] != _NO_CHANGE)
76 chtype *src = win->_y[i];
77 chtype *dest = curscr->_y[j] + begx;
79 int first = win->_firstch[i]; /* first changed */
80 int last = win->_lastch[i]; /* last changed */
82 /* ignore areas on the outside that are marked as changed,
83 but really aren't */
85 while (first <= last && src[first] == dest[first])
86 first++;
88 while (last >= first && src[last] == dest[last])
89 last--;
91 /* if any have really changed... */
93 if (first <= last)
95 memcpy(dest + first, src + first,
96 (last - first + 1) * sizeof(chtype));
98 first += begx;
99 last += begx;
101 if (first < curscr->_firstch[j] ||
102 curscr->_firstch[j] == _NO_CHANGE)
103 curscr->_firstch[j] = first;
105 if (last > curscr->_lastch[j])
106 curscr->_lastch[j] = last;
109 win->_firstch[i] = _NO_CHANGE; /* updated now */
112 win->_lastch[i] = _NO_CHANGE; /* updated now */
115 if (win->_clear)
116 win->_clear = FALSE;
118 if (!win->_leaveit)
120 curscr->_cury = win->_cury + begy;
121 curscr->_curx = win->_curx + begx;
124 return OK;
127 int doupdate(void)
129 int y;
130 bool clearall;
132 PDC_LOG(("doupdate() - called\n"));
134 if (!curscr)
135 return ERR;
137 if (isendwin()) /* coming back after endwin() called */
139 reset_prog_mode();
140 clearall = TRUE;
141 SP->alive = TRUE; /* so isendwin() result is correct */
143 else
144 clearall = curscr->_clear;
146 for (y = 0; y < SP->lines; y++)
148 PDC_LOG(("doupdate() - Transforming line %d of %d: %s\n",
149 y, SP->lines, (curscr->_firstch[y] != _NO_CHANGE) ?
150 "Yes" : "No"));
152 if (clearall || curscr->_firstch[y] != _NO_CHANGE)
154 int first, last;
156 chtype *src = curscr->_y[y];
157 chtype *dest = pdc_lastscr->_y[y];
159 if (clearall)
161 first = 0;
162 last = COLS - 1;
164 else
166 first = curscr->_firstch[y];
167 last = curscr->_lastch[y];
170 while (first <= last)
172 int len = 0;
174 /* build up a run of changed cells; if two runs are
175 separated by a single unchanged cell, ignore the
176 break */
178 if (clearall)
179 len = last - first + 1;
180 else
181 while (first + len <= last &&
182 (src[first + len] != dest[first + len] ||
183 (len && first + len < last &&
184 src[first + len + 1] != dest[first + len + 1])
187 len++;
189 /* update the screen, and pdc_lastscr */
191 if (len)
193 PDC_transform_line(y, first, len, src + first);
194 memcpy(dest + first, src + first, len * sizeof(chtype));
195 first += len;
198 /* skip over runs of unchanged cells */
200 while (first <= last && src[first] == dest[first])
201 first++;
204 curscr->_firstch[y] = _NO_CHANGE;
205 curscr->_lastch[y] = _NO_CHANGE;
209 curscr->_clear = FALSE;
211 if (SP->visibility)
212 PDC_gotoyx(curscr->_cury, curscr->_curx);
214 SP->cursrow = curscr->_cury;
215 SP->curscol = curscr->_curx;
217 return OK;
220 int wrefresh(WINDOW *win)
222 bool save_clear;
224 PDC_LOG(("wrefresh() - called\n"));
226 if ( !win || (win->_flags & (_PAD|_SUBPAD)) )
227 return ERR;
229 save_clear = win->_clear;
231 if (win == curscr)
232 curscr->_clear = TRUE;
233 else
234 wnoutrefresh(win);
236 if (save_clear && win->_maxy == SP->lines && win->_maxx == SP->cols)
237 curscr->_clear = TRUE;
239 return doupdate();
242 int refresh(void)
244 PDC_LOG(("refresh() - called\n"));
246 return wrefresh(stdscr);
249 int wredrawln(WINDOW *win, int start, int num)
251 int i;
253 PDC_LOG(("wredrawln() - called: win=%p start=%d num=%d\n",
254 win, start, num));
256 if (!win || start > win->_maxy || start + num > win->_maxy)
257 return ERR;
259 for (i = start; i < start + num; i++)
261 win->_firstch[i] = 0;
262 win->_lastch[i] = win->_maxx - 1;
265 return OK;
268 int redrawwin(WINDOW *win)
270 PDC_LOG(("redrawwin() - called: win=%p\n", win));
272 if (!win)
273 return ERR;
275 return wredrawln(win, 0, win->_maxy);