mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-29 00:55:22 +00:00
6a4d938dd3
Missing semicolon at the end of macros can confuse some analyzers (like cppcheck <filename>), and we have a mix of semicolon and non-semicolon usage through the code. Let's standardize on using a semicolon for VIR_ENUM_IMPL calls. Move the verify() statement to the end of the macro and drop the semicolon, so the compiler will require callers to add a semicolon. While we are touching these call sites, standardize on putting the closing parenth on its own line, as discussed here: https://www.redhat.com/archives/libvir-list/2019-January/msg00750.html Reviewed-by: John Ferlan <jferlan@redhat.com> Signed-off-by: Cole Robinson <crobinso@redhat.com>
121 lines
4.0 KiB
C
121 lines
4.0 KiB
C
/*
|
|
* Copyright (c) 2011 Lai Jiangshan
|
|
*
|
|
* This library 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 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library 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 library. If not, see
|
|
* <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
#include <config.h>
|
|
#include "virkeycode.h"
|
|
#include <stddef.h>
|
|
|
|
#include "virkeycodetable_atset1.h"
|
|
#include "virkeycodetable_atset2.h"
|
|
#include "virkeycodetable_atset3.h"
|
|
#include "virkeycodetable_linux.h"
|
|
#include "virkeycodetable_osx.h"
|
|
#include "virkeycodetable_qnum.h"
|
|
#include "virkeycodetable_usb.h"
|
|
#include "virkeycodetable_win32.h"
|
|
#include "virkeycodetable_xtkbd.h"
|
|
#include "virkeynametable_linux.h"
|
|
#include "virkeynametable_osx.h"
|
|
#include "virkeynametable_win32.h"
|
|
|
|
static const char **virKeymapNames[VIR_KEYCODE_SET_LAST] = {
|
|
[VIR_KEYCODE_SET_LINUX] = virKeyNameTable_linux,
|
|
[VIR_KEYCODE_SET_OSX] = virKeyNameTable_osx,
|
|
[VIR_KEYCODE_SET_WIN32] = virKeyNameTable_win32,
|
|
};
|
|
|
|
static const unsigned short *virKeymapValues[VIR_KEYCODE_SET_LAST] = {
|
|
[VIR_KEYCODE_SET_LINUX] = virKeyCodeTable_linux,
|
|
/* XT is same as AT Set1 - it was included by mistake */
|
|
[VIR_KEYCODE_SET_XT] = virKeyCodeTable_atset1,
|
|
[VIR_KEYCODE_SET_ATSET1] = virKeyCodeTable_atset1,
|
|
[VIR_KEYCODE_SET_ATSET2] = virKeyCodeTable_atset2,
|
|
[VIR_KEYCODE_SET_ATSET3] = virKeyCodeTable_atset3,
|
|
[VIR_KEYCODE_SET_OSX] = virKeyCodeTable_osx,
|
|
[VIR_KEYCODE_SET_XT_KBD] = virKeyCodeTable_xtkbd,
|
|
[VIR_KEYCODE_SET_USB] = virKeyCodeTable_usb,
|
|
[VIR_KEYCODE_SET_WIN32] = virKeyCodeTable_win32,
|
|
[VIR_KEYCODE_SET_QNUM] = virKeyCodeTable_qnum,
|
|
};
|
|
|
|
#define VIR_KEYMAP_ENTRY_MAX ARRAY_CARDINALITY(virKeyCodeTable_linux)
|
|
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_atset1));
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_atset2));
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_atset3));
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_osx));
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_xtkbd));
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_usb));
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_win32));
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_qnum));
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyNameTable_linux));
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyNameTable_osx));
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyNameTable_win32));
|
|
|
|
VIR_ENUM_IMPL(virKeycodeSet, VIR_KEYCODE_SET_LAST,
|
|
"linux",
|
|
"xt",
|
|
"atset1",
|
|
"atset2",
|
|
"atset3",
|
|
"os_x",
|
|
"xt_kbd",
|
|
"usb",
|
|
"win32",
|
|
"qnum",
|
|
);
|
|
|
|
int virKeycodeValueFromString(virKeycodeSet codeset,
|
|
const char *keyname)
|
|
{
|
|
size_t i;
|
|
|
|
for (i = 0; i < VIR_KEYMAP_ENTRY_MAX; i++) {
|
|
if (!virKeymapNames[codeset] ||
|
|
!virKeymapValues[codeset])
|
|
continue;
|
|
|
|
const char *name = virKeymapNames[codeset][i];
|
|
|
|
if (name && STREQ_NULLABLE(name, keyname))
|
|
return virKeymapValues[codeset][i];
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
|
|
int virKeycodeValueTranslate(virKeycodeSet from_codeset,
|
|
virKeycodeSet to_codeset,
|
|
int key_value)
|
|
{
|
|
size_t i;
|
|
|
|
if (key_value < 0)
|
|
return -1;
|
|
|
|
|
|
for (i = 0; i < VIR_KEYMAP_ENTRY_MAX; i++) {
|
|
if (virKeymapValues[from_codeset][i] == key_value)
|
|
return virKeymapValues[to_codeset][i];
|
|
}
|
|
|
|
return -1;
|
|
}
|