⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vs1.0_tokens.l

📁 使用stl技术,(还没看,是听说的)
💻 L
📖 第 1 页 / 共 5 页
字号:
		}

		curMT->macroText = foundParm;
		// search for next parameters, delimited by comma
		foundParm = strchr(foundParm, ',');
		if (foundParm == NULL)
		{
			foundParm = endStr;
			*foundParm = '\0';
		}
		else
		{
			// skip comma
			*foundParm = '\0';
			foundParm++;
		}
		prevMT = curMT;
	}

	return true;
}

//=====================================================================
// Function:	MacroMathFunction
// Description:	Comes here after macro replacement is done to perform
//				some mathematic function on parameter (macro replacement
//				 string (ie, register))
// Parameters:	invMacro = macroentry pointer containing macro information
//				recognizedLen = # characters recoginized so far
//				invStr = invoked replacement string so far
//				mathStr = "-", "+", etc for mathematic function
// Returns:		new recognizedLen, invStr, with incremented #
//=====================================================================
void MacroMathFunction(MACROENTRY *invMacro, unsigned int *recognizedLen, char **invStr,
						char *mathStr)
{
	char *numStartStr;
	unsigned int sLen;
	char numberStr[256];
	unsigned int number;
	char *operand;


	// verify enough paramters to complete operation
	if (invMacro->numParms != 2)
	{
		LexError("Two parameters are required for %s macro\n", invMacro->macroName);
		return;
	}

	// get second macro parm, which is add by amount.
	operand = invMacro->firstMacroParms->next->macroText;

	// first find inner most bracket if any
	numStartStr = strrchr(*invStr, ']');
	if (numStartStr == NULL)
	{
		numStartStr = strrchr(*invStr, ')');
	}

	if (numStartStr != NULL)
	{
		if ((strlen(*invStr)+strlen(operand)+1) > MAXREPLACESTRING)
		{
			LexError("Out of Temporary string replacement memory inside builtin macro %s\n",
					invMacro->macroName);
		}
		else
		{
			sLen = (numStartStr - *invStr);
			gReplaceText[0] = '\0';
			strncat(gReplaceText, *invStr, sLen);
			strcat(gReplaceText, mathStr);
			strcat(gReplaceText, operand);
			strcat(gReplaceText, numStartStr);
			*invStr = gReplaceText;
		}
	}
	else
	{
		numStartStr = strpbrk(*invStr, "0123456789");
		if (numStartStr != NULL)
		{
			// put up to number we found
			sLen = numStartStr - *invStr;
			if (sLen > MAXREPLACESTRING)
				goto ErrOut;

			gReplaceText[0] = '\0';
			strncat(gReplaceText, *invStr, sLen);

			switch (mathStr[0])
			{
				case '-':
					number = atoi(numStartStr)-atoi(operand);
					break;
				case '+':
					number = atoi(numStartStr)+atoi(operand);
					break;
			}
			sprintf(numberStr, "%d", number);

			if ((strlen(gReplaceText) + strlen(numberStr)) > MAXREPLACESTRING)
				goto ErrOut;

			strcat(gReplaceText, numberStr);

			while ((*numStartStr != '\0') && (*numStartStr >= '0' && *numStartStr <= '9'))
				numStartStr++;

			if ((strlen(gReplaceText) + strlen(numStartStr)) > MAXREPLACESTRING)
				goto ErrOut;

			strcat(gReplaceText, numStartStr);

			*invStr = gReplaceText;
		}
		else
		{
			if ((strlen(*invStr)+strlen(operand)+1) > MAXREPLACESTRING)
			{
				LexError("Out of Temporary string replacement memory inside builtin macro %s\n",
					invMacro->macroName);
			}
			else
			{
				sprintf(gReplaceText, "%s%s%s", *invStr, mathStr, operand);
				*invStr = gReplaceText;
			}
		}
	}


	return;

ErrOut:
	LexError("Out of Temporary string replacement memory inside builtin macro %s\n",
				invMacro->macroName);
	// skip ')'
	(*recognizedLen)++;
}

