Beispiel #1
0
const char *GetNextToken(const char *&pString)
{
	while(MFIsWhite(*pString) || MFIsNewline(*pString))
		++pString;

	const char *pEnd = pString;

	while(*pEnd && !MFIsWhite(*pEnd) && !MFIsNewline(*pEnd))
		++pEnd;

	const char *pToken = MFStrN(pString, (int)((uintp)pEnd-(uintp)pString));
	pString = pEnd;

	return pToken;
}
Beispiel #2
0
char* GetFloat(char *pFilePtr, float *pFloat)
{
	char *pEnd, *pToken;
	bool negative = false;
	int dotFound = 1;

	pFilePtr = MFSkipWhite(pFilePtr);

	if(*pFilePtr == '-')
	{
		negative = true;
		pFilePtr++;
	}

	pEnd = pFilePtr;
	while(MFIsNumeric(*pEnd) || (*pEnd == '.' && dotFound--)) pEnd++;

	pToken = (char*)MFStrN(pFilePtr, (int)(pEnd-pFilePtr));
	if(*pEnd == 'f') pEnd++;

	if(!MFIsWhite(*pEnd) && !MFIsNewline(*pEnd) && *pEnd != 0)
	{
		MFDebug_Warn(3, "Error: GetFloat() found non numeric character.");
		*pFloat = 0.0f;
		return pFilePtr;
	}

	pFilePtr = pEnd;

	*pFloat = (float)atof(pToken);
	if(negative) *pFloat = -*pFloat;

	return pFilePtr;
}
Beispiel #3
0
char* GetInt(char *pFilePtr, int *pInt)
{
	char *pEnd, *pToken;
	bool negative = false;

	pFilePtr = MFSkipWhite(pFilePtr);

	if(*pFilePtr == '-')
	{
		negative = true;
		pFilePtr++;
	}

	pEnd = pFilePtr;
	while(MFIsNumeric(*pEnd)) pEnd++;

	if(!MFIsWhite(*pEnd) && !MFIsNewline(*pEnd) && *pEnd != 0)
	{
		MFDebug_Warn(3, "Error: GetInt() found non numeric character.");
		*pInt = 0;
		return pFilePtr;
	}

	pToken = (char*)MFStrN(pFilePtr, (int)(pEnd - pFilePtr));
	pFilePtr = pEnd;

	*pInt = atoi(pToken);
	if(negative) *pInt = -*pInt;

	return pFilePtr;
}
Beispiel #4
0
const char *GetNextToken(const char *pText, const char **ppTokenEnd = NULL, char *pBuffer = gTokenBuffer)
{
	char *pT = pBuffer;

	while(MFIsWhite(*pText) || MFIsNewline(*pText))
		++pText;

	if(!*pText)
		return NULL;

	// skip comments
	while(*pText == '/' && pText[1] == '/')
	{
		while(*pText && !MFIsNewline(*pText))
			++pText;

		while(MFIsWhite(*pText) || MFIsNewline(*pText))
			++pText;

		if(!*pText)
			return NULL;
	}

	while(*pText && !MFIsWhite(*pText) && !MFIsNewline(*pText) && *pText != ',' && *pText != ';' && *pText != '{' && *pText != '}')
	{
		*pT++ = *pText++;
	}

	if(pT == pBuffer)
		*pT++ = *pText++;

	*pT = 0;

	if(ppTokenEnd)
		*ppTokenEnd = pText;

	return pBuffer;
}
Beispiel #5
0
const char *GetRestOfLine(const char *&pString)
{
	while(MFIsWhite(*pString))
		++pString;

	const char *pEnd = pString;
	while(*pEnd && !MFIsNewline(*pEnd))
		++pEnd;

	const char *pRestOfLine = MFStrN(pString, (int)((uintp)pEnd - (uintp)pString));
	pString = pEnd;

	return pRestOfLine;
}
Beispiel #6
0
char *ProcessBlock(char *pFilePtr, const char *pBlockName, char* (*BlockFunc)(char*, char*))
{
	char *pEnd;
	char *pToken;

	int braceCount = 0;
	bool inQuote = false;

	pFilePtr = MFSkipWhite(pFilePtr);

	if(*pFilePtr != '{')
	{
		MFDebug_Warn(3, MFStr("Error: Expected %s Block.", pBlockName));
		return pFilePtr;
	}

	pFilePtr++;

	while(*pFilePtr != 0)
	{
		while(!(*pFilePtr == '*' && !braceCount && !inQuote) && *pFilePtr != 0)
		{
			if(*pFilePtr == '\"') inQuote = !inQuote;
			if(!inQuote)
			{
				if(*pFilePtr == '{') braceCount++;
				if(*pFilePtr == '}') braceCount--;
			}
			pFilePtr++;

			if(braceCount < 0) return pFilePtr;
		}

		pEnd = pFilePtr;

		while(!MFIsWhite(*pEnd) && *pEnd != 0) pEnd++;

		pToken = (char*)MFStrN(pFilePtr, (int)(pEnd - pFilePtr));
		pFilePtr = pEnd;

		pFilePtr = BlockFunc(pFilePtr, pToken);
	}

	return pFilePtr;
}
Beispiel #7
0
void ParseASEFile(char *pFilePtr, F3DFile *_pModel)
{
	pModel = _pModel;

	char *pEnd;
	char *pToken;

	int braceCount = 0;
	bool inQuote = false;

	while(*pFilePtr != 0)
	{
		while(!(*pFilePtr == '*' && !braceCount && !inQuote) && *pFilePtr != 0)
		{
			if(*pFilePtr == '\"') inQuote = !inQuote;
			if(!inQuote)
			{
				if(*pFilePtr == '{') braceCount++;
				if(*pFilePtr == '}') braceCount--;
			}
			pFilePtr++;
		}

		pEnd = pFilePtr;

		while(!MFIsWhite(*pEnd) && *pEnd != 0) pEnd++;

		pToken = (char*)MFStrN(pFilePtr, (int)(pEnd - pFilePtr));
		pFilePtr = pEnd;

		if(!MFString_CaseCmp(pToken, "*3DSMAX_ASCIIEXPORT"))
		{
			int version = 0;

			pFilePtr = GetInt(pFilePtr, &version);

			MFDebug_Log(4, MFStr("Recognised .ASE file version: %d\n", version));
		}
		else if(!MFString_CaseCmp(pToken, "*COMMENT"))
		{
			char *pComment;

			pFilePtr = GetString(pFilePtr, &pComment);

			MFDebug_Log(4, MFStr("Comment: %s", pComment));
		}
		else if(!MFString_CaseCmp(pToken, "*SCENE"))
		{
			pFilePtr = ProcessBlock(pFilePtr, "*SCENE", ReadSceneChunk);
		}
		else if(!MFString_CaseCmp(pToken, "*MATERIAL_LIST"))
		{
			pFilePtr = ProcessBlock(pFilePtr, "*MATERIAL_LIST", ReadMaterialChunk);
		}
		else if(!MFString_CaseCmp(pToken, "*GEOMOBJECT"))
		{
			pFilePtr = ProcessBlock(pFilePtr, "*GEOMOBJECT", ReadGeomChunk);
		}
		else
		{
			MFDebug_Warn(3, MFStr("Unknown token: %s", pToken));
		}
	}
}
void HKStringEntryLogic::Update()
{
	bool shiftL = !!MFInput_Read(Key_LShift, IDD_Keyboard);
	bool shiftR = !!MFInput_Read(Key_RShift, IDD_Keyboard);
	bool ctrlL = !!MFInput_Read(Key_LControl, IDD_Keyboard);
	bool ctrlR = !!MFInput_Read(Key_RControl, IDD_Keyboard);

	int keyPressed = 0;

	bool shift = shiftL || shiftR;
	bool ctrl = ctrlL || ctrlR;

#if defined(MF_WINDOWS)
	if(ctrl && MFInput_WasPressed(Key_C, IDD_Keyboard) && selectionStart != selectionEnd)
	{
		BOOL opened = OpenClipboard(apphWnd);

		if(opened)
		{
			int selMin = MFMin(selectionStart, selectionEnd);
			int selMax = MFMax(selectionStart, selectionEnd);

			int numChars = selMax-selMin;

			HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, numChars + 1);
			char *pString = (char*)GlobalLock(hData);

			MFString_Copy(pString, GetRenderString().SubStr(selMin, numChars).CStr());

			GlobalUnlock(hData);

			EmptyClipboard();
			SetClipboardData(CF_TEXT, hData);

			CloseClipboard();
		}
	}
	else if(ctrl && MFInput_WasPressed(Key_X, IDD_Keyboard) && selectionStart != selectionEnd)
	{
		BOOL opened = OpenClipboard(apphWnd);

		if(opened)
		{
			int selMin = MFMin(selectionStart, selectionEnd);
			int selMax = MFMax(selectionStart, selectionEnd);

			int numChars = selMax-selMin;

			HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, numChars + 1);
			char *pString = (char*)GlobalLock(hData);

			MFString_Copy(pString, GetRenderString().SubStr(selMin, numChars).CStr());

			GlobalUnlock(hData);

			EmptyClipboard();
			SetClipboardData(CF_TEXT, hData);

			CloseClipboard();

			ClearSelection();
		}
	}
	else if(ctrl && MFInput_WasPressed(Key_V, IDD_Keyboard))
	{
		BOOL opened = OpenClipboard(apphWnd);

		if(opened)
		{
			int selMin = MFMin(selectionStart, selectionEnd);
			int selMax = MFMax(selectionStart, selectionEnd);

			int numChars = selMax-selMin;

			HANDLE hData = GetClipboardData(CF_TEXT);
			MFString paste((const char*)GlobalLock(hData), true);

			buffer.Replace(selMin, numChars, paste);

			GlobalUnlock(hData);

			cursorPos = selMin + paste.NumBytes();
			selectionStart = selectionEnd = cursorPos;

			GlobalUnlock(hData);

			CloseClipboard();

			if((numChars || cursorPos != selMin) && changeCallback)
				changeCallback(buffer.CStr());
		}
	}
	else
