Example #1
0
/* a method that handels "LABELS:" in a given line*/
char *HandleLabel(char* label,char *line,int* loc)
{
	char *temp,*address_10=NULL,*address_12=NULL;
	enum Directive dir;
	label[strlen(label)-1]='\0';
	temp=line+(*loc);
	temp=StringTrim(temp);
	/*ALLOCATE_STRING(address_10,1);
	ALLOCATE_STRING(address_12,1);*/
	FIX_NULL_STRING(address_10);
	FIX_NULL_STRING(address_12);

	if(strlen(temp)==0) /* Label only */
	{
		strcpy(address_10,ConvertIntToCharByBase(IC,ConversionToAddress,10));
		strcpy(address_12,ConvertIntToCharByBase(IC,ConversionToAddress,12));
		AddLabelItem(_labels,label,address_10,address_12,'c');
		IC++;
	}
	else if(temp[0]=='.') /* Label with Directive */
	{
			dir=WhatDirective(temp);
			temp=StringMoveToNextItem(temp);
			temp=StringTrim(temp);
			switch(dir)
			{
			case STRING:
				strcpy(address_10,ConvertIntToCharByBase(DC,ConversionToAddress,10));
				strcpy(address_12,ConvertIntToCharByBase(DC,ConversionToAddress,12));
				AddLabelItem(_labels,label,address_10,address_12,'d');
				break;
				
				break;

			case DATA:
				strcpy(address_10,ConvertIntToCharByBase(DC,ConversionToAddress,10));
				strcpy(address_12,ConvertIntToCharByBase(DC,ConversionToAddress,12));
				AddLabelItem(_labels,label,address_10,address_12,'d');
				break;
			case EXTERN:
			case ENTRY:
				FIX_NULL_STRING(label);
				break;
			case NONE:
				strcpy(address_10,ConvertIntToCharByBase(IC,ConversionToAddress,10));
				strcpy(address_12,ConvertIntToCharByBase(IC,ConversionToAddress,12));
				AddLabelItem(_labels,label,address_10,address_12,'c');
				return NULL;
				break;
			default:
				break;
			}
	}
	else
	{
		AnalyzeCommand(line);
		*loc=strlen(line);
	}
	return label;
}
Example #2
0
File: main.cpp Project: niklasf/k2
//-------------------------------
void SetboardCommand(std::string in)
{
    if(busy)
        return;

    int firstSymbol = in.find_first_not_of(" \t");
    in.erase(0, firstSymbol);

    if(!FenStringToEngine((char *)in.c_str()))
        std::cout << "Illegal position" << std::endl;
    else if(infinite_analyze && xboard)
        AnalyzeCommand(in);
}
Example #3
0
	void AnalyzeMessage(udtCuMessageOutput& message)
	{
		if(message.IsGameState && 
		   message.GameStateOrSnapshot.GameState != NULL)
		{
			AnalyzeGameState(*message.GameStateOrSnapshot.GameState);
		}
		else if(message.ServerCommandCount > 0 && 
				message.Commands != NULL && 
				message.GameStateOrSnapshot.Snapshot != NULL)
		{
			const s32 serverTimeMs = message.GameStateOrSnapshot.Snapshot->ServerTimeMs;
			for(u32 i = 0; i < message.ServerCommandCount; ++i)
			{
				AnalyzeCommand(message.Commands[i], serverTimeMs);
			}
		}
	}
Example #4
0
enum Boolean AnalyzeText(char *tempInputCommand)
{
		enum Boolean labelFound=FALSE,firstField=TRUE,handleLineDone=FALSE;
		char *directive=NULL;
		enum ItemType type;
		char *tempItem=NULL;
		char *label=NULL,*command=NULL,*operands=NULL;
		int loc=0;
		enum Directive currentDirective;
		int *curLoc,stringLength;


		curLoc=&loc;

