SDL: Support comma-separated lists in SDL_VIDEODRIVER

From 5ec69285fa365cf417c89d062a33e1148ad2f0c9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luis=20C=C3=A1ceres?= <[EMAIL REDACTED]>
Date: Fri, 2 Apr 2021 06:16:09 +0100
Subject: [PATCH] Support comma-separated lists in SDL_VIDEODRIVER

---
 src/video/SDL_video.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 47f19b188f..f6c25c03df 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -498,11 +498,20 @@ SDL_VideoInit(const char *driver_name)
         driver_name = SDL_getenv("SDL_VIDEODRIVER");
     }
     if (driver_name != NULL) {
-        for (i = 0; bootstrap[i]; ++i) {
-            if (SDL_strncasecmp(bootstrap[i]->name, driver_name, SDL_strlen(driver_name)) == 0) {
-                video = bootstrap[i]->create(index);
-                break;
+        const char *driver_attempt = driver_name;
+        while(driver_attempt != NULL && *driver_attempt != 0 && video == NULL) {
+            const char* driver_attempt_end = SDL_strchr(driver_attempt, ',');
+            size_t driver_attempt_len = (driver_attempt_end != NULL) ? (driver_attempt_end - driver_attempt)
+                                                                     : SDL_strlen(driver_attempt);
+
+            for (i = 0; bootstrap[i]; ++i) {
+                if (SDL_strncasecmp(bootstrap[i]->name, driver_attempt, driver_attempt_len) == 0) {
+                    video = bootstrap[i]->create(index);
+                    break;
+                }
             }
+
+            driver_attempt = (driver_attempt_end != NULL) ? (driver_attempt_end + 1) : NULL;
         }
     } else {
         for (i = 0; bootstrap[i]; ++i) {