#endif
	{
		// check for new keypresses
		for(int a=0; a<255; a++)
		{
			if(MFInput_WasPressed(a, IDD_Keyboard))
			{
				keyPressed = a;
				holdKey = a;
				repeatDelay = gRepeatDelay;
				break;
			}
		}

		// handle repeat keys
		if(holdKey && MFInput_Read(holdKey, IDD_Keyboard))
		{
			repeatDelay -= MFSystem_TimeDelta();
			if(repeatDelay <= 0.f)
			{
				keyPressed = holdKey;
				repeatDelay += gRepeatRate;
			}
		}
		else
			holdKey = 0;

		// if there was a new key press
		if(keyPressed)
		{
			switch(keyPressed)
			{
				case Key_Backspace:
				case Key_Delete:
				{
					if(selectionStart != selectionEnd)
					{
						ClearSelection();
					}
					else
					{
						if(keyPressed == Key_Backspace && cursorPos > 0)
						{
							buffer.ClearRange(--cursorPos, 1);
							selectionStart = selectionEnd = cursorPos;

							if(changeCallback)
								changeCallback(buffer.CStr());
						}
						else if(keyPressed == Key_Delete && cursorPos < buffer.NumBytes())
						{
							buffer.ClearRange(cursorPos, 1);
							selectionStart = selectionEnd = cursorPos;

							if(changeCallback)
								changeCallback(buffer.CStr());
						}
					}
					break;
				}

				case Key_Left:
				case Key_Right:
				case Key_Home:
				case Key_End:
				{
					if(ctrl)
					{
						if(keyPressed == Key_Left)
						{
							while(cursorPos && MFIsWhite(buffer[cursorPos-1]))
								--cursorPos;
							if(MFIsAlphaNumeric(buffer[cursorPos-1]))
							{
								while(cursorPos && MFIsAlphaNumeric(buffer[cursorPos-1]))
									--cursorPos;
							}
							else if(cursorPos)
							{
								--cursorPos;
								while(cursorPos && buffer[cursorPos-1] == buffer[cursorPos])
									--cursorPos;
							}
						}
						else if(keyPressed == Key_Right)
						{
							while(cursorPos < buffer.NumBytes() && MFIsWhite(buffer[cursorPos]))
								++cursorPos;
							if(MFIsAlphaNumeric(buffer[cursorPos]))
							{
								while(cursorPos < buffer.NumBytes() && MFIsAlphaNumeric(buffer[cursorPos]))
									++cursorPos;
							}
							else if(cursorPos < buffer.NumBytes())
							{
								++cursorPos;
								while(cursorPos < buffer.NumBytes() && buffer[cursorPos] == buffer[cursorPos-1])
									++cursorPos;
							}
						}
						else if(keyPressed == Key_Home)
							cursorPos = 0;
						else if(keyPressed == Key_End)
							cursorPos = buffer.NumBytes();
					}
					else
					{
						if(keyPressed == Key_Left)
							cursorPos = (!shift && selectionStart != selectionEnd ? MFMin(selectionStart, selectionEnd) : MFMax(cursorPos-1, 0));
						else if(keyPressed == Key_Right)
							cursorPos = (!shift && selectionStart != selectionEnd ? MFMax(selectionStart, selectionEnd) : MFMin(cursorPos+1, buffer.NumBytes()));
						else if(keyPressed == Key_Home)
							cursorPos = 0;	// TODO: if multiline, go to start of line..
						else if(keyPressed == Key_End)
							cursorPos = buffer.NumBytes();	// TODO: if multiline, go to end of line...
					}

					if(shift)
						selectionEnd = cursorPos;
					else
						selectionStart = selectionEnd = cursorPos;

					break;
				}

				default:
				{
					bool caps = MFInput_GetKeyboardStatusState(KSS_CapsLock);
					int ascii = MFInput_KeyToAscii(keyPressed, shift, caps);

					if(ascii && (!maxLen || buffer.NumBytes() < maxLen-1))
					{
						// check character exclusions
						if(MFIsNewline(ascii) && type != ST_MultiLine)
							break;
						if(ascii == '\t' && type != ST_MultiLine)
							break;
						if(type == ST_Numeric && !MFIsNumeric(ascii))
							break;
						if(include)
						{
							if(include.FindChar(ascii) < 0)
								break;
						}
						if(exclude)
						{
							if(exclude.FindChar(ascii) >= 0)
								break;
						}

						int selMin = MFMin(selectionStart, selectionEnd);
						int selMax = MFMax(selectionStart, selectionEnd);
						int selRange = selMax - selMin;

						const uint16 wstr[] = { (uint16)ascii, 0 };
						char insert[5];
						MFString_CopyUTF16ToUTF8(insert, wstr);
						buffer.Replace(selMin, selRange, insert);
						cursorPos = selMin + 1;

						selectionStart = selectionEnd = cursorPos;

						if(changeCallback)
							changeCallback(buffer.CStr());
					}
					break;
				}
			}
		}
	}
}