//=====================================================================
// Function:	MacroIncFunction
// Description:	Comes here after macro replacement is done to increment
//				macro replacement string (ie, register)
// Parameters:	lookStr = string after '(', so we can get parameters
//				recognizedLen = # characters recoginized so far
//				invStr = invoked replacement string so far
// Returns:		new recognizedLen, invStr, with incremented #
//=====================================================================
void MacroIncFunction(char *lookStr, unsigned int *recognizedLen, char **invStr)
{
	MACROENTRY tMEntry;
	MACROTEXT parm1;
	MACROTEXT parm2;

	tMEntry.macroName = "%inc()";
	tMEntry.numParms = 2;
	tMEntry.firstMacroParms = &parm1;
	parm1.prev = NULL;
	parm1.next = &parm2;
	parm1.macroText = *invStr;
	parm2.prev = &parm1;
	parm2.next = NULL;
	parm2.macroText = "1";

	MacroMathFunction(&tMEntry, recognizedLen, invStr, "+");
	// skip ')'
	(*recognizedLen)++;
}

//=====================================================================
// Function:	MacroDecFunction
// Description:	Comes here after macro replacement is done to decrement
//				macro replacement string (ie, register)
// Parameters:	lookStr = string after '(', so we can get parameters
//				recognizedLen = # characters recoginized so far
//				invStr = invoked replacement string so far
// Returns:		new recognizedLen, invStr, with decremented #
//=====================================================================
void MacroDecFunction(char *lookStr, unsigned int *recognizedLen, char **invStr)
{
	MACROENTRY tMEntry;
	MACROTEXT parm1;
	MACROTEXT parm2;

	tMEntry.macroName = "%dec()";
	tMEntry.numParms = 2;
	tMEntry.firstMacroParms = &parm1;
	parm1.prev = NULL;
	parm1.next = &parm2;
	parm1.macroText = *invStr;
	parm2.prev = &parm1;
	parm2.next = NULL;
	parm2.macroText = "1";

	MacroMathFunction(&tMEntry, recognizedLen, invStr, "-");
	// skip ')'
	(*recognizedLen)++;
}

//=====================================================================
// Function:	MacroAddFunction
// Description:	Comes here after macro replacement is done to add
//				macro replacement string (ie, register)
// Parameters:	lookStr = string after '(', so we can get parameters
//				recognizedLen = # characters recoginized so far
//				invStr = invoked replacement string so far
// Returns:		new recognizedLen, invStr, with incremented #
//=====================================================================
void MacroAddFunction(char *lookStr, unsigned int *recognizedLen, char **invStr)
{
	MACROENTRY tMEntry;
	MACROTEXT *curMT;
	MACROTEXT *nextMT;
	unsigned int i;

	tMEntry.macroName = "%add()";
	if (strlen(lookStr) > MAXREPLACESTRING)
	{
		LexError("Out of Temporary string replacement memory inside builtin macro %add()\n");
		return;
	}
	if (ParseBuiltInMacroParms(&tMEntry, lookStr))
	{
		MacroMathFunction(&tMEntry, recognizedLen, invStr, "+");
		// skip ',' strlen(parm2)+ ')'
		(*recognizedLen) += strlen(tMEntry.firstMacroParms->next->macroText)+2;
	}

	curMT = tMEntry.firstMacroParms;
	// in this case only one string was allocated
	free(curMT->macroText);
	for (i=0; i<tMEntry.numParms; i++)
	{
		nextMT = curMT->next;
		free(curMT);
		curMT = nextMT;
	}
}

//=====================================================================
// Function:	MacroSubFunction
// Description:	Comes here after macro replacement is done to subtract
//				macro replacement string (ie, register)
// Parameters:	invParms, parameters that macro was invoked with
//				recognizedLen = # characters recoginized so far
//				invStr = invoked replacement string so far
// Returns:		new recognizedLen, invStr, with incremented #
//=====================================================================
void MacroSubFunction(char *lookStr, unsigned int *recognizedLen, char **invStr)
{
	MACROENTRY tMEntry;
	MACROTEXT *curMT;
	MACROTEXT *nextMT;
	unsigned int i;

	tMEntry.macroName = "%sub()";
	if (ParseBuiltInMacroParms(&tMEntry, lookStr))
	{
		MacroMathFunction(&tMEntry, recognizedLen, invStr, "-");
		// skip ',' strlen(parm2)+ ')'
		(*recognizedLen) += strlen(tMEntry.firstMacroParms->next->macroText)+2;
	}
	curMT = tMEntry.firstMacroParms;
	// in this case only one string was allocated
	free(curMT->macroText);
	for (i=0; i<tMEntry.numParms; i++)
	{
		nextMT = curMT->next;
		free(curMT);
		curMT = nextMT;
	}
}

