diff options
Diffstat (limited to '')
-rw-r--r-- | scripts/kconfig/libcurses/attr.c | 411 |
1 files changed, 411 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/attr.c b/scripts/kconfig/libcurses/attr.c new file mode 100644 index 000000000..d7bc36c73 --- /dev/null +++ b/scripts/kconfig/libcurses/attr.c | |||
@@ -0,0 +1,411 @@ | |||
1 | /* PDCurses */ | ||
2 | |||
3 | #include "curspriv.h" | ||
4 | |||
5 | /*man-start************************************************************** | ||
6 | |||
7 | attr | ||
8 | ---- | ||
9 | |||
10 | ### Synopsis | ||
11 | |||
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 | int underend(void); | ||
48 | int wunderend(WINDOW *win); | ||
49 | int underscore(void); | ||
50 | int wunderscore(WINDOW *win); | ||
51 | |||
52 | ### Description | ||
53 | |||
54 | These functions manipulate the current attributes and/or colors of | ||
55 | the named window. These attributes can be any combination of | ||
56 | A_STANDOUT, A_REVERSE, A_BOLD, A_DIM, A_BLINK, A_UNDERLINE. These | ||
57 | constants are defined in "curses.h" and can be combined with the | ||
58 | bitwise-OR operator (|). | ||
59 | |||
60 | The current attributes of a window are applied to all chtypes that | ||
61 | are written into the window with waddch(). Attributes are a property | ||
62 | of the chtype, and move with the character through any scrolling or | ||
63 | insert/delete operations. | ||
64 | |||
65 | wattrset() sets the current attributes of the given window to attrs. | ||
66 | attrset() is the stdscr version. | ||
67 | |||
68 | wattroff() turns off the named attributes without affecting any other | ||
69 | attributes; wattron() turns them on. | ||
70 | |||
71 | wcolor_set() sets the window color to the value of color_pair. opts | ||
72 | is unused. | ||
73 | |||
74 | standout() is the same as attron(A_STANDOUT). standend() is the same | ||
75 | as attrset(A_NORMAL); that is, it turns off all attributes. | ||
76 | |||
77 | The attr_* and wattr_* functions are intended for use with the WA_* | ||
78 | attributes. In PDCurses, these are the same as A_*, and there is no | ||
79 | difference in bevahior from the chtype-based functions. In all cases, | ||
80 | opts is unused. | ||
81 | |||
82 | wattr_get() retrieves the attributes and color pair for the specified | ||
83 | window. | ||
84 | |||
85 | wchgat() sets the color pair and attributes for the next n cells on | ||
86 | the current line of a given window, without changing the existing | ||
87 | text, or alterting the window's attributes. An n of -1 extends the | ||
88 | change to the edge of the window. The changes take effect | ||
89 | immediately. opts is unused. | ||
90 | |||
91 | wunderscore() turns on the A_UNDERLINE attribute; wunderend() turns | ||
92 | it off. underscore() and underend() are the stdscr versions. | ||
93 | |||
94 | ### Return Value | ||
95 | |||
96 | All functions return OK on success and ERR on error. | ||
97 | |||
98 | ### Portability | ||
99 | |||
100 | Function | X/Open | ncurses | NetBSD | ||
101 | :---------------------|:------:|:-------:|:------: | ||
102 | attroff | Y | Y | Y | ||
103 | wattroff | Y | Y | Y | ||
104 | attron | Y | Y | Y | ||
105 | wattron | Y | Y | Y | ||
106 | attrset | Y | Y | Y | ||
107 | wattrset | Y | Y | Y | ||
108 | standend | Y | Y | Y | ||
109 | wstandend | Y | Y | Y | ||
110 | standout | Y | Y | Y | ||
111 | wstandout | Y | Y | Y | ||
112 | color_set | Y | Y | Y | ||
113 | wcolor_set | Y | Y | Y | ||
114 | attr_get | Y | Y | Y | ||
115 | wattr_get | Y | Y | Y | ||
116 | attr_on | Y | Y | Y | ||
117 | wattr_on | Y | Y | Y | ||
118 | attr_off | Y | Y | Y | ||
119 | wattr_off | Y | Y | Y | ||
120 | attr_set | Y | Y | Y | ||
121 | wattr_set | Y | Y | Y | ||
122 | chgat | Y | Y | Y | ||
123 | wchgat | Y | Y | Y | ||
124 | mvchgat | Y | Y | Y | ||
125 | mvwchgat | Y | Y | Y | ||
126 | getattrs | - | Y | Y | ||
127 | underend | - | - | Y | ||
128 | wunderend | - | - | Y | ||
129 | underscore | - | - | Y | ||
130 | wunderscore | - | - | Y | ||
131 | |||
132 | **man-end****************************************************************/ | ||
133 | |||
134 | int wattroff(WINDOW *win, chtype attrs) | ||
135 | { | ||
136 | PDC_LOG(("wattroff() - called\n")); | ||
137 | |||
138 | if (!win) | ||
139 | return ERR; | ||
140 | |||
141 | win->_attrs &= (~attrs & A_ATTRIBUTES); | ||
142 | |||
143 | return OK; | ||
144 | } | ||
145 | |||
146 | int attroff(chtype attrs) | ||
147 | { | ||
148 | PDC_LOG(("attroff() - called\n")); | ||
149 | |||
150 | return wattroff(stdscr, attrs); | ||
151 | } | ||
152 | |||
153 | int wattron(WINDOW *win, chtype attrs) | ||
154 | { | ||
155 | chtype newcolr, oldcolr, newattr, oldattr; | ||
156 | |||
157 | PDC_LOG(("wattron() - called\n")); | ||
158 | |||
159 | if (!win) | ||
160 | return ERR; | ||
161 | |||
162 | if ((win->_attrs & A_COLOR) && (attrs & A_COLOR)) | ||
163 | { | ||
164 | oldcolr = win->_attrs & A_COLOR; | ||
165 | oldattr = win->_attrs ^ oldcolr; | ||
166 | newcolr = attrs & A_COLOR; | ||
167 | newattr = (attrs & A_ATTRIBUTES) ^ newcolr; | ||
168 | newattr |= oldattr; | ||
169 | win->_attrs = newattr | newcolr; | ||
170 | } | ||
171 | else | ||
172 | win->_attrs |= (attrs & A_ATTRIBUTES); | ||
173 | |||
174 | return OK; | ||
175 | } | ||
176 | |||
177 | int attron(chtype attrs) | ||
178 | { | ||
179 | PDC_LOG(("attron() - called\n")); | ||
180 | |||
181 | return wattron(stdscr, attrs); | ||
182 | } | ||
183 | |||
184 | int wattrset(WINDOW *win, chtype attrs) | ||
185 | { | ||
186 | PDC_LOG(("wattrset() - called\n")); | ||
187 | |||
188 | if (!win) | ||
189 | return ERR; | ||
190 | |||
191 | win->_attrs = attrs & A_ATTRIBUTES; | ||
192 | |||
193 | return OK; | ||
194 | } | ||
195 | |||
196 | int attrset(chtype attrs) | ||
197 | { | ||
198 | PDC_LOG(("attrset() - called\n")); | ||
199 | |||
200 | return wattrset(stdscr, attrs); | ||
201 | } | ||
202 | |||
203 | int standend(void) | ||
204 | { | ||
205 | PDC_LOG(("standend() - called\n")); | ||
206 | |||
207 | return wattrset(stdscr, A_NORMAL); | ||
208 | } | ||
209 | |||
210 | int standout(void) | ||
211 | { | ||
212 | PDC_LOG(("standout() - called\n")); | ||
213 | |||
214 | return wattrset(stdscr, A_STANDOUT); | ||
215 | } | ||
216 | |||
217 | int wstandend(WINDOW *win) | ||
218 | { | ||
219 | PDC_LOG(("wstandend() - called\n")); | ||
220 | |||
221 | return wattrset(win, A_NORMAL); | ||
222 | } | ||
223 | |||
224 | int wstandout(WINDOW *win) | ||
225 | { | ||
226 | PDC_LOG(("wstandout() - called\n")); | ||
227 | |||
228 | return wattrset(win, A_STANDOUT); | ||
229 | } | ||
230 | |||
231 | chtype getattrs(WINDOW *win) | ||
232 | { | ||
233 | return win ? win->_attrs : 0; | ||
234 | } | ||
235 | |||
236 | int wcolor_set(WINDOW *win, short color_pair, void *opts) | ||
237 | { | ||
238 | PDC_LOG(("wcolor_set() - called\n")); | ||
239 | |||
240 | if (!win) | ||
241 | return ERR; | ||
242 | |||
243 | win->_attrs = (win->_attrs & ~A_COLOR) | COLOR_PAIR(color_pair); | ||
244 | |||
245 | return OK; | ||
246 | } | ||
247 | |||
248 | int color_set(short color_pair, void *opts) | ||
249 | { | ||
250 | PDC_LOG(("color_set() - called\n")); | ||
251 | |||
252 | return wcolor_set(stdscr, color_pair, opts); | ||
253 | } | ||
254 | |||
255 | int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair, void *opts) | ||
256 | { | ||
257 | PDC_LOG(("wattr_get() - called\n")); | ||
258 | |||
259 | if (!win) | ||
260 | return ERR; | ||
261 | |||
262 | if (attrs) | ||
263 | *attrs = win->_attrs & (A_ATTRIBUTES & ~A_COLOR); | ||
264 | |||
265 | if (color_pair) | ||
266 | *color_pair = PAIR_NUMBER(win->_attrs); | ||
267 | |||
268 | return OK; | ||
269 | } | ||
270 | |||
271 | int attr_get(attr_t *attrs, short *color_pair, void *opts) | ||
272 | { | ||
273 | PDC_LOG(("attr_get() - called\n")); | ||
274 | |||
275 | return wattr_get(stdscr, attrs, color_pair, opts); | ||
276 | } | ||
277 | |||
278 | int wattr_off(WINDOW *win, attr_t attrs, void *opts) | ||
279 | { | ||
280 | PDC_LOG(("wattr_off() - called\n")); | ||
281 | |||
282 | return wattroff(win, attrs); | ||
283 | } | ||
284 | |||
285 | int attr_off(attr_t attrs, void *opts) | ||
286 | { | ||
287 | PDC_LOG(("attr_off() - called\n")); | ||
288 | |||
289 | return wattroff(stdscr, attrs); | ||
290 | } | ||
291 | |||
292 | int wattr_on(WINDOW *win, attr_t attrs, void *opts) | ||
293 | { | ||
294 | PDC_LOG(("wattr_off() - called\n")); | ||
295 | |||
296 | return wattron(win, attrs); | ||
297 | } | ||
298 | |||
299 | int attr_on(attr_t attrs, void *opts) | ||
300 | { | ||
301 | PDC_LOG(("attr_on() - called\n")); | ||
302 | |||
303 | return wattron(stdscr, attrs); | ||
304 | } | ||
305 | |||
306 | int wattr_set(WINDOW *win, attr_t attrs, short color_pair, void *opts) | ||
307 | { | ||
308 | PDC_LOG(("wattr_set() - called\n")); | ||
309 | |||
310 | if (!win) | ||
311 | return ERR; | ||
312 | |||
313 | win->_attrs = (attrs & (A_ATTRIBUTES & ~A_COLOR)) | COLOR_PAIR(color_pair); | ||
314 | |||
315 | return OK; | ||
316 | } | ||
317 | |||
318 | int attr_set(attr_t attrs, short color_pair, void *opts) | ||
319 | { | ||
320 | PDC_LOG(("attr_get() - called\n")); | ||
321 | |||
322 | return wattr_set(stdscr, attrs, color_pair, opts); | ||
323 | } | ||
324 | |||
325 | int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts) | ||
326 | { | ||
327 | chtype *dest, newattr; | ||
328 | int startpos, endpos; | ||
329 | |||
330 | PDC_LOG(("wchgat() - called\n")); | ||
331 | |||
332 | if (!win) | ||
333 | return ERR; | ||
334 | |||
335 | newattr = (attr & A_ATTRIBUTES) | COLOR_PAIR(color); | ||
336 | |||
337 | startpos = win->_curx; | ||
338 | endpos = ((n < 0) ? win->_maxx : min(startpos + n, win->_maxx)) - 1; | ||
339 | dest = win->_y[win->_cury]; | ||
340 | |||
341 | for (n = startpos; n <= endpos; n++) | ||
342 | dest[n] = (dest[n] & A_CHARTEXT) | newattr; | ||
343 | |||
344 | n = win->_cury; | ||
345 | |||
346 | if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE) | ||
347 | win->_firstch[n] = startpos; | ||
348 | |||
349 | if (endpos > win->_lastch[n]) | ||
350 | win->_lastch[n] = endpos; | ||
351 | |||
352 | PDC_sync(win); | ||
353 | |||
354 | return OK; | ||
355 | } | ||
356 | |||
357 | int chgat(int n, attr_t attr, short color, const void *opts) | ||
358 | { | ||
359 | PDC_LOG(("chgat() - called\n")); | ||
360 | |||
361 | return wchgat(stdscr, n, attr, color, opts); | ||
362 | } | ||
363 | |||
364 | int mvchgat(int y, int x, int n, attr_t attr, short color, const void *opts) | ||
365 | { | ||
366 | PDC_LOG(("mvchgat() - called\n")); | ||
367 | |||
368 | if (move(y, x) == ERR) | ||
369 | return ERR; | ||
370 | |||
371 | return wchgat(stdscr, n, attr, color, opts); | ||
372 | } | ||
373 | |||
374 | int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr, short color, | ||
375 | const void *opts) | ||
376 | { | ||
377 | PDC_LOG(("mvwchgat() - called\n")); | ||
378 | |||
379 | if (wmove(win, y, x) == ERR) | ||
380 | return ERR; | ||
381 | |||
382 | return wchgat(win, n, attr, color, opts); | ||
383 | } | ||
384 | |||
385 | int underend(void) | ||
386 | { | ||
387 | PDC_LOG(("underend() - called\n")); | ||
388 | |||
389 | return wattroff(stdscr, A_UNDERLINE); | ||
390 | } | ||
391 | |||
392 | int wunderend(WINDOW *win) | ||
393 | { | ||
394 | PDC_LOG(("wunderend() - called\n")); | ||
395 | |||
396 | return wattroff(win, A_UNDERLINE); | ||
397 | } | ||
398 | |||
399 | int underscore(void) | ||
400 | { | ||
401 | PDC_LOG(("underscore() - called\n")); | ||
402 | |||
403 | return wattron(stdscr, A_UNDERLINE); | ||
404 | } | ||
405 | |||
406 | int wunderscore(WINDOW *win) | ||
407 | { | ||
408 | PDC_LOG(("wunderscore() - called\n")); | ||
409 | |||
410 | return wattron(win, A_UNDERLINE); | ||
411 | } | ||