src/joystick/SDL_gamecontroller.c
changeset 7191 75360622e65f
parent 7181 d35a0936c674
child 7247 6a4570f12c20
--- a/src/joystick/SDL_gamecontroller.c	Sat May 18 12:48:50 2013 -0700
+++ b/src/joystick/SDL_gamecontroller.c	Sat May 18 14:17:52 2013 -0700
@@ -39,8 +39,8 @@
 /* keep track of the hat and mask value that transforms this hat movement into a button/axis press */
 struct _SDL_HatMapping
 {
-	int hat;
-	Uint8 mask;
+    int hat;
+    Uint8 mask;
 };
 
 #define k_nMaxReverseEntries 20
@@ -54,24 +54,24 @@
 /* our in memory mapping db between joystick objects and controller mappings*/
 struct _SDL_ControllerMapping
 {
-	SDL_JoystickGUID guid;
-	const char *name;
+    SDL_JoystickGUID guid;
+    const char *name;
 
-	// mapping of axis/button id to controller version
-	int axes[SDL_CONTROLLER_AXIS_MAX];
-	int buttonasaxis[SDL_CONTROLLER_AXIS_MAX];
+    /* mapping of axis/button id to controller version */
+    int axes[SDL_CONTROLLER_AXIS_MAX];
+    int buttonasaxis[SDL_CONTROLLER_AXIS_MAX];
 
-	int buttons[SDL_CONTROLLER_BUTTON_MAX];
-	int axesasbutton[SDL_CONTROLLER_BUTTON_MAX];
-	struct _SDL_HatMapping hatasbutton[SDL_CONTROLLER_BUTTON_MAX];
+    int buttons[SDL_CONTROLLER_BUTTON_MAX];
+    int axesasbutton[SDL_CONTROLLER_BUTTON_MAX];
+    struct _SDL_HatMapping hatasbutton[SDL_CONTROLLER_BUTTON_MAX];
 
-	// reverse mapping, joystick indices to buttons
-	SDL_GameControllerAxis raxes[k_nMaxReverseEntries];
-	SDL_GameControllerAxis rbuttonasaxis[k_nMaxReverseEntries];
+    /* reverse mapping, joystick indices to buttons */
+    SDL_GameControllerAxis raxes[k_nMaxReverseEntries];
+    SDL_GameControllerAxis rbuttonasaxis[k_nMaxReverseEntries];
 
-	SDL_GameControllerButton rbuttons[k_nMaxReverseEntries];
-	SDL_GameControllerButton raxesasbutton[k_nMaxReverseEntries];
-	SDL_GameControllerButton rhatasbutton[k_nMaxHatEntries];
+    SDL_GameControllerButton rbuttons[k_nMaxReverseEntries];
+    SDL_GameControllerButton raxesasbutton[k_nMaxReverseEntries];
+    SDL_GameControllerButton rhatasbutton[k_nMaxHatEntries];
 
 };
 
@@ -79,10 +79,10 @@
 /* our hard coded list of mapping support */
 typedef struct _ControllerMapping_t
 {
-	SDL_JoystickGUID guid;
-	char *name;
-	char *mapping;
-	struct _ControllerMapping_t *next;
+    SDL_JoystickGUID guid;
+    char *name;
+    char *mapping;
+    struct _ControllerMapping_t *next;
 } ControllerMapping_t;
 
 
@@ -90,33 +90,33 @@
 const char *s_ControllerMappings [] =
 {
 #ifdef SDL_JOYSTICK_DINPUT
-	"xinput,X360 Controller,a:b10,b:b11,y:b13,x:b12,start:b4,guide:b14,back:b5,dpup:b0,dpleft:b2,dpdown:b1,dpright:b3,leftshoulder:b8,rightshoulder:b9,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5",
-	"341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7",
-	"88880803000000000000504944564944,PS3 Controller,a:b2,b:b1,x:b0,y:b3,start:b11,back:b8,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,guide:b12",
-	"4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,y:b12,x:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9,",
-	"25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,x:b0,y:b3,start:b8,guide:,back:b9,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5",
+    "xinput,X360 Controller,a:b10,b:b11,y:b13,x:b12,start:b4,guide:b14,back:b5,dpup:b0,dpleft:b2,dpdown:b1,dpright:b3,leftshoulder:b8,rightshoulder:b9,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5",
+    "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7",
+    "88880803000000000000504944564944,PS3 Controller,a:b2,b:b1,x:b0,y:b3,start:b11,back:b8,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,guide:b12",
+    "4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,y:b12,x:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9,",
+    "25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,x:b0,y:b3,start:b8,guide:,back:b9,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5",
     "ffff0000000000000000504944564944,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,",
     "6d0416c2000000000000504944564944,Generic DirectInput Controller,a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,",
 #elif defined(__MACOSX__)
-	"5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftshoulder:b4,rightshoulder:b5,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5",
-	"4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,x:b12,y:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b6,dpdown:b7,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9",
+    "5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftshoulder:b4,rightshoulder:b5,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5",
+    "4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,x:b12,y:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b6,dpdown:b7,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9",
     "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,",
     "6d040000000000001fc2000000000000,Logitech F710 Gamepad Controller (XInput),a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,leftstick:b6,rightstick:b7,leftshoulder:b4,rightshoulder:b5,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,",
-    "6d0400000000000016c2000000000000,Logitech F310 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", // Guide button doesn't seem to be sent in DInput mode.
-    "6d0400000000000019c2000000000000,Logitech Wireless Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", // This includes F710 in DInput mode and the "Logitech Cordless RumblePad 2", at the very least.
+    "6d0400000000000016c2000000000000,Logitech F310 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", /* Guide button doesn't seem to be sent in DInput mode. */
+    "6d0400000000000019c2000000000000,Logitech Wireless Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", /* This includes F710 in DInput mode and the "Logitech Cordless RumblePad 2", at the very least. */
 #elif defined(__LINUX__)
-	"030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5",
+    "030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5",
     "030000005e0400008e02000010010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,",
     "030000005e0400001907000000010000,X360 Wireless Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:b13,dpleft:b11,dpdown:b14,dpright:b12,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,",
-	"030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,x:b15,y:b12,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9",
+    "030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,x:b15,y:b12,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9",
     "030000006d0400001fc2000005030000,Logitech F710 Gamepad Controller (XInput),a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,",
-    "030000006d04000019c2000011010000,Logitech F710 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", // Guide button doesn't seem to be sent in DInput mode.
+    "030000006d04000019c2000011010000,Logitech F710 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", /* Guide button doesn't seem to be sent in DInput mode. */
     "030000006d0400001dc2000014400000,Logitech F310 Gamepad (XInput),a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,",
     "030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,y:b3,x:b0,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,",
     "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,",
     "03000000ba2200002010000001010000,Jess Technology USB Game Controller,start:b9,a:b2,b:b1,x:b3,y:b0,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b6,righttrigger:b7,leftshoulder:b4,rightshoulder:b5,guide:,back:b8",
 #endif
-	NULL
+    NULL
 };
 
 static ControllerMapping_t *s_pSupportedControllers = NULL;
