Skip to content

Commit

Permalink
SDL_GUIDToString() follows the SDL_GetStringRule
Browse files Browse the repository at this point in the history
Also removed the distinction between SDL_GUID and SDL_JoystickGUID
  • Loading branch information
slouken committed Jul 19, 2024
1 parent a721f8f commit fe92da1
Show file tree
Hide file tree
Showing 44 changed files with 182 additions and 260 deletions.
12 changes: 6 additions & 6 deletions build-scripts/SDL_migration.cocci
Original file line number Diff line number Diff line change
Expand Up @@ -1353,12 +1353,7 @@ typedef SDL_GameControllerButton, SDL_GamepadButton;
@@
@@
- SDL_JoystickGetGUIDFromString
+ SDL_GetJoystickGUIDFromString
(...)
@@
@@
- SDL_JoystickGetGUIDString
+ SDL_GetJoystickGUIDString
+ SDL_GUIDFromString
(...)
@@
@@
Expand Down Expand Up @@ -3581,3 +3576,8 @@ typedef SDL_Colour, SDL_Color;
- SDL_AndroidSendMessage
+ SDL_SendAndroidMessage
(...)
@@
typedef SDL_JoystickGUID, SDL_GUID;
@@
- SDL_JoystickGUID
+ SDL_GUID
7 changes: 5 additions & 2 deletions docs/README-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,7 @@ The following functions have been renamed:
* SDL_JoystickGetButton() => SDL_GetJoystickButton()
* SDL_JoystickGetFirmwareVersion() => SDL_GetJoystickFirmwareVersion()
* SDL_JoystickGetGUID() => SDL_GetJoystickGUID()
* SDL_JoystickGetGUIDFromString() => SDL_GetJoystickGUIDFromString()
* SDL_JoystickGetGUIDString() => SDL_GetJoystickGUIDString()
* SDL_JoystickGetGUIDFromString() => SDL_GUIDFromString()
* SDL_JoystickGetHat() => SDL_GetJoystickHat()
* SDL_JoystickGetPlayerIndex() => SDL_GetJoystickPlayerIndex()
* SDL_JoystickGetProduct() => SDL_GetJoystickProduct()
Expand Down Expand Up @@ -902,6 +901,7 @@ The following functions have been removed:
* SDL_JoystickGetDeviceProductVersion() - replaced with SDL_GetJoystickProductVersionForID()
* SDL_JoystickGetDeviceType() - replaced with SDL_GetJoystickTypeForID()
* SDL_JoystickGetDeviceVendor() - replaced with SDL_GetJoystickVendorForID()
* SDL_JoystickGetGUIDString() - replaced with SDL_GUIDToString()
* SDL_JoystickHasLED() - replaced with SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN
* SDL_JoystickHasRumble() - replaced with SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN
* SDL_JoystickHasRumbleTriggers() - replaced with SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN
Expand All @@ -913,6 +913,9 @@ The following functions have been removed:
The following symbols have been removed:
* SDL_JOYBALLMOTION

The following structures have been renamed:
* SDL_JoystickGUID => SDL_GUID

## SDL_keyboard.h

Text input is no longer automatically enabled when initializing video, you should call SDL_StartTextInput() when you want to receive text input and call SDL_StopTextInput() when you are done. Starting text input may shown an input method editor (IME) and cause key up/down events to be skipped, so should only be enabled when the application wants text input.
Expand Down
6 changes: 3 additions & 3 deletions include/SDL3/SDL_gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ typedef struct SDL_GamepadBinding
* existing gamepad.
*
* The mapping string has the format "GUID,name,mapping", where GUID is the
* string value from SDL_GetJoystickGUIDString(), name is the human readable
* string value from SDL_GUIDToString(), name is the human readable
* string for the device and mappings are gamepad mappings to joystick ones.
* Under Windows there is a reserved GUID of "xinput" that covers all XInput
* devices. The mapping format for joystick is:
Expand Down Expand Up @@ -414,7 +414,7 @@ extern SDL_DECLSPEC const char * const * SDLCALL SDL_GetGamepadMappings(int *cou
* \sa SDL_GetJoystickGUIDForID
* \sa SDL_GetJoystickGUID
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_JoystickGUID guid);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_GUID guid);

/**
* Get the current mapping of a gamepad.
Expand Down Expand Up @@ -561,7 +561,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndexForID(SDL_JoystickID in
* \sa SDL_GetGamepadGUIDString
* \sa SDL_GetGamepads
*/
extern SDL_DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetGamepadGUIDForID(SDL_JoystickID instance_id);
extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetGamepadGUIDForID(SDL_JoystickID instance_id);

