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
|
/*
* libexplain - Explain errno values returned by libc functions
* Copyright (C) 2009, 2011, 2013 Peter Miller
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libexplain/ac/linux/tiocl.h>
#include <libexplain/ac/stdint.h>
#include <libexplain/ac/string.h>
#include <libexplain/buffer/int.h>
#include <libexplain/buffer/int32_t.h>
#include <libexplain/buffer/int8.h>
#include <libexplain/buffer/pointer.h>
#include <libexplain/buffer/tioclinux.h>
#include <libexplain/parse_bits.h>
#include <libexplain/is_efault.h>
#include <libexplain/sizeof.h>
#ifdef HAVE_LINUX_TIOCL_H
static void
explain_buffer_tiocl(explain_string_buffer_t *sb, int value)
{
static const explain_parse_bits_table_t table[] =
{
{ "TIOCL_SETSEL", TIOCL_SETSEL },
{ "TIOCL_PASTESEL", TIOCL_PASTESEL },
{ "TIOCL_UNBLANKSCREEN", TIOCL_UNBLANKSCREEN },
{ "TIOCL_SELLOADLUT", TIOCL_SELLOADLUT },
{ "TIOCL_GETSHIFTSTATE", TIOCL_GETSHIFTSTATE },
{ "TIOCL_GETMOUSEREPORTING", TIOCL_GETMOUSEREPORTING },
{ "TIOCL_SETVESABLANK", TIOCL_SETVESABLANK },
{ "TIOCL_SETKMSGREDIRECT", TIOCL_SETKMSGREDIRECT },
{ "TIOCL_GETFGCONSOLE", TIOCL_GETFGCONSOLE },
{ "TIOCL_SCROLLCONSOLE", TIOCL_SCROLLCONSOLE },
{ "TIOCL_BLANKSCREEN", TIOCL_BLANKSCREEN },
{ "TIOCL_BLANKEDSCREEN", TIOCL_BLANKEDSCREEN },
#ifdef TIOCL_GETKMSGREDIRECT
{ "TIOCL_GETKMSGREDIRECT", TIOCL_GETKMSGREDIRECT },
#endif
};
explain_parse_bits_print_single(sb, value, table, SIZEOF(table));
}
static void
explain_buffer_tiocl_setsel(explain_string_buffer_t *sb, int value)
{
static const explain_parse_bits_table_t table[] =
{
{ "TIOCL_SELCHAR", TIOCL_SELCHAR },
{ "TIOCL_SELWORD", TIOCL_SELWORD },
{ "TIOCL_SELLINE", TIOCL_SELLINE },
{ "TIOCL_SELPOINTER", TIOCL_SELPOINTER },
{ "TIOCL_SELCLEAR", TIOCL_SELCLEAR },
{ "TIOCL_SELMOUSEREPORT", TIOCL_SELMOUSEREPORT },
{ "TIOCL_SELBUTTONMASK", TIOCL_SELBUTTONMASK },
};
explain_parse_bits_print_single(sb, value, table, SIZEOF(table));
}
void
explain_buffer_tioclinux(explain_string_buffer_t *sb, const void *data)
{
/* See console_ioctl(4) for more information. */
if (!data)
{
print_pointer:
explain_buffer_pointer(sb, data);
}
else
{
const unsigned char *cp;
cp = data;
switch (*cp)
{
case TIOCL_SETSEL:
{
struct tiocl_selection sel;
if (explain_is_efault_pointer(cp, 1 + sizeof(sel)))
goto print_pointer;
memcpy(&sel, cp + 1, sizeof(sel));
explain_buffer_tiocl(sb, cp[0]);
explain_string_buffer_puts(sb, "{ case = ");
explain_buffer_tiocl(sb, cp[0]);
explain_string_buffer_puts(sb, ", xs = ");
explain_buffer_uint(sb, sel.xs);
explain_string_buffer_puts(sb, ", ys = ");
explain_buffer_uint(sb, sel.ys);
explain_string_buffer_puts(sb, ", xe = ");
explain_buffer_uint(sb, sel.xe);
explain_string_buffer_puts(sb, ", ye = ");
explain_buffer_uint(sb, sel.ye);
explain_string_buffer_puts(sb, ", sel_mode = ");
explain_buffer_tiocl_setsel(sb, sel.sel_mode);
explain_string_buffer_puts(sb, " }");
}
break;
case TIOCL_SETVESABLANK:
if (explain_is_efault_pointer(data, 2))
goto print_pointer;
explain_string_buffer_puts(sb, "{ case = ");
explain_buffer_tiocl(sb, cp[0]);
explain_string_buffer_puts(sb, ", value = ");
explain_buffer_uint8(sb, cp[1]);
explain_string_buffer_puts(sb, " }");
break;
case TIOCL_SELLOADLUT:
{
uint32_t lut[8];
if (explain_is_efault_pointer(data, 4 + sizeof(lut)))
goto print_pointer;
memcpy(lut, cp + 4, sizeof(lut));
explain_string_buffer_puts(sb, "{ case = ");
explain_buffer_tiocl(sb, cp[0]);
explain_string_buffer_puts(sb, ", value = ");
explain_buffer_uint32_array(sb, lut, SIZEOF(lut));
explain_string_buffer_puts(sb, " }");
}
break;
case TIOCL_SCROLLCONSOLE:
{
int32_t value;
if (explain_is_efault_pointer(data, 4 + sizeof(value)))
goto print_pointer;
memcpy(&value, cp + 4, sizeof(value));
explain_string_buffer_puts(sb, "{ case = ");
explain_buffer_tiocl(sb, cp[0]);
explain_string_buffer_puts(sb, ", value = ");
explain_buffer_int32_t(sb, value);
explain_string_buffer_puts(sb, " }");
}
break;
case TIOCL_GETSHIFTSTATE:
case TIOCL_GETMOUSEREPORTING:
case TIOCL_SETKMSGREDIRECT:
case TIOCL_GETFGCONSOLE:
/*
* The above 4 cases return data BUT they overwrite the
* control bytes, so we don't know at print_data_returned
* time which code it was, and thus can't print a
* representation. Sigh.
*
* Fall through...
*/
case TIOCL_BLANKEDSCREEN:
case TIOCL_BLANKSCREEN:
case TIOCL_PASTESEL:
case TIOCL_UNBLANKSCREEN:
#ifdef TIOCL_GETKMSGREDIRECT
case TIOCL_GETKMSGREDIRECT:
#endif
default:
if (explain_is_efault_pointer(data, 1))
goto print_pointer;
explain_string_buffer_puts(sb, "{ case = ");
explain_buffer_tiocl(sb, cp[0]);
explain_string_buffer_puts(sb, " }");
break;
}
}
}
#else
void
explain_buffer_tioclinux(explain_string_buffer_t *sb, const void *data)
{
explain_buffer_pointer(sb, data);
}
#endif
/* vim: set ts=8 sw=4 et : */
|