@@ -127,166 +127,166 @@
 /* The SDL game controller structure */
 struct _SDL_GameController
 {
-	SDL_Joystick *joystick;	/* underlying joystick device */
-	int ref_count;
-	Uint8 hatState[4]; /* the current hat state for this controller */
-	struct _SDL_ControllerMapping mapping; /* the mapping object for this controller */
-	struct _SDL_GameController *next; /* pointer to next game controller we have allocated */
+    SDL_Joystick *joystick; /* underlying joystick device */
+    int ref_count;
+    Uint8 hatState[4]; /* the current hat state for this controller */
+    struct _SDL_ControllerMapping mapping; /* the mapping object for this controller */
+    struct _SDL_GameController *next; /* pointer to next game controller we have allocated */
 };
 
 
 int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value);
-int	SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state);
+int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state);
 
 /*
  * Event filter to fire controller events from joystick ones
  */
 int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
 {
-	switch( event->type )
-	{
-	case SDL_JOYAXISMOTION:
-		{
-			SDL_GameController *controllerlist;
+    switch( event->type )
+    {
+    case SDL_JOYAXISMOTION:
+        {
+            SDL_GameController *controllerlist;
 
-			if ( event->jaxis.axis >= k_nMaxReverseEntries ) break;
+            if ( event->jaxis.axis >= k_nMaxReverseEntries ) break;
 
-			controllerlist = SDL_gamecontrollers;
-			while ( controllerlist )
-			{
-				if ( controllerlist->joystick->instance_id == event->jaxis.which )
-				{
-					if ( controllerlist->mapping.raxes[event->jaxis.axis] >= 0 ) // simple axis to axis, send it through
-					{
-						SDL_GameControllerAxis axis = controllerlist->mapping.raxes[event->jaxis.axis];
+            controllerlist = SDL_gamecontrollers;
+            while ( controllerlist )
+            {
+                if ( controllerlist->joystick->instance_id == event->jaxis.which )
+                {
+                    if ( controllerlist->mapping.raxes[event->jaxis.axis] >= 0 ) /* simple axis to axis, send it through */
+                    {
+                        SDL_GameControllerAxis axis = controllerlist->mapping.raxes[event->jaxis.axis];
                         Sint16 value = event->jaxis.value;
-						switch (axis)
-						{
-							case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
-							case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
-								/* Shift it to be 0 - 32767. */
-								value = value / 2 + 16384;
-							default:
-								break;
-						}
-						SDL_PrivateGameControllerAxis( controllerlist, axis, value );
-					}
-					else if ( controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0 ) // simulate an axis as a button
-					{
-						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.raxesasbutton[event->jaxis.axis], ABS(event->jaxis.value) > 32768/2 ? SDL_PRESSED : SDL_RELEASED );
-					}
-					break;
-				}
-				controllerlist = controllerlist->next;
-			}
-		}
-		break;
-	case SDL_JOYBUTTONDOWN:
-	case SDL_JOYBUTTONUP:
-		{
-			SDL_GameController *controllerlist;
+                        switch (axis)
+                        {
+                            case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
+                            case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
+                                /* Shift it to be 0 - 32767. */
+                                value = value / 2 + 16384;
+                            default:
+                                break;
+                        }
+                        SDL_PrivateGameControllerAxis( controllerlist, axis, value );
+                    }
+                    else if ( controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0 ) /* simulate an axis as a button */
+                    {
+                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.raxesasbutton[event->jaxis.axis], ABS(event->jaxis.value) > 32768/2 ? SDL_PRESSED : SDL_RELEASED );
+                    }
+                    break;
+                }
+                controllerlist = controllerlist->next;
+            }
+        }
+        break;
+    case SDL_JOYBUTTONDOWN:
+    case SDL_JOYBUTTONUP:
+        {
+            SDL_GameController *controllerlist;
 
-			if ( event->jbutton.button >= k_nMaxReverseEntries ) break;
+            if ( event->jbutton.button >= k_nMaxReverseEntries ) break;
 
-			controllerlist = SDL_gamecontrollers;
-			while ( controllerlist )
-			{
-				if ( controllerlist->joystick->instance_id == event->jbutton.which )
-				{
-					if ( controllerlist->mapping.rbuttons[event->jbutton.button] >= 0 ) // simple button as button
-					{
-						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rbuttons[event->jbutton.button], event->jbutton.state );
-					}
-					else if ( controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0 ) // an button pretending to be an axis
-					{
-						SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32767 : 0 );
-					}
-					break;
-				}
-				controllerlist = controllerlist->next;
-			}
-		}
-		break;
-	case SDL_JOYHATMOTION:
-		{
-			SDL_GameController *controllerlist;
+            controllerlist = SDL_gamecontrollers;
+            while ( controllerlist )
+            {
+                if ( controllerlist->joystick->instance_id == event->jbutton.which )
+                {
+                    if ( controllerlist->mapping.rbuttons[event->jbutton.button] >= 0 ) /* simple button as button */
+                    {
+                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rbuttons[event->jbutton.button], event->jbutton.state );
+                    }
+                    else if ( controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0 ) /* an button pretending to be an axis */
+                    {
+                        SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32767 : 0 );
+                    }
+                    break;
+                }
+                controllerlist = controllerlist->next;
+            }
+        }
+        break;
+    case SDL_JOYHATMOTION:
+        {
+            SDL_GameController *controllerlist;
 
-			if ( event->jhat.hat >= 4 ) break;
+            if ( event->jhat.hat >= 4 ) break;
 
-			controllerlist = SDL_gamecontrollers;
-			while ( controllerlist )
-			{
-				if ( controllerlist->joystick->instance_id == event->jhat.which )
-				{
-					Uint8 bSame = controllerlist->hatState[event->jhat.hat] & event->jhat.value;
-					// Get list of removed bits (button release)
-					Uint8 bChanged = controllerlist->hatState[event->jhat.hat] ^ bSame;
-					// the hat idx in the high nibble
-					int bHighHat = event->jhat.hat << 4;
+            controllerlist = SDL_gamecontrollers;
+            while ( controllerlist )
+            {
+                if ( controllerlist->joystick->instance_id == event->jhat.which )
+                {
+                    Uint8 bSame = controllerlist->hatState[event->jhat.hat] & event->jhat.value;
+                    /* Get list of removed bits (button release) */
+                    Uint8 bChanged = controllerlist->hatState[event->jhat.hat] ^ bSame;
+                    /* the hat idx in the high nibble */
+                    int bHighHat = event->jhat.hat << 4;
 
-					if ( bChanged & SDL_HAT_DOWN )
-						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_DOWN], SDL_RELEASED );
-					if ( bChanged & SDL_HAT_UP )
-						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_UP], SDL_RELEASED );
-					if ( bChanged & SDL_HAT_LEFT )
-						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_LEFT], SDL_RELEASED );
-					if ( bChanged & SDL_HAT_RIGHT )
-						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_RIGHT], SDL_RELEASED );
+                    if ( bChanged & SDL_HAT_DOWN )
+                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_DOWN], SDL_RELEASED );
+                    if ( bChanged & SDL_HAT_UP )
+                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_UP], SDL_RELEASED );
+                    if ( bChanged & SDL_HAT_LEFT )
+                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_LEFT], SDL_RELEASED );
+                    if ( bChanged & SDL_HAT_RIGHT )
+                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_RIGHT], SDL_RELEASED );
 