		stringLength=strlen(tempInputCommand);
		if(strlen(tempInputCommand)==0 || strcmp(tempInputCommand,"")==0)
				return FALSE;
		if(tempInputCommand[0]==';')
			return FALSE;
		while((*curLoc)<stringLength && handleLineDone==FALSE)
		{
			tempItem=ReadWord(tempInputCommand,curLoc,' ');

			tempItem=StringTrim(tempItem);
			if(tempItem[strlen(tempItem)-1]==':')
			{
					type=TLabel;
					labelFound=TRUE;
			}
			else if(tempItem[0]=='.')
					type=TDirective;
			else
				type=TCommand;

			switch(type)
			{
			case TDirective:
				/*directive*/

				ALLOCATE_STRING(directive,strlen(tempItem));
				strcpy(directive,tempItem);

				/* Create BMC  */
				CreateBmc(tempInputCommand+(*curLoc),directive,type,label,command,operands);
				handleLineDone=TRUE;
				currentDirective=WhatDirective(directive);

				if(currentDirective!=EXTERN && currentDirective !=ENTRY)
					HandleDirective(tempInputCommand,label,directive);	
				else
				{
					operands=ReadWord(tempInputCommand,curLoc,' ');
					operands=StringTrim(operands);
					FIX_NULL_STRING(operands);
					AddLinkageItem(&Linkage_List,currentDirective,operands,"?");
				}

					break;
			case TCommand:
				AnalyzeCommand(tempInputCommand);
				handleLineDone=TRUE;
					break;
			case TLabel:
				label=(char*)malloc(sizeof(char));
				label=HandleLabel(tempItem,tempInputCommand,curLoc);
					break;
				default: /* cosmetics only*/
					break;
			}
			firstField=FALSE;

		}
return TRUE;
}
Example #5
0
/* this function creates the binary machine code for all its given parameters*/
void CreateBmc(char* inputCommand,char* directive,enum ItemType type,char *label,char* command,char* operands)
{
	enum Directive dir;
	char *tempWord=NULL;
	char *tempInputString=StringTrim(inputCommand);
	BinaryMachineCode bmc;
	char *base_12_value=NULL;
	char bmcCreator[BMC_LENGTH+1]={0};
	char newBmc[BMC_LENGTH+1]={0},kind;
	int curLoc=0,castingInteger=0,number_of_items=0,i,*pToCurloc;
	Cmd tempCommand;
	pToCurloc=&curLoc;
	FIX_NULL_STRING(base_12_value);



	switch(type)
	{
	case TCommand:
		AnalyzeCommand(inputCommand);
		break;
	case TDirective:
		dir=WhatDirective(directive);

		switch(dir)
		{
		case STRING:
			kind=' ';
			newBmc[0]='\0';
			tempWord=ReadWord(tempInputString,pToCurloc,' ');
			for(i=0;i<strlen(tempWord);i++)
			{
				if(tempWord[i]=='\"')
					continue;
				castingInteger=(int)tempWord[i];
				strcpy(base_12_value,ConvertIntToCharByBase(castingInteger,ConversionToBase_12_Code,12));
				strcpy(bmcCreator,ConvertIntToCharByBase(castingInteger,ConversionToBmcType,2));
				for(curLoc=0;curLoc<(BMC_LENGTH-strlen(bmcCreator));curLoc++)
				{
					newBmc[curLoc]='0';
				}
				newBmc[curLoc]='\0';
				strcat(newBmc,bmcCreator);
				newBmc[BMC_LENGTH]='\0';
				bmc=CreateBmcCode(newBmc);
				FIX_NULL_STRING(label);

				tempCommand=CreateCmdObject(label,ConvertIntToCharByBase(DC,ConversionToAddress,10),ConvertIntToCharByBase(DC,ConversionToAddress,12),directive,tempInputString,bmc,base_12_value,'d');
				CmdQueue_AddRecord(tempCommand,computerLanguage);
				label="";
				directive="";
				tempInputString="";
				DC++;

			}
			castingInteger=0;
			strcpy(bmcCreator,ConvertIntToCharByBase(0,ConversionToBmcType,2));
			strcpy(base_12_value,ConvertIntToCharByBase(castingInteger,ConversionToBase_12_Code,12));

			for(curLoc=0;curLoc<(BMC_LENGTH-strlen(bmcCreator));curLoc++)
				{
					newBmc[curLoc]='0';
				}
				newBmc[curLoc]='\0';
			strcat(newBmc,bmcCreator);
			bmc=CreateBmcCode(newBmc);
			tempCommand=CreateCmdObject(label,ConvertIntToCharByBase(DC,ConversionToAddress,10),ConvertIntToCharByBase(DC,ConversionToAddress,12),"","",bmc,base_12_value,'d');
			CmdQueue_AddRecord(tempCommand,computerLanguage);
			DC++;

			break;
		case DATA:
			while(tempWord=ReadWord(tempInputString,pToCurloc,' '))
			{
				if(tempWord==NULL)
					break;
				newBmc[0]='\0';
				kind=' ';
				number_of_items++;
				if(IsLegalNumber(tempWord)==FALSE)
				{
					ErrorHandler(CompilingError,"One or more Not-a-number in .data array");
					return;
				}
				castingInteger=ConvertCharToInt(tempWord);

				if(tempInputString[curLoc]==',')
					curLoc++;

				/* Single BMC creation - added to multi BMC link */
				strcpy(bmcCreator, ConvertIntToCharByBase(castingInteger,ConversionToBmcType,2));
				if(tempWord[0]=='-')
					bmcCreator[BMC_LENGTH]='\0';
				for(i=0;i<(BMC_LENGTH-strlen(bmcCreator));i++)
				{
					newBmc[i]='0';
				}

				newBmc[i]='\0';
				FIX_NULL_STRING(label);
				strcat(newBmc,bmcCreator);
				newBmc[BMC_LENGTH]='\0';
				bmc=CreateBmcCode(newBmc);
				FIX_NULL_STRING((base_12_value));
				strcpy(base_12_value,ConvertIntToCharByBase(castingInteger,ConversionToBase_12_Code,12));
				tempCommand=CreateCmdObject(label,ConvertIntToCharByBase(DC,ConversionToAddress,10),ConvertIntToCharByBase(DC,ConversionToAddress,12),directive,inputCommand,bmc,base_12_value,'d');
				CmdQueue_AddRecord(tempCommand,computerLanguage);
				label="";
				DC++;
				inputCommand="";
				directive="";
			}
			break;
			
		case NONE:

			break;
		default:
			break;
		}
		default:
			break;
	}
	

}