Fix to Pass tests

This commit is contained in:
Locria Cyber 2023-06-14 18:53:01 +00:00
parent 337a4589a9
commit 0c181dcf74
No known key found for this signature in database
GPG Key ID: ED0D424AE4406330

View File

@ -67,6 +67,8 @@ static GLFWbool initJoysticks(void)
return _glfw.joysticksInitialized = GLFW_TRUE; return _glfw.joysticksInitialized = GLFW_TRUE;
} }
#if defined(GLFW_BUILD_LINUX_JOYSTICK)
uint16_t parseHexDigit(char c) uint16_t parseHexDigit(char c)
{ {
if (c >= '0' && c <= '9') return c - '0'; if (c >= '0' && c <= '9') return c - '0';
@ -89,21 +91,10 @@ static struct vendor_product parseGUID(const char* guid)
return result; return result;
} }
// Finds a mapping based on joystick GUID static _GLFWmapping* findMappingUSBVendorProduct(const char* guid)
//
static _GLFWmapping* findMapping(const char* guid)
{ {
struct vendor_product this; struct vendor_product this;
// exact match
for (int i = 0; i < _glfw.mappingCount; i++)
{
if (strncmp(_glfw.mappings[i].guid, guid, 32) == 0)
return _glfw.mappings + i;
}
#if defined(GLFW_BUILD_LINUX_JOYSTICK)
// only match vendor product
this = parseGUID(guid); this = parseGUID(guid);
for (int i = 0; i < _glfw.mappingCount; i++) for (int i = 0; i < _glfw.mappingCount; i++)
@ -113,11 +104,31 @@ static _GLFWmapping* findMapping(const char* guid)
if (memcmp(&this, &that, sizeof(struct vendor_product)) == 0) if (memcmp(&this, &that, sizeof(struct vendor_product)) == 0)
return _glfw.mappings + i; return _glfw.mappings + i;
} }
#endif
return NULL; return NULL;
} }
#endif
// Finds a mapping based on joystick GUID
//
static _GLFWmapping* findMapping(const char* guid)
{
// exact match
for (int i = 0; i < _glfw.mappingCount; i++)
{
if (strncmp(_glfw.mappings[i].guid, guid, 32) == 0)
return _glfw.mappings + i;
}
#if defined(GLFW_BUILD_LINUX_JOYSTICK)
// only match vendor id, product id
return findMappingUSBVendorProduct(guid);
#else
return NULL;
#endif
}
// Checks whether a gamepad mapping element is present in the hardware // Checks whether a gamepad mapping element is present in the hardware
// //
static GLFWbool isValidElementForJoystick(const _GLFWmapelement* e, static GLFWbool isValidElementForJoystick(const _GLFWmapelement* e,