-					// Get list of added bits (button press)
-					bChanged = event->jhat.value ^ bSame;
+                    /* Get list of added bits (button press) */
+                    bChanged = event->jhat.value ^ bSame;
 
-					if ( bChanged & SDL_HAT_DOWN )
-						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_DOWN], SDL_PRESSED );
-					if ( bChanged & SDL_HAT_UP )
-						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_UP], SDL_PRESSED );
-					if ( bChanged & SDL_HAT_LEFT )
-						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_LEFT], SDL_PRESSED );
-					if ( bChanged & SDL_HAT_RIGHT )
-						SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_RIGHT], SDL_PRESSED );
+                    if ( bChanged & SDL_HAT_DOWN )
+                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_DOWN], SDL_PRESSED );
+                    if ( bChanged & SDL_HAT_UP )
+                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_UP], SDL_PRESSED );
+                    if ( bChanged & SDL_HAT_LEFT )
+                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_LEFT], SDL_PRESSED );
+                    if ( bChanged & SDL_HAT_RIGHT )
+                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_RIGHT], SDL_PRESSED );
 
-					// update our state cache
-					controllerlist->hatState[event->jhat.hat] = event->jhat.value;
+                    /* update our state cache */
+                    controllerlist->hatState[event->jhat.hat] = event->jhat.value;
 
-					break;
-				}
-				controllerlist = controllerlist->next;
-			}
-		}
-		break;
-	case SDL_JOYDEVICEADDED:
-		{
-			if ( SDL_IsGameController(event->jdevice.which ) )
-			{
-				SDL_Event deviceevent;
-				deviceevent.type = SDL_CONTROLLERDEVICEADDED;
-				deviceevent.cdevice.which = event->jdevice.which;
-				SDL_PushEvent(&deviceevent);
-			}
-		}
-		break;
-	case SDL_JOYDEVICEREMOVED:
-		{
-			SDL_GameController *controllerlist = SDL_gamecontrollers;
-			while ( controllerlist )
-			{
-				if ( controllerlist->joystick->instance_id == event->jdevice.which )
-				{
-					SDL_Event deviceevent;
-					deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
-					deviceevent.cdevice.which = event->jdevice.which;
-					SDL_PushEvent(&deviceevent);
-					break;
-				}
-				controllerlist = controllerlist->next;
-			}
-		}
-		break;
-	default:
-		break;
-	}
+                    break;
+                }
+                controllerlist = controllerlist->next;
+            }
+        }
+        break;
+    case SDL_JOYDEVICEADDED:
+        {
+            if ( SDL_IsGameController(event->jdevice.which ) )
+            {
+                SDL_Event deviceevent;
+                deviceevent.type = SDL_CONTROLLERDEVICEADDED;
+                deviceevent.cdevice.which = event->jdevice.which;
+                SDL_PushEvent(&deviceevent);
+            }
+        }
+        break;
+    case SDL_JOYDEVICEREMOVED:
+        {
+            SDL_GameController *controllerlist = SDL_gamecontrollers;
+            while ( controllerlist )
+            {
+                if ( controllerlist->joystick->instance_id == event->jdevice.which )
+                {
+                    SDL_Event deviceevent;
+                    deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
+                    deviceevent.cdevice.which = event->jdevice.which;
+                    SDL_PushEvent(&deviceevent);
+                    break;
+                }
+                controllerlist = controllerlist->next;
+            }
+        }
+        break;
+    default:
+        break;
+    }
 
-	return 1;
+    return 1;
 }
 
 /*
@@ -294,15 +294,15 @@
  */
 ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid)
 {
-	ControllerMapping_t *pSupportedController = s_pSupportedControllers;
-	while ( pSupportedController )
-	{
-		if ( !SDL_memcmp( guid, &pSupportedController->guid, sizeof(*guid) ) )
-		{
-			return pSupportedController;
-		}
-		pSupportedController = pSupportedController->next;
-	}
+    ControllerMapping_t *pSupportedController = s_pSupportedControllers;
+    while ( pSupportedController )
+    {
+        if ( !SDL_memcmp( guid, &pSupportedController->guid, sizeof(*guid) ) )
+        {
+            return pSupportedController;
+        }
+        pSupportedController = pSupportedController->next;
+    }
     return NULL;
 }
 
