From 6af529f89881b3cfd6cbb03de1ab411ddbaa6dd1 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 27 Jul 2022 18:04:20 +0200 Subject: Add support for prefix-prefixed numerical values for reverse name-lookup (for future internal use) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libgamepad_get_absolute_axis_by_name.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libgamepad_get_absolute_axis_by_name.c') diff --git a/libgamepad_get_absolute_axis_by_name.c b/libgamepad_get_absolute_axis_by_name.c index 4d5aaa4..69b8d6f 100644 --- a/libgamepad_get_absolute_axis_by_name.c +++ b/libgamepad_get_absolute_axis_by_name.c @@ -11,6 +11,7 @@ libgamepad_get_absolute_axis_by_name(const char *name) if (!name || !*name) return -1; if (isdigit(*name)) { + numerical: saved_errno = errno; errno = 0; code = (size_t)strtoul(name, &end, 0); @@ -21,6 +22,12 @@ libgamepad_get_absolute_axis_by_name(const char *name) errno = saved_errno; return (int16_t)code; } else { + if (!strncasecmp(name, "ABS_#", 5)) { + if (isdigit(name[5])) { + name = &name[5]; + goto numerical; + } + } for (code = 0; code < ELEMSOF(libgamepad_absolute_axis_names__); code++) if (!strcasecmp(name, libgamepad_absolute_axis_names__[code])) return (int16_t)code; -- cgit v1.2.3-70-g09d2