From 65f0142fac6515efedd51c59f7ba3aadeda72258 Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Wed, 25 Dec 2013 00:11:28 +0100 Subject: [PATCH] Fixed access of command line arguments on Android in two test programs. --- test/controllermap.c | 11 +++++++---- test/testjoystick.c | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/test/controllermap.c b/test/controllermap.c index 08b85a73aece4..df4c892c68dee 100644 --- a/test/controllermap.c +++ b/test/controllermap.c @@ -386,15 +386,18 @@ main(int argc, char *argv[]) SDL_bool reportederror = SDL_FALSE; SDL_bool keepGoing = SDL_TRUE; SDL_Event event; + int device; #ifdef ANDROID - joystick = SDL_JoystickOpen(0); + device = 0; #else - joystick = SDL_JoystickOpen(atoi(argv[1])); + device = atoi(argv[1]); #endif + joystick = SDL_JoystickOpen(device); + while ( keepGoing ) { if (joystick == NULL) { if ( !reportederror ) { - SDL_Log("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError()); + SDL_Log("Couldn't open joystick %d: %s\n", device, SDL_GetError()); keepGoing = SDL_FALSE; reportederror = SDL_TRUE; } @@ -414,7 +417,7 @@ main(int argc, char *argv[]) || (event.type == SDL_MOUSEBUTTONDOWN)) { keepGoing = SDL_FALSE; } else if (event.type == SDL_JOYDEVICEADDED) { - joystick = SDL_JoystickOpen(atoi(argv[1])); + joystick = SDL_JoystickOpen(device); break; } } diff --git a/test/testjoystick.c b/test/testjoystick.c index 9c4771974ed5b..2984145dcdc8b 100644 --- a/test/testjoystick.c +++ b/test/testjoystick.c @@ -251,15 +251,18 @@ main(int argc, char *argv[]) SDL_bool reportederror = SDL_FALSE; SDL_bool keepGoing = SDL_TRUE; SDL_Event event; + int device; #ifdef ANDROID - joystick = SDL_JoystickOpen(0); + device = 0; #else - joystick = SDL_JoystickOpen(atoi(argv[1])); + device = atoi(argv[1]); #endif + joystick = SDL_JoystickOpen(device); + while ( keepGoing ) { if (joystick == NULL) { if ( !reportederror ) { - SDL_Log("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError()); + SDL_Log("Couldn't open joystick %d: %s\n", device, SDL_GetError()); keepGoing = SDL_FALSE; reportederror = SDL_TRUE; } @@ -279,7 +282,7 @@ main(int argc, char *argv[]) || (event.type == SDL_MOUSEBUTTONDOWN)) { keepGoing = SDL_FALSE; } else if (event.type == SDL_JOYDEVICEADDED) { - joystick = SDL_JoystickOpen(atoi(argv[1])); + joystick = SDL_JoystickOpen(device); break; } }