Changes from Alfred:
authorSam Lantinga <slouken@libsdl.org>
Tue, 11 Dec 2012 11:54:32 -0800
changeset 6738b408d5a406a3
parent 6737 63ba9e5b1272
child 6739 d365b03b9207
Changes from Alfred:
- rename JoystickGUID -> SDL_JoystickGUID
- change SDL_JoystickGetGUIDString to take the string as an arg, rather than doing a malloc
include/SDL_joystick.h
src/joystick/SDL_gamecontroller.c
src/joystick/SDL_joystick.c
src/joystick/SDL_sysjoystick.h
src/joystick/darwin/SDL_sysjoystick.c
src/joystick/linux/SDL_sysjoystick.c
src/joystick/windows/SDL_dxjoystick.c
src/joystick/windows/SDL_dxjoystick_c.h
src/joystick/windows/SDL_mmjoystick.c
     1.1 --- a/include/SDL_joystick.h	Tue Dec 11 10:50:45 2012 -0800
     1.2 +++ b/include/SDL_joystick.h	Tue Dec 11 11:54:32 2012 -0800
     1.3 @@ -65,7 +65,7 @@
     1.4  /* A structure that encodes the stable unique id for a joystick device */
     1.5  typedef struct {
     1.6  	Uint8 data[16];
     1.7 -} JoystickGUID;
     1.8 +} SDL_JoystickGUID;
     1.9  
    1.10  typedef int SDL_JoystickID;
    1.11  
    1.12 @@ -102,22 +102,22 @@
    1.13  /**
    1.14   *  Return the GUID for the joystick at this index
    1.15   */
    1.16 -extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
    1.17 +extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
    1.18  
    1.19  /**
    1.20   *  Return the GUID for this opened joystick
    1.21   */
    1.22 -extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
    1.23 +extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
    1.24  
    1.25  /**
    1.26   *  Return a string representation for this guid. You are responsible for freeing memory from this call
    1.27   */
    1.28 -extern DECLSPEC char *SDLCALL SDL_JoystickGetGUIDString(JoystickGUID guid);
    1.29 +extern DECLSPEC void SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
    1.30  
    1.31  /**
    1.32   *  convert a string into a joystick formatted guid
    1.33   */
    1.34 -extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
    1.35 +extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
    1.36  
    1.37  /**
    1.38   *  Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.
     2.1 --- a/src/joystick/SDL_gamecontroller.c	Tue Dec 11 10:50:45 2012 -0800
     2.2 +++ b/src/joystick/SDL_gamecontroller.c	Tue Dec 11 11:54:32 2012 -0800
     2.3 @@ -48,7 +48,7 @@
     2.4  /* our in memory mapping db between joystick objects and controller mappings*/
     2.5  struct _SDL_ControllerMapping
     2.6  {
     2.7 -	JoystickGUID guid;
     2.8 +	SDL_JoystickGUID guid;
     2.9  	const char *name;
    2.10  
    2.11  	// mapping of axis/button id to controller version
    2.12 @@ -71,7 +71,7 @@
    2.13  /* our hard coded list of mapping support */
    2.14  typedef struct _ControllerMapping_t
    2.15  {
    2.16 -	JoystickGUID guid;
    2.17 +	SDL_JoystickGUID guid;
    2.18  	char *name;
    2.19  	const char *mapping;
    2.20  	struct _ControllerMapping_t *next;
    2.21 @@ -458,7 +458,7 @@
    2.22  /*
    2.23   * Make a new button mapping struct
    2.24   */
    2.25 -void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, JoystickGUID guid, const char *pchName, const char *pchMapping )
    2.26 +void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping )
    2.27  {
    2.28  	int j;
    2.29  
    2.30 @@ -673,7 +673,7 @@
    2.31  	}
    2.32  	else
    2.33  	{
    2.34 -		JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
    2.35 +		SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
    2.36  		pSupportedController = s_pSupportedControllers;
    2.37  		while ( pSupportedController )
    2.38  		{
    2.39 @@ -700,10 +700,11 @@
    2.40  	}
    2.41  	else
    2.42  	{
    2.43 -		JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
    2.44 +		SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
    2.45  		pSupportedController = s_pSupportedControllers;
    2.46  		// debug code to help get the guid string for a new joystick
    2.47 -		/*const char *pchGUID = SDL_JoystickGetGUIDString( jGUID );
    2.48 +		/* char szGUID[33];
    2.49 +		SDL_JoystickGetGUIDString( jGUID, szGUID, sizeof(szGUID) );
    2.50  		printf( "%s\n", pchGUID );
    2.51  		SDL_free( pchGUID );*/
    2.52  		while ( pSupportedController )
    2.53 @@ -759,7 +760,7 @@
    2.54  	pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
    2.55  	if ( !pSupportedController )
    2.56  	{
    2.57 -		JoystickGUID jGUID;
    2.58 +		SDL_JoystickGUID jGUID;
    2.59  
    2.60  		jGUID = SDL_JoystickGetDeviceGUID( device_index );
    2.61  		pSupportedController = s_pSupportedControllers;
     3.1 --- a/src/joystick/SDL_joystick.c	Tue Dec 11 10:50:45 2012 -0800
     3.2 +++ b/src/joystick/SDL_joystick.c	Tue Dec 11 11:54:32 2012 -0800
     3.3 @@ -683,34 +683,28 @@
     3.4  
     3.5  
     3.6  /* return the guid for this index */
     3.7 -JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
     3.8 +SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
     3.9  {
    3.10  	return SDL_SYS_JoystickGetDeviceGUID( device_index );
    3.11  }
    3.12  
    3.13  /* return the guid for this opened device */
    3.14 -JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
    3.15 +SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
    3.16  {
    3.17  	return SDL_SYS_JoystickGetGUID( joystick );
    3.18  }
    3.19  
    3.20  /* convert the guid to a printable string */
    3.21 -char *SDL_JoystickGetGUIDString(JoystickGUID guid)
    3.22 +void SDL_JoystickGetGUIDString( SDL_JoystickGUID guid, char *pszGUID, int cbGUID )
    3.23  {
    3.24  	static const char k_rgchHexToASCII[] = "0123456789abcdef";
    3.25  	char *pchOut = NULL;
    3.26  	char *pchString = NULL;
    3.27  	int i;
    3.28 -	pchString = SDL_malloc(33); // 16 bytes
    3.29 -	if ( !pchString )
    3.30 -	{
    3.31 -		SDL_OutOfMemory();
    3.32 -		return NULL;
    3.33 -	}
    3.34  	
    3.35 -	pchOut = pchString;
    3.36 +	pchOut = pszGUID;
    3.37  
    3.38 -	for ( i = 0; i < sizeof(guid); i++ )
    3.39 +	for ( i = 0; i < sizeof(guid) && i < (cbGUID-1); i++ )
    3.40  	{
    3.41  		// each input byte writes 2 ascii chars, and might write a null byte.
    3.42  		// If we don't have room for next input byte, stop
    3.43 @@ -720,7 +714,6 @@
    3.44  		*pchOut++ = k_rgchHexToASCII[ c & 0x0F ];
    3.45  	}
    3.46  	*pchOut = '\0';
    3.47 -	return pchString;
    3.48  }
    3.49  
    3.50  
    3.51 @@ -756,9 +749,9 @@
    3.52  
    3.53  
    3.54  /* convert the string version of a joystick guid to the struct */
    3.55 -JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
    3.56 +SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
    3.57  {
    3.58 -	JoystickGUID guid;
    3.59 +	SDL_JoystickGUID guid;
    3.60  	int maxoutputbytes= sizeof(guid);
    3.61  	int len = SDL_strlen( pchGUID );
    3.62  	Uint8 *p;
     4.1 --- a/src/joystick/SDL_sysjoystick.h	Tue Dec 11 10:50:45 2012 -0800
     4.2 +++ b/src/joystick/SDL_sysjoystick.h	Tue Dec 11 11:54:32 2012 -0800
     4.3 @@ -104,10 +104,10 @@
     4.4  extern void SDL_SYS_JoystickQuit(void);
     4.5  
     4.6  /* Function to return the stable GUID for a plugged in device */
     4.7 -extern JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index);
     4.8 +extern SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index);
     4.9  
    4.10  /* Function to return the stable GUID for a opened joystick */
    4.11 -extern JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);
    4.12 +extern SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);
    4.13  
    4.14  #ifdef SDL_JOYSTICK_DINPUT
    4.15  /* Function to get the current instance id of the joystick located at device_index */
     5.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Tue Dec 11 10:50:45 2012 -0800
     5.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Tue Dec 11 11:54:32 2012 -0800
     5.3 @@ -1083,7 +1083,7 @@
     5.4  }
     5.5  
     5.6  
     5.7 -JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
     5.8 +SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
     5.9  {
    5.10      recDevice *device = gpDeviceList;
    5.11      int index;
    5.12 @@ -1094,7 +1094,7 @@
    5.13  	return device->guid;	
    5.14  }
    5.15  
    5.16 -JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
    5.17 +SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
    5.18  {
    5.19  	return joystick->hwdata->guid;
    5.20  }
     6.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Tue Dec 11 10:50:45 2012 -0800
     6.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Tue Dec 11 11:54:32 2012 -0800
     6.3 @@ -953,13 +953,15 @@
     6.4  #endif
     6.5  }
     6.6  
     6.7 -JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
     6.8 +SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
     6.9  {
    6.10 +    JoystickGUID guid;
    6.11      return JoystickByDevIndex(device_index)->guid;
    6.12  }
    6.13  
    6.14 -JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
    6.15 +SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
    6.16  {
    6.17 +    JoystickGUID guid;
    6.18      return joystick->hwdata->guid;
    6.19  }
    6.20  
     7.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Tue Dec 11 10:50:45 2012 -0800
     7.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Tue Dec 11 11:54:32 2012 -0800
     7.3 @@ -79,7 +79,7 @@
     7.4                                         LPUNKNOWN punkOuter);
     7.5  struct JoyStick_DeviceData_
     7.6  {
     7.7 -	JoystickGUID guid;
     7.8 +	SDL_JoystickGUID guid;
     7.9  	DIDEVICEINSTANCE dxdevice;
    7.10  	char *joystickname;
    7.11  	Uint8 send_add_event;
    7.12 @@ -1676,7 +1676,7 @@
    7.13  
    7.14  
    7.15  /* return the stable device guid for this device index */
    7.16 -JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
    7.17 +SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
    7.18  {
    7.19  	JoyStick_DeviceData *device = SYS_Joystick;
    7.20  	int index;
    7.21 @@ -1687,7 +1687,7 @@
    7.22  	return device->guid;
    7.23  }
    7.24  
    7.25 -JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
    7.26 +SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
    7.27  {
    7.28  	return joystick->hwdata->guid;
    7.29  }
     8.1 --- a/src/joystick/windows/SDL_dxjoystick_c.h	Tue Dec 11 10:50:45 2012 -0800
     8.2 +++ b/src/joystick/windows/SDL_dxjoystick_c.h	Tue Dec 11 11:54:32 2012 -0800
     8.3 @@ -87,7 +87,7 @@
     8.4      LPDIRECTINPUTDEVICE8 InputDevice;
     8.5      DIDEVCAPS Capabilities;
     8.6      int buffered;
     8.7 -	JoystickGUID guid;
     8.8 +	SDL_JoystickGUID guid;
     8.9  
    8.10      input_t Inputs[MAX_INPUTS];
    8.11      int NumInputs;
     9.1 --- a/src/joystick/windows/SDL_mmjoystick.c	Tue Dec 11 10:50:45 2012 -0800
     9.2 +++ b/src/joystick/windows/SDL_mmjoystick.c	Tue Dec 11 11:54:32 2012 -0800
     9.3 @@ -405,9 +405,9 @@
     9.4      }
     9.5  }
     9.6  
     9.7 -JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
     9.8 +SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
     9.9  {
    9.10 -    JoystickGUID guid;
    9.11 +    SDL_JoystickGUID guid;
    9.12      // the GUID is just the first 16 chars of the name for now
    9.13      const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
    9.14      SDL_zero( guid );
    9.15 @@ -415,9 +415,9 @@
    9.16      return guid;
    9.17  }
    9.18  
    9.19 -JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
    9.20 +SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
    9.21  {
    9.22 -    JoystickGUID guid;
    9.23 +    SDL_JoystickGUID guid;
    9.24      // the GUID is just the first 16 chars of the name for now
    9.25      const char *name = joystick->name;
    9.26      SDL_zero( guid );