drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / payloads / libpayload / curses / PDCurses / pdcurses / border.c
blob2a2ebcf5f7aaa589de8990e0ed57ceac78a01bd5
1 /* Public Domain Curses */
3 #include <curspriv.h>
5 RCSID("$Id: border.c,v 1.53 2008/07/13 16:08:18 wmcbrine Exp $")
7 /*man-start**************************************************************
9 Name: border
11 Synopsis:
12 int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl,
13 chtype tr, chtype bl, chtype br);
14 int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts,
15 chtype bs, chtype tl, chtype tr, chtype bl, chtype br);
16 int box(WINDOW *win, chtype verch, chtype horch);
17 int hline(chtype ch, int n);
18 int vline(chtype ch, int n);
19 int whline(WINDOW *win, chtype ch, int n);
20 int wvline(WINDOW *win, chtype ch, int n);
21 int mvhline(int y, int x, chtype ch, int n);
22 int mvvline(int y, int x, chtype ch, int n);
23 int mvwhline(WINDOW *win, int y, int x, chtype ch, int n);
24 int mvwvline(WINDOW *win, int y, int x, chtype ch, int n);
26 int border_set(const cchar_t *ls, const cchar_t *rs,
27 const cchar_t *ts, const cchar_t *bs,
28 const cchar_t *tl, const cchar_t *tr,
29 const cchar_t *bl, const cchar_t *br);
30 int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
31 const cchar_t *ts, const cchar_t *bs,
32 const cchar_t *tl, const cchar_t *tr,
33 const cchar_t *bl, const cchar_t *br);
34 int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch);
35 int hline_set(const cchar_t *wch, int n);
36 int vline_set(const cchar_t *wch, int n);
37 int whline_set(WINDOW *win, const cchar_t *wch, int n);
38 int wvline_set(WINDOW *win, const cchar_t *wch, int n);
39 int mvhline_set(int y, int x, const cchar_t *wch, int n);
40 int mvvline_set(int y, int x, const cchar_t *wch, int n);
41 int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n);
42 int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n);
44 Description:
45 border(), wborder(), and box() draw a border around the edge of
46 the window. If any argument is zero, an appropriate default is
47 used:
49 ls left side of border ACS_VLINE
50 rs right side of border ACS_VLINE
51 ts top side of border ACS_HLINE
52 bs bottom side of border ACS_HLINE
53 tl top left corner of border ACS_ULCORNER
54 tr top right corner of border ACS_URCORNER
55 bl bottom left corner of border ACS_LLCORNER
56 br bottom right corner of border ACS_LRCORNER
58 hline() and whline() draw a horizontal line, using ch, starting
59 from the current cursor position. The cursor position does not
60 change. The line is at most n characters long, or as many as
61 will fit in the window.
63 vline() and wvline() draw a vertical line, using ch, starting
64 from the current cursor position. The cursor position does not
65 change. The line is at most n characters long, or as many as
66 will fit in the window.
68 Return Value:
69 These functions return OK on success and ERR on error.
71 Portability X/Open BSD SYS V
72 border Y - 4.0
73 wborder Y - 4.0
74 box Y Y Y
75 hline Y - 4.0
76 vline Y - 4.0
77 whline Y - 4.0
78 wvline Y - 4.0
79 mvhline Y
80 mvvline Y
81 mvwhline Y
82 mvwvline Y
83 border_set Y
84 wborder_set Y
85 box_set Y
86 hline_set Y
87 vline_set Y
88 whline_set Y
89 wvline_set Y
90 mvhline_set Y
91 mvvline_set Y
92 mvwhline_set Y
93 mvwvline_set Y
95 **man-end****************************************************************/
97 /* _attr_passthru() -- Takes a single chtype 'ch' and checks if the
98 current attribute of window 'win', as set by wattrset(), and/or the
99 current background of win, as set by wbkgd(), should by combined with
100 it. Attributes set explicitly in ch take precedence. */
102 static chtype _attr_passthru(WINDOW *win, chtype ch)
104 chtype attr;
106 /* If the incoming character doesn't have its own attribute, then
107 use the current attributes for the window. If the incoming
108 character has attributes, but not a color component, OR the
109 attributes to the current attributes for the window. If the
110 incoming character has a color component, use only the attributes
111 from the incoming character. */
113 attr = ch & A_ATTRIBUTES;
114 if (!(attr & A_COLOR))
115 attr |= win->_attrs;
117 /* wrs (4/10/93) -- Apply the same sort of logic for the window
118 background, in that it only takes precedence if other color
119 attributes are not there. */
121 if (!(attr & A_COLOR))
122 attr |= win->_bkgd & A_ATTRIBUTES;
123 else
124 attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);
126 ch = (ch & A_CHARTEXT) | attr;
128 return ch;
131 int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs,
132 chtype tl, chtype tr, chtype bl, chtype br)
134 int i, ymax, xmax;
136 PDC_LOG(("wborder() - called\n"));
138 if (!win)
139 return ERR;
141 ymax = win->_maxy - 1;
142 xmax = win->_maxx - 1;
144 ls = _attr_passthru(win, ls ? ls : ACS_VLINE);
145 rs = _attr_passthru(win, rs ? rs : ACS_VLINE);
146 ts = _attr_passthru(win, ts ? ts : ACS_HLINE);
147 bs = _attr_passthru(win, bs ? bs : ACS_HLINE);
148 tl = _attr_passthru(win, tl ? tl : ACS_ULCORNER);
149 tr = _attr_passthru(win, tr ? tr : ACS_URCORNER);
150 bl = _attr_passthru(win, bl ? bl : ACS_LLCORNER);
151 br = _attr_passthru(win, br ? br : ACS_LRCORNER);
153 for (i = 1; i < xmax; i++)
155 win->_y[0][i] = ts;
156 win->_y[ymax][i] = bs;
159 for (i = 1; i < ymax; i++)
161 win->_y[i][0] = ls;
162 win->_y[i][xmax] = rs;
165 win->_y[0][0] = tl;
166 win->_y[0][xmax] = tr;
167 win->_y[ymax][0] = bl;
168 win->_y[ymax][xmax] = br;
170 for (i = 0; i <= ymax; i++)
172 win->_firstch[i] = 0;
173 win->_lastch[i] = xmax;
176 PDC_sync(win);
178 return OK;
181 int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl,
182 chtype tr, chtype bl, chtype br)
184 PDC_LOG(("border() - called\n"));
186 return wborder(stdscr, ls, rs, ts, bs, tl, tr, bl, br);
189 int box(WINDOW *win, chtype verch, chtype horch)
191 PDC_LOG(("box() - called\n"));
193 return wborder(win, verch, verch, horch, horch, 0, 0, 0, 0);
196 int whline(WINDOW *win, chtype ch, int n)
198 chtype *dest;
199 int startpos, endpos;
201 PDC_LOG(("whline() - called\n"));
203 if (!win || n < 1)
204 return ERR;
206 startpos = win->_curx;
207 endpos = min(startpos + n, win->_maxx) - 1;
208 dest = win->_y[win->_cury];
209 ch = _attr_passthru(win, ch ? ch : ACS_HLINE);
211 for (n = startpos; n <= endpos; n++)
212 dest[n] = ch;
214 n = win->_cury;
216 if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
217 win->_firstch[n] = startpos;
219 if (endpos > win->_lastch[n])
220 win->_lastch[n] = endpos;
222 PDC_sync(win);
224 return OK;
227 int hline(chtype ch, int n)
229 PDC_LOG(("hline() - called\n"));
231 return whline(stdscr, ch, n);
234 int mvhline(int y, int x, chtype ch, int n)
236 PDC_LOG(("mvhline() - called\n"));
238 if (move(y, x) == ERR)
239 return ERR;
241 return whline(stdscr, ch, n);
244 int mvwhline(WINDOW *win, int y, int x, chtype ch, int n)
246 PDC_LOG(("mvwhline() - called\n"));
248 if (wmove(win, y, x) == ERR)
249 return ERR;
251 return whline(win, ch, n);
254 int wvline(WINDOW *win, chtype ch, int n)
256 int endpos, x;
258 PDC_LOG(("wvline() - called\n"));
260 if (!win || n < 1)
261 return ERR;
263 endpos = min(win->_cury + n, win->_maxy);
264 x = win->_curx;
266 ch = _attr_passthru(win, ch ? ch : ACS_VLINE);
268 for (n = win->_cury; n < endpos; n++)
270 win->_y[n][x] = ch;
272 if (x < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
273 win->_firstch[n] = x;
275 if (x > win->_lastch[n])
276 win->_lastch[n] = x;
279 PDC_sync(win);
281 return OK;
284 int vline(chtype ch, int n)
286 PDC_LOG(("vline() - called\n"));
288 return wvline(stdscr, ch, n);
291 int mvvline(int y, int x, chtype ch, int n)
293 PDC_LOG(("mvvline() - called\n"));
295 if (move(y, x) == ERR)
296 return ERR;
298 return wvline(stdscr, ch, n);
301 int mvwvline(WINDOW *win, int y, int x, chtype ch, int n)
303 PDC_LOG(("mvwvline() - called\n"));
305 if (wmove(win, y, x) == ERR)
306 return ERR;
308 return wvline(win, ch, n);
311 #ifdef PDC_WIDE
312 int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
313 const cchar_t *ts, const cchar_t *bs, const cchar_t *tl,
314 const cchar_t *tr, const cchar_t *bl, const cchar_t *br)
316 PDC_LOG(("wborder_set() - called\n"));
318 return wborder(win, ls ? *ls : 0, rs ? *rs : 0, ts ? *ts : 0,
319 bs ? *bs : 0, tl ? *tl : 0, tr ? *tr : 0,
320 bl ? *bl : 0, br ? *br : 0);
323 int border_set(const cchar_t *ls, const cchar_t *rs, const cchar_t *ts,
324 const cchar_t *bs, const cchar_t *tl, const cchar_t *tr,
325 const cchar_t *bl, const cchar_t *br)
327 PDC_LOG(("border_set() - called\n"));
329 return wborder_set(stdscr, ls, rs, ts, bs, tl, tr, bl, br);
332 int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch)
334 PDC_LOG(("box_set() - called\n"));
336 return wborder_set(win, verch, verch, horch, horch,
337 (const cchar_t *)NULL, (const cchar_t *)NULL,
338 (const cchar_t *)NULL, (const cchar_t *)NULL);
341 int whline_set(WINDOW *win, const cchar_t *wch, int n)
343 PDC_LOG(("whline_set() - called\n"));
345 return wch ? whline(win, *wch, n) : ERR;
348 int hline_set(const cchar_t *wch, int n)
350 PDC_LOG(("hline_set() - called\n"));
352 return whline_set(stdscr, wch, n);
355 int mvhline_set(int y, int x, const cchar_t *wch, int n)
357 PDC_LOG(("mvhline_set() - called\n"));
359 if (move(y, x) == ERR)
360 return ERR;
362 return whline_set(stdscr, wch, n);
365 int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)
367 PDC_LOG(("mvwhline_set() - called\n"));
369 if (wmove(win, y, x) == ERR)
370 return ERR;
372 return whline_set(win, wch, n);
375 int wvline_set(WINDOW *win, const cchar_t *wch, int n)
377 PDC_LOG(("wvline_set() - called\n"));
379 return wch ? wvline(win, *wch, n) : ERR;
382 int vline_set(const cchar_t *wch, int n)
384 PDC_LOG(("vline_set() - called\n"));
386 return wvline_set(stdscr, wch, n);
389 int mvvline_set(int y, int x, const cchar_t *wch, int n)
391 PDC_LOG(("mvvline_set() - called\n"));
393 if (move(y, x) == ERR)
394 return ERR;
396 return wvline_set(stdscr, wch, n);
399 int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)
401 PDC_LOG(("mvwvline_set() - called\n"));
403 if (wmove(win, y, x) == ERR)
404 return ERR;
406 return wvline_set(win, wch, n);
408 #endif