Updated coding style to match the rest of SDL
authorSam Lantinga <slouken@libsdl.org>
Tue, 13 May 2014 11:32:36 -0700
changeset 87724f34097233f9
parent 8771 8af7a4af8fe0
child 8773 83077b1f989a
Updated coding style to match the rest of SDL
src/joystick/SDL_gamecontroller.c
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Sun May 11 15:59:22 2014 +0200
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Tue May 13 11:32:36 2014 -0700
     1.3 @@ -111,25 +111,20 @@
     1.4   */
     1.5  int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
     1.6  {
     1.7 -    switch( event->type )
     1.8 -    {
     1.9 +    switch(event->type) {
    1.10      case SDL_JOYAXISMOTION:
    1.11          {
    1.12              SDL_GameController *controllerlist;
    1.13  
    1.14 -            if ( event->jaxis.axis >= k_nMaxReverseEntries ) break;
    1.15 +            if (event->jaxis.axis >= k_nMaxReverseEntries) break;
    1.16  
    1.17              controllerlist = SDL_gamecontrollers;
    1.18 -            while ( controllerlist )
    1.19 -            {
    1.20 -                if ( controllerlist->joystick->instance_id == event->jaxis.which )
    1.21 -                {
    1.22 -                    if ( controllerlist->mapping.raxes[event->jaxis.axis] >= 0 ) /* simple axis to axis, send it through */
    1.23 -                    {
    1.24 +            while (controllerlist) {
    1.25 +                if (controllerlist->joystick->instance_id == event->jaxis.which) {
    1.26 +                    if (controllerlist->mapping.raxes[event->jaxis.axis] >= 0) /* simple axis to axis, send it through */ {
    1.27                          SDL_GameControllerAxis axis = controllerlist->mapping.raxes[event->jaxis.axis];
    1.28                          Sint16 value = event->jaxis.value;
    1.29 -                        switch (axis)
    1.30 -                        {
    1.31 +                        switch (axis) {
    1.32                              case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
    1.33                              case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
    1.34                                  /* Shift it to be 0 - 32767. */
    1.35 @@ -137,11 +132,9 @@
    1.36                              default:
    1.37                                  break;
    1.38                          }
    1.39 -                        SDL_PrivateGameControllerAxis( controllerlist, axis, value );
    1.40 -                    }
    1.41 -                    else if ( controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0 ) /* simulate an axis as a button */
    1.42 -                    {
    1.43 -                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.raxesasbutton[event->jaxis.axis], ABS(event->jaxis.value) > 32768/2 ? SDL_PRESSED : SDL_RELEASED );
    1.44 +                        SDL_PrivateGameControllerAxis(controllerlist, axis, value);
    1.45 +                    } else if (controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0) { /* simulate an axis as a button */
    1.46 +                        SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.raxesasbutton[event->jaxis.axis], ABS(event->jaxis.value) > 32768/2 ? SDL_PRESSED : SDL_RELEASED);
    1.47                      }
    1.48                      break;
    1.49                  }
    1.50 @@ -154,20 +147,15 @@
    1.51          {
    1.52              SDL_GameController *controllerlist;
    1.53  
    1.54 -            if ( event->jbutton.button >= k_nMaxReverseEntries ) break;
    1.55 +            if (event->jbutton.button >= k_nMaxReverseEntries) break;
    1.56  
    1.57              controllerlist = SDL_gamecontrollers;
    1.58 -            while ( controllerlist )
    1.59 -            {
    1.60 -                if ( controllerlist->joystick->instance_id == event->jbutton.which )
    1.61 -                {
    1.62 -                    if ( controllerlist->mapping.rbuttons[event->jbutton.button] >= 0 ) /* simple button as button */
    1.63 -                    {
    1.64 -                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rbuttons[event->jbutton.button], event->jbutton.state );
    1.65 -                    }
    1.66 -                    else if ( controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0 ) /* an button pretending to be an axis */
    1.67 -                    {
    1.68 -                        SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32767 : 0 );
    1.69 +            while (controllerlist) {
    1.70 +                if (controllerlist->joystick->instance_id == event->jbutton.which) {
    1.71 +                    if (controllerlist->mapping.rbuttons[event->jbutton.button] >= 0) { /* simple button as button */
    1.72 +                        SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rbuttons[event->jbutton.button], event->jbutton.state);
    1.73 +                    } else if (controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0) { /* an button pretending to be an axis */
    1.74 +                        SDL_PrivateGameControllerAxis(controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32767 : 0);
    1.75                      }
    1.76                      break;
    1.77                  }
    1.78 @@ -179,39 +167,37 @@
    1.79          {
    1.80              SDL_GameController *controllerlist;
    1.81  
    1.82 -            if ( event->jhat.hat >= 4 ) break;
    1.83 +            if (event->jhat.hat >= 4) break;
    1.84  
    1.85              controllerlist = SDL_gamecontrollers;
    1.86 -            while ( controllerlist )
    1.87 -            {
    1.88 -                if ( controllerlist->joystick->instance_id == event->jhat.which )
    1.89 -                {
    1.90 +            while (controllerlist) {
    1.91 +                if (controllerlist->joystick->instance_id == event->jhat.which) {
    1.92                      Uint8 bSame = controllerlist->hatState[event->jhat.hat] & event->jhat.value;
    1.93                      /* Get list of removed bits (button release) */
    1.94                      Uint8 bChanged = controllerlist->hatState[event->jhat.hat] ^ bSame;
    1.95                      /* the hat idx in the high nibble */
    1.96                      int bHighHat = event->jhat.hat << 4;
    1.97  
    1.98 -                    if ( bChanged & SDL_HAT_DOWN )
    1.99 -                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_DOWN], SDL_RELEASED );
   1.100 -                    if ( bChanged & SDL_HAT_UP )
   1.101 -                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_UP], SDL_RELEASED );
   1.102 -                    if ( bChanged & SDL_HAT_LEFT )
   1.103 -                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_LEFT], SDL_RELEASED );
   1.104 -                    if ( bChanged & SDL_HAT_RIGHT )
   1.105 -                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_RIGHT], SDL_RELEASED );
   1.106 +                    if (bChanged & SDL_HAT_DOWN)
   1.107 +                        SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_DOWN], SDL_RELEASED);
   1.108 +                    if (bChanged & SDL_HAT_UP)
   1.109 +                        SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_UP], SDL_RELEASED);
   1.110 +                    if (bChanged & SDL_HAT_LEFT)
   1.111 +                        SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_LEFT], SDL_RELEASED);
   1.112 +                    if (bChanged & SDL_HAT_RIGHT)
   1.113 +                        SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_RIGHT], SDL_RELEASED);
   1.114  
   1.115                      /* Get list of added bits (button press) */
   1.116                      bChanged = event->jhat.value ^ bSame;
   1.117  
   1.118 -                    if ( bChanged & SDL_HAT_DOWN )
   1.119 -                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_DOWN], SDL_PRESSED );
   1.120 -                    if ( bChanged & SDL_HAT_UP )
   1.121 -                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_UP], SDL_PRESSED );
   1.122 -                    if ( bChanged & SDL_HAT_LEFT )
   1.123 -                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_LEFT], SDL_PRESSED );
   1.124 -                    if ( bChanged & SDL_HAT_RIGHT )
   1.125 -                        SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_RIGHT], SDL_PRESSED );
   1.126 +                    if (bChanged & SDL_HAT_DOWN)
   1.127 +                        SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_DOWN], SDL_PRESSED);
   1.128 +                    if (bChanged & SDL_HAT_UP)
   1.129 +                        SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_UP], SDL_PRESSED);
   1.130 +                    if (bChanged & SDL_HAT_LEFT)
   1.131 +                        SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_LEFT], SDL_PRESSED);
   1.132 +                    if (bChanged & SDL_HAT_RIGHT)
   1.133 +                        SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_RIGHT], SDL_PRESSED);
   1.134  
   1.135                      /* update our state cache */
   1.136                      controllerlist->hatState[event->jhat.hat] = event->jhat.value;
   1.137 @@ -224,8 +210,7 @@
   1.138          break;
   1.139      case SDL_JOYDEVICEADDED:
   1.140          {
   1.141 -            if ( SDL_IsGameController(event->jdevice.which ) )
   1.142 -            {
   1.143 +            if (SDL_IsGameController(event->jdevice.which)) {
   1.144                  SDL_Event deviceevent;
   1.145                  deviceevent.type = SDL_CONTROLLERDEVICEADDED;
   1.146                  deviceevent.cdevice.which = event->jdevice.which;
   1.147 @@ -236,10 +221,8 @@
   1.148      case SDL_JOYDEVICEREMOVED:
   1.149          {
   1.150              SDL_GameController *controllerlist = SDL_gamecontrollers;
   1.151 -            while ( controllerlist )
   1.152 -            {
   1.153 -                if ( controllerlist->joystick->instance_id == event->jdevice.which )
   1.154 -                {
   1.155 +            while (controllerlist) {
   1.156 +                if (controllerlist->joystick->instance_id == event->jdevice.which) {
   1.157                      SDL_Event deviceevent;
   1.158                      deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
   1.159                      deviceevent.cdevice.which = event->jdevice.which;
   1.160 @@ -263,10 +246,8 @@
   1.161  ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid)
   1.162  {
   1.163      ControllerMapping_t *pSupportedController = s_pSupportedControllers;
   1.164 -    while ( pSupportedController )
   1.165 -    {
   1.166 -        if ( !SDL_memcmp( guid, &pSupportedController->guid, sizeof(*guid) ) )
   1.167 -        {
   1.168 +    while (pSupportedController) {
   1.169 +        if (SDL_memcmp(guid, &pSupportedController->guid, sizeof(*guid)) == 0) {
   1.170              return pSupportedController;
   1.171          }
   1.172          pSupportedController = pSupportedController->next;
   1.173 @@ -280,14 +261,13 @@
   1.174  ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
   1.175  {
   1.176  #if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
   1.177 -    if ( SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping )
   1.178 -    {
   1.179 +    if (SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping) {
   1.180          return s_pXInputMapping;
   1.181      }
   1.182      else
   1.183  #endif
   1.184      {
   1.185 -        SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
   1.186 +        SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID(device_index);
   1.187          return SDL_PrivateGetControllerMappingForGUID(&jGUID);
   1.188      }
   1.189  }
   1.190 @@ -305,15 +285,14 @@
   1.191  /*
   1.192   * convert a string to its enum equivalent
   1.193   */
   1.194 -SDL_GameControllerAxis SDL_GameControllerGetAxisFromString( const char *pchString )
   1.195 +SDL_GameControllerAxis SDL_GameControllerGetAxisFromString(const char *pchString)
   1.196  {
   1.197      int entry;
   1.198 -    if ( !pchString || !pchString[0] )
   1.199 +    if (!pchString || !pchString[0])
   1.200          return SDL_CONTROLLER_AXIS_INVALID;
   1.201  
   1.202 -    for ( entry = 0; map_StringForControllerAxis[entry]; ++entry)
   1.203 -    {
   1.204 -        if ( !SDL_strcasecmp( pchString, map_StringForControllerAxis[entry] ) )
   1.205 +    for (entry = 0; map_StringForControllerAxis[entry]; ++entry) {
   1.206 +        if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry]))
   1.207              return entry;
   1.208      }
   1.209      return SDL_CONTROLLER_AXIS_INVALID;
   1.210 @@ -322,10 +301,9 @@
   1.211  /*
   1.212   * convert an enum to its string equivalent
   1.213   */
   1.214 -const char* SDL_GameControllerGetStringForAxis( SDL_GameControllerAxis axis )
   1.215 +const char* SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis)
   1.216  {
   1.217 -    if (axis > SDL_CONTROLLER_AXIS_INVALID && axis < SDL_CONTROLLER_AXIS_MAX)
   1.218 -    {
   1.219 +    if (axis > SDL_CONTROLLER_AXIS_INVALID && axis < SDL_CONTROLLER_AXIS_MAX) {
   1.220          return map_StringForControllerAxis[axis];
   1.221      }
   1.222      return NULL;
   1.223 @@ -353,16 +331,15 @@
   1.224  /*
   1.225   * convert a string to its enum equivalent
   1.226   */
   1.227 -SDL_GameControllerButton SDL_GameControllerGetButtonFromString( const char *pchString )
   1.228 +SDL_GameControllerButton SDL_GameControllerGetButtonFromString(const char *pchString)
   1.229  {
   1.230      int entry;
   1.231 -    if ( !pchString || !pchString[0] )
   1.232 +    if (!pchString || !pchString[0])
   1.233          return SDL_CONTROLLER_BUTTON_INVALID;
   1.234  
   1.235 -    for ( entry = 0; map_StringForControllerButton[entry]; ++entry)
   1.236 -    {
   1.237 -        if ( !SDL_strcasecmp( pchString, map_StringForControllerButton[entry] ) )
   1.238 -        return entry;
   1.239 +    for (entry = 0; map_StringForControllerButton[entry]; ++entry) {
   1.240 +        if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0)
   1.241 +            return entry;
   1.242      }
   1.243      return SDL_CONTROLLER_BUTTON_INVALID;
   1.244  }
   1.245 @@ -370,10 +347,9 @@
   1.246  /*
   1.247   * convert an enum to its string equivalent
   1.248   */
   1.249 -const char* SDL_GameControllerGetStringForButton( SDL_GameControllerButton axis )
   1.250 +const char* SDL_GameControllerGetStringForButton(SDL_GameControllerButton axis)
   1.251  {
   1.252 -    if (axis > SDL_CONTROLLER_BUTTON_INVALID && axis < SDL_CONTROLLER_BUTTON_MAX)
   1.253 -    {
   1.254 +    if (axis > SDL_CONTROLLER_BUTTON_INVALID && axis < SDL_CONTROLLER_BUTTON_MAX) {
   1.255          return map_StringForControllerButton[axis];
   1.256      }
   1.257      return NULL;
   1.258 @@ -382,83 +358,61 @@
   1.259  /*
   1.260   * given a controller button name and a joystick name update our mapping structure with it
   1.261   */
   1.262 -void SDL_PrivateGameControllerParseButton( const char *szGameButton, const char *szJoystickButton, struct _SDL_ControllerMapping *pMapping )
   1.263 +void SDL_PrivateGameControllerParseButton(const char *szGameButton, const char *szJoystickButton, struct _SDL_ControllerMapping *pMapping)
   1.264  {
   1.265      int iSDLButton = 0;
   1.266      SDL_GameControllerButton button;
   1.267      SDL_GameControllerAxis axis;
   1.268 -    button = SDL_GameControllerGetButtonFromString( szGameButton );
   1.269 -    axis = SDL_GameControllerGetAxisFromString( szGameButton );
   1.270 -    iSDLButton = SDL_atoi( &szJoystickButton[1] );
   1.271 +    button = SDL_GameControllerGetButtonFromString(szGameButton);
   1.272 +    axis = SDL_GameControllerGetAxisFromString(szGameButton);
   1.273 +    iSDLButton = SDL_atoi(&szJoystickButton[1]);
   1.274  
   1.275 -    if ( szJoystickButton[0] == 'a' )
   1.276 -    {
   1.277 -        if ( iSDLButton >= k_nMaxReverseEntries )
   1.278 -        {
   1.279 -            SDL_SetError("Axis index too large: %d", iSDLButton );
   1.280 +    if (szJoystickButton[0] == 'a') {
   1.281 +        if (iSDLButton >= k_nMaxReverseEntries) {
   1.282 +            SDL_SetError("Axis index too large: %d", iSDLButton);
   1.283              return;
   1.284          }
   1.285 -        if ( axis != SDL_CONTROLLER_AXIS_INVALID )
   1.286 -        {
   1.287 +        if (axis != SDL_CONTROLLER_AXIS_INVALID) {
   1.288              pMapping->axes[ axis ] = iSDLButton;
   1.289              pMapping->raxes[ iSDLButton ] = axis;
   1.290 -        }
   1.291 -        else if ( button != SDL_CONTROLLER_BUTTON_INVALID )
   1.292 -        {
   1.293 +        } else if (button != SDL_CONTROLLER_BUTTON_INVALID) {
   1.294              pMapping->axesasbutton[ button ] = iSDLButton;
   1.295              pMapping->raxesasbutton[ iSDLButton ] = button;
   1.296 -        }
   1.297 -        else
   1.298 -        {
   1.299 -            SDL_assert( !"How did we get here?" );
   1.300 +        } else {
   1.301 +            SDL_assert(!"How did we get here?");
   1.302          }
   1.303  
   1.304 -    }
   1.305 -    else if ( szJoystickButton[0] == 'b' )
   1.306 -    {
   1.307 -        if ( iSDLButton >= k_nMaxReverseEntries )
   1.308 -        {
   1.309 -            SDL_SetError("Button index too large: %d", iSDLButton );
   1.310 +    } else if (szJoystickButton[0] == 'b') {
   1.311 +        if (iSDLButton >= k_nMaxReverseEntries) {
   1.312 +            SDL_SetError("Button index too large: %d", iSDLButton);
   1.313              return;
   1.314          }
   1.315 -        if ( button != SDL_CONTROLLER_BUTTON_INVALID )
   1.316 -        {
   1.317 +        if (button != SDL_CONTROLLER_BUTTON_INVALID) {
   1.318              pMapping->buttons[ button ] = iSDLButton;
   1.319              pMapping->rbuttons[ iSDLButton ] = button;
   1.320 -        }
   1.321 -        else if ( axis != SDL_CONTROLLER_AXIS_INVALID )
   1.322 -        {
   1.323 +        } else if (axis != SDL_CONTROLLER_AXIS_INVALID) {
   1.324              pMapping->buttonasaxis[ axis ] = iSDLButton;
   1.325              pMapping->rbuttonasaxis[ iSDLButton ] = axis;
   1.326 +        } else {
   1.327 +            SDL_assert(!"How did we get here?");
   1.328          }
   1.329 -        else
   1.330 -        {
   1.331 -            SDL_assert( !"How did we get here?" );
   1.332 -        }
   1.333 -    }
   1.334 -    else if ( szJoystickButton[0] == 'h' )
   1.335 -    {
   1.336 -        int hat = SDL_atoi( &szJoystickButton[1] );
   1.337 -        int mask = SDL_atoi( &szJoystickButton[3] );
   1.338 +    } else if (szJoystickButton[0] == 'h') {
   1.339 +        int hat = SDL_atoi(&szJoystickButton[1]);
   1.340 +        int mask = SDL_atoi(&szJoystickButton[3]);
   1.341          if (hat >= 4) {
   1.342 -            SDL_SetError("Hat index too large: %d", iSDLButton );
   1.343 +            SDL_SetError("Hat index too large: %d", iSDLButton);
   1.344          }
   1.345  
   1.346 -        if ( button != SDL_CONTROLLER_BUTTON_INVALID )
   1.347 -        {
   1.348 +        if (button != SDL_CONTROLLER_BUTTON_INVALID) {
   1.349              int ridx;
   1.350              pMapping->hatasbutton[ button ].hat = hat;
   1.351              pMapping->hatasbutton[ button ].mask = mask;
   1.352              ridx = (hat << 4) | mask;
   1.353              pMapping->rhatasbutton[ ridx ] = button;
   1.354 -        }
   1.355 -        else if ( axis != SDL_CONTROLLER_AXIS_INVALID )
   1.356 -        {
   1.357 -            SDL_assert( !"Support hat as axis" );
   1.358 -        }
   1.359 -        else
   1.360 -        {
   1.361 -            SDL_assert( !"How did we get here?" );
   1.362 +        } else if (axis != SDL_CONTROLLER_AXIS_INVALID) {
   1.363 +            SDL_assert(!"Support hat as axis");
   1.364 +        } else {
   1.365 +            SDL_assert(!"How did we get here?");
   1.366          }
   1.367      }
   1.368  }
   1.369 @@ -468,7 +422,7 @@
   1.370   * given a controller mapping string update our mapping object
   1.371   */
   1.372  static void
   1.373 -SDL_PrivateGameControllerParseControllerConfigString( struct _SDL_ControllerMapping *pMapping, const char *pchString )
   1.374 +SDL_PrivateGameControllerParseControllerConfigString(struct _SDL_ControllerMapping *pMapping, const char *pchString)
   1.375  {
   1.376      char szGameButton[20];
   1.377      char szJoystickButton[20];
   1.378 @@ -476,44 +430,32 @@
   1.379      int i = 0;
   1.380      const char *pchPos = pchString;
   1.381  
   1.382 -    SDL_memset( szGameButton, 0x0, sizeof(szGameButton) );
   1.383 -    SDL_memset( szJoystickButton, 0x0, sizeof(szJoystickButton) );
   1.384 +    SDL_memset(szGameButton, 0x0, sizeof(szGameButton));
   1.385 +    SDL_memset(szJoystickButton, 0x0, sizeof(szJoystickButton));
   1.386  
   1.387 -    while ( pchPos && *pchPos )
   1.388 -    {
   1.389 -        if ( *pchPos == ':' )
   1.390 -        {
   1.391 +    while (pchPos && *pchPos) {
   1.392 +        if (*pchPos == ':') {
   1.393              i = 0;
   1.394              bGameButton = SDL_FALSE;
   1.395 -        }
   1.396 -        else if ( *pchPos == ' ' )
   1.397 -        {
   1.398 +        } else if (*pchPos == ' ') {
   1.399  
   1.400 -        }
   1.401 -        else if ( *pchPos == ',' )
   1.402 -        {
   1.403 +        } else if (*pchPos == ',') {
   1.404              i = 0;
   1.405              bGameButton = SDL_TRUE;
   1.406 -            SDL_PrivateGameControllerParseButton( szGameButton, szJoystickButton, pMapping );
   1.407 -            SDL_memset( szGameButton, 0x0, sizeof(szGameButton) );
   1.408 -            SDL_memset( szJoystickButton, 0x0, sizeof(szJoystickButton) );
   1.409 +            SDL_PrivateGameControllerParseButton(szGameButton, szJoystickButton, pMapping);
   1.410 +            SDL_memset(szGameButton, 0x0, sizeof(szGameButton));
   1.411 +            SDL_memset(szJoystickButton, 0x0, sizeof(szJoystickButton));
   1.412  
   1.413 -        }
   1.414 -        else if ( bGameButton )
   1.415 -        {
   1.416 -            if ( i >=  sizeof(szGameButton))
   1.417 -            {
   1.418 -                SDL_SetError( "Button name too large: %s", szGameButton );
   1.419 +        } else if (bGameButton) {
   1.420 +            if (i >= sizeof(szGameButton)) {
   1.421 +                SDL_SetError("Button name too large: %s", szGameButton);
   1.422                  return;
   1.423              }
   1.424              szGameButton[i] = *pchPos;
   1.425              i++;
   1.426 -        }
   1.427 -        else
   1.428 -        {
   1.429 -            if ( i >=  sizeof(szJoystickButton))
   1.430 -            {
   1.431 -                SDL_SetError( "Joystick button name too large: %s", szJoystickButton );
   1.432 +        } else {
   1.433 +            if (i >= sizeof(szJoystickButton)) {
   1.434 +                SDL_SetError("Joystick button name too large: %s", szJoystickButton);
   1.435                  return;
   1.436              }
   1.437              szJoystickButton[i] = *pchPos;
   1.438 @@ -522,14 +464,14 @@
   1.439          pchPos++;
   1.440      }
   1.441  
   1.442 -    SDL_PrivateGameControllerParseButton( szGameButton, szJoystickButton, pMapping );
   1.443 +    SDL_PrivateGameControllerParseButton(szGameButton, szJoystickButton, pMapping);
   1.444  
   1.445  }
   1.446  
   1.447  /*
   1.448   * Make a new button mapping struct
   1.449   */
   1.450 -void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping )
   1.451 +void SDL_PrivateLoadButtonMapping(struct _SDL_ControllerMapping *pMapping, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping)
   1.452  {
   1.453      int j;
   1.454  
   1.455 @@ -537,50 +479,44 @@
   1.456      pMapping->name = pchName;
   1.457  
   1.458      /* set all the button mappings to non defaults */
   1.459 -    for ( j = 0; j < SDL_CONTROLLER_AXIS_MAX; j++ )
   1.460 -    {
   1.461 +    for (j = 0; j < SDL_CONTROLLER_AXIS_MAX; j++) {
   1.462          pMapping->axes[j] = -1;
   1.463          pMapping->buttonasaxis[j] = -1;
   1.464      }
   1.465 -    for ( j = 0; j < SDL_CONTROLLER_BUTTON_MAX; j++ )
   1.466 -    {
   1.467 +    for (j = 0; j < SDL_CONTROLLER_BUTTON_MAX; j++) {
   1.468          pMapping->buttons[j] = -1;
   1.469          pMapping->axesasbutton[j] = -1;
   1.470          pMapping->hatasbutton[j].hat = -1;
   1.471      }
   1.472  
   1.473 -    for ( j = 0; j < k_nMaxReverseEntries; j++ )
   1.474 -    {
   1.475 +    for (j = 0; j < k_nMaxReverseEntries; j++) {
   1.476          pMapping->raxes[j] = SDL_CONTROLLER_AXIS_INVALID;
   1.477          pMapping->rbuttonasaxis[j] = SDL_CONTROLLER_AXIS_INVALID;
   1.478          pMapping->rbuttons[j] = SDL_CONTROLLER_BUTTON_INVALID;
   1.479          pMapping->raxesasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID;
   1.480      }
   1.481  
   1.482 -    for (j = 0; j < k_nMaxHatEntries; j++)
   1.483 -    {
   1.484 +    for (j = 0; j < k_nMaxHatEntries; j++) {
   1.485          pMapping->rhatasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID;
   1.486      }
   1.487  
   1.488 -    SDL_PrivateGameControllerParseControllerConfigString( pMapping, pchMapping );
   1.489 +    SDL_PrivateGameControllerParseControllerConfigString(pMapping, pchMapping);
   1.490  }
   1.491  
   1.492  
   1.493  /*
   1.494   * grab the guid string from a mapping string
   1.495   */
   1.496 -char *SDL_PrivateGetControllerGUIDFromMappingString( const char *pMapping )
   1.497 +char *SDL_PrivateGetControllerGUIDFromMappingString(const char *pMapping)
   1.498  {
   1.499 -    const char *pFirstComma = SDL_strchr( pMapping, ',' );
   1.500 -    if ( pFirstComma )
   1.501 -    {
   1.502 -        char *pchGUID = SDL_malloc( pFirstComma - pMapping + 1 );
   1.503 -        if ( !pchGUID )
   1.504 -        {
   1.505 +    const char *pFirstComma = SDL_strchr(pMapping, ',');
   1.506 +    if (pFirstComma) {
   1.507 +        char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1);
   1.508 +        if (!pchGUID) {
   1.509              SDL_OutOfMemory();
   1.510              return NULL;
   1.511          }
   1.512 -        SDL_memcpy( pchGUID, pMapping, pFirstComma - pMapping );
   1.513 +        SDL_memcpy(pchGUID, pMapping, pFirstComma - pMapping);
   1.514          pchGUID[ pFirstComma - pMapping ] = 0;
   1.515          return pchGUID;
   1.516      }
   1.517 @@ -591,26 +527,25 @@
   1.518  /*
   1.519   * grab the name string from a mapping string
   1.520   */
   1.521 -char *SDL_PrivateGetControllerNameFromMappingString( const char *pMapping )
   1.522 +char *SDL_PrivateGetControllerNameFromMappingString(const char *pMapping)
   1.523  {
   1.524      const char *pFirstComma, *pSecondComma;
   1.525      char *pchName;
   1.526  
   1.527 -    pFirstComma = SDL_strchr( pMapping, ',' );
   1.528 -    if ( !pFirstComma )
   1.529 +    pFirstComma = SDL_strchr(pMapping, ',');
   1.530 +    if (!pFirstComma)
   1.531          return NULL;
   1.532  
   1.533 -    pSecondComma = SDL_strchr( pFirstComma + 1, ',' );
   1.534 -    if ( !pSecondComma )
   1.535 +    pSecondComma = SDL_strchr(pFirstComma + 1, ',');
   1.536 +    if (!pSecondComma)
   1.537          return NULL;
   1.538  
   1.539 -    pchName = SDL_malloc( pSecondComma - pFirstComma );
   1.540 -    if ( !pchName )
   1.541 -    {
   1.542 +    pchName = SDL_malloc(pSecondComma - pFirstComma);
   1.543 +    if (!pchName) {
   1.544          SDL_OutOfMemory();
   1.545          return NULL;
   1.546      }
   1.547 -    SDL_memcpy( pchName, pFirstComma + 1, pSecondComma - pFirstComma );
   1.548 +    SDL_memcpy(pchName, pFirstComma + 1, pSecondComma - pFirstComma);
   1.549      pchName[ pSecondComma - pFirstComma - 1 ] = 0;
   1.550      return pchName;
   1.551  }
   1.552 @@ -619,28 +554,26 @@
   1.553  /*
   1.554   * grab the button mapping string from a mapping string
   1.555   */
   1.556 -char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMapping )
   1.557 +char *SDL_PrivateGetControllerMappingFromMappingString(const char *pMapping)
   1.558  {
   1.559      const char *pFirstComma, *pSecondComma;
   1.560  
   1.561 -    pFirstComma = SDL_strchr( pMapping, ',' );
   1.562 -    if ( !pFirstComma )
   1.563 +    pFirstComma = SDL_strchr(pMapping, ',');
   1.564 +    if (!pFirstComma)
   1.565          return NULL;
   1.566  
   1.567 -    pSecondComma = SDL_strchr( pFirstComma + 1, ',' );
   1.568 -    if ( !pSecondComma )
   1.569 +    pSecondComma = SDL_strchr(pFirstComma + 1, ',');
   1.570 +    if (!pSecondComma)
   1.571          return NULL;
   1.572  
   1.573      return SDL_strdup(pSecondComma + 1); /* mapping is everything after the 3rd comma */
   1.574  }
   1.575  
   1.576 -void SDL_PrivateGameControllerRefreshMapping( ControllerMapping_t *pControllerMapping )
   1.577 +void SDL_PrivateGameControllerRefreshMapping(ControllerMapping_t *pControllerMapping)
   1.578  {
   1.579      SDL_GameController *gamecontrollerlist = SDL_gamecontrollers;
   1.580 -    while ( gamecontrollerlist )
   1.581 -    {
   1.582 -        if ( !SDL_memcmp( &gamecontrollerlist->mapping.guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid) ) )
   1.583 -        {
   1.584 +    while (gamecontrollerlist) {
   1.585 +        if (!SDL_memcmp(&gamecontrollerlist->mapping.guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid))) {
   1.586              SDL_Event event;
   1.587              event.type = SDL_CONTROLLERDEVICEREMAPPED;
   1.588              event.cdevice.which = gamecontrollerlist->joystick->instance_id;
   1.589 @@ -658,7 +591,7 @@
   1.590   * Add or update an entry into the Mappings Database
   1.591   */
   1.592  int
   1.593 -SDL_GameControllerAddMappingsFromRW( SDL_RWops * rw, int freerw )
   1.594 +SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw)
   1.595  {
   1.596      const char *platform = SDL_GetPlatform();
   1.597      int controllers = 0;
   1.598 @@ -694,25 +627,24 @@
   1.599      line = buf;
   1.600      
   1.601      while (line < buf + db_size) {
   1.602 -        line_end = SDL_strchr( line, '\n' );
   1.603 +        line_end = SDL_strchr(line, '\n');
   1.604          if (line_end != NULL) {
   1.605              *line_end = '\0';
   1.606 -        }
   1.607 -        else {
   1.608 +        } else {
   1.609              line_end = buf + db_size;
   1.610          }
   1.611          
   1.612          /* Extract and verify the platform */
   1.613          tmp = SDL_strstr(line, SDL_CONTROLLER_PLATFORM_FIELD);
   1.614 -        if ( tmp != NULL ) {
   1.615 +        if (tmp != NULL) {
   1.616              tmp += SDL_strlen(SDL_CONTROLLER_PLATFORM_FIELD);
   1.617              comma = SDL_strchr(tmp, ',');
   1.618              if (comma != NULL) {
   1.619                  platform_len = comma - tmp + 1;
   1.620                  if (platform_len + 1 < SDL_arraysize(line_platform)) {
   1.621                      SDL_strlcpy(line_platform, tmp, platform_len);
   1.622 -                    if(SDL_strncasecmp(line_platform, platform, platform_len) == 0
   1.623 -                        && SDL_GameControllerAddMapping(line) > 0) {
   1.624 +                    if (SDL_strncasecmp(line_platform, platform, platform_len) == 0 &&
   1.625 +                        SDL_GameControllerAddMapping(line) > 0) {
   1.626                          controllers++;
   1.627                      }
   1.628                  }
   1.629 @@ -730,7 +662,7 @@
   1.630   * Add or update an entry into the Mappings Database
   1.631   */
   1.632  int
   1.633 -SDL_GameControllerAddMapping( const char *mappingString )
   1.634 +SDL_GameControllerAddMapping(const char *mappingString)
   1.635  {
   1.636      char *pchGUID;
   1.637      char *pchName;
   1.638 @@ -741,26 +673,26 @@
   1.639      SDL_bool is_xinput_mapping = SDL_FALSE;
   1.640  #endif
   1.641  
   1.642 -    pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( mappingString );
   1.643 +    pchGUID = SDL_PrivateGetControllerGUIDFromMappingString(mappingString);
   1.644      if (!pchGUID) {
   1.645          return SDL_SetError("Couldn't parse GUID from %s", mappingString);
   1.646      }
   1.647  #if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
   1.648 -    if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) {
   1.649 +    if (!SDL_strcasecmp(pchGUID, "xinput")) {
   1.650          is_xinput_mapping = SDL_TRUE;
   1.651      }
   1.652  #endif
   1.653      jGUID = SDL_JoystickGetGUIDFromString(pchGUID);
   1.654      SDL_free(pchGUID);
   1.655  
   1.656 -    pchName = SDL_PrivateGetControllerNameFromMappingString( mappingString );
   1.657 +    pchName = SDL_PrivateGetControllerNameFromMappingString(mappingString);
   1.658      if (!pchName) {
   1.659          return SDL_SetError("Couldn't parse name from %s", mappingString);
   1.660      }
   1.661  
   1.662 -    pchMapping = SDL_PrivateGetControllerMappingFromMappingString( mappingString );
   1.663 +    pchMapping = SDL_PrivateGetControllerMappingFromMappingString(mappingString);
   1.664      if (!pchMapping) {
   1.665 -        SDL_free( pchName );
   1.666 +        SDL_free(pchName);
   1.667          return SDL_SetError("Couldn't parse %s", mappingString);
   1.668      }
   1.669  
   1.670 @@ -768,23 +700,22 @@
   1.671  
   1.672      if (pControllerMapping) {
   1.673          /* Update existing mapping */
   1.674 -        SDL_free( pControllerMapping->name );
   1.675 +        SDL_free(pControllerMapping->name);
   1.676          pControllerMapping->name = pchName;
   1.677 -        SDL_free( pControllerMapping->mapping );
   1.678 +        SDL_free(pControllerMapping->mapping);
   1.679          pControllerMapping->mapping = pchMapping;
   1.680          /* refresh open controllers */
   1.681 -        SDL_PrivateGameControllerRefreshMapping( pControllerMapping );
   1.682 +        SDL_PrivateGameControllerRefreshMapping(pControllerMapping);
   1.683          return 0;
   1.684      } else {
   1.685 -        pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) );
   1.686 +        pControllerMapping = SDL_malloc(sizeof(*pControllerMapping));
   1.687          if (!pControllerMapping) {
   1.688 -            SDL_free( pchName );
   1.689 -            SDL_free( pchMapping );
   1.690 +            SDL_free(pchName);
   1.691 +            SDL_free(pchMapping);
   1.692              return SDL_OutOfMemory();
   1.693          }
   1.694  #if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
   1.695 -        if ( is_xinput_mapping )
   1.696 -        {
   1.697 +        if (is_xinput_mapping) {
   1.698              s_pXInputMapping = pControllerMapping;
   1.699          }
   1.700  #endif
   1.701 @@ -801,7 +732,7 @@
   1.702   * Get the mapping string for this GUID
   1.703   */
   1.704  char *
   1.705 -SDL_GameControllerMappingForGUID( SDL_JoystickGUID guid )
   1.706 +SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
   1.707  {
   1.708      char *pMappingString = NULL;
   1.709      ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid);
   1.710 @@ -811,8 +742,8 @@
   1.711          SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID));
   1.712          /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
   1.713          needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
   1.714 -        pMappingString = SDL_malloc( needed );
   1.715 -        SDL_snprintf( pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping );
   1.716 +        pMappingString = SDL_malloc(needed);
   1.717 +        SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
   1.718      }
   1.719      return pMappingString;
   1.720  }
   1.721 @@ -821,34 +752,35 @@
   1.722   * Get the mapping string for this device
   1.723   */
   1.724  char *
   1.725 -SDL_GameControllerMapping( SDL_GameController * gamecontroller )
   1.726 +SDL_GameControllerMapping(SDL_GameController * gamecontroller)
   1.727  {
   1.728 -    return SDL_GameControllerMappingForGUID( gamecontroller->mapping.guid );
   1.729 +    return SDL_GameControllerMappingForGUID(gamecontroller->mapping.guid);
   1.730  }
   1.731  
   1.732  static void
   1.733  SDL_GameControllerLoadHints()
   1.734  {
   1.735      const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG);
   1.736 -    if ( hint && hint[0] ) {
   1.737 -        size_t nchHints = SDL_strlen( hint );
   1.738 -        char *pUserMappings = SDL_malloc( nchHints + 1 );
   1.739 +    if (hint && hint[0]) {
   1.740 +        size_t nchHints = SDL_strlen(hint);
   1.741 +        char *pUserMappings = SDL_malloc(nchHints + 1);
   1.742          char *pTempMappings = pUserMappings;
   1.743 -        SDL_memcpy( pUserMappings, hint, nchHints );
   1.744 +        SDL_memcpy(pUserMappings, hint, nchHints);
   1.745          pUserMappings[nchHints] = '\0';
   1.746 -        while ( pUserMappings ) {
   1.747 +        while (pUserMappings) {
   1.748              char *pchNewLine = NULL;
   1.749  
   1.750 -            pchNewLine = SDL_strchr( pUserMappings, '\n' );
   1.751 -            if ( pchNewLine )
   1.752 +            pchNewLine = SDL_strchr(pUserMappings, '\n');
   1.753 +            if (pchNewLine)
   1.754                  *pchNewLine = '\0';
   1.755  
   1.756 -            SDL_GameControllerAddMapping( pUserMappings );
   1.757 +            SDL_GameControllerAddMapping(pUserMappings);
   1.758  
   1.759 -            if ( pchNewLine )
   1.760 +            if (pchNewLine) {
   1.761                  pUserMappings = pchNewLine + 1;
   1.762 -            else
   1.763 +            } else {
   1.764                  pUserMappings = NULL;
   1.765 +            }
   1.766          }
   1.767          SDL_free(pTempMappings);
   1.768      }
   1.769 @@ -864,8 +796,8 @@
   1.770      const char *pMappingString = NULL;
   1.771      s_pSupportedControllers = NULL;
   1.772      pMappingString = s_ControllerMappings[i];
   1.773 -    while ( pMappingString ) {
   1.774 -        SDL_GameControllerAddMapping( pMappingString );
   1.775 +    while (pMappingString) {
   1.776 +        SDL_GameControllerAddMapping(pMappingString);
   1.777  
   1.778          i++;
   1.779          pMappingString = s_ControllerMappings[i];
   1.780 @@ -875,7 +807,7 @@
   1.781      SDL_GameControllerLoadHints();
   1.782  
   1.783      /* watch for joy events and fire controller ones if needed */
   1.784 -    SDL_AddEventWatch( SDL_GameControllerEventWatcher, NULL );
   1.785 +    SDL_AddEventWatch(SDL_GameControllerEventWatcher, NULL);
   1.786  
   1.787      /* Send added events for controllers currently attached */
   1.788      for (i = 0; i < SDL_NumJoysticks(); ++i) {
   1.789 @@ -898,8 +830,7 @@
   1.790  SDL_GameControllerNameForIndex(int device_index)
   1.791  {
   1.792      ControllerMapping_t *pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
   1.793 -    if ( pSupportedController )
   1.794 -    {
   1.795 +    if (pSupportedController) {
   1.796          return pSupportedController->name;
   1.797      }
   1.798      return NULL;
   1.799 @@ -913,8 +844,7 @@
   1.800  SDL_IsGameController(int device_index)
   1.801  {
   1.802      ControllerMapping_t *pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
   1.803 -    if ( pSupportedController )
   1.804 -    {
   1.805 +    if (pSupportedController) {
   1.806          return SDL_TRUE;
   1.807      }
   1.808  
   1.809 @@ -942,9 +872,8 @@
   1.810  
   1.811      gamecontrollerlist = SDL_gamecontrollers;
   1.812      /* If the controller is already open, return it */
   1.813 -    while ( gamecontrollerlist )
   1.814 -    {
   1.815 -        if ( SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id ) {
   1.816 +    while (gamecontrollerlist) {
   1.817 +        if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id) {
   1.818                  gamecontroller = gamecontrollerlist;
   1.819                  ++gamecontroller->ref_count;
   1.820                  return (gamecontroller);
   1.821 @@ -954,8 +883,8 @@
   1.822  
   1.823      /* Find a controller mapping */
   1.824      pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
   1.825 -    if ( !pSupportedController ) {
   1.826 -        SDL_SetError("Couldn't find mapping for device (%d)", device_index );
   1.827 +    if (!pSupportedController) {
   1.828 +        SDL_SetError("Couldn't find mapping for device (%d)", device_index);
   1.829          return (NULL);
   1.830      }
   1.831  
   1.832 @@ -968,12 +897,12 @@
   1.833  
   1.834      SDL_memset(gamecontroller, 0, (sizeof *gamecontroller));
   1.835      gamecontroller->joystick = SDL_JoystickOpen(device_index);
   1.836 -    if ( !gamecontroller->joystick ) {
   1.837 +    if (!gamecontroller->joystick) {
   1.838          SDL_free(gamecontroller);
   1.839          return NULL;
   1.840      }
   1.841  
   1.842 -    SDL_PrivateLoadButtonMapping( &gamecontroller->mapping, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping );
   1.843 +    SDL_PrivateLoadButtonMapping(&gamecontroller->mapping, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping);
   1.844  
   1.845      /* Add joystick to list */
   1.846      ++gamecontroller->ref_count;
   1.847 @@ -981,7 +910,7 @@
   1.848      gamecontroller->next = SDL_gamecontrollers;
   1.849      SDL_gamecontrollers = gamecontroller;
   1.850  
   1.851 -    SDL_SYS_JoystickUpdate( gamecontroller->joystick );
   1.852 +    SDL_SYS_JoystickUpdate(gamecontroller->joystick);
   1.853  
   1.854      return (gamecontroller);
   1.855  }
   1.856 @@ -1003,14 +932,12 @@
   1.857  Sint16
   1.858  SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis)
   1.859  {
   1.860 -    if ( !gamecontroller )
   1.861 +    if (!gamecontroller)
   1.862          return 0;
   1.863  
   1.864 -    if (gamecontroller->mapping.axes[axis] >= 0 )
   1.865 -    {
   1.866 -        Sint16 value = ( SDL_JoystickGetAxis( gamecontroller->joystick, gamecontroller->mapping.axes[axis]) );
   1.867 -        switch (axis)
   1.868 -        {
   1.869 +    if (gamecontroller->mapping.axes[axis] >= 0) {
   1.870 +        Sint16 value = (SDL_JoystickGetAxis(gamecontroller->joystick, gamecontroller->mapping.axes[axis]));
   1.871 +        switch (axis) {
   1.872              case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
   1.873              case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
   1.874                  /* Shift it to be 0 - 32767. */
   1.875 @@ -1019,12 +946,10 @@
   1.876                  break;
   1.877          }
   1.878          return value;
   1.879 -    }
   1.880 -    else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 )
   1.881 -    {
   1.882 +    } else if (gamecontroller->mapping.buttonasaxis[axis] >= 0) {
   1.883          Uint8 value;
   1.884 -        value = SDL_JoystickGetButton( gamecontroller->joystick, gamecontroller->mapping.buttonasaxis[axis] );
   1.885 -        if ( value > 0 )
   1.886 +        value = SDL_JoystickGetButton(gamecontroller->joystick, gamecontroller->mapping.buttonasaxis[axis]);
   1.887 +        if (value > 0)
   1.888              return 32767;
   1.889          return 0;
   1.890      }
   1.891 @@ -1038,27 +963,22 @@
   1.892  Uint8
   1.893  SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button)
   1.894  {
   1.895 -    if ( !gamecontroller )
   1.896 +    if (!gamecontroller)
   1.897          return 0;
   1.898  
   1.899 -    if ( gamecontroller->mapping.buttons[button] >= 0 )
   1.900 -    {
   1.901 -        return ( SDL_JoystickGetButton( gamecontroller->joystick, gamecontroller->mapping.buttons[button] ) );
   1.902 -    }
   1.903 -    else if ( gamecontroller->mapping.axesasbutton[button] >= 0 )
   1.904 -    {
   1.905 +    if (gamecontroller->mapping.buttons[button] >= 0) {
   1.906 +        return (SDL_JoystickGetButton(gamecontroller->joystick, gamecontroller->mapping.buttons[button]));
   1.907 +    } else if (gamecontroller->mapping.axesasbutton[button] >= 0) {
   1.908          Sint16 value;
   1.909 -        value = SDL_JoystickGetAxis( gamecontroller->joystick, gamecontroller->mapping.axesasbutton[button] );
   1.910 -        if ( ABS(value) > 32768/2 )
   1.911 +        value = SDL_JoystickGetAxis(gamecontroller->joystick, gamecontroller->mapping.axesasbutton[button]);
   1.912 +        if (ABS(value) > 32768/2)
   1.913              return 1;
   1.914          return 0;
   1.915 -    }
   1.916 -    else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 )
   1.917 -    {
   1.918 +    } else if (gamecontroller->mapping.hatasbutton[button].hat >= 0) {
   1.919          Uint8 value;
   1.920 -        value = SDL_JoystickGetHat( gamecontroller->joystick, gamecontroller->mapping.hatasbutton[button].hat );
   1.921 +        value = SDL_JoystickGetHat(gamecontroller->joystick, gamecontroller->mapping.hatasbutton[button].hat);
   1.922  
   1.923 -        if ( value & gamecontroller->mapping.hatasbutton[button].mask )
   1.924 +        if (value & gamecontroller->mapping.hatasbutton[button].mask)
   1.925              return 1;
   1.926          return 0;
   1.927      }
   1.928 @@ -1071,9 +991,9 @@
   1.929   *  \return 0 if not plugged in, 1 if still present.
   1.930   */
   1.931  SDL_bool
   1.932 -SDL_GameControllerGetAttached( SDL_GameController * gamecontroller )
   1.933 +SDL_GameControllerGetAttached(SDL_GameController * gamecontroller)
   1.934  {
   1.935 -    if ( !gamecontroller )
   1.936 +    if (!gamecontroller)
   1.937          return SDL_FALSE;
   1.938  
   1.939      return SDL_JoystickGetAttached(gamecontroller->joystick);
   1.940 @@ -1086,7 +1006,7 @@
   1.941  const char *
   1.942  SDL_GameControllerName(SDL_GameController * gamecontroller)
   1.943  {
   1.944 -    if ( !gamecontroller )
   1.945 +    if (!gamecontroller)
   1.946          return NULL;
   1.947  
   1.948      return (gamecontroller->mapping.name);
   1.949 @@ -1098,7 +1018,7 @@
   1.950   */
   1.951  SDL_Joystick *SDL_GameControllerGetJoystick(SDL_GameController * gamecontroller)
   1.952  {
   1.953 -    if ( !gamecontroller )
   1.954 +    if (!gamecontroller)
   1.955          return NULL;
   1.956  
   1.957      return gamecontroller->joystick;
   1.958 @@ -1110,18 +1030,15 @@
   1.959  SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis)
   1.960  {
   1.961      SDL_GameControllerButtonBind bind;
   1.962 -    SDL_memset( &bind, 0x0, sizeof(bind) );
   1.963 +    SDL_memset(&bind, 0x0, sizeof(bind));
   1.964  
   1.965 -    if ( !gamecontroller || axis == SDL_CONTROLLER_AXIS_INVALID )
   1.966 +    if (!gamecontroller || axis == SDL_CONTROLLER_AXIS_INVALID)
   1.967          return bind;
   1.968  
   1.969 -    if (gamecontroller->mapping.axes[axis] >= 0 )
   1.970 -    {
   1.971 +    if (gamecontroller->mapping.axes[axis] >= 0) {
   1.972          bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
   1.973          bind.value.button = gamecontroller->mapping.axes[axis];
   1.974 -    }
   1.975 -    else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 )
   1.976 -    {
   1.977 +    } else if (gamecontroller->mapping.buttonasaxis[axis] >= 0) {
   1.978          bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
   1.979          bind.value.button = gamecontroller->mapping.buttonasaxis[axis];
   1.980      }
   1.981 @@ -1136,23 +1053,18 @@
   1.982  SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button)
   1.983  {
   1.984      SDL_GameControllerButtonBind bind;
   1.985 -    SDL_memset( &bind, 0x0, sizeof(bind) );
   1.986 +    SDL_memset(&bind, 0x0, sizeof(bind));
   1.987  
   1.988 -    if ( !gamecontroller || button == SDL_CONTROLLER_BUTTON_INVALID )
   1.989 +    if (!gamecontroller || button == SDL_CONTROLLER_BUTTON_INVALID)
   1.990          return bind;
   1.991  
   1.992 -    if ( gamecontroller->mapping.buttons[button] >= 0 )
   1.993 -    {
   1.994 +    if (gamecontroller->mapping.buttons[button] >= 0) {
   1.995          bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
   1.996          bind.value.button = gamecontroller->mapping.buttons[button];
   1.997 -    }
   1.998 -    else if ( gamecontroller->mapping.axesasbutton[button] >= 0 )
   1.999 -    {
  1.1000 +    } else if (gamecontroller->mapping.axesasbutton[button] >= 0) {
  1.1001          bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
  1.1002          bind.value.axis = gamecontroller->mapping.axesasbutton[button];
  1.1003 -    }
  1.1004 -    else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 )
  1.1005 -    {
  1.1006 +    } else if (gamecontroller->mapping.hatasbutton[button].hat >= 0) {
  1.1007          bind.bindType = SDL_CONTROLLER_BINDTYPE_HAT;
  1.1008          bind.value.hat.hat = gamecontroller->mapping.hatasbutton[button].hat;
  1.1009          bind.value.hat.hat_mask = gamecontroller->mapping.hatasbutton[button].mask;
  1.1010 @@ -1170,7 +1082,7 @@
  1.1011  {
  1.1012      SDL_GameController *gamecontrollerlist, *gamecontrollerlistprev;
  1.1013  
  1.1014 -    if ( !gamecontroller )
  1.1015 +    if (!gamecontroller)
  1.1016          return;
  1.1017  
  1.1018      /* First decrement ref count */
  1.1019 @@ -1178,21 +1090,16 @@
  1.1020          return;
  1.1021      }
  1.1022  
  1.1023 -    SDL_JoystickClose( gamecontroller->joystick );
  1.1024 +    SDL_JoystickClose(gamecontroller->joystick);
  1.1025  
  1.1026      gamecontrollerlist = SDL_gamecontrollers;
  1.1027      gamecontrollerlistprev = NULL;
  1.1028 -    while ( gamecontrollerlist )
  1.1029 -    {
  1.1030 -        if (gamecontroller == gamecontrollerlist)
  1.1031 -        {
  1.1032 -            if ( gamecontrollerlistprev )
  1.1033 -            {
  1.1034 +    while (gamecontrollerlist) {
  1.1035 +        if (gamecontroller == gamecontrollerlist) {
  1.1036 +            if (gamecontrollerlistprev) {
  1.1037                  /* unlink this entry */
  1.1038                  gamecontrollerlistprev->next = gamecontrollerlist->next;
  1.1039 -            }
  1.1040 -            else
  1.1041 -            {
  1.1042 +            } else {
  1.1043                  SDL_gamecontrollers = gamecontroller->next;
  1.1044              }
  1.1045  
  1.1046 @@ -1213,22 +1120,20 @@
  1.1047  SDL_GameControllerQuit(void)
  1.1048  {
  1.1049      ControllerMapping_t *pControllerMap;
  1.1050 -    while ( SDL_gamecontrollers )
  1.1051 -    {
  1.1052 +    while (SDL_gamecontrollers) {
  1.1053          SDL_gamecontrollers->ref_count = 1;
  1.1054          SDL_GameControllerClose(SDL_gamecontrollers);
  1.1055      }
  1.1056  
  1.1057 -    while ( s_pSupportedControllers )
  1.1058 -    {
  1.1059 +    while (s_pSupportedControllers) {
  1.1060          pControllerMap = s_pSupportedControllers;
  1.1061          s_pSupportedControllers = s_pSupportedControllers->next;
  1.1062 -        SDL_free( pControllerMap->name );
  1.1063 -        SDL_free( pControllerMap->mapping );
  1.1064 -        SDL_free( pControllerMap );
  1.1065 +        SDL_free(pControllerMap->name);
  1.1066 +        SDL_free(pControllerMap->mapping);
  1.1067 +        SDL_free(pControllerMap);
  1.1068      }
  1.1069  
  1.1070 -    SDL_DelEventWatch( SDL_GameControllerEventWatcher, NULL );
  1.1071 +    SDL_DelEventWatch(SDL_GameControllerEventWatcher, NULL);
  1.1072  
  1.1073  }
  1.1074  
  1.1075 @@ -1266,7 +1171,7 @@
  1.1076  #if !SDL_EVENTS_DISABLED
  1.1077      SDL_Event event;
  1.1078  
  1.1079 -    if ( button == SDL_CONTROLLER_BUTTON_INVALID )
  1.1080 +    if (button == SDL_CONTROLLER_BUTTON_INVALID)
  1.1081          return (0);
  1.1082  
  1.1083      switch (state) {