summaryrefslogtreecommitdiff
path: root/payloads/libpayload/curses/PDCurses/pdcurses/attr.c
blob: 123cb908591237b38959ba091b93a2ee8d0ba37f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/* Public Domain Curses */

#include <curspriv.h>

RCSID("$Id: attr.c,v 1.41 2008/07/13 16:08:17 wmcbrine Exp $")

/*man-start**************************************************************

  Name:                                                         attr

  Synopsis:
        int attroff(chtype attrs);
        int wattroff(WINDOW *win, chtype attrs);
        int attron(chtype attrs);
        int wattron(WINDOW *win, chtype attrs);
        int attrset(chtype attrs);
        int wattrset(WINDOW *win, chtype attrs);
        int standend(void);
        int wstandend(WINDOW *win);
        int standout(void);
        int wstandout(WINDOW *win);

        int color_set(short color_pair, void *opts);
        int wcolor_set(WINDOW *win, short color_pair, void *opts);

        int attr_get(attr_t *attrs, short *color_pair, void *opts);
        int attr_off(attr_t attrs, void *opts);
        int attr_on(attr_t attrs, void *opts);
        int attr_set(attr_t attrs, short color_pair, void *opts);
        int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair,
                void *opts);
        int wattr_off(WINDOW *win, attr_t attrs, void *opts);
        int wattr_on(WINDOW *win, attr_t attrs, void *opts);
        int wattr_set(WINDOW *win, attr_t attrs, short color_pair,
                void *opts);

        int chgat(int n, attr_t attr, short color, const void *opts);
        int mvchgat(int y, int x, int n, attr_t attr, short color,
                const void *opts);
        int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr,
                short color, const void *opts);
        int wchgat(WINDOW *win, int n, attr_t attr, short color,
                const void *opts);

        chtype getattrs(WINDOW *win);

  Description:
        These functions manipulate the current attributes and/or colors
        of the named window.  These attributes can be any combination
        of A_STANDOUT, A_REVERSE, A_BOLD, A_DIM, A_BLINK, A_UNDERLINE.

        These constants are defined in <curses.h> and can be combined
        with the bitwise-OR operator (|).

        The current attributes of a window are applied to all chtypes
        that are written into the window with waddch(). Attributes are
        a property of the chtype, and move with the character through
        any scrolling or insert/delete operations.

        attrset() sets the current attributes of the given window to
        attrs. attroff() turns off the named attributes without
        affecting any other attributes; attron() turns them on.
        color_set() sets the window color to the value of color_pair.

        standout() is the same as attron(A_STANDOUT). standend() is the
        same as attrset(A_NORMAL); that is, it turns off all attributes.

  Return Value:
        All functions return OK on success and ERR on error.

  Portability                                X/Open    BSD    SYS V
        attroff                                 Y       Y       Y
        wattroff                                Y       Y       Y
        attron                                  Y       Y       Y
        wattron                                 Y       Y       Y
        attrset                                 Y       Y       Y
        wattrset                                Y       Y       Y
        standend                                Y       Y       Y
        wstandend                               Y       Y       Y
        standout                                Y       Y       Y
        wstandout                               Y       Y       Y
        color_set                               Y
        wcolor_set                              Y
        attr_get                                Y
        wattr_get                               Y
        attr_on                                 Y
        wattr_on                                Y
        attr_off                                Y
        wattr_off                               Y
        attr_set                                Y
        wattr_set                               Y
        chgat                                   Y
        wchgat                                  Y
        mvchgat                                 Y
        mvwchgat                                Y
        getattrs                                -

**man-end****************************************************************/

int wattroff(WINDOW *win, chtype attrs)
{
    PDC_LOG(("wattroff() - called\n"));

    if (!win)
        return ERR;

    win->_attrs &= (~attrs & A_ATTRIBUTES);

    return OK;
}

int attroff(chtype attrs)
{
    PDC_LOG(("attroff() - called\n"));

    return wattroff(stdscr, attrs);
}

int wattron(WINDOW *win, chtype attrs)
{
    chtype newcolr, oldcolr, newattr, oldattr;

    PDC_LOG(("wattron() - called\n"));

    if (!win)
        return ERR;

    if ((win->_attrs & A_COLOR) && (attrs & A_COLOR))
    {
        oldcolr = win->_attrs & A_COLOR;
        oldattr = win->_attrs ^ oldcolr;
        newcolr = attrs & A_COLOR;
        newattr = (attrs & A_ATTRIBUTES) ^ newcolr;
        newattr |= oldattr;
        win->_attrs = newattr | newcolr;
    }
    else
        win->_attrs |= (attrs & A_ATTRIBUTES);

    return OK;
}

int attron(chtype attrs)
{
    PDC_LOG(("attron() - called\n"));

    return wattron(stdscr, attrs);
}

