aboutsummaryrefslogtreecommitdiffstats
path: root/libgamepad_get_relative_axis_by_name.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-07-26 16:01:13 +0200
committerMattias Andrée <maandree@kth.se>2022-07-26 16:02:05 +0200
commit9de0de4d3d32ab97226fa9868de1fa2290120429 (patch)
tree292473831841529716f97565391303fb9b071c15 /libgamepad_get_relative_axis_by_name.c
parentUpdate information about Sixaxis (diff)
downloadlibgamepad-9de0de4d3d32ab97226fa9868de1fa2290120429.tar.gz
libgamepad-9de0de4d3d32ab97226fa9868de1fa2290120429.tar.bz2
libgamepad-9de0de4d3d32ab97226fa9868de1fa2290120429.tar.xz
Do not relay on libevdev for button/axis names, an prepare for device specific names, and add reverse lookup functions
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--libgamepad_get_relative_axis_by_name.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/libgamepad_get_relative_axis_by_name.c b/libgamepad_get_relative_axis_by_name.c
new file mode 100644
index 0000000..f7f2a72
--- /dev/null
+++ b/libgamepad_get_relative_axis_by_name.c
@@ -0,0 +1,29 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int16_t
+libgamepad_get_relative_axis_by_name(const char *name)
+{
+ size_t code;
+ int saved_errno;
+ char *end;
+ if (!name || !*name)
+ return -1;
+ if (isdigit(*name)) {
+ saved_errno = errno;
+ errno = 0;
+ code = (size_t)strtoul(name, &end, 0);
+ if (errno || *end || code > (size_t)REL_MAX) {
+ errno = saved_errno;
+ return -1;
+ }
+ errno = saved_errno;
+ return (int16_t)code;
+ } else {
+ for (code = 0; code < ELEMSOF(libgamepad_relative_axis_names__); code++)
+ if (!strcasecmp(name, libgamepad_relative_axis_names__[code]))
+ return (int16_t)code;
+ return -1;
+ }
+}