@@ -312,18 +312,18 @@
 ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
 {
 #ifdef SDL_JOYSTICK_DINPUT
-	if ( SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping )
-	{
-		return s_pXInputMapping;
-	}
-	else
+    if ( SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping )
+    {
+        return s_pXInputMapping;
+    }
+    else
 #endif
-	{
-		SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
-		return SDL_PrivateGetControllerMappingForGUID(&jGUID);
-	}
+    {
+        SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
+        return SDL_PrivateGetControllerMappingForGUID(&jGUID);
+    }
 
-	return NULL;
+    return NULL;
 }
 
 static const char* map_StringForControllerAxis[] = {
@@ -342,8 +342,8 @@
 SDL_GameControllerAxis SDL_GameControllerGetAxisFromString( const char *pchString )
 {
     int entry;
-	if ( !pchString || !pchString[0] )
-		return SDL_CONTROLLER_AXIS_INVALID;
+    if ( !pchString || !pchString[0] )
+        return SDL_CONTROLLER_AXIS_INVALID;
 
     for ( entry = 0; map_StringForControllerAxis[entry]; ++entry)
     {
@@ -390,15 +390,15 @@
 SDL_GameControllerButton SDL_GameControllerGetButtonFromString( const char *pchString )
 {
     int entry;
-	if ( !pchString || !pchString[0] )
-		return SDL_CONTROLLER_BUTTON_INVALID;
+    if ( !pchString || !pchString[0] )
+        return SDL_CONTROLLER_BUTTON_INVALID;
 
     for ( entry = 0; map_StringForControllerButton[entry]; ++entry)
-	{
-		if ( !SDL_strcasecmp( pchString, map_StringForControllerButton[entry] ) )
-		return entry;
-	}
-	return SDL_CONTROLLER_BUTTON_INVALID;
+    {
+        if ( !SDL_strcasecmp( pchString, map_StringForControllerButton[entry] ) )
+        return entry;
+    }
+    return SDL_CONTROLLER_BUTTON_INVALID;
 }
 
 /*
@@ -418,83 +418,83 @@
  */
 void SDL_PrivateGameControllerParseButton( const char *szGameButton, const char *szJoystickButton, struct _SDL_ControllerMapping *pMapping )
 {
-	int iSDLButton = 0;
-	SDL_GameControllerButton button;
-	SDL_GameControllerAxis axis;
-	button = SDL_GameControllerGetButtonFromString( szGameButton );
-	axis = SDL_GameControllerGetAxisFromString( szGameButton );
-	iSDLButton = SDL_atoi( &szJoystickButton[1] );
+    int iSDLButton = 0;
+    SDL_GameControllerButton button;
+    SDL_GameControllerAxis axis;
+    button = SDL_GameControllerGetButtonFromString( szGameButton );
+    axis = SDL_GameControllerGetAxisFromString( szGameButton );
+    iSDLButton = SDL_atoi( &szJoystickButton[1] );
 
-	if ( szJoystickButton[0] == 'a' )
-	{
-		if ( iSDLButton >= k_nMaxReverseEntries )
-		{
-			SDL_SetError("Axis index too large: %d", iSDLButton );
-			return;
-		}
-		if ( axis != SDL_CONTROLLER_AXIS_INVALID )
-		{
-			pMapping->axes[ axis ] = iSDLButton;
-			pMapping->raxes[ iSDLButton ] = axis;
-		}
-		else if ( button != SDL_CONTROLLER_BUTTON_INVALID )
-		{
-			pMapping->axesasbutton[ button ] = iSDLButton;
-			pMapping->raxesasbutton[ iSDLButton ] = button;
-		}
-		else
-		{
-			SDL_assert( !"How did we get here?" );
-		}
+    if ( szJoystickButton[0] == 'a' )
+    {
+        if ( iSDLButton >= k_nMaxReverseEntries )
+        {
+            SDL_SetError("Axis index too large: %d", iSDLButton );
+            return;
+        }
+        if ( axis != SDL_CONTROLLER_AXIS_INVALID )
+        {
+            pMapping->axes[ axis ] = iSDLButton;
+            pMapping->raxes[ iSDLButton ] = axis;
+        }
+        else if ( button != SDL_CONTROLLER_BUTTON_INVALID )
+        {
+            pMapping->axesasbutton[ button ] = iSDLButton;
+            pMapping->raxesasbutton[ iSDLButton ] = button;
+        }
+        else
+        {
+            SDL_assert( !"How did we get here?" );
+        }
 
-	}
-	else if ( szJoystickButton[0] == 'b' )
-	{
-		if ( iSDLButton >= k_nMaxReverseEntries )
-		{
-			SDL_SetError("Button index too large: %d", iSDLButton );
-			return;
-		}
-		if ( button != SDL_CONTROLLER_BUTTON_INVALID )
-		{
-			pMapping->buttons[ button ] = iSDLButton;
-			pMapping->rbuttons[ iSDLButton ] = button;
-		}
-		else if ( axis != SDL_CONTROLLER_AXIS_INVALID )
-		{
-			pMapping->buttonasaxis[ axis ] = iSDLButton;
-			pMapping->rbuttonasaxis[ iSDLButton ] = axis;
-		}
-		else
-		{
-			SDL_assert( !"How did we get here?" );
-		}
-	}
-	else if ( szJoystickButton[0] == 'h' )
-	{
-		int hat = SDL_atoi( &szJoystickButton[1] );
-		int mask = SDL_atoi( &szJoystickButton[3] );
-		if (hat >= 4) {
-			SDL_SetError("Hat index too large: %d", iSDLButton );
-		}
+    }
+    else if ( szJoystickButton[0] == 'b' )
+    {
+        if ( iSDLButton >= k_nMaxReverseEntries )
+        {
+            SDL_SetError("Button index too large: %d", iSDLButton );
+            return;
+        }
+        if ( button != SDL_CONTROLLER_BUTTON_INVALID )
+        {
+            pMapping->buttons[ button ] = iSDLButton;
+            pMapping->rbuttons[ iSDLButton ] = button;
+        }
+        else if ( axis != SDL_CONTROLLER_AXIS_INVALID )
+        {
+            pMapping->buttonasaxis[ axis ] = iSDLButton;
+            pMapping->rbuttonasaxis[ iSDLButton ] = axis;
+        }
+        else
+        {
+            SDL_assert( !"How did we get here?" );
+        }
+    }
+    else if ( szJoystickButton[0] == 'h' )
+    {
+        int hat = SDL_atoi( &szJoystickButton[1] );
+        int mask = SDL_atoi( &szJoystickButton[3] );
+        if (hat >= 4) {
+            SDL_SetError("Hat index too large: %d", iSDLButton );
+        }
 
-		if ( button != SDL_CONTROLLER_BUTTON_INVALID )
-		{
+        if ( button != SDL_CONTROLLER_BUTTON_INVALID )
+        {
             int ridx;
-			pMapping->hatasbutton[ button ].hat = hat;
-			pMapping->hatasbutton[ button ].mask = mask;
-			ridx = (hat << 4) | mask;
-			pMapping->rhatasbutton[ ridx ] = button;
-		}
-		else if ( axis != SDL_CONTROLLER_AXIS_INVALID )
-		{
-			SDL_assert( !"Support hat as axis" );
-		}
-		else
-		{
-			SDL_assert( !"How did we get here?" );
-		}
-	}
+            pMapping->hatasbutton[ button ].hat = hat;
+            pMapping->hatasbutton[ button ].mask = mask;
+            ridx = (hat << 4) | mask;
+            pMapping->rhatasbutton[ ridx ] = button;
+        }
+        else if ( axis != SDL_CONTROLLER_AXIS_INVALID )
+        {
+            SDL_assert( !"Support hat as axis" );
+        }
+        else
+        {
+            SDL_assert( !"How did we get here?" );
+        }
+    }
 }
 
 
@@ -504,59 +504,59 @@
 static void
 SDL_PrivateGameControllerParseControllerConfigString( struct _SDL_ControllerMapping *pMapping, const char *pchString )
 {
-	char szGameButton[20];
-	char szJoystickButton[20];
-	SDL_bool bGameButton = SDL_TRUE;
-	int i = 0;
-	const char *pchPos = pchString;
+    char szGameButton[20];
+    char szJoystickButton[20];
+    SDL_bool bGameButton = SDL_TRUE;
+    int i = 0;
+    const char *pchPos = pchString;
 
-	SDL_memset( szGameButton, 0x0, sizeof(szGameButton) );
-	SDL_memset( szJoystickButton, 0x0, sizeof(szJoystickButton) );
+    SDL_memset( szGameButton, 0x0, sizeof(szGameButton) );
+    SDL_memset( szJoystickButton, 0x0, sizeof(szJoystickButton) );
 
-	while ( pchPos && *pchPos )
-	{
-		if ( *pchPos == ':' )
-		{
-			i = 0;
-			bGameButton = SDL_FALSE;
-		}
-		else if ( *pchPos == ' ' )
-		{
+    while ( pchPos && *pchPos )
+    {
+        if ( *pchPos == ':' )
+        {
+            i = 0;
+            bGameButton = SDL_FALSE;
+        }
+        else if ( *pchPos == ' ' )
+        {
 
-		}
-		else if ( *pchPos == ',' )
-		{
-			i = 0;
-			bGameButton = SDL_TRUE;
-			SDL_PrivateGameControllerParseButton( szGameButton, szJoystickButton, pMapping );
-			SDL_memset( szGameButton, 0x0, sizeof(szGameButton) );
-			SDL_memset( szJoystickButton, 0x0, sizeof(szJoystickButton) );
+        }
+        else if ( *pchPos == ',' )
+        {
+            i = 0;
+            bGameButton = SDL_TRUE;
+            SDL_PrivateGameControllerParseButton( szGameButton, szJoystickButton, pMapping );
+            SDL_memset( szGameButton, 0x0, sizeof(szGameButton) );
+            SDL_memset( szJoystickButton, 0x0, sizeof(szJoystickButton) );
 
-		}
-		else if ( bGameButton )
-		{
-			if ( i >=  sizeof(szGameButton))
-			{
-				SDL_SetError( "Button name too large: %s", szGameButton );
-				return;
-			}
-			szGameButton[i] = *pchPos;
-			i++;
-		}
-		else
-		{
-			if ( i >=  sizeof(szJoystickButton))
-			{
-				SDL_SetError( "Joystick button name too large: %s", szJoystickButton );
-				return;
-			}
-			szJoystickButton[i] = *pchPos;
-			i++;
-		}
-		pchPos++;
-	}
+        }
+        else if ( bGameButton )
+        {
+            if ( i >=  sizeof(szGameButton))
+            {
+                SDL_SetError( "Button name too large: %s", szGameButton );
+                return;
+            }
+            szGameButton[i] = *pchPos;
+            i++;
+        }
+        else
+        {
+            if ( i >=  sizeof(szJoystickButton))
+            {
+                SDL_SetError( "Joystick button name too large: %s", szJoystickButton );
+                return;
+            }
+            szJoystickButton[i] = *pchPos;
+            i++;
+        }
+        pchPos++;
+    }
 
-	SDL_PrivateGameControllerParseButton( szGameButton, szJoystickButton, pMapping );
+    SDL_PrivateGameControllerParseButton( szGameButton, szJoystickButton, pMapping );
 
 }
 
@@ -565,38 +565,38 @@
  */
 void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping )
 {
-	int j;
+    int j;
 
-	pMapping->guid = guid;
-	pMapping->name = pchName;
+    pMapping->guid = guid;
+    pMapping->name = pchName;
 
-	// set all the button mappings to non defaults
-	for ( j = 0; j < SDL_CONTROLLER_AXIS_MAX; j++ )
-	{
-		pMapping->axes[j] = -1;
-		pMapping->buttonasaxis[j] = -1;
-	}
-	for ( j = 0; j < SDL_CONTROLLER_BUTTON_MAX; j++ )
-	{
-		pMapping->buttons[j] = -1;
-		pMapping->axesasbutton[j] = -1;
-		pMapping->hatasbutton[j].hat = -1;
-	}
+    /* set all the button mappings to non defaults */
+    for ( j = 0; j < SDL_CONTROLLER_AXIS_MAX; j++ )
+    {
+        pMapping->axes[j] = -1;
+        pMapping->buttonasaxis[j] = -1;
+    }
+    for ( j = 0; j < SDL_CONTROLLER_BUTTON_MAX; j++ )
+    {
+        pMapping->buttons[j] = -1;
+        pMapping->axesasbutton[j] = -1;
+        pMapping->hatasbutton[j].hat = -1;
+    }
 
-	for ( j = 0; j < k_nMaxReverseEntries; j++ )
-	{
-		pMapping->raxes[j] = SDL_CONTROLLER_AXIS_INVALID;
-		pMapping->rbuttonasaxis[j] = SDL_CONTROLLER_AXIS_INVALID;
-		pMapping->rbuttons[j] = SDL_CONTROLLER_BUTTON_INVALID;
-		pMapping->raxesasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID;
-	}
+    for ( j = 0; j < k_nMaxReverseEntries; j++ )
+    {
+        pMapping->raxes[j] = SDL_CONTROLLER_AXIS_INVALID;
+        pMapping->rbuttonasaxis[j] = SDL_CONTROLLER_AXIS_INVALID;
+        pMapping->rbuttons[j] = SDL_CONTROLLER_BUTTON_INVALID;
+        pMapping->raxesasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID;
+    }
 
-	for (j = 0; j < k_nMaxHatEntries; j++)
-	{
-		pMapping->rhatasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID;
-	}
+    for (j = 0; j < k_nMaxHatEntries; j++)
+    {
+        pMapping->rhatasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID;
+    }
 
-	SDL_PrivateGameControllerParseControllerConfigString( pMapping, pchMapping );
+    SDL_PrivateGameControllerParseControllerConfigString( pMapping, pchMapping );
 }
 
 
@@ -605,20 +605,20 @@
  */
 char *SDL_PrivateGetControllerGUIDFromMappingString( const char *pMapping )
 {
-	const char *pFirstComma = SDL_strchr( pMapping, ',' );
-	if ( pFirstComma )
-	{
-		char *pchGUID = SDL_malloc( pFirstComma - pMapping + 1 );
-		if ( !pchGUID )
-		{
-			SDL_OutOfMemory();
-			return NULL;
-		}
-		SDL_memcpy( pchGUID, pMapping, pFirstComma - pMapping );
-		pchGUID[ pFirstComma - pMapping ] = 0;
-		return pchGUID;
-	}
-	return NULL;
+    const char *pFirstComma = SDL_strchr( pMapping, ',' );
+    if ( pFirstComma )
+    {
+        char *pchGUID = SDL_malloc( pFirstComma - pMapping + 1 );
+        if ( !pchGUID )
+        {
+            SDL_OutOfMemory();
+            return NULL;
+        }
+        SDL_memcpy( pchGUID, pMapping, pFirstComma - pMapping );
+        pchGUID[ pFirstComma - pMapping ] = 0;
+        return pchGUID;
+    }
+    return NULL;
 }
 
 
@@ -627,14 +627,14 @@
  */
 char *SDL_PrivateGetControllerNameFromMappingString( const char *pMapping )
 {
-	const char *pFirstComma, *pSecondComma;
+    const char *pFirstComma, *pSecondComma;
     char *pchName;
 
     pFirstComma = SDL_strchr( pMapping, ',' );
     if ( !pFirstComma )
         return NULL;
 
-	pSecondComma = SDL_strchr( pFirstComma + 1, ',' );
+    pSecondComma = SDL_strchr( pFirstComma + 1, ',' );
     if ( !pSecondComma )
         return NULL;
 
@@ -655,13 +655,13 @@
  */
 char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMapping )
 {
-	const char *pFirstComma, *pSecondComma;
+    const char *pFirstComma, *pSecondComma;
 
     pFirstComma = SDL_strchr( pMapping, ',' );
     if ( !pFirstComma )
         return NULL;
 
-	pSecondComma = SDL_strchr( pFirstComma + 1, ',' );
+    pSecondComma = SDL_strchr( pFirstComma + 1, ',' );
     if ( !pSecondComma )
         return NULL;
 
@@ -679,11 +679,11 @@
             event.type = SDL_CONTROLLERDEVICEREMAPPED;
             event.cdevice.which = gamecontrollerlist->joystick->instance_id;
             SDL_PushEvent(&event);
-            
-            // Not really threadsafe.  Should this lock access within SDL_GameControllerEventWatcher?
+
+            /* Not really threadsafe.  Should this lock access within SDL_GameControllerEventWatcher? */
             SDL_PrivateLoadButtonMapping(&gamecontrollerlist->mapping, pControllerMapping->guid, pControllerMapping->name, pControllerMapping->mapping);
         }
-        
+
         gamecontrollerlist = gamecontrollerlist->next;
     }
 }