/**
* Get the USB vendor ID of a gamepad, if available.
Expand Down
8 changes: 3 additions & 5 deletions include/SDL3/SDL_guid.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,17 @@ typedef struct SDL_GUID {
/**
* Get an ASCII string representation for a given SDL_GUID.
*
* You should supply at least 33 bytes for pszGUID.
* The returned string follows the SDL_GetStringRule, and will be automatically freed later.
*
* \param guid the SDL_GUID you wish to convert to string.
* \param pszGUID buffer in which to write the ASCII string.
* \param cbGUID the size of pszGUID.
* \returns 0 on success or a negative error code on failure; call
* \returns the string representation of the GUID or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GUIDFromString
*/
extern SDL_DECLSPEC int SDLCALL SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID);
extern SDL_DECLSPEC const char * SDLCALL SDL_GUIDToString(SDL_GUID guid);

/**
* Convert a GUID string into a SDL_GUID structure.
Expand Down
54 changes: 13 additions & 41 deletions include/SDL3/SDL_joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
* controller. For XInput controllers this returns the XInput user index. Many
* joysticks will not be able to supply this information.
*
* The term SDL_JoystickGUID is a stable 128-bit identifier for a joystick
* device that does not change over time, it identifies class of the device (a
* SDL_GUID is used as a stable 128-bit identifier for a joystick
* device that does not change over time. It identifies class of the device (a
* X360 wired controller for example). This identifier is platform dependent.
*
* In order to use these functions, SDL_Init() must have been called with the
Expand Down Expand Up @@ -85,15 +85,6 @@ extern SDL_Mutex *SDL_joystick_lock;
*/
typedef struct SDL_Joystick SDL_Joystick;

/**
* A structure that encodes the stable unique id for a joystick device.
*
* This is just a standard SDL_GUID by a different name.
*
* \since This datatype is available since SDL 3.0.0.
*/
typedef SDL_GUID SDL_JoystickGUID;

/**
* This is a unique ID for a joystick for the time it is connected to the
* system, and is never reused for the lifetime of the application.
Expand Down Expand Up @@ -286,9 +277,9 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndexForID(SDL_JoystickID i
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetJoystickGUID
* \sa SDL_GetJoystickGUIDString
* \sa SDL_GUIDToString
*/
extern SDL_DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetJoystickGUIDForID(SDL_JoystickID instance_id);
extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUIDForID(SDL_JoystickID instance_id);

/**
* Get the USB vendor ID of a joystick, if available.
Expand Down Expand Up @@ -737,9 +728,9 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystic
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetJoystickGUIDForID
* \sa SDL_GetJoystickGUIDString
* \sa SDL_GUIDToString
*/
extern SDL_DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetJoystickGUID(SDL_Joystick *joystick);
extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUID(SDL_Joystick *joystick);

/**
* Get the USB vendor ID of an opened joystick, if available.
Expand Down Expand Up @@ -824,44 +815,25 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joy
extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickType(SDL_Joystick *joystick);

/**
* Get an ASCII string representation for a given SDL_JoystickGUID.
*
* You should supply at least 33 bytes for pszGUID.
*
* \param guid the SDL_JoystickGUID you wish to convert to string.
* \param pszGUID buffer in which to write the ASCII string.
* \param cbGUID the size of pszGUID.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetJoystickGUIDForID
* \sa SDL_GetJoystickGUID
* \sa SDL_GetJoystickGUIDFromString
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);

/**
* Convert a GUID string into a SDL_JoystickGUID structure.
* Convert a GUID string into a SDL_GUID structure.
*
* Performs no error checking. If this function is given a string containing
* an invalid GUID, the function will silently succeed, but the GUID generated
* will not be useful.
*
* \param pchGUID string containing an ASCII representation of a GUID.
* \returns a SDL_JoystickGUID structure.
* \returns a SDL_GUID structure.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetJoystickGUIDString
* \sa SDL_GUIDToString
*/
extern SDL_DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetJoystickGUIDFromString(const char *pchGUID);
extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GUIDFromString(const char *pchGUID);

/**
* Get the device information encoded in a SDL_JoystickGUID structure.
* Get the device information encoded in a SDL_GUID structure.
*
* \param guid the SDL_JoystickGUID you wish to get info about.
* \param guid the SDL_GUID you wish to get info about.
* \param vendor a pointer filled in with the device VID, or 0 if not
* available.
* \param product a pointer filled in with the device PID, or 0 if not
Expand All @@ -875,7 +847,7 @@ extern SDL_DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetJoystickGUIDFromString(const
*
* \sa SDL_GetJoystickGUIDForID
*/
extern SDL_DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16);
extern SDL_DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_GUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16);

