blob: f82ba0af26e4112c45843dd475d5566bad9a4fe5 (
plain) (
tree)
|
|
/* 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)) {
numerical:
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 if (!strncasecmp(name, "REL_#", 5)) {
if (isdigit(name[5])) {
name = &name[5];
goto numerical;
}
for (code = 0; code < ELEMSOF(libgamepad_relative_axis_names__); code++)
if (!strcasecmp(name, libgamepad_relative_axis_names__[code]))
return (int16_t)code;
}
return -1;
}
|