libpayload: remove trailing whitespace and run dos2unix
[coreboot.git] / payloads / libpayload / curses / PDCurses-3.4 / pdcurses / attr.c
1 /* Public Domain Curses */
2
3 #include <curspriv.h>
4
5 RCSID("$Id: attr.c,v 1.41 2008/07/13 16:08:17 wmcbrine Exp $")
6
7 /*man-start**************************************************************
8
9   Name:                                                         attr
10
11   Synopsis:
12         int attroff(chtype attrs);
13         int wattroff(WINDOW *win, chtype attrs);
14         int attron(chtype attrs);
15         int wattron(WINDOW *win, chtype attrs);
16         int attrset(chtype attrs);
17         int wattrset(WINDOW *win, chtype attrs);
18         int standend(void);
19         int wstandend(WINDOW *win);
20         int standout(void);
21         int wstandout(WINDOW *win);
22
23         int color_set(short color_pair, void *opts);
24         int wcolor_set(WINDOW *win, short color_pair, void *opts);
25
26         int attr_get(attr_t *attrs, short *color_pair, void *opts);
27         int attr_off(attr_t attrs, void *opts);
28         int attr_on(attr_t attrs, void *opts);
29         int attr_set(attr_t attrs, short color_pair, void *opts);
30         int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair,
31                 void *opts);
32         int wattr_off(WINDOW *win, attr_t attrs, void *opts);
33         int wattr_on(WINDOW *win, attr_t attrs, void *opts);
34         int wattr_set(WINDOW *win, attr_t attrs, short color_pair,
35                 void *opts);
36
37         int chgat(int n, attr_t attr, short color, const void *opts);
38         int mvchgat(int y, int x, int n, attr_t attr, short color,
39                 const void *opts);
40         int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr,
41                 short color, const void *opts);
42         int wchgat(WINDOW *win, int n, attr_t attr, short color,
43                 const void *opts);
44
45         chtype getattrs(WINDOW *win);
46
47   Description:
48         These functions manipulate the current attributes and/or colors
49         of the named window.  These attributes can be any combination
50         of A_STANDOUT, A_REVERSE, A_BOLD, A_DIM, A_BLINK, A_UNDERLINE.
51
52         These constants are defined in <curses.h> and can be combined
53         with the bitwise-OR operator (|).
54
55         The current attributes of a window are applied to all chtypes
56         that are written into the window with waddch(). Attributes are
57         a property of the chtype, and move with the character through
58         any scrolling or insert/delete operations.
59
60         attrset() sets the current attributes of the given window to
61         attrs. attroff() turns off the named attributes without
62         affecting any other attributes; attron() turns them on.
63         color_set() sets the window color to the value of color_pair.
64
65         standout() is the same as attron(A_STANDOUT). standend() is the
66         same as attrset(A_NORMAL); that is, it turns off all attributes.
67
68   Return Value:
69         All functions return OK on success and ERR on error.
70
71   Portability                                X/Open    BSD    SYS V
72         attroff                                 Y       Y       Y
73         wattroff                                Y       Y       Y
74         attron                                  Y       Y       Y
75         wattron                                 Y       Y       Y
76         attrset                                 Y       Y       Y
77         wattrset                                Y       Y       Y
78         standend                                Y       Y       Y
79         wstandend                               Y       Y       Y
80         standout                                Y       Y       Y
81         wstandout                               Y       Y       Y
82         color_set                               Y
83         wcolor_set                              Y
84         attr_get                                Y
85         wattr_get                               Y
86         attr_on                                 Y
87         wattr_on                                Y
88         attr_off                                Y
89         wattr_off                               Y
90         attr_set                                Y
91         wattr_set                               Y
92         chgat                                   Y
93         wchgat                                  Y
94         mvchgat                                 Y
95         mvwchgat                                Y
96         getattrs                                -
97
98 **man-end****************************************************************/
99
100 int wattroff(WINDOW *win, chtype attrs)
101 {
102     PDC_LOG(("wattroff() - called\n"));
103
104     if (!win)
105         return ERR;
106
107     win->_attrs &= (~attrs & A_ATTRIBUTES);
108
109     return OK;
110 }
111
112 int attroff(chtype attrs)
113 {
114     PDC_LOG(("attroff() - called\n"));
115
116     return wattroff(stdscr, attrs);
117 }
118
119 int wattron(WINDOW *win, chtype attrs)
120 {
121     chtype newcolr, oldcolr, newattr, oldattr;
122
123     PDC_LOG(("wattron() - called\n"));
124
125     if (!win)
126         return ERR;
127
128     if ((win->_attrs & A_COLOR) && (attrs & A_COLOR))
129     {
130         oldcolr = win->_attrs & A_COLOR;
131         oldattr = win->_attrs ^ oldcolr;
132         newcolr = attrs & A_COLOR;
133         newattr = (attrs & A_ATTRIBUTES) ^ newcolr;
134         newattr |= oldattr;
135         win->_attrs = newattr | newcolr;
136     }
137     else
138         win->_attrs |= (attrs & A_ATTRIBUTES);
139
140     return OK;
141 }
142
143 int attron(chtype attrs)
144 {
145     PDC_LOG(("attron() - called\n"));
146
147     return wattron(stdscr, attrs);
148 }
149
150 int wattrset(WINDOW *win, chtype attrs)
151 {
152     PDC_LOG(("wattrset() - called\n"));
153
154     if (!win)
155         return ERR;
156
157     win->_attrs = attrs & A_ATTRIBUTES;
158
159     return OK;
160 }
161
162 int attrset(chtype attrs)
163 {
164     PDC_LOG(("attrset() - called\n"));
165
166     return wattrset(stdscr, attrs);
167 }
168
169 int standend(void)
170 {
171     PDC_LOG(("standend() - called\n"));
172
173     return wattrset(stdscr, A_NORMAL);
174 }
175
176 int standout(void)
177 {
178     PDC_LOG(("standout() - called\n"));
179
180     return wattrset(stdscr, A_STANDOUT);
181 }
182
183 int wstandend(WINDOW *win)
184 {
185     PDC_LOG(("wstandend() - called\n"));
186
187     return wattrset(win, A_NORMAL);
188 }
189
190 int wstandout(WINDOW *win)
191 {
192     PDC_LOG(("wstandout() - called\n"));
193
194     return wattrset(win, A_STANDOUT);
195 }
196
197 chtype getattrs(WINDOW *win)
198 {
199     return win ? win->_attrs : 0;
200 }
201
202 int wcolor_set(WINDOW *win, short color_pair, void *opts)
203 {
204     PDC_LOG(("wcolor_set() - called\n"));
205
206     if (!win)
207         return ERR;
208
209     win->_attrs = (win->_attrs & ~A_COLOR) | COLOR_PAIR(color_pair);
210
211     return OK;
212 }
213
214 int color_set(short color_pair, void *opts)
215 {
216     PDC_LOG(("color_set() - called\n"));
217
218     return wcolor_set(stdscr, color_pair, opts);
219 }
220
221 int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair, void *opts)
222 {
223     PDC_LOG(("wattr_get() - called\n"));
224
225     if (!win)
226         return ERR;
227
228     if (attrs)
229         *attrs = win->_attrs & (A_ATTRIBUTES & ~A_COLOR);
230
231     if (color_pair)
232         *color_pair = PAIR_NUMBER(win->_attrs);
233
234     return OK;
235 }
236
237 int attr_get(attr_t *attrs, short *color_pair, void *opts)
238 {
239     PDC_LOG(("attr_get() - called\n"));
240
241     return wattr_get(stdscr, attrs, color_pair, opts);
242 }
243
244 int wattr_off(WINDOW *win, attr_t attrs, void *opts)
245 {
246     PDC_LOG(("wattr_off() - called\n"));
247
248     return wattroff(win, attrs);
249 }
250
251 int attr_off(attr_t attrs, void *opts)
252 {
253     PDC_LOG(("attr_off() - called\n"));
254
255     return wattroff(stdscr, attrs);
256 }
257
258 int wattr_on(WINDOW *win, attr_t attrs, void *opts)
259 {
260     PDC_LOG(("wattr_off() - called\n"));
261
262     return wattron(win, attrs);
263 }
264
265 int attr_on(attr_t attrs, void *opts)
266 {
267     PDC_LOG(("attr_on() - called\n"));
268
269     return wattron(stdscr, attrs);
270 }
271
272 int wattr_set(WINDOW *win, attr_t attrs, short color_pair, void *opts)
273 {
274     PDC_LOG(("wattr_set() - called\n"));
275
276     if (!win)
277         return ERR;
278
279     win->_attrs = (attrs & (A_ATTRIBUTES & ~A_COLOR)) | COLOR_PAIR(color_pair);
280
281     return OK;
282 }
283
284 int attr_set(attr_t attrs, short color_pair, void *opts)
285 {
286     PDC_LOG(("attr_get() - called\n"));
287
288     return wattr_set(stdscr, attrs, color_pair, opts);
289 }
290
291 int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts)
292 {
293     chtype *dest, newattr;
294     int startpos, endpos;
295
296     PDC_LOG(("wchgat() - called\n"));
297
298     if (!win)
299         return ERR;
300
301     newattr = (attr & A_ATTRIBUTES) | COLOR_PAIR(color);
302
303     startpos = win->_curx;
304     endpos = ((n < 0) ? win->_maxx : min(startpos + n, win->_maxx)) - 1;
305     dest = win->_y[win->_cury];
306
307     for (n = startpos; n <= endpos; n++)
308         dest[n] = (dest[n] & A_CHARTEXT) | newattr;
309
310     n = win->_cury;
311
312     if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
313         win->_firstch[n] = startpos;
314
315     if (endpos > win->_lastch[n])
316         win->_lastch[n] = endpos;
317
318     PDC_sync(win);
319
320     return OK;
321 }
322
323 int chgat(int n, attr_t attr, short color, const void *opts)
324 {
325     PDC_LOG(("chgat() - called\n"));
326
327     return wchgat(stdscr, n, attr, color, opts);
328 }
329
330 int mvchgat(int y, int x, int n, attr_t attr, short color, const void *opts)
331 {
332     PDC_LOG(("mvchgat() - called\n"));
333
334     if (move(y, x) == ERR)
335         return ERR;
336
337     return wchgat(stdscr, n, attr, color, opts);
338 }
339
340 int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr, short color,
341              const void *opts)
342 {
343     PDC_LOG(("mvwchgat() - called\n"));
344
345     if (wmove(win, y, x) == ERR)
346         return ERR;
347
348     return wchgat(win, n, attr, color, opts);
349 }