/**
* Get the status of a specified joystick.
Expand Down
8 changes: 4 additions & 4 deletions include/SDL3/SDL_oldnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,15 @@
#define SDL_JoystickDetachVirtual SDL_DetachVirtualJoystick
#define SDL_JoystickFromInstanceID SDL_GetJoystickFromID
#define SDL_JoystickFromPlayerIndex SDL_GetJoystickFromPlayerIndex
#define SDL_JoystickGUID SDL_GUID
#define SDL_JoystickGetAttached SDL_JoystickConnected
#define SDL_JoystickGetAxis SDL_GetJoystickAxis
#define SDL_JoystickGetAxisInitialState SDL_GetJoystickAxisInitialState
#define SDL_JoystickGetBall SDL_GetJoystickBall
#define SDL_JoystickGetButton SDL_GetJoystickButton
#define SDL_JoystickGetFirmwareVersion SDL_GetJoystickFirmwareVersion
#define SDL_JoystickGetGUID SDL_GetJoystickGUID
#define SDL_JoystickGetGUIDFromString SDL_GetJoystickGUIDFromString
#define SDL_JoystickGetGUIDString SDL_GetJoystickGUIDString
#define SDL_JoystickGetGUIDFromString SDL_GUIDFromString
#define SDL_JoystickGetHat SDL_GetJoystickHat
#define SDL_JoystickGetPlayerIndex SDL_GetJoystickPlayerIndex
#define SDL_JoystickGetProduct SDL_GetJoystickProduct
Expand Down Expand Up @@ -925,15 +925,15 @@
#define SDL_JoystickDetachVirtual SDL_JoystickDetachVirtual_renamed_SDL_DetachVirtualJoystick
#define SDL_JoystickFromInstanceID SDL_JoystickFromInstanceID_renamed_SDL_GetJoystickFromID
#define SDL_JoystickFromPlayerIndex SDL_JoystickFromPlayerIndex_renamed_SDL_GetJoystickFromPlayerIndex
#define SDL_JoystickGUID SDL_JoystickGUID_renamed_SDL_GUID
#define SDL_JoystickGetAttached SDL_JoystickGetAttached_renamed_SDL_JoystickConnected
#define SDL_JoystickGetAxis SDL_JoystickGetAxis_renamed_SDL_GetJoystickAxis
#define SDL_JoystickGetAxisInitialState SDL_JoystickGetAxisInitialState_renamed_SDL_GetJoystickAxisInitialState
#define SDL_JoystickGetBall SDL_JoystickGetBall_renamed_SDL_GetJoystickBall
#define SDL_JoystickGetButton SDL_JoystickGetButton_renamed_SDL_GetJoystickButton
#define SDL_JoystickGetFirmwareVersion SDL_JoystickGetFirmwareVersion_renamed_SDL_GetJoystickFirmwareVersion
#define SDL_JoystickGetGUID SDL_JoystickGetGUID_renamed_SDL_GetJoystickGUID
#define SDL_JoystickGetGUIDFromString SDL_JoystickGetGUIDFromString_renamed_SDL_GetJoystickGUIDFromString
#define SDL_JoystickGetGUIDString SDL_JoystickGetGUIDString_renamed_SDL_GetJoystickGUIDString
#define SDL_JoystickGetGUIDFromString SDL_JoystickGetGUIDFromString_renamed_SDL_GUIDFromString
#define SDL_JoystickGetHat SDL_JoystickGetHat_renamed_SDL_GetJoystickHat
#define SDL_JoystickGetPlayerIndex SDL_JoystickGetPlayerIndex_renamed_SDL_GetJoystickPlayerIndex
#define SDL_JoystickGetProduct SDL_JoystickGetProduct_renamed_SDL_GetJoystickProduct
Expand Down
23 changes: 8 additions & 15 deletions src/SDL_guid.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,21 @@
#include "SDL_internal.h"

/* convert the guid to a printable string */
int SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)
const char *SDL_GUIDToString(SDL_GUID guid)
{
static const char k_rgchHexToASCII[] = "0123456789abcdef";
int i;
char string[sizeof(guid) * 2 + 1];

if (!pszGUID) {
return SDL_InvalidParamError("pszGUID");
}
if (cbGUID <= 0) {
return SDL_InvalidParamError("cbGUID");
}

for (i = 0; i < sizeof(guid.data) && i < (cbGUID - 1) / 2; 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 */
for (i = 0; i < sizeof(guid.data); ++i) {
unsigned char c = guid.data[i];

*pszGUID++ = k_rgchHexToASCII[c >> 4];
*pszGUID++ = k_rgchHexToASCII[c & 0x0F];
string[i * 2 + 0] = k_rgchHexToASCII[c >> 4];
string[i * 2 + 1] = k_rgchHexToASCII[c & 0x0F];
}
*pszGUID = '\0';
return 0;
string[sizeof(string) -1] = '\0';

return SDL_CreateTemporaryString(string);
}

/*-----------------------------------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions src/dynapi/SDL_dynapi.sym
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ SDL3_0.0.0 {
SDL_GetJoystickFromPlayerIndex;
SDL_GetJoystickGUID;
SDL_GetJoystickGUIDForID;
SDL_GetJoystickGUIDFromString;
SDL_GetJoystickGUIDInfo;
SDL_GetJoystickGUIDString;
SDL_GetJoystickHat;
SDL_GetJoystickID;
SDL_GetJoystickName;
Expand Down
2 changes: 0 additions & 2 deletions src/dynapi/SDL_dynapi_overrides.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@
#define SDL_GetJoystickFromPlayerIndex SDL_GetJoystickFromPlayerIndex_REAL
#define SDL_GetJoystickGUID SDL_GetJoystickGUID_REAL
#define SDL_GetJoystickGUIDForID SDL_GetJoystickGUIDForID_REAL
#define SDL_GetJoystickGUIDFromString SDL_GetJoystickGUIDFromString_REAL
#define SDL_GetJoystickGUIDInfo SDL_GetJoystickGUIDInfo_REAL
#define SDL_GetJoystickGUIDString SDL_GetJoystickGUIDString_REAL
#define SDL_GetJoystickHat SDL_GetJoystickHat_REAL
#define SDL_GetJoystickID SDL_GetJoystickID_REAL
#define SDL_GetJoystickName SDL_GetJoystickName_REAL
Expand Down
14 changes: 6 additions & 8 deletions src/dynapi/SDL_dynapi_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ SDL_DYNAPI_PROC(int,SDL_GL_SetSwapInterval,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GL_SwapWindow,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_GL_UnloadLibrary,(void),(),)
SDL_DYNAPI_PROC(SDL_GUID,SDL_GUIDFromString,(const char *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GUIDToString,(SDL_GUID a, char *b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(const char *,SDL_GUIDToString,(SDL_GUID a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GamepadConnected,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GamepadEventsEnabled,(void),(),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GamepadHasAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return)
Expand Down Expand Up @@ -285,11 +285,11 @@ SDL_DYNAPI_PROC(SDL_JoystickConnectionState,SDL_GetGamepadConnectionState,(SDL_G
SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadFirmwareVersion,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(SDL_Gamepad*,SDL_GetGamepadFromID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_Gamepad*,SDL_GetGamepadFromPlayerIndex,(int a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickGUID,SDL_GetGamepadGUIDForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_GUID,SDL_GetGamepadGUIDForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickID,SDL_GetGamepadID,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(SDL_Joystick*,SDL_GetGamepadJoystick,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadMapping,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadMappingForGUID,(SDL_JoystickGUID a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadMappingForGUID,(SDL_GUID a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadMappingForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(const char * const *,SDL_GetGamepadMappings,(int *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadName,(SDL_Gamepad *a),(a),return)
Expand Down Expand Up @@ -341,11 +341,9 @@ SDL_DYNAPI_PROC(SDL_JoystickConnectionState,SDL_GetJoystickConnectionState,(SDL_
SDL_DYNAPI_PROC(Uint16,SDL_GetJoystickFirmwareVersion,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(SDL_Joystick*,SDL_GetJoystickFromID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_Joystick*,SDL_GetJoystickFromPlayerIndex,(int a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickGUID,SDL_GetJoystickGUID,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickGUID,SDL_GetJoystickGUIDForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickGUID,SDL_GetJoystickGUIDFromString,(const char *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_GetJoystickGUIDInfo,(SDL_JoystickGUID a, Uint16 *b, Uint16 *c, Uint16 *d, Uint16 *e),(a,b,c,d,e),)
SDL_DYNAPI_PROC(int,SDL_GetJoystickGUIDString,(SDL_JoystickGUID a, char *b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_GUID,SDL_GetJoystickGUID,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(SDL_GUID,SDL_GetJoystickGUIDForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(void,SDL_GetJoystickGUIDInfo,(SDL_GUID a, Uint16 *b, Uint16 *c, Uint16 *d, Uint16 *e),(a,b,c,d,e),)
SDL_DYNAPI_PROC(Uint8,SDL_GetJoystickHat,(SDL_Joystick *a, int b),(a,b),return)
SDL_DYNAPI_PROC(SDL_JoystickID,SDL_GetJoystickID,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetJoystickName,(SDL_Joystick *a),(a),return)
Expand Down
Loading

0 comments on commit fe92da1

Please sign in to comment.