Esempio n. 1
0
main()
{
    dataBlockT db;
    string line, cmd, token, var;
    int pos;
    printf("List structure test program\n");
    printf("Type \"help\" for help\n");
    db = NewDataBlock();
    while (TRUE) {
        printf(">");
        line = GetLine();
        SetScannerString(db->scanner, line);
        cmd = ConvertToLowerCase(ReadToken(db->scanner));
        if (IsVariableName(cmd)) {
            var = cmd;
            token = ReadToken(db->scanner);
            if (StringEqual(token, "")) {
                DisplayStringList(GetValue(db, var));
            } else if (StringEqual(token, "=")) {
                ParseOperation(db, var);
            } else {
                Error("Unexpected token %s", token);
            }
        } else if (StringEqual(cmd, "help")) {
            HelpCmd();
        } else if (StringEqual(cmd, "quit")) {
            break;
        } else {
            SaveToken(db->scanner, cmd);
            ParseOperation(db, NULL);
        }
    }
}
Esempio n. 2
0
//******************************************************************************
//
// FUNCTION:        CmdParser
//
// USAGE:             Parses commands to find debug actions
//				
//
// INPUT:              cmdBuffer - buffer containing input string
//
// OUTPUT:           N/A
//
// GLOBALS:         debugParameters, globalCurrentCmdListPtr
//
//******************************************************************************
static BOOL CmdParser(BYTE *cmdBuffer, ROM CMD_LIST_STRUCT *cmdListToUse)
{
	BYTE cmdSearchCounter = 0;
	BOOL cmdStringMatchFound = FALSE; 
	
	BYTE *cmdBufferPtr;
	char *cmdString;
	ROM DEBUG_CMD_STRUCT *debugCmdStructPtr;
	BYTE sizeOfDebugList;
	
	globalCurrentCmdListPtr = cmdListToUse;
	sizeOfDebugList = cmdListToUse->numOfCmdsInList;
	

	//Look for help command
	cmdBufferPtr = cmdBuffer;
	if (*cmdBufferPtr++ == 'h' &&
		*cmdBufferPtr++ == 'e' &&
		*cmdBufferPtr++ == 'l' &&
		*cmdBufferPtr++ == 'p' )
	{
		HelpCmd();
		return TRUE;
	}


	while (cmdSearchCounter < sizeOfDebugList && !cmdStringMatchFound)
	{
		BOOL byteMatchContinue = TRUE;

		cmdBufferPtr = cmdBuffer;
		debugCmdStructPtr = &(cmdListToUse->debugCmdList[cmdSearchCounter]);

		
		cmdString = debugCmdStructPtr->cmdString;
/*
		DebugMsg("Matching Command: ");
		DebugMsg(cmdString);
		DebugMsg("\n\r");
*/
		do 
		{
			if (*cmdString != ASCII_NULL)
			{
				//Case sensitivity is not matched
				if (( (*cmdBufferPtr >= 'a' && *cmdBufferPtr <= 'z') ||
					(*cmdBufferPtr >= 'A' && *cmdBufferPtr <= 'Z')  ) &&

					( (*cmdString >= 'a' && *cmdString <= 'z') ||
					(*cmdString >= 'A' && *cmdString <= 'Z')  ) )
					
				{
					if ( (*cmdString & 0x1F) != (*cmdBufferPtr & 0x1F) )
					{
						byteMatchContinue = FALSE;
					}
				}			
				else if ( *cmdString != *cmdBufferPtr )
					byteMatchContinue = FALSE;
				
				cmdString++;
				cmdBufferPtr++;
			}
			//
			//CmdString Terminated with all matching
			//
			else 
			{
				byteMatchContinue = FALSE;

				//CmdBuffer Terminated with all matching
				if (*cmdBufferPtr == ASCII_SPACE || *cmdBufferPtr == NULL)
				{
					//
					// MATCH FOUND
					//
					cmdStringMatchFound = TRUE;
					cmdBuffer = cmdBufferPtr;
				}
					
			}
		} while ( byteMatchContinue && cmdBufferPtr != NULL);

		cmdSearchCounter++;		
	}

	//Skip Spaces, look for space after command
	while (*cmdBuffer == ASCII_SPACE)
		cmdBuffer++;


	//
	// Match found
	//
	if (cmdStringMatchFound)
	{
		BYTE numOfCmdParameters = debugCmdStructPtr->numOfCmdParameters;
		BYTE numOfCmdParametersFound = 0;
		SWORD parsedParameter;
		BOOL invalidNumeralFound = FALSE;


		//
		// Recursive parsing of subcommands
		//
		if (debugCmdStructPtr->subCmdList != NULL)
		{
			if (CmdParser(cmdBuffer, (CMD_LIST_STRUCT*)debugCmdStructPtr->subCmdList) == TRUE)
			{
				return TRUE;
			}
			else
			{
				DebugMsg("the command is not complete, please type 'cmd help' for list \n\r");
			}
		}

		//
		// Now Parse Numerical Arguments
		//			
		while ( (numOfCmdParametersFound < MAX_NUM_DEBUG_PARAMETERS) && (*cmdBuffer != NULL) && !invalidNumeralFound )
		{
			parsedParameter = 0;
			
			//parse hex
			if ( *cmdBuffer == '0'  && *(cmdBuffer + 1) == 'x')
			{
				cmdBuffer += 2;

				while (*cmdBuffer != NULL && *cmdBuffer != ASCII_SPACE)
				{
					parsedParameter *= 16;
					
					if (*cmdBuffer >= '0' && *cmdBuffer <= '9')
					{
						parsedParameter += (*cmdBuffer & 0xF);
					}
					else if ( (*cmdBuffer >= 'a'  && *cmdBuffer <= 'f') ||
							(*cmdBuffer >= 'A' && *cmdBuffer <= 'F') )
					{
						parsedParameter += (*cmdBuffer & 0xF) + 9;
					}
					// Invalid Hex Numeral Found, Let Parameter Parser Terminate
					else
					{						
						invalidNumeralFound = TRUE;
					}
					cmdBuffer++;
				}
			}
			else if  (*cmdBuffer =='b')
			{
				cmdBuffer++;
				while (*cmdBuffer != NULL && *cmdBuffer != ASCII_SPACE)
				{
					parsedParameter = parsedParameter << 1;
					if (*cmdBuffer == '0' || *cmdBuffer == '1')
					{
						parsedParameter += *cmdBuffer & 0x1;
					}
					// Invalid Binary Numeral Found, Let Parameter Parser Terminate
					else
					{
						invalidNumeralFound = TRUE;
					}
					cmdBuffer++;
				}
			}
			else 
			{
				BOOL isNegative = FALSE;
				
				if (*cmdBuffer == '-')
				{
					cmdBuffer++;
					isNegative = TRUE;
				}
				
				while (*cmdBuffer != NULL && *cmdBuffer != ASCII_SPACE)
				{
					parsedParameter = parsedParameter * 10;
					if (*cmdBuffer >= '0' && *cmdBuffer <= '9')
					{
						parsedParameter += *cmdBuffer & 0xF;
					}
					// Invalid Decimall Found, Let Parameter Parser Terminate
					else
					{
						invalidNumeralFound = TRUE;
					}
					cmdBuffer++;
				}

				if (isNegative)
				{
					parsedParameter *= -1;
				}
			}
			

			debugParameters[numOfCmdParametersFound++] = parsedParameter;

			//Skip Spaces, look for space after command
			while (*cmdBuffer == ASCII_SPACE)
				cmdBuffer++;
 		}
		

		//
		// Now Command Function
		//
		if ( ( (numOfCmdParameters == numOfCmdParametersFound)  ||
				( numOfCmdParameters == NUMOFCMDPARAMETERS_CANBEANYSIZE))
				&& !invalidNumeralFound)
		{
			numOfDebugParametersFound = numOfCmdParametersFound;
			if (debugCmdStructPtr->CmdFunctionPtr != NULL)
				debugCmdStructPtr->CmdFunctionPtr(debugParameters);
			return (TRUE);
		}
	}
	return (FALSE);

}