@@ -694,9 +694,9 @@
 int
 SDL_GameControllerAddMapping( const char *mappingString )
 {
-	char *pchGUID;
-	char *pchName;
-	char *pchMapping;
+    char *pchGUID;
+    char *pchName;
+    char *pchMapping;
     SDL_JoystickGUID jGUID;
     ControllerMapping_t *pControllerMapping;
 #ifdef SDL_JOYSTICK_DINPUT
@@ -715,46 +715,46 @@
     jGUID = SDL_JoystickGetGUIDFromString(pchGUID);
     SDL_free(pchGUID);
 
-	pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID);
+    pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID);
 
-	pchName = SDL_PrivateGetControllerNameFromMappingString( mappingString );
-	if (!pchName) return -1;
+    pchName = SDL_PrivateGetControllerNameFromMappingString( mappingString );
+    if (!pchName) return -1;
 
-	pchMapping = SDL_PrivateGetControllerMappingFromMappingString( mappingString );
-	if (!pchMapping) {
-		SDL_free( pchName );
-		return -1;
-	}
+    pchMapping = SDL_PrivateGetControllerMappingFromMappingString( mappingString );
+    if (!pchMapping) {
+        SDL_free( pchName );
+        return -1;
+    }
 
-	if (pControllerMapping) {
-		// Update existing mapping
-		SDL_free( pControllerMapping->name );
-		pControllerMapping->name = pchName;
-		SDL_free( pControllerMapping->mapping );
-		pControllerMapping->mapping = pchMapping;
-		// refresh open controllers
-		SDL_PrivateGameControllerRefreshMapping( pControllerMapping );
-		return 0;
-	} else {
-		pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) );
-		if (!pControllerMapping) {
-			SDL_free( pchName );
-			SDL_free( pchMapping );
-			return SDL_OutOfMemory();
-		}
+    if (pControllerMapping) {
+        /* Update existing mapping */
+        SDL_free( pControllerMapping->name );
+        pControllerMapping->name = pchName;
+        SDL_free( pControllerMapping->mapping );
+        pControllerMapping->mapping = pchMapping;
+        /* refresh open controllers */
+        SDL_PrivateGameControllerRefreshMapping( pControllerMapping );
+        return 0;
+    } else {
+        pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) );
+        if (!pControllerMapping) {
+            SDL_free( pchName );
+            SDL_free( pchMapping );
+            return SDL_OutOfMemory();
+        }
 #ifdef SDL_JOYSTICK_DINPUT