int wattrset(WINDOW *win, chtype attrs)
{
    PDC_LOG(("wattrset() - called\n"));

    if (!win)
        return ERR;

    win->_attrs = attrs & A_ATTRIBUTES;

    return OK;
}

int attrset(chtype attrs)
{
    PDC_LOG(("attrset() - called\n"));

    return wattrset(stdscr, attrs);
}

int standend(void)
{
    PDC_LOG(("standend() - called\n"));

    return wattrset(stdscr, A_NORMAL);
}

int standout(void)
{
    PDC_LOG(("standout() - called\n"));

    return wattrset(stdscr, A_STANDOUT);
}

int wstandend(WINDOW *win)
{
    PDC_LOG(("wstandend() - called\n"));

    return wattrset(win, A_NORMAL);
}

int wstandout(WINDOW *win)
{
    PDC_LOG(("wstandout() - called\n"));

    return wattrset(win, A_STANDOUT);
}

chtype getattrs(WINDOW *win)
{
    return win ? win->_attrs : 0;
}

int wcolor_set(WINDOW *win, short color_pair, void *opts)
{
    PDC_LOG(("wcolor_set() - called\n"));

    if (!win)
        return ERR;

    win->_attrs = (win->_attrs & ~A_COLOR) | COLOR_PAIR(color_pair);

    return OK;
}

int color_set(short color_pair, void *opts)
{
    PDC_LOG(("color_set() - called\n"));

    return wcolor_set(stdscr, color_pair, opts);
}

int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair, void *opts)
{
    PDC_LOG(("wattr_get() - called\n"));

    if (!win)
        return ERR;

    if (attrs)
        *attrs = win->_attrs & (A_ATTRIBUTES & ~A_COLOR);

    if (color_pair)
        *color_pair = PAIR_NUMBER(win->_attrs);

    return OK;
}

int attr_get(attr_t *attrs, short *color_pair, void *opts)
{
    PDC_LOG(("attr_get() - called\n"));

    return wattr_get(stdscr, attrs, color_pair, opts);
}

int wattr_off(WINDOW *win, attr_t attrs, void *opts)
{
    PDC_LOG(("wattr_off() - called\n"));

    return wattroff(win, attrs);
}

int attr_off(attr_t attrs, void *opts)
{
    PDC_LOG(("attr_off() - called\n"));

    return wattroff(stdscr, attrs);
}

int wattr_on(WINDOW *win, attr_t attrs, void *opts)
{
    PDC_LOG(("wattr_off() - called\n"));

    return wattron(win, attrs);
}

int attr_on(attr_t attrs, void *opts)
{
    PDC_LOG(("attr_on() - called\n"));

    return wattron(stdscr, attrs);
}

int wattr_set(WINDOW *win, attr_t attrs, short color_pair, void *opts)
{
    PDC_LOG(("wattr_set() - called\n"));

    if (!win)
        return ERR;

    win->_attrs = (attrs & (A_ATTRIBUTES & ~A_COLOR)) | COLOR_PAIR(color_pair);

    return OK;
}

int attr_set(attr_t attrs, short color_pair, void *opts)
{
    PDC_LOG(("attr_get() - called\n"));

    return wattr_set(stdscr, attrs, color_pair, opts);
}

int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts)
{
    chtype *dest, newattr;
    int startpos, endpos;

    PDC_LOG(("wchgat() - called\n"));

    if (!win)
        return ERR;

    newattr = (attr & A_ATTRIBUTES) | COLOR_PAIR(color);

    startpos = win->_curx;
    endpos = ((n < 0) ? win->_maxx : min(startpos + n, win->_maxx)) - 1;
    dest = win->_y[win->_cury];

    for (n = startpos; n <= endpos; n++)
        dest[n] = (dest[n] & A_CHARTEXT) | newattr;

    n = win->_cury;

    if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
        win->_firstch[n] = startpos;

    if (endpos > win->_lastch[n])
        win->_lastch[n] = endpos;

    PDC_sync(win);

    return OK;
}

int chgat(int n, attr_t attr, short color, const void *opts)
{
    PDC_LOG(("chgat() - called\n"));

    return wchgat(stdscr, n, attr, color, opts);
}

int mvchgat(int y, int x, int n, attr_t attr, short color, const void *opts)
{
    PDC_LOG(("mvchgat() - called\n"));

    if (move(y, x) == ERR)
        return ERR;

    return wchgat(stdscr, n, attr, color, opts);
}

int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr, short color,
             const void *opts)
{
    PDC_LOG(("mvwchgat() - called\n"));

    if (wmove(win, y, x) == ERR)
        return ERR;

    return wchgat(win, n, attr, color, opts);
}