SDL: Merge commit '84cd7214bdc766beffbbef79ff9df3127fb95a8d' into main

From 84cd7214bdc766beffbbef79ff9df3127fb95a8d Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Wed, 11 Jan 2023 23:26:53 +0100
Subject: [PATCH] SDL_migration.cocci / rename_api.py: handle migration of
 enum/structure and fix previous one in SDL_migration.cocci.

---
 build-scripts/SDL_migration.cocci | 20 ++++++++++----------
 build-scripts/rename_api.py       | 30 ++++++++++++++++++++++++++----
 2 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci
index 37436ebfb3fd..f6e0582889b8 100644
--- a/build-scripts/SDL_migration.cocci
+++ b/build-scripts/SDL_migration.cocci
@@ -540,30 +540,30 @@ SDL_CreateRenderer(e1,
 - SDL_CONTROLLERTOUCHPADUP
 + SDL_GAMEPADTOUCHPADUP
 @@
+typedef SDL_ControllerAxisEvent, SDL_GamepadAxisEvent;
 @@
 - SDL_ControllerAxisEvent
 + SDL_GamepadAxisEvent
-  (...)
 @@
+typedef SDL_ControllerButtonEvent, SDL_GamepadButtonEvent;
 @@
 - SDL_ControllerButtonEvent
 + SDL_GamepadButtonEvent
-  (...)
 @@
+typedef SDL_ControllerDeviceEvent, SDL_GamepadDeviceEvent;
 @@
 - SDL_ControllerDeviceEvent
 + SDL_GamepadDeviceEvent
-  (...)
 @@
+typedef SDL_ControllerSensorEvent, SDL_GamepadSensorEvent;
 @@
 - SDL_ControllerSensorEvent
 + SDL_GamepadSensorEvent
-  (...)
 @@
+typedef SDL_ControllerTouchpadEvent, SDL_GamepadTouchpadEvent;
 @@
 - SDL_ControllerTouchpadEvent
 + SDL_GamepadTouchpadEvent
-  (...)
 @@
 @@
 - SDL_CONTROLLER_AXIS_INVALID
@@ -761,10 +761,10 @@ SDL_CreateRenderer(e1,
 - SDL_CONTROLLER_TYPE_XBOXONE
 + SDL_GAMEPAD_TYPE_XBOXONE
 @@
+typedef SDL_GameController, SDL_Gamepad;
 @@
 - SDL_GameController
 + SDL_Gamepad
-  (...)
 @@
 @@
 - SDL_GameControllerAddMapping
@@ -781,25 +781,25 @@ SDL_CreateRenderer(e1,
 + SDL_AddGamepadMappingsFromRW
   (...)
 @@
+typedef SDL_GameControllerAxis, SDL_GamepadAxis;
 @@
 - SDL_GameControllerAxis
 + SDL_GamepadAxis
-  (...)
 @@
+typedef SDL_GameControllerBindType, SDL_GamepadBindingType;
 @@
 - SDL_GameControllerBindType
 + SDL_GamepadBindingType
-  (...)
 @@
+typedef SDL_GameControllerButton, SDL_GamepadButton;
 @@
 - SDL_GameControllerButton
 + SDL_GamepadButton
-  (...)
 @@
+typedef SDL_GameControllerButtonBind, SDL_GamepadBinding;
 @@
 - SDL_GameControllerButtonBind
 + SDL_GamepadBinding
-  (...)
 @@
 @@
 - SDL_GameControllerClose
diff --git a/build-scripts/rename_api.py b/build-scripts/rename_api.py
index 98c68d471ee9..fe0ac67854a0 100755
--- a/build-scripts/rename_api.py
+++ b/build-scripts/rename_api.py
@@ -88,12 +88,34 @@ def add_content(lines, i, content, add_trailing_line):
 def add_symbol_to_coccinelle(symbol_type, oldname, newname):
     file = open(SDL_BUILD_SCRIPTS / "SDL_migration.cocci", "a")
     # Append-adds at last
-    file.write("@@\n")
-    file.write("@@\n")
-    file.write("- %s\n" % oldname)
-    file.write("+ %s\n" % newname)
+
     if symbol_type == "function":
+        file.write("@@\n")
+        file.write("@@\n")
+        file.write("- %s\n" % oldname)
+        file.write("+ %s\n" % newname)
         file.write("  (...)\n")
+
+    if symbol_type == "symbol":
+        file.write("@@\n")
+        file.write("@@\n")
+        file.write("- %s\n" % oldname)
+        file.write("+ %s\n" % newname)
+
+    # double check ?
+    if symbol_type == "hint":
+        file.write("@@\n")
+        file.write("@@\n")
+        file.write("- %s\n" % oldname)
+        file.write("+ %s\n" % newname)
+
+    if symbol_type == "enum" or symbol_type == "structure":
+        file.write("@@\n")
+        file.write("typedef %s, %s;\n" % (oldname, newname))
+        file.write("@@\n")
+        file.write("- %s\n" % oldname)
+        file.write("+ %s\n" % newname)
+
     file.close()