-		if ( is_xinput_mapping )
-		{
-			s_pXInputMapping = pControllerMapping;
-		}
+        if ( is_xinput_mapping )
+        {
+            s_pXInputMapping = pControllerMapping;
+        }
 #endif
-		pControllerMapping->guid = jGUID;
-		pControllerMapping->name = pchName;
-		pControllerMapping->mapping = pchMapping;
-		pControllerMapping->next = s_pSupportedControllers;
-		s_pSupportedControllers = pControllerMapping;
-		return 1;
-	}
+        pControllerMapping->guid = jGUID;
+        pControllerMapping->name = pchName;
+        pControllerMapping->mapping = pchMapping;
+        pControllerMapping->next = s_pSupportedControllers;
+        s_pSupportedControllers = pControllerMapping;
+        return 1;
+    }
 }
 
 /*
@@ -763,18 +763,18 @@
 char *
 SDL_GameControllerMappingForGUID( SDL_JoystickGUID guid )
 {
-	char *pMappingString = NULL;
-	ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid);
-	if (mapping) {
-		char pchGUID[33];
+    char *pMappingString = NULL;
+    ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid);
+    if (mapping) {
+        char pchGUID[33];
         size_t needed;
-		SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID));
-		// allocate enough memory for GUID + ',' + name + ',' + mapping + \0
-		needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
-		pMappingString = SDL_malloc( needed );
-		SDL_snprintf( pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping );
-	}
-	return pMappingString;
+        SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID));
+        /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
+        needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
+        pMappingString = SDL_malloc( needed );
+        SDL_snprintf( pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping );
+    }
+    return pMappingString;
 }
 
 /*
@@ -783,7 +783,7 @@
 char *
 SDL_GameControllerMapping( SDL_GameController * gamecontroller )
 {
-	return SDL_GameControllerMappingForGUID( gamecontroller->mapping.guid );
+    return SDL_GameControllerMappingForGUID( gamecontroller->mapping.guid );
 }
 
 static void
@@ -819,25 +819,25 @@
 int
 SDL_GameControllerInit(void)
 {
-	int i = 0;
-	const char *pMappingString = NULL;
-	s_pSupportedControllers = NULL;
-	pMappingString = s_ControllerMappings[i];
-	while ( pMappingString )
-	{
-		SDL_GameControllerAddMapping( pMappingString );
+    int i = 0;
+    const char *pMappingString = NULL;
+    s_pSupportedControllers = NULL;
+    pMappingString = s_ControllerMappings[i];
+    while ( pMappingString )
+    {
+        SDL_GameControllerAddMapping( pMappingString );
 
-		i++;
-		pMappingString = s_ControllerMappings[i];
-	}
+        i++;
+        pMappingString = s_ControllerMappings[i];
+    }
 
-	// load in any user supplied config
+    /* load in any user supplied config */
     SDL_GameControllerLoadHints();
 
-	/* watch for joy events and fire controller ones if needed */
-	SDL_AddEventWatch( SDL_GameControllerEventWatcher, NULL );
+    /* watch for joy events and fire controller ones if needed */
+    SDL_AddEventWatch( SDL_GameControllerEventWatcher, NULL );
 
-	return (0);
+    return (0);
 }
 
 
@@ -847,11 +847,11 @@
 const char *
 SDL_GameControllerNameForIndex(int device_index)
 {
-	ControllerMapping_t *pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
-	if ( pSupportedController )
-	{
-		return pSupportedController->name;
-	}
+    ControllerMapping_t *pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
+    if ( pSupportedController )
+    {
+        return pSupportedController->name;
+    }
     return NULL;
 }
 
@@ -862,13 +862,13 @@
 SDL_bool
 SDL_IsGameController(int device_index)
 {
-	ControllerMapping_t *pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
-	if ( pSupportedController )
-	{
-		return SDL_TRUE;
-	}
+    ControllerMapping_t *pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
+    if ( pSupportedController )
+    {
+        return SDL_TRUE;
+    }
 
-	return SDL_FALSE;
+    return SDL_FALSE;
 }
 
 /*
@@ -882,56 +882,56 @@
 SDL_GameControllerOpen(int device_index)
 {
     SDL_GameController *gamecontroller;
-	SDL_GameController *gamecontrollerlist;
-	ControllerMapping_t *pSupportedController = NULL;
+    SDL_GameController *gamecontrollerlist;
+    ControllerMapping_t *pSupportedController = NULL;
 
     if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
         SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
         return (NULL);
     }
 
-	gamecontrollerlist = SDL_gamecontrollers;
-    // If the controller is already open, return it 
-	while ( gamecontrollerlist )
-	{
-		if ( SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id ) {
-				gamecontroller = gamecontrollerlist;
-				++gamecontroller->ref_count;
-				return (gamecontroller);
-		}
-		gamecontrollerlist = gamecontrollerlist->next;
+    gamecontrollerlist = SDL_gamecontrollers;
+    /* If the controller is already open, return it */
+    while ( gamecontrollerlist )
+    {
+        if ( SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id ) {
+                gamecontroller = gamecontrollerlist;
+                ++gamecontroller->ref_count;
+                return (gamecontroller);
+        }
+        gamecontrollerlist = gamecontrollerlist->next;
     }
 
