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 80
teken_subr_cons25_set_border(const teken_t *t, unsigned int c)
32
{
33
34 80
        teken_funcs_param(t, TP_SETBORDER, c);
35 80
}
36
37
static void
38 160
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 160
        if (ncmds > 3)
51 80
                return;
52 80
        code = 0;
53 320
        for (i = ncmds; i > 0; i--)
54 240
                code = (code << 8) | (cmds[i - 1] & 0xff);
55 80
        code = (code << 8) | ncmds;
56 80
        teken_funcs_param(t, TP_SETGLOBALCURSOR, code);
57 160
}
58
59
static void
60 80
teken_subr_cons25_set_local_cursor_type(const teken_t *t, unsigned int type)
61
{
62
63 80
        teken_funcs_param(t, TP_SETLOCALCURSOR, type);
64 80
}
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 80
teken_subr_cons25_set_default_background(teken_t *t, unsigned int c)
71
{
72
73 80
        t->t_defattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8);
74 80
        t->t_curattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8);
75 80
}
76
77
static void
78 80
teken_subr_cons25_set_default_foreground(teken_t *t, unsigned int c)
79
{
80
81 80
        t->t_defattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8);
82 80
        t->t_curattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8);
83 80
}
84
85
static const teken_color_t cons25_revcolors[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
86
87
void
88 2240
teken_get_defattr_cons25(const teken_t *t, int *fg, int *bg)
89
{
90
91 2240
        *fg = cons25_revcolors[teken_256to8(t->t_defattr.ta_fgcolor)];
92 2240
        if (t->t_defattr.ta_format & TF_BOLD)
93 0
                *fg += 8;
94 2240
        *bg = cons25_revcolors[teken_256to8(t->t_defattr.ta_bgcolor)];
95 2240
}
96
97
static void
98 80
teken_subr_cons25_switch_virtual_terminal(const teken_t *t, unsigned int vt)
99
{
100
101 80
        teken_funcs_param(t, TP_SWITCHVT, vt);
102 80
}
103
104
static void
105 80
teken_subr_cons25_set_bell_pitch_duration(const teken_t *t, unsigned int pitch,
106
    unsigned int duration)
107
{
108
109 160
        teken_funcs_param(t, TP_SETBELLPD, (pitch << 16) |
110 80
            (duration & 0xffff));
111 80
}
112
113
static void
114 80
teken_subr_cons25_set_graphic_rendition(teken_t *t, unsigned int cmd,
115
    unsigned int param)
116
{
117
118 80
        (void)param;
119 80
        switch (cmd) {
120
        case 0: /* Reset. */
121 80
                t->t_curattr = t->t_defattr;
122 80
                break;
123
        default:
124
                teken_printf("unsupported attribute %u\n", cmd);
125 0
        }
126 80
}
127
128
static void
129 240
teken_subr_cons25_set_terminal_mode(teken_t *t, unsigned int mode)
130
{
131
132 240
        switch (mode) {
133
        case 0: /* Switch terminal to xterm. */
134 80
                t->t_stateflags &= ~TS_CONS25;
135 80
                break;
136
        case 1: /* Switch terminal to cons25. */
137 80
                t->t_stateflags |= TS_CONS25;
138 80
                break;
139
        default:
140 80
                break;
141
        }
142 240
}
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