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