mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
Remove any duplicate manufacturer in the joystick name
This commit is contained in:
parent
3469481ef6
commit
2a161e7add
@ -88,11 +88,26 @@ static time_t last_input_dir_mtime;
|
|||||||
(((1UL << ((nr) % (sizeof(long) * 8))) & ((addr)[(nr) / (sizeof(long) * 8)])) != 0)
|
(((1UL << ((nr) % (sizeof(long) * 8))) & ((addr)[(nr) / (sizeof(long) * 8)])) != 0)
|
||||||
#define NBITS(x) ((((x)-1)/(sizeof(long) * 8))+1)
|
#define NBITS(x) ((((x)-1)/(sizeof(long) * 8))+1)
|
||||||
|
|
||||||
|
static int
|
||||||
|
PrefixMatch(const char *a, const char *b)
|
||||||
|
{
|
||||||
|
int matchlen = 0;
|
||||||
|
while (*a && *b) {
|
||||||
|
if (*a++ == *b++) {
|
||||||
|
++matchlen;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matchlen;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
|
IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
|
||||||
{
|
{
|
||||||
struct input_id inpid;
|
struct input_id inpid;
|
||||||
Uint16 *guid16 = (Uint16 *)guid->data;
|
Uint16 *guid16 = (Uint16 *)guid->data;
|
||||||
|
const char *spot;
|
||||||
|
|
||||||
#if !SDL_USE_LIBUDEV
|
#if !SDL_USE_LIBUDEV
|
||||||
/* When udev is enabled we only get joystick devices here, so there's no need to test them */
|
/* When udev is enabled we only get joystick devices here, so there's no need to test them */
|
||||||
@ -116,6 +131,15 @@ IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *gui
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Remove duplicate manufacturer in the name */
|
||||||
|
for (spot = namebuf + 1; *spot; ++spot) {
|
||||||
|
int matchlen = PrefixMatch(namebuf, spot);
|
||||||
|
if (matchlen > 0 && spot[matchlen - 1] == ' ') {
|
||||||
|
SDL_memmove(namebuf, spot, SDL_strlen(spot)+1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ioctl(fd, EVIOCGID, &inpid) < 0) {
|
if (ioctl(fd, EVIOCGID, &inpid) < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user