SDL: Allow mapping a controller other than the first one

From a7fde3f835a14d354b48b56850d51a02e9755ef0 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 7 Sep 2022 01:58:42 -0700
Subject: [PATCH] Allow mapping a controller other than the first one

---
 test/controllermap.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/test/controllermap.c b/test/controllermap.c
index 7fb5f687bac..c2bee4016ed 100644
--- a/test/controllermap.c
+++ b/test/controllermap.c
@@ -711,6 +711,7 @@ main(int argc, char *argv[])
 {
     const char *name;
     int i;
+    int joystick_index;
     SDL_Joystick *joystick;
 
     SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
@@ -787,9 +788,16 @@ main(int argc, char *argv[])
         }
     }
 
-    joystick = SDL_JoystickOpen(0);
+    joystick_index = 0;
+    for (i = 1; i < argc; ++i) {
+        if (argv[i] && *argv[i] != '-') {
+            joystick_index = SDL_atoi(argv[i]);
+            break;
+        }
+    }
+    joystick = SDL_JoystickOpen(joystick_index);
     if (joystick == NULL) {
-        SDL_Log("Couldn't open joystick 0: %s\n", SDL_GetError());
+        SDL_Log("Couldn't open joystick %d: %s\n", joystick_index, SDL_GetError());
     } else {
         WatchJoystick(joystick);
         SDL_JoystickClose(joystick);