-	// Find a controller mapping 
-	pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
-	if ( !pSupportedController ) {
-		SDL_SetError("Couldn't find mapping for device (%d)", device_index );
-		return (NULL);
-	}
+    /* Find a controller mapping */
+    pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
+    if ( !pSupportedController ) {
+        SDL_SetError("Couldn't find mapping for device (%d)", device_index );
+        return (NULL);
+    }
 
-	// Create and initialize the joystick 
-	gamecontroller = (SDL_GameController *) SDL_malloc((sizeof *gamecontroller));
-	if (gamecontroller == NULL) {
-		SDL_OutOfMemory();
-		return NULL;
-	}
+    /* Create and initialize the joystick */
+    gamecontroller = (SDL_GameController *) SDL_malloc((sizeof *gamecontroller));
+    if (gamecontroller == NULL) {
+        SDL_OutOfMemory();
+        return NULL;
+    }
 
     SDL_memset(gamecontroller, 0, (sizeof *gamecontroller));
     gamecontroller->joystick = SDL_JoystickOpen(device_index);
-	if ( !gamecontroller->joystick ) {
+    if ( !gamecontroller->joystick ) {
         SDL_free(gamecontroller);
         return NULL;
     }
 
-	SDL_PrivateLoadButtonMapping( &gamecontroller->mapping, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping );
+    SDL_PrivateLoadButtonMapping( &gamecontroller->mapping, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping );
 
-    // Add joystick to list 
+    /* Add joystick to list */
     ++gamecontroller->ref_count;
-	// Link the joystick in the list 
-	gamecontroller->next = SDL_gamecontrollers;
-	SDL_gamecontrollers = gamecontroller;
+    /* Link the joystick in the list */
+    gamecontroller->next = SDL_gamecontrollers;
+    SDL_gamecontrollers = gamecontroller;
 
-	SDL_SYS_JoystickUpdate( gamecontroller->joystick );
+    SDL_SYS_JoystickUpdate( gamecontroller->joystick );
 
     return (gamecontroller);
 }
@@ -953,22 +953,22 @@
 Sint16
 SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis)
 {
-	if ( !gamecontroller )
-		return 0;
+    if ( !gamecontroller )
+        return 0;
 
-	if (gamecontroller->mapping.axes[axis] >= 0 )
-	{
-		return ( SDL_JoystickGetAxis( gamecontroller->joystick, gamecontroller->mapping.axes[axis]) );
-	}
-	else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 )
-	{
-		Uint8 value;
-		value = SDL_JoystickGetButton( gamecontroller->joystick, gamecontroller->mapping.buttonasaxis[axis] );
-		if ( value > 0 )
-			return 32767;
-		return 0;
-	}
-	return 0;
+    if (gamecontroller->mapping.axes[axis] >= 0 )
+    {
+        return ( SDL_JoystickGetAxis( gamecontroller->joystick, gamecontroller->mapping.axes[axis]) );
+    }
+    else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 )
+    {
+        Uint8 value;
+        value = SDL_JoystickGetButton( gamecontroller->joystick, gamecontroller->mapping.buttonasaxis[axis] );
+        if ( value > 0 )
+            return 32767;
+        return 0;
+    }
+    return 0;
 }
 
 
@@ -978,32 +978,32 @@
 Uint8
 SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button)
 {
-	if ( !gamecontroller )
-		return 0;
+    if ( !gamecontroller )
+        return 0;
 
-	if ( gamecontroller->mapping.buttons[button] >= 0 )
-	{
-		return ( SDL_JoystickGetButton( gamecontroller->joystick, gamecontroller->mapping.buttons[button] ) );
-	}
-	else if ( gamecontroller->mapping.axesasbutton[button] >= 0 )
-	{
-		Sint16 value;
-		value = SDL_JoystickGetAxis( gamecontroller->joystick, gamecontroller->mapping.axesasbutton[button] );
-		if ( ABS(value) > 32768/2 )
-			return 1;
-		return 0;
-	}
-	else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 )
-	{
-		Uint8 value;
-		value = SDL_JoystickGetHat( gamecontroller->joystick, gamecontroller->mapping.hatasbutton[button].hat );
-		
-		if ( value & gamecontroller->mapping.hatasbutton[button].mask )
-			return 1;
-		return 0;
-	}
+    if ( gamecontroller->mapping.buttons[button] >= 0 )
+    {
+        return ( SDL_JoystickGetButton( gamecontroller->joystick, gamecontroller->mapping.buttons[button] ) );
+    }
+    else if ( gamecontroller->mapping.axesasbutton[button] >= 0 )
+    {
+        Sint16 value;
+        value = SDL_JoystickGetAxis( gamecontroller->joystick, gamecontroller->mapping.axesasbutton[button] );
+        if ( ABS(value) > 32768/2 )
+            return 1;
+        return 0;
+    }
+    else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 )
+    {
+        Uint8 value;
+        value = SDL_JoystickGetHat( gamecontroller->joystick, gamecontroller->mapping.hatasbutton[button].hat );
 
-	return 0;
+        if ( value & gamecontroller->mapping.hatasbutton[button].mask )
+            return 1;
+        return 0;
+    }
+
+    return 0;
 }
 
 /*
@@ -1013,10 +1013,10 @@
 SDL_bool
 SDL_GameControllerGetAttached( SDL_GameController * gamecontroller )
 {
-	if ( !gamecontroller )
-		return SDL_FALSE;
+    if ( !gamecontroller )
+        return SDL_FALSE;
 
-	return SDL_JoystickGetAttached(gamecontroller->joystick);
+    return SDL_JoystickGetAttached(gamecontroller->joystick);
 }
 
 
@@ -1026,8 +1026,8 @@
 const char *
 SDL_GameControllerName(SDL_GameController * gamecontroller)
 {
-	if ( !gamecontroller )
-		return NULL;
+    if ( !gamecontroller )
+        return NULL;
 
     return (gamecontroller->mapping.name);
 }
@@ -1038,10 +1038,10 @@
  */
 SDL_Joystick *SDL_GameControllerGetJoystick(SDL_GameController * gamecontroller)
 {
-	if ( !gamecontroller )
-		return NULL;
+    if ( !gamecontroller )
+        return NULL;
 
-	return gamecontroller->joystick;
+    return gamecontroller->joystick;
 }
 
 /**
@@ -1049,24 +1049,24 @@
  */
 SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis)
 {
-	SDL_GameControllerButtonBind bind;
-	SDL_memset( &bind, 0x0, sizeof(bind) );
+    SDL_GameControllerButtonBind bind;
+    SDL_memset( &bind, 0x0, sizeof(bind) );
 
-	if ( !gamecontroller || axis == SDL_CONTROLLER_AXIS_INVALID )
-		return bind;
+    if ( !gamecontroller || axis == SDL_CONTROLLER_AXIS_INVALID )
+        return bind;
 
-	if (gamecontroller->mapping.axes[axis] >= 0 )
-	{
-		bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
-		bind.value.button = gamecontroller->mapping.axes[axis];
-	}
-	else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 )
-	{
-		bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
-		bind.value.button = gamecontroller->mapping.buttonasaxis[axis];
-	}
+    if (gamecontroller->mapping.axes[axis] >= 0 )
+    {
+        bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
+        bind.value.button = gamecontroller->mapping.axes[axis];
+    }
+    else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 )
+    {
+        bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
+        bind.value.button = gamecontroller->mapping.buttonasaxis[axis];
+    }
 
