Code Coverage: vinyl-cache/bin/vinyltest/vtest2/src/teken_subr_compat.h
 
82217aa4fc7094b3610340078afaf78cd95a8ec9
 
0
/*-
1
 * SPDX-License-Identifier: BSD-2-Clause
2
 *
3
 * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 * 1. Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 *    notice, this list of conditions and the following disclaimer in the
13
 *    documentation and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
 * SUCH DAMAGE.
26
 */
27
28
static void
29
teken_subr_cons25_set_border(const teken_t *t, unsigned int c)
30 2
{
31
32 2
        teken_funcs_param(t, TP_SETBORDER, c);
33 2
}
34
35
static void
36
teken_subr_cons25_set_global_cursor_shape(const teken_t *t, unsigned int ncmds,
37
    const unsigned int cmds[])
38 4
{
39 4
        unsigned int code, i;
40
41
        /*
42
         * Pack the args to work around API deficiencies.  This requires
43
         * knowing too much about the low level to be fully compatible.
44
         * Returning when ncmds > 3 is necessary and happens to be
45
         * compatible.  Discarding high bits is necessary and happens to
46
         * be incompatible only for invalid args when ncmds == 3.
47
         */
48 4
        if (ncmds > 3)
49 2
                return;
50 2
        code = 0;
51 8
        for (i = ncmds; i > 0; i--)
52 6
                code = (code << 8) | (cmds[i - 1] & 0xff);
53 2
        code = (code << 8) | ncmds;
54 2
        teken_funcs_param(t, TP_SETGLOBALCURSOR, code);
55 2
}
56
57
static void
58
teken_subr_cons25_set_local_cursor_type(const teken_t *t, unsigned int type)
59 2
{
60
61 2
        teken_funcs_param(t, TP_SETLOCALCURSOR, type);
62 2
}
63
64
static const teken_color_t cons25_colors[8] = { TC_BLACK, TC_BLUE,
65
    TC_GREEN, TC_CYAN, TC_RED, TC_MAGENTA, TC_YELLOW, TC_WHITE };
66
67
static void
68
teken_subr_cons25_set_default_background(teken_t *t, unsigned int c)
69 2
{
70
71 2
        t->t_defattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8);
72 2
        t->t_curattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8);
73 2
}
74
75
static void
76
teken_subr_cons25_set_default_foreground(teken_t *t, unsigned int c)
77 2
{
78
79 2
        t->t_defattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8);
80 2
        t->t_curattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8);
81 2
}
82
83
static const teken_color_t cons25_revcolors[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
84
85
void
86
teken_get_defattr_cons25(const teken_t *t, int *fg, int *bg)
87 59
{
88
89 59
        *fg = cons25_revcolors[teken_256to8(t->t_defattr.ta_fgcolor)];
90 59
        if (t->t_defattr.ta_format & TF_BOLD)
91 0
                *fg += 8;
92 59
        *bg = cons25_revcolors[teken_256to8(t->t_defattr.ta_bgcolor)];
93 59
}
94
95
static void
96
teken_subr_cons25_switch_virtual_terminal(const teken_t *t, unsigned int vt)
97 2
{
98
99 2
        teken_funcs_param(t, TP_SWITCHVT, vt);
100 2
}
101
102
static void
103
teken_subr_cons25_set_bell_pitch_duration(const teken_t *t, unsigned int pitch,
104
    unsigned int duration)
105 2
{
106
107 2
        teken_funcs_param(t, TP_SETBELLPD, (pitch << 16) |
108 2
            (duration & 0xffff));
109 2
}
110
111
static void
112
teken_subr_cons25_set_graphic_rendition(teken_t *t, unsigned int cmd,
113
    unsigned int param)
114 2
{
115
116 2
        (void)param;
117 2
        switch (cmd) {
118 2
        case 0: /* Reset. */
119 2
                t->t_curattr = t->t_defattr;
120 2
                break;
121 0
        default:
122 0
                teken_printf("unsupported attribute %u\n", cmd);
123 2
        }
124 2
}
125
126
static void
127
teken_subr_cons25_set_terminal_mode(teken_t *t, unsigned int mode)
128 6
{
129
130 6
        switch (mode) {
131 2
        case 0: /* Switch terminal to xterm. */
132 2
                t->t_stateflags &= ~TS_CONS25;
133 2
                break;
134 2
        case 1: /* Switch terminal to cons25. */
135 2
                t->t_stateflags |= TS_CONS25;
136 2
                break;
137 2
        default:
138 2
                break;
139 6
        }
140 6
}
141
142
#if 0
143
static void
144
teken_subr_vt52_decid(teken_t *t)
145
{
146
        const char response[] = "\x1B/Z";
147
148
        teken_funcs_respond(t, response, sizeof response - 1);
149
}
150
#endif