//=====================================================================
// Function:	EndMacroParms
// Description:	Does update and cleanup one end of macro parameters
//				is reached
// Parameters:	.
// Returns:		.
//=====================================================================
void EndMacroParms()
{
	char *curFileName;
	char *macroFileName;
	char tempStr[1024];
	char *macroText;

	if (gbTempInsideMacro)
	{
		if (gTempParseMacro->numParms != gTempMacro->numParms)
		{
			LexError("Macro invocation number of parameters do not match macro definition, skipping\n");
			BEGIN(INITIAL);
			SAFEFREE(gTempMacro);
		}
		else
		{
			// we got all the parameters for the MACRO invocation, so start inside
			// the macro now, by saving off current state on stack
			gIncludeStack[gIncludeStackIndex].lineNo = yylineno;
			gIncludeStack[gIncludeStackIndex].fileName = gCurFileName;
//			gIncludeStack[gIncludeStackIndex].fileHandle = yyin;
//fprintf( stderr, "Chris fix this code with myin stuff\n" );
			gIncludeStack[gIncludeStackIndex].prevString = myin;
			gIncludeStack[gIncludeStackIndex].nextString = NULL;
			gIncludeStack[gIncludeStackIndex].lastInvokeMacro = gInvokeMacro;
			gIncludeStack[gIncludeStackIndex].lastParseMacro = gParseMacro;
			gIncludeStack[gIncludeStackIndex].lastMacroLineParse = gMacroLineParse;
			gIncludeStack[gIncludeStackIndex].lastbInsideMacro = gbInsideMacro;
			gIncludeStack[gIncludeStackIndex].lastbInsideInclude = gbInsideInclude;
			gIncludeStack[gIncludeStackIndex].buffer = YY_CURRENT_BUFFER;
			gIncludeStack[gIncludeStackIndex].lastbProcessingIFDEF = gbProcessingIFDEF;
			gIncludeStackIndex++;

			gParseMacro = gTempParseMacro;
			gInvokeMacro = gTempMacro;
			gbInsideMacro = gbTempInsideMacro;

			gbTempInsideMacro = false;

//			yyin = NULL;
			myin = NULL;
			curFileName = gCurFileName;
			if (curFileName == NULL)
				curFileName = "";

			macroFileName = gParseMacro->fileName;
			if (macroFileName == NULL)
				macroFileName = "";

			sprintf(tempStr, "%s(%d) : References ->\n%s", curFileName, yylineno, macroFileName); 
			gCurFileName = strdup(tempStr);
			gMacroLineParse = gParseMacro->firstMacroLines;

			macroText = gMacroLine;
			// if no replacement text, just use source line
			if (gParseMacro->firstMacroParms == NULL)
			{
				macroText = gMacroLineParse->macroText;
			}
			else
			{
				// replace the macro parameters
				ReplaceMacroParms(gMacroLineParse->macroText, gMacroLine, gParseMacro, gInvokeMacro);
			}

			yylineno = gParseMacro->lineNo;
			if (gParseMacro->nLines >= 1)
			{
				strcpy(gSaveLine, macroText);
			}

//			if (gExpandMacros && (gParseMacro->nLines >= 1))
//			{
//				// in case there is anything there dump it out
//				GenDebugLine();
//				GenListString();			
//				if (gInvokeMacro->nLines >= 1)
//					GenSwitchFileNames(macroFileName);
//			}

			BEGIN(gInvokeState);
			yy_scan_string(macroText);
			gInvokeState = INITIAL;
		}
	}
	else
	{
		if (gLastMacro != NULL)
		{
			gLastMacro->next = gTempMacro;
		}
		gLastMacro = gTempMacro;
		BEGIN(MACROBODY);
	}
}