-	return bind;
+    return bind;
 }
 
 
@@ -1075,30 +1075,30 @@
  */
 SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button)
 {
-	SDL_GameControllerButtonBind bind;
-	SDL_memset( &bind, 0x0, sizeof(bind) );
+    SDL_GameControllerButtonBind bind;
+    SDL_memset( &bind, 0x0, sizeof(bind) );
 
-	if ( !gamecontroller || button == SDL_CONTROLLER_BUTTON_INVALID )
-		return bind;
+    if ( !gamecontroller || button == SDL_CONTROLLER_BUTTON_INVALID )
+        return bind;
 
-	if ( gamecontroller->mapping.buttons[button] >= 0 )
-	{
-		bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
-		bind.value.button = gamecontroller->mapping.buttons[button];
-	}
-	else if ( gamecontroller->mapping.axesasbutton[button] >= 0 )
-	{
-		bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
-		bind.value.axis = gamecontroller->mapping.axesasbutton[button];
-	}
-	else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 )
-	{
-		bind.bindType = SDL_CONTROLLER_BINDTYPE_HAT;
-		bind.value.hat.hat = gamecontroller->mapping.hatasbutton[button].hat;
-		bind.value.hat.hat_mask = gamecontroller->mapping.hatasbutton[button].mask;
-	}
+    if ( gamecontroller->mapping.buttons[button] >= 0 )
+    {
+        bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
+        bind.value.button = gamecontroller->mapping.buttons[button];
+    }
+    else if ( gamecontroller->mapping.axesasbutton[button] >= 0 )
+    {
+        bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
+        bind.value.axis = gamecontroller->mapping.axesasbutton[button];
+    }
+    else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 )
+    {
+        bind.bindType = SDL_CONTROLLER_BINDTYPE_HAT;
+        bind.value.hat.hat = gamecontroller->mapping.hatasbutton[button].hat;
+        bind.value.hat.hat_mask = gamecontroller->mapping.hatasbutton[button].mask;
+    }
 
-	return bind;
+    return bind;
 }
 
 
@@ -1108,39 +1108,39 @@
 void
 SDL_GameControllerClose(SDL_GameController * gamecontroller)
 {
-	SDL_GameController *gamecontrollerlist, *gamecontrollerlistprev;
+    SDL_GameController *gamecontrollerlist, *gamecontrollerlistprev;
 
-	if ( !gamecontroller )
-		return;
+    if ( !gamecontroller )
+        return;
 
-	// First decrement ref count 
+    /* First decrement ref count */
     if (--gamecontroller->ref_count > 0) {
         return;
     }
 
-	SDL_JoystickClose( gamecontroller->joystick );
-	
-	gamecontrollerlist = SDL_gamecontrollers;
-	gamecontrollerlistprev = NULL;
-	while ( gamecontrollerlist )
-	{
-		if (gamecontroller == gamecontrollerlist) 
-		{
-			if ( gamecontrollerlistprev )
-			{
-				// unlink this entry
-				gamecontrollerlistprev->next = gamecontrollerlist->next;
-			}
-			else
-			{
-				SDL_gamecontrollers = gamecontroller->next;
-			}
+    SDL_JoystickClose( gamecontroller->joystick );
 
-			break;
-		}
-		gamecontrollerlistprev = gamecontrollerlist;
-		gamecontrollerlist = gamecontrollerlist->next;
-	}
+    gamecontrollerlist = SDL_gamecontrollers;
+    gamecontrollerlistprev = NULL;
+    while ( gamecontrollerlist )
+    {
+        if (gamecontroller == gamecontrollerlist)
+        {
+            if ( gamecontrollerlistprev )
+            {
+                /* unlink this entry */
+                gamecontrollerlistprev->next = gamecontrollerlist->next;
+            }
+            else
+            {
+                SDL_gamecontrollers = gamecontroller->next;
+            }
+
+            break;
+        }
+        gamecontrollerlistprev = gamecontrollerlist;
+        gamecontrollerlist = gamecontrollerlist->next;
+    }
 
     SDL_free(gamecontroller);
 }
@@ -1152,22 +1152,22 @@
 void
 SDL_GameControllerQuit(void)
 {
-	ControllerMapping_t *pControllerMap;
-	while ( SDL_gamecontrollers )
-	{
-		SDL_gamecontrollers->ref_count = 1;
+    ControllerMapping_t *pControllerMap;
+    while ( SDL_gamecontrollers )
+    {
+        SDL_gamecontrollers->ref_count = 1;
         SDL_GameControllerClose(SDL_gamecontrollers);
- 	}
+    }
 
-	while ( s_pSupportedControllers )
-	{
-		pControllerMap = s_pSupportedControllers;
-		s_pSupportedControllers = s_pSupportedControllers->next;
-		SDL_free( pControllerMap->name );
-		SDL_free( pControllerMap );
-	}
+    while ( s_pSupportedControllers )
+    {
+        pControllerMap = s_pSupportedControllers;
+        s_pSupportedControllers = s_pSupportedControllers->next;
+        SDL_free( pControllerMap->name );
+        SDL_free( pControllerMap );
+    }
 
-	SDL_DelEventWatch( SDL_GameControllerEventWatcher, NULL );
+    SDL_DelEventWatch( SDL_GameControllerEventWatcher, NULL );
 
 }
 
@@ -1177,7 +1177,7 @@
 int
 SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value)
 {
-	int posted;
+    int posted;
 
     /* translate the event, if desired */
     posted = 0;
@@ -1188,7 +1188,7 @@
         event.caxis.which = gamecontroller->joystick->instance_id;
         event.caxis.axis = axis;
         event.caxis.value = value;
-		posted = SDL_PushEvent(&event) == 1;
+        posted = SDL_PushEvent(&event) == 1;
     }
 #endif /* !SDL_EVENTS_DISABLED */
     return (posted);
@@ -1203,7 +1203,7 @@
 {
     int posted;
 #if !SDL_EVENTS_DISABLED
-	SDL_Event event;
+    SDL_Event event;
 
     if ( button == SDL_CONTROLLER_BUTTON_INVALID )
         return (0);
@@ -1228,7 +1228,7 @@
         event.cbutton.which = gamecontroller->joystick->instance_id;
         event.cbutton.button = button;
         event.cbutton.state = state;
-		posted = SDL_PushEvent(&event) == 1;
+        posted = SDL_PushEvent(&event) == 1;
     }
 #endif /* !SDL_EVENTS_DISABLED */
     return (posted);
@@ -1269,5 +1269,4 @@
 #endif /* SDL_EVENTS_DISABLED */
 }
 
-
 /* vi: set ts=4 sw=4 expandtab: */