Fixed bug #1121 (More than one device through SDL_JOYSTICK_DEVICE)

Chusslove Illich      2011-02-13 04:30:28 PST

Currently SDL_JOYSTICK_DEVICE environment variable can be used to add
exactly one topmost device. I think it would be nice if one could also set
several devices (e.g. a stick and a throttle) in this way, as a colon-
separated list. The attached patch implements this

--HG--
branch : SDL-1.2
This commit is contained in:
Sam Lantinga 2011-02-16 04:49:07 -08:00
parent 04c6d9c5d9
commit 8a45a9a9ef

View file

@ -417,21 +417,31 @@ int SDL_SYS_JoystickInit(void)
numjoysticks = 0; numjoysticks = 0;
/* First see if the user specified a joystick to use */ /* First see if the user specified one or more joysticks to use */
if ( SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL ) { if ( SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL ) {
SDL_strlcpy(path, SDL_getenv("SDL_JOYSTICK_DEVICE"), sizeof(path)); char *envcopy, *envpath, *delim;
if ( stat(path, &sb) == 0 ) { envcopy = SDL_strdup(SDL_getenv("SDL_JOYSTICK_DEVICE"));
fd = open(path, O_RDONLY, 0); envpath = envcopy;
if ( fd >= 0 ) { while ( envpath != NULL ) {
/* Assume the user knows what they're doing. */ delim = SDL_strchr(envpath, ':');
SDL_joylist[numjoysticks].fname = SDL_strdup(path); if ( delim != NULL ) {
if ( SDL_joylist[numjoysticks].fname ) { *delim++ = '\0';
dev_nums[numjoysticks] = sb.st_rdev;
++numjoysticks;
}
close(fd);
} }
if ( stat(envpath, &sb) == 0 ) {
fd = open(envpath, O_RDONLY, 0);
if ( fd >= 0 ) {
/* Assume the user knows what they're doing. */
SDL_joylist[numjoysticks].fname = SDL_strdup(envpath);
if ( SDL_joylist[numjoysticks].fname ) {
dev_nums[numjoysticks] = sb.st_rdev;
++numjoysticks;
}
close(fd);
}
}
envpath = delim;
} }
SDL_free(envcopy);
} }
for ( i=0; i<SDL_arraysize(joydev_pattern); ++i ) { for ( i=0; i<SDL_arraysize(joydev_pattern); ++i ) {