Exemplo n.º 1
0
MF_API int MFString_AsciiToInteger(const char *pString, bool bDetectBase, int base, const char **ppNextChar)
{
	pString = MFSkipWhite(pString);

	int number = 0;

	if(base == 16 || (bDetectBase && ((pString[0] == '0' && pString[1] == 'x') || pString[0] == '$')))
	{
		// hex number
		if(pString[0] == '0' && pString[1] == 'x')
			pString += 2;
		else if(pString[0] == '$')
			pString += 1;

		while(*pString)
		{
			int digit = *pString++;
			if(!MFIsHex(digit))
				return number;
			number <<= 4;
			number += MFIsNumeric(digit) ? digit - '0' : MFToLower(digit) - 'a' + 10;
		}
	}
	else if(base == 2 || (bDetectBase && pString[0] == 'b'))
	{
		if(pString[0] == 'b')
			++pString;

		while(*pString == '0' || *pString == '1')
		{
			number <<= 1;
			number |= *pString - '0';
		}
	}
	else if(base == 10)
	{
		// decimal number
		bool neg = false;
		if(*pString == '-' || *pString == '+')
		{
			neg = *pString == '-';
			++pString;
		}

		while(*pString)
		{
			if(!MFIsNumeric(*pString))
				return neg ? -number : number;
			number = number*10 + (*pString++) - '0';
		}

		if(neg)
			number = -number;
	}

	if(ppNextChar)
		*ppNextChar = pString;

	return number;
}
Exemplo n.º 2
0
MF_API bool MFString_IsNumber(const char *pString, bool bAllowHex)
{
	pString = MFSkipWhite(pString);

	int numDigits = 0;

	if(bAllowHex && pString[0] == '0' && pString[1] == 'x')
	{
		// hex number
		pString += 2;
		while(*pString)
		{
			if(!MFIsHex(*pString++))
				return false;
			++numDigits;
		}
	}
	else
	{
		// decimal number
		if(*pString == '-' || *pString == '+')
			++pString;

		bool bHasDot = false;
		while(*pString)
		{
			if(!MFIsNumeric(*pString) && (bHasDot || *pString != '.'))
				return false;
			if(*pString++ == '.')
			{
				bHasDot = true;
				numDigits = 0;
			}
			else
				++numDigits;
		}
	}

	return numDigits > 0 ? true : false;
}
Exemplo n.º 3
0
void MFInputLinux_InitGamepad(int fd, LinuxGamepad *pGamepad)
{
#if !defined(__CYGWIN__)
	MFCALLSTACK;

	pGamepad->joyFD = fd;

	// get the pad details
	ioctl(fd, JSIOCGNAME(80), pGamepad->identifier);
	ioctl(fd, JSIOCGAXES, &pGamepad->numAxiis);
	ioctl(fd, JSIOCGBUTTONS, &pGamepad->numButtons);

	MFGamepadInfo *pGI = pGamepadMappingRegistry;

	// we need to find a better way to get the VID/PID from the gamepad...
	if(!MFString_CompareN(pGamepad->identifier, "HID", 3))
	{
		// the device was unnamed, but it is a HID device, so we'll try and match the VID/PID
		char *pBase = pGamepad->identifier + 3, *pEnd;

		// get the VID string
		while(*pBase && !MFIsHex(*pBase))
			++pBase;

		pEnd = pBase + 1;
		while(MFIsHex(*pEnd))
			++pEnd;

		uint32 vid = MFHexToInt(MFStrN(pBase, pEnd - pBase));

		// get the PID string
		pBase = pEnd;
		while(*pBase && !MFIsHex(*pBase))
			++pBase;

		pEnd = pBase + 1;
		while(MFIsHex(*pEnd))
			++pEnd;

		uint32 pid = MFHexToInt(MFStrN(pBase, pEnd - pBase));

		// find a matching descriptor
		for(; pGI; pGI = pGI->pNext)
		{
			if(pGI->vendorID == vid && pGI->productID == pid)
				break;
		}
	}
	else
	{
		// the device is named, so we'll compare the name against our list and hope its the same as windows..
		// since we dont have the VID/PID though, we cant verify its not a device with an aliased name.
		pGI = pGI->pNext; // skip the first one
		for(; pGI; pGI = pGI->pNext)
		{
			// since linux appends the manufacturer name, we'll just check for a match on the end of the string
			int len1 = MFString_Length(pGamepad->identifier);
			int len2 = MFString_Length(pGI->pIdentifier);
			if(!MFString_Compare(pGamepad->identifier + (len1 - len2), pGI->pIdentifier))
				break;
		}
	}

	if(!pGI)
	{
		// use default descriptor
		pGamepad->pGamepadInfo = pGamepadMappingRegistry;
		MFDebug_Warn(1, MFStr("Found an unknown gamepad '%s', using default mappings.", pGamepad->identifier));

		// offer to send email detailing controller info..
//		MessageBox(NULL, "An unknown gamepad has been detected.\r\nWe strive to support every gamepad natively, please report your gamepad to Manu at [email protected].\r\nI will contact you and request a few details about the gamepad so it can be added to the registry for the next release.", "Unknown gamepad detected...", MB_OK);
	}
	else
	{
		// use applicable descriptor
		pGamepad->pGamepadInfo = pGI;
		MFDebug_Log(2, MFStr("Found gamepad: %s '%s'.", pGI->pName, pGI->pIdentifier));
	}
/*
	// fix up the linux mapping table
	const int *pButtonMap = pGamepad->pGamepadInfo->pButtonMap;
	int numAxiis = 0;

	for(int a=0; a<60; a++)
	{
		for(int b=0; b<GamepadType_Max; ++b)
		{
			if((pButtonMap[b] & AID_Analog) && MFGETAXIS(pButtonMap[b]) == a)
			{
				pGamepad->axisMap[a] = numAxiis;
				printf("%d = %d\n", a, numAxiis);
				++numAxiis;
			}
		}
	}
*/
#endif
}