From 721963afb78bcd6b78b25c6f87b67bb65bbba291 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 11 Dec 2012 11:54:32 -0800 Subject: [PATCH] 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 | 10 +++++----- src/joystick/SDL_gamecontroller.c | 15 ++++++++------- src/joystick/SDL_joystick.c | 21 +++++++-------------- src/joystick/SDL_sysjoystick.h | 4 ++-- src/joystick/darwin/SDL_sysjoystick.c | 4 ++-- src/joystick/linux/SDL_sysjoystick.c | 6 ++++-- src/joystick/windows/SDL_dxjoystick.c | 6 +++--- src/joystick/windows/SDL_dxjoystick_c.h | 2 +- src/joystick/windows/SDL_mmjoystick.c | 8 ++++---- 9 files changed, 36 insertions(+), 40 deletions(-) diff --git a/include/SDL_joystick.h b/include/SDL_joystick.h index aa719faa3..622c73bca 100644 --- a/include/SDL_joystick.h +++ b/include/SDL_joystick.h @@ -65,7 +65,7 @@ typedef struct _SDL_Joystick SDL_Joystick; /* A structure that encodes the stable unique id for a joystick device */ typedef struct { Uint8 data[16]; -} JoystickGUID; +} SDL_JoystickGUID; typedef int SDL_JoystickID; @@ -102,22 +102,22 @@ extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick); /** * Return the GUID for the joystick at this index */ -extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index); +extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index); /** * Return the GUID for this opened joystick */ -extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick); +extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick); /** * Return a string representation for this guid. You are responsible for freeing memory from this call */ -extern DECLSPEC char *SDLCALL SDL_JoystickGetGUIDString(JoystickGUID guid); +extern DECLSPEC void SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID); /** * convert a string into a joystick formatted guid */ -extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID); +extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID); /** * Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not. diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 17f66ee60..b1de6ee7a 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -48,7 +48,7 @@ struct _SDL_HatAsButton /* our in memory mapping db between joystick objects and controller mappings*/ struct _SDL_ControllerMapping { - JoystickGUID guid; + SDL_JoystickGUID guid; const char *name; // mapping of axis/button id to controller version @@ -71,7 +71,7 @@ struct _SDL_ControllerMapping /* our hard coded list of mapping support */ typedef struct _ControllerMapping_t { - JoystickGUID guid; + SDL_JoystickGUID guid; char *name; const char *mapping; struct _ControllerMapping_t *next; @@ -458,7 +458,7 @@ SDL_PrivateGameControllerParseControllerConfigString( struct _SDL_ControllerMapp /* * Make a new button mapping struct */ -void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, JoystickGUID guid, const char *pchName, const char *pchMapping ) +void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping ) { int j; @@ -673,7 +673,7 @@ SDL_GameControllerNameForIndex(int device_index) } else { - JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index ); + SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index ); pSupportedController = s_pSupportedControllers; while ( pSupportedController ) { @@ -700,10 +700,11 @@ int SDL_IsGameController(int device_index) } else { - JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index ); + SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index ); pSupportedController = s_pSupportedControllers; // debug code to help get the guid string for a new joystick - /*const char *pchGUID = SDL_JoystickGetGUIDString( jGUID ); + /* char szGUID[33]; + SDL_JoystickGetGUIDString( jGUID, szGUID, sizeof(szGUID) ); printf( "%s\n", pchGUID ); SDL_free( pchGUID );*/ while ( pSupportedController ) @@ -759,7 +760,7 @@ SDL_GameControllerOpen(int device_index) pSupportedController = SDL_PrivateGetControllerMapping(device_index); if ( !pSupportedController ) { - JoystickGUID jGUID; + SDL_JoystickGUID jGUID; jGUID = SDL_JoystickGetDeviceGUID( device_index ); pSupportedController = s_pSupportedControllers; diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 1f7581ff1..077f131d2 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -683,34 +683,28 @@ SDL_PrivateJoystickNeedsPolling() /* return the guid for this index */ -JoystickGUID SDL_JoystickGetDeviceGUID(int device_index) +SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index) { return SDL_SYS_JoystickGetDeviceGUID( device_index ); } /* return the guid for this opened device */ -JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick) +SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick) { return SDL_SYS_JoystickGetGUID( joystick ); } /* convert the guid to a printable string */ -char *SDL_JoystickGetGUIDString(JoystickGUID guid) +void SDL_JoystickGetGUIDString( SDL_JoystickGUID guid, char *pszGUID, int cbGUID ) { static const char k_rgchHexToASCII[] = "0123456789abcdef"; char *pchOut = NULL; char *pchString = NULL; int i; - pchString = SDL_malloc(33); // 16 bytes - if ( !pchString ) - { - SDL_OutOfMemory(); - return NULL; - } - pchOut = pchString; + pchOut = pszGUID; - for ( i = 0; i < sizeof(guid); i++ ) + for ( i = 0; i < sizeof(guid) && i < (cbGUID-1); i++ ) { // each input byte writes 2 ascii chars, and might write a null byte. // If we don't have room for next input byte, stop @@ -720,7 +714,6 @@ char *SDL_JoystickGetGUIDString(JoystickGUID guid) *pchOut++ = k_rgchHexToASCII[ c & 0x0F ]; } *pchOut = '\0'; - return pchString; } @@ -756,9 +749,9 @@ static unsigned char nibble( char c ) /* convert the string version of a joystick guid to the struct */ -JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID) +SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID) { - JoystickGUID guid; + SDL_JoystickGUID guid; int maxoutputbytes= sizeof(guid); int len = SDL_strlen( pchGUID ); Uint8 *p; diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h index f0183e017..1821beec7 100644 --- a/src/joystick/SDL_sysjoystick.h +++ b/src/joystick/SDL_sysjoystick.h @@ -104,10 +104,10 @@ extern void SDL_SYS_JoystickClose(SDL_Joystick * joystick); extern void SDL_SYS_JoystickQuit(void); /* Function to return the stable GUID for a plugged in device */ -extern JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index); +extern SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index); /* Function to return the stable GUID for a opened joystick */ -extern JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick); +extern SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick); #ifdef SDL_JOYSTICK_DINPUT /* Function to get the current instance id of the joystick located at device_index */ diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c index d9fefcca7..abba9307d 100644 --- a/src/joystick/darwin/SDL_sysjoystick.c +++ b/src/joystick/darwin/SDL_sysjoystick.c @@ -1083,7 +1083,7 @@ SDL_SYS_JoystickQuit(void) } -JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) +SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) { recDevice *device = gpDeviceList; int index; @@ -1094,7 +1094,7 @@ JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) return device->guid; } -JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick) +SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick) { return joystick->hwdata->guid; } diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 77d75800f..5f7bb2c15 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -953,13 +953,15 @@ SDL_SYS_JoystickQuit(void) #endif } -JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) +SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) { + JoystickGUID guid; return JoystickByDevIndex(device_index)->guid; } -JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) +SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) { + JoystickGUID guid; return joystick->hwdata->guid; } diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index f9bb4a7e2..f63bdc41d 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -79,7 +79,7 @@ extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, LPUNKNOWN punkOuter); struct JoyStick_DeviceData_ { - JoystickGUID guid; + SDL_JoystickGUID guid; DIDEVICEINSTANCE dxdevice; char *joystickname; Uint8 send_add_event; @@ -1676,7 +1676,7 @@ SDL_SYS_JoystickQuit(void) /* return the stable device guid for this device index */ -JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) +SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) { JoyStick_DeviceData *device = SYS_Joystick; int index; @@ -1687,7 +1687,7 @@ JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) return device->guid; } -JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) +SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) { return joystick->hwdata->guid; } diff --git a/src/joystick/windows/SDL_dxjoystick_c.h b/src/joystick/windows/SDL_dxjoystick_c.h index 5b401d25b..08e6cf1af 100644 --- a/src/joystick/windows/SDL_dxjoystick_c.h +++ b/src/joystick/windows/SDL_dxjoystick_c.h @@ -87,7 +87,7 @@ struct joystick_hwdata LPDIRECTINPUTDEVICE8 InputDevice; DIDEVCAPS Capabilities; int buffered; - JoystickGUID guid; + SDL_JoystickGUID guid; input_t Inputs[MAX_INPUTS]; int NumInputs; diff --git a/src/joystick/windows/SDL_mmjoystick.c b/src/joystick/windows/SDL_mmjoystick.c index 90e98fe5c..a7093601f 100644 --- a/src/joystick/windows/SDL_mmjoystick.c +++ b/src/joystick/windows/SDL_mmjoystick.c @@ -405,9 +405,9 @@ SDL_SYS_JoystickQuit(void) } } -JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) +SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) { - JoystickGUID guid; + SDL_JoystickGUID guid; // the GUID is just the first 16 chars of the name for now const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index ); SDL_zero( guid ); @@ -415,9 +415,9 @@ JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) return guid; } -JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) +SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) { - JoystickGUID guid; + SDL_JoystickGUID guid; // the GUID is just the first 16 chars of the name for now const char *name = joystick->name; SDL_zero( guid );