Add the controller mappings to the linked list in order
authorSam Lantinga <slouken@libsdl.org>
Tue, 29 Nov 2016 22:02:37 -0800
changeset 10662c6756f2a187b
parent 10661 74b42fb2a9e4
child 10663 6bbd07f9fc08
Add the controller mappings to the linked list in order
src/joystick/SDL_gamecontroller.c
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Tue Nov 29 06:36:57 2016 -0800
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Tue Nov 29 22:02:37 2016 -0800
     1.3 @@ -692,9 +692,22 @@
     1.4          pControllerMapping->guid = jGUID;
     1.5          pControllerMapping->name = pchName;
     1.6          pControllerMapping->mapping = pchMapping;
     1.7 -        pControllerMapping->next = s_pSupportedControllers;
     1.8 +        pControllerMapping->next = NULL;
     1.9          pControllerMapping->priority = priority;
    1.10 -        s_pSupportedControllers = pControllerMapping;
    1.11 +
    1.12 +        if (s_pSupportedControllers) {
    1.13 +            /* Add the mapping to the end of the list */
    1.14 +            ControllerMapping_t *pCurrMapping, *pPrevMapping;
    1.15 +
    1.16 +            for ( pPrevMapping = s_pSupportedControllers, pCurrMapping = pPrevMapping->next;
    1.17 +                  pCurrMapping; 
    1.18 +                  pPrevMapping = pCurrMapping, pCurrMapping = pCurrMapping->next ) {
    1.19 +                continue;
    1.20 +            }
    1.21 +            pPrevMapping->next = pControllerMapping;
    1.22 +        } else {
    1.23 +            s_pSupportedControllers = pControllerMapping;
    1.24 +        }
    1.25          *existing = SDL_FALSE;
    1.26      }
    1.27      return pControllerMapping;