//=====================================================================
// Function:	FindSwizzleValue
// Description:	see if valid swizzle value and return the bits
// Parameters:	swizzleTex = pointer to characters to analyze
// Returns:		unsigned int = bits for swizzle values, or 0 for error
//=====================================================================
unsigned int FindSwizzleValue(char *swizzleText)
{
	unsigned int swizzleBits;
	unsigned int sLen;
	unsigned int i;
	unsigned int lastMask;

	sLen = strlen(swizzleText);
	swizzleBits = 0;
	lastMask = 0;

	for (i=0; i<sLen; i++)
	{
		switch (swizzleText[i])
		{
		case 'x':
			swizzleBits |= (WRITEMASK_X << (4*(3-i)));
			lastMask = WRITEMASK_X;
			break;
		case 'y':
			swizzleBits |= (WRITEMASK_Y << (4*(3-i)));
			lastMask = WRITEMASK_Y;
			break;
		case 'z':
			swizzleBits |= (WRITEMASK_Z << (4*(3-i)));
			lastMask = WRITEMASK_Z;
			break;
		case 'w':
			swizzleBits |= (WRITEMASK_W << (4*(3-i)));
			lastMask = WRITEMASK_W;
			break;
		}
	}

	for (; i<4; i++)
	{
		swizzleBits |= (lastMask << (4*(3-i)));
	}

	return swizzleBits;
}

#if 0
unsigned int FindSwizzleValue(char *swizzleText)
{

	DWORD swizzleBits;
	DWORD sLen;
	DWORD i;
	DWORD lastIndex;

	sLen = strlen(swizzleText);
	swizzleBits = 0;
	lastIndex = 0;

	for (i=0; i<sLen; i++)
	{
		switch (swizzleText[i])
		{
		case 'x':
			swizzleBits |= (0 << (D3DVS_SWIZZLE_SHIFT + (i * 2)));
			lastIndex = 0;
			break;
		case 'y':
			swizzleBits |= (1 << (D3DVS_SWIZZLE_SHIFT + (i * 2)));
			lastIndex = 1;
			break;
		case 'z':
			swizzleBits |= (2 << (D3DVS_SWIZZLE_SHIFT + (i * 2)));
			lastIndex = 2;
			break;
		case 'w':
			swizzleBits |= (3 << (D3DVS_SWIZZLE_SHIFT + (i * 2)));
			lastIndex = 3;
			break;
		}
	}

	for (; i<4; i++)
	{
		swizzleBits |= (lastIndex << (D3DVS_SWIZZLE_SHIFT + (i * 2)));
	}

	return swizzleBits;

	
}
#endif

//=====================================================================
// Function:	FindRegisterMask
// Description:	Look through register mask strings
// Parameters:	findName = name to lookup
// Returns:		unsigned int with token value
//=====================================================================
unsigned int MakeRegisterMask(char *findName)
{

	unsigned int regMask;
	char *findFirst;

	regMask = 0;

	findFirst = strchr(findName, 'x');
	if (findFirst != NULL)
	{
		if (strchr(findFirst+1, 'x') != NULL)
		{
			return 0;
		}

		regMask |= WRITEMASK_X;
	}

	findFirst = strchr(findName, 'y');
	if (findFirst != NULL)
	{
		regMask |= WRITEMASK_Y;
		// invalide write mask, must be swizzle
		if (strchr(findFirst+1, 'x') != NULL)
		{
			return 0;
		}

		if (strchr(findFirst+1, 'y') != NULL)
		{
			return 0;
		}

	}

	findFirst = strchr(findName, 'z');
	if (findFirst != NULL)
	{
		regMask |= WRITEMASK_Z;
		if (strchr(findFirst+1, 'x') != NULL)
		{
			return 0;
		}

		if (strchr(findFirst+1, 'y') != NULL)
		{
			return 0;
		}

		if (strchr(findFirst+1, 'z') != NULL)
		{
			return 0;
		}
	}

	findFirst = strchr(findName, 'w');
	if (findFirst != NULL)
	{

		regMask |= WRITEMASK_W;
		if (strchr(findFirst+1, 'x') != NULL)
		{
			return 0;
		}

		if (strchr(findFirst+1, 'y') != NULL)
		{
			return 0;
		}

		if 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -