diff options
author | Mattias Andrée <maandree@kth.se> | 2022-07-27 18:04:20 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-07-27 18:04:20 +0200 |
commit | 6af529f89881b3cfd6cbb03de1ab411ddbaa6dd1 (patch) | |
tree | 1dda09d69a8b48c08b82748da3f7dfa9fb1c9da2 /libgamepad_get_button_by_name.c | |
parent | Add inline functions for testing support (diff) | |
download | libgamepad-6af529f89881b3cfd6cbb03de1ab411ddbaa6dd1.tar.gz libgamepad-6af529f89881b3cfd6cbb03de1ab411ddbaa6dd1.tar.bz2 libgamepad-6af529f89881b3cfd6cbb03de1ab411ddbaa6dd1.tar.xz |
Add support for prefix-prefixed numerical values for reverse name-lookup (for future internal use)
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libgamepad_get_button_by_name.c')
-rw-r--r-- | libgamepad_get_button_by_name.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/libgamepad_get_button_by_name.c b/libgamepad_get_button_by_name.c index 2b37e93..63af9d8 100644 --- a/libgamepad_get_button_by_name.c +++ b/libgamepad_get_button_by_name.c @@ -27,6 +27,7 @@ libgamepad_get_button_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); @@ -37,6 +38,12 @@ libgamepad_get_button_by_name(const char *name) errno = saved_errno; return (int16_t)code; } else { + if (!strncasecmp(name, "KEY_#", 5) || !strncasecmp(name, "BTN_#", 5)) { + if (isdigit(name[5])) { + name = &name[5]; + goto numerical; + } + } for (code = 0; code < ELEMSOF(libgamepad_button_names__); code++) if (!strcasecmp(name, libgamepad_button_names__[code])) return (int16_t)code; |