varnish-cache/bin/varnishtest/teken_subr_compat.h
0
/*-
1
 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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
 * $FreeBSD: head/sys/teken/teken_subr_compat.h 332297 2018-04-08 19:23:50Z phk $
28
 */
29
30
static void
31 36
teken_subr_cons25_set_border(const teken_t *t, unsigned int c)
32
{
33
34 36
        teken_funcs_param(t, TP_SETBORDER, c);
35 36
}
36
37
static void
38 72
teken_subr_cons25_set_global_cursor_shape(const teken_t *t, unsigned int ncmds,
39
    const unsigned int cmds[])
40
{
41
        unsigned int code, i;
42
43
        /*
44
         * Pack the args to work around API deficiencies.  This requires
45
         * knowing too much about the low level to be fully compatible.
46
         * Returning when ncmds > 3 is necessary and happens to be
47
         * compatible.  Discarding high bits is necessary and happens to
48
         * be incompatible only for invalid args when ncmds == 3.
49
         */
50 72
        if (ncmds > 3)
51 36
                return;
52 36
        code = 0;
53 144
        for (i = ncmds; i > 0; i--)
54 108
                code = (code << 8) | (cmds[i - 1] & 0xff);
55 36
        code = (code << 8) | ncmds;
56 36
        teken_funcs_param(t, TP_SETGLOBALCURSOR, code);
57 72
}
58
59
static void
60 36
teken_subr_cons25_set_local_cursor_type(const teken_t *t, unsigned int type)
61
{
62
63 36
        teken_funcs_param(t, TP_SETLOCALCURSOR, type);
64 36
}
65
66
static const teken_color_t cons25_colors[8] = { TC_BLACK, TC_BLUE,
67
    TC_GREEN, TC_CYAN, TC_RED, TC_MAGENTA, TC_BROWN, TC_WHITE };
68
69
static void
70 36
teken_subr_cons25_set_default_background(teken_t *t, unsigned int c)
71
{
72
73 36
        t->t_defattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8);
74 36
        t->t_curattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8);
75 36
}
76
77
static void
78 36
teken_subr_cons25_set_default_foreground(teken_t *t, unsigned int c)
79
{
80
81 36
        t->t_defattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8);
82 36
        t->t_curattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8);
83 36
}
84
85
static const teken_color_t cons25_revcolors[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
86
87
void
88 1008
teken_get_defattr_cons25(const teken_t *t, int *fg, int *bg)
89
{
90
91 1008
        *fg = cons25_revcolors[teken_256to8(t->t_defattr.ta_fgcolor)];
92 1008
        if (t->t_defattr.ta_format & TF_BOLD)
93 0
                *fg += 8;
94 1008
        *bg = cons25_revcolors[teken_256to8(t->t_defattr.ta_bgcolor)];
95 1008
}
96
97
static void
98 36
teken_subr_cons25_switch_virtual_terminal(const teken_t *t, unsigned int vt)
99
{
100
101 36
        teken_funcs_param(t, TP_SWITCHVT, vt);
102 36
}
103
104
static void
105 36
teken_subr_cons25_set_bell_pitch_duration(const teken_t *t, unsigned int pitch,
106
    unsigned int duration)
107
{
108
109 72
        teken_funcs_param(t, TP_SETBELLPD, (pitch << 16) |
110 36
            (duration & 0xffff));
111 36
}
112
113
static void
114 36
teken_subr_cons25_set_graphic_rendition(teken_t *t, unsigned int cmd,
115
    unsigned int param)
116
{
117
118 36
        (void)param;
119 36
        switch (cmd) {
120
        case 0: /* Reset. */
121 36
                t->t_curattr = t->t_defattr;
122 36
                break;
123
        default:
124
                teken_printf("unsupported attribute %u\n", cmd);
125 0
        }
126 36
}
127
128
static void
129 108
teken_subr_cons25_set_terminal_mode(teken_t *t, unsigned int mode)
130
{
131
132 108
        switch (mode) {
133
        case 0: /* Switch terminal to xterm. */
134 36
                t->t_stateflags &= ~TS_CONS25;
135 36
                break;
136
        case 1: /* Switch terminal to cons25. */
137 36
                t->t_stateflags |= TS_CONS25;
138 36
                break;
139
        default:
140 36
                break;
141
        }
142 108
}
143
144
#if 0
145
static void
146
teken_subr_vt52_decid(teken_t *t)
147
{
148
        const char response[] = "\x1B/Z";
149
150
        teken_funcs_respond(t, response, sizeof response - 1);
151
}
152
#endif