Exemplo n.º 1
0
static void
cmd_newvar(const char *cmd, const char *args)
{
    char vn[MAX_CMDLEN], tn[MAX_CMDLEN];
    if (get_token(&args, vn, sizeof(vn), 1)
        || get_token(&args, tn, sizeof(tn), 1)) {
        ScriptError("Expected <varname>");
        return;
    }
    variableBase *var = FindVar(tn);
    if (!var) {
        ScriptError("Expected <varname>");
        return;
    }
    variableBase *newvar = FindVar(vn);
    if (newvar) {
        ScriptError("Variable already exists");
        return;
    }

    newvar = var->newVar();
    if (!newvar) {
        char type[variableBase::MAXTYPELEN];
        var->fillVarType(type);
        Output(C_WARN "Unable to clone variables of type %s", type);
        return;
    }

    char desc[MAX_CMDLEN];
    if (get_token(&args, desc, sizeof(desc)))
        AddVar(vn, newvar);
    else
        AddVar(vn, newvar, desc);
}
Exemplo n.º 2
0
// Translate a variable to an integer for argument parsing.
static bool GetVar(const char *vn, const char **s, uint32 *v)
{
    variableBase *var = FindVar(vn);
    if (!var)
        return false;
    return var->getVar(s, v);
}
Exemplo n.º 3
0
int CInterpreter::GetVariable( int type )
{
	const char	*varName;
	variable_t	*var;
	CToken		*token;

	//Get the variable's name
	token = m_tokenizer->GetToken( 0, 0 );
	varName = token->GetStringValue();

	//See if we already have a variable by this name
	var = FindVar( varName );

	//Variable names must be unique on creation
	if ( var )
		return Error( "\"%s\" : already exists\n", varName );

	//Add the variable
	AddVar( varName, type );

	//Insert the variable into the stream

	CBlock	block;

	block.Create( TYPE_VARIABLE );
	block.Write( TK_FLOAT, (float) type );
	block.Write( TK_STRING, varName );

	m_blockStream->WriteBlock( &block );

	token->Delete();

	return true;
}
Exemplo n.º 4
0
BOOL CVar::RemoveVar(LPCTSTR pVar)
{_STTEX();
	LPVAR node = FindVar( pVar );
	if ( node == NULL ) return FALSE;
	Delete( node );
	return TRUE;
}
Exemplo n.º 5
0
	/// <summary>
	/// Find the variable name in the codepack
	/// if it isn't exist, find it in the upvalue table
	///
	/// Find the variable in the previous codepack.
	/// if the variable name in the previous codepack and
	///		if it's a local in the previous codepack
	///			let it be a upvalue
	///		else if it's already a upvalue
	///			you guess what
	/// </summary>
	CodeGen::VarType CodeGen::FindVar(GenState * cs, const std::u16string& _Str)
	{
		int _var_id;
		if (cs->TryGetVarId(_Str, _var_id))
			return VarType(VarType::TYPE::LOCAL, _var_id);

		for (int i = 0; i < cs->GetUpValuesVector()->size(); ++i)
			if (cs->GetUpValuesVector()->at(i) == _Str)
				return VarType(VarType::TYPE::UPVAL, i);

		if (cs->GetFather())
		{
			VarType _p = FindVar(cs->GetFather(), _Str);
			switch (_p.type())
			{
			case VarType::TYPE::LOCAL:
			{
				cs->GetRequireUpvaluesVector()->push_back(_p.id());
				auto t = cs->AddUpValue(_Str);
				return VarType(VarType::TYPE::UPVAL, t);
			}
			case VarType::TYPE::UPVAL:
			{
				cs->GetRequireUpvaluesVector()->push_back(-1 - _p.id());
				auto i = cs->AddUpValue(_Str);
				return VarType(VarType::TYPE::UPVAL, i);
			}

			}
		}
		return VarType(VarType::TYPE::NONE);
	}
Exemplo n.º 6
0
	ToggleButton::ToggleButton( const string & tbTextureFilename, const string & tbVarName ) 
	: Button( tbTextureFilename ), onColor( .4f, 1.f, .4f, .9f ), offColor( .65f, .65f, .65f, .75f ) {
		var = FindVar( tbVarName.c_str() );
		float f;
		if ( StringToFloat( var->Get(), f ) ) {
			color = ( f != 0 ) ? onColor : offColor;
		}
	}
Exemplo n.º 7
0
void CConsole::SetFloatVar(char* pVarName, float floatValue)
{
	consoleVarStruct* ConVar = FindVar(pVarName);
	if (ConVar != NULL)
	{
		if (ConVar->varType == CONSOLE_VARTYPE_FLOAT)
			*(float*)ConVar->varValue = floatValue;
	}
}
Exemplo n.º 8
0
void CConsole::SetIntVar(char* pVarName, int intValue)
{
	consoleVarStruct* ConVar = FindVar(pVarName);
	if (ConVar != NULL)
	{
		if (ConVar->varType == CONSOLE_VARTYPE_INT)
			*(int*)ConVar->varValue = intValue;
	}
}
Exemplo n.º 9
0
int PreserveVar(char const *name)
{
    Var *v;

    v = FindVar(name, 1);
    if (!v) return E_NO_MEM;
    v->preserve = 1;
    return OK;
}
Exemplo n.º 10
0
void CConsole::SetBoolVar(char* pVarName, bool boolValue)
{
	consoleVarStruct* ConVar = FindVar(pVarName);
	if (ConVar != NULL)
	{
		if (ConVar->varType == CONSOLE_VARTYPE_BOOL)
			*(bool*)ConVar->varValue = boolValue;
	}
}
Exemplo n.º 11
0
//-----------------------------------------------------------------------------
mglDataA *mglParser::AddVar(const wchar_t *name)
{	// TODO add list of forbidden names (like function names)
	mglDataA *d=FindVar(name);
	if(name[0]=='!' && dynamic_cast<mglDataC*>(d)==0)
	{	d = new mglDataC;	d->s=(name+1);	DataList.push_back(d);	}
	else if(!d)
	{	d = new mglData;	d->s = name;	DataList.push_back(d);	}
	return d;
}
Exemplo n.º 12
0
char* CConsole::GetStringVar(char* pVarName)
{
	consoleVarStruct* ConVar = FindVar(pVarName);
	if (ConVar != NULL)
	{
		if (ConVar->varType == CONSOLE_VARTYPE_STRING) // string
			return (char*)ConVar->varValue;
	}
	return NULL;
}
Exemplo n.º 13
0
CBotVar* CBotStack::CopyVar(CBotToken& Token, bool bUpdate)
{
    CBotVar*    pVar = FindVar( Token, bUpdate );

    if ( pVar == NULL) return NULL;

    CBotVar*    pCopy = CBotVar::Create(pVar);
    pCopy->Copy(pVar);
    return    pCopy;
}
Exemplo n.º 14
0
CBotVar* CBotCStack::CopyVar(CBotToken& Token)
{
    CBotVar*    pVar = FindVar( Token );

    if ( pVar == NULL) return NULL;

    CBotVar*    pCopy = CBotVar::Create( "", pVar->GetType() );
    pCopy->Copy(pVar);
    return    pCopy;
}
Exemplo n.º 15
0
float CConsole::GetFloatVar(char* pVarName)
{
	consoleVarStruct* ConVar = FindVar(pVarName);
	if (ConVar != NULL)
	{
		if (ConVar->varType == CONSOLE_VARTYPE_FLOAT)
			return *(float*)ConVar->varValue;
	}
	return 0.0f;
}
Exemplo n.º 16
0
int SetVar(char const *str, Value *val)
{
    Var *v = FindVar(str, 1);

    if (!v) return E_NO_MEM;  /* Only way FindVar can fail */

    DestroyValue(v->v);
    v->v = *val;
    return OK;
}
Exemplo n.º 17
0
int CConsole::GetIntVar(char* pVarName)
{
	consoleVarStruct* ConVar = FindVar(pVarName);
	if (ConVar != NULL)
	{
		if (ConVar->varType == CONSOLE_VARTYPE_INT)
			return *(int*)ConVar->varValue;
	}
	return 0;
}
Exemplo n.º 18
0
LPVAR CVar::AddVar(LPCTSTR pVar, DWORD dwType, LPVOID pVal, DWORD dwSize)
{_STTEX();
	// Sanity checks
	if ( pVar == NULL ) return NULL;

	// Does the variable already exist?
	BOOL  add = FALSE;
	LPVAR node = FindVar( pVar );
	if ( node != NULL )
	{
		// Delete variable if needed
		if ( node->size != 0 && node->val != NULL ) 
		{
			delete [] node->val;
			node->val = NULL;
		} // end if
	} // end if
	else
	{
		// Allocate memory
		node = (LPVAR)New();
		if ( node == NULL ) return NULL;

	} // end if

	// Save variable type
	node->type = dwType;

	// Copy variable name
	strcpy_sz( node->name, pVar );

	// Copy variable size
	node->size = dwSize;

	// Copy the data
	if ( dwSize == 0 ) node->val = pVal;
	else
	{
		// Allocate variable value memory plus one for NULL char
		node->val = new LPBYTE[ dwSize + 1 ];
		if ( node->val == NULL ) { Delete( node ); return NULL; }

		// Check for init data
		if ( pVal == NULL ) ZeroMemory( node->val, dwSize );
		
		// Copy the value
		else memcpy( node->val, pVal, dwSize );

		// NULL terminate for good measure
		( (LPBYTE)node->val )[ dwSize ] = 0;

	} // end else

	return node;
}
Exemplo n.º 19
0
void    pfConsoleContext::AddVar( const char *name, const pfConsoleCmdParam &value )
{
    int32_t idx = FindVar( name );
    if( idx != -1 )
    {
        hsAssert( false, "AddVar() failed because variable already in console context" );
        return;
    }

    IAddVar( name, value );
}
Exemplo n.º 20
0
clCVar* clConsole::GetVarDefaultFloat( const LString& VarName, float Default )
{
	clCVar* CVar = FindVar( VarName );

	if ( CVar ) { return CVar; }

	CVar = GetVar( VarName );
	CVar->SetFloat( Default );

	return CVar;
}
Exemplo n.º 21
0
bool CConsole::GetBoolVar(char* pVarName)
{
	consoleVarStruct* ConVar = FindVar(pVarName);
	if (ConVar != NULL)
	{
		if (ConVar->varType == CONSOLE_VARTYPE_BOOL)
			return *(bool*)ConVar->varValue;
	}
	return true;
	return false;
}
TBool CTe_LbsIniFileReader::FindVar(const TDesC &aVarName, TReal32 &aResult) const
{
    TPtrC ptr(NULL,0);
    if (FindVar(aVarName,ptr))
    {
        TLex lex(ptr);
        if (lex.Val(aResult)==KErrNone)
            return(ETrue);
    }
    return(EFalse);
}
void CTe_LbsIniFileReader::ReadDeviceCapabilities(TPositionModuleInfoExtended::TDeviceGpsModeCapabilities& aDeviceCapabilities)
{
    //An ini file is expected to contain the line DeviceGpsModeCaps if this is missing, populate aDeviceCapabilities
    //We assume the value is TPositionModuleInfoExtended::EDeviceGpsModeSimultaneousTATB when .ini parameter is missing
    TInt intValue = 100; //EDeviceGpsModeSimultaneousTATB

    //An ini file is expected to contain the line DeviceGpsModeCaps
    //if this is missing, populate aDeviceCapabilities with default
    FindVar(KDeviceGpsModeCapabilitiesStr, intValue);

    aDeviceCapabilities = DecimalToBitmask(intValue);
}
Exemplo n.º 24
0
TBool CIniFile::FindVar(const TDesC &aSection,const TDesC &aVarName,
						TInt &aResult)
	{
	TInt ret = EFalse;
	TPtrC ptr(NULL,0);
	if (FindVar(aSection,aVarName,ptr))
		{
		TLex lex(ptr);
		if (lex.Val(aResult)==KErrNone)
			ret = ETrue;
		}

	return ret;
	}
Exemplo n.º 25
0
void SetVar(const char *name, const char *val)
{
    variableBase *var = FindVar(name);
    if (var) {
        var->setVar(val);
        return;
    }

    // Need to create a new user variable.
    integerVar *iv = new integerVar(0, "", 0, 0);
    iv->data = &iv->dynstorage;
    iv->setVar(val);
    AddVar(name, iv);
}
Exemplo n.º 26
0
bool    pfConsoleContext::SetVar( const char *name, const pfConsoleCmdParam &value )
{
    int32_t idx = FindVar( name );
    if( idx == -1 )
    {
        if( fAddWhenNotFound )
        {
            // Don't panic, just add
            IAddVar( name, value );
            return true;
        }
        return false;
    }

    return SetVar( idx, value );
}
void CTe_LbsIniFileReader::ReadPlugInUid(TUid& aDataSourcePluginId)
{
    TInt    intValue=0;

    FindVar(KDataSrcPluginIdStr, intValue);

    if(intValue>0)
    {
        aDataSourcePluginId = (TUid::Uid(intValue));
    }
    else
    {
        aDataSourcePluginId = TUid::Uid(0);
    }

}
Exemplo n.º 28
0
	void CodeGen::Visit(AssignmentNode* _node)
	{
		// find if the var is exisits
		// if not exisits add a possition for it
		auto _id_node = dynamic_cast<IdentifierNode*>(_node->identifier);

		auto _var = FindVar(state, _id_node->name);

		int _id;
		switch(_var.type())
		{
		case VarType::TYPE::GLOBAL:
			Visit(_node->expression);
			AddInst(Instruction(VM_CODE::STORE_G, _var.id()));
			AddInst(Instruction(VM_CODE::LOAD_G, _var.id()));
			break;
		case VarType::TYPE::LOCAL:
			Visit(_node->expression);
			AddInst(Instruction(VM_CODE::STORE_V, _var.id()));
			AddInst(Instruction(VM_CODE::LOAD_V, _var.id()));
			break;
		case VarType::TYPE::UPVAL:
			Visit(_node->expression);
			AddInst(Instruction(VM_CODE::STORE_UPVAL, _var.id()));
			AddInst(Instruction(VM_CODE::LOAD_UPVAL, _var.id()));
			break;
		case VarType::TYPE::NONE:
			if (_var_statement)
			{
				_id = state->AddVariable(_id_node->name);

				// you must add the name first and then Visit the expression.
				// to generate the next code
				Visit(_node->expression);
				AddInst(Instruction(VM_CODE::STORE_V, _id));
				AddInst(Instruction(VM_CODE::LOAD_V, _id));
			}
			else
			{
				// i don't know how to fix it, f**k you.
				// ReportError(std::u16string(u"<Assignment>Identifier not found: ") + _id_node->name);
			}
			break;
		}

	}
TBool CTe_LbsIniFileReader::FindVar(const TDesC &aVarName, TVersion &aVersion) const
{
    TPtrC ptr(NULL,0);
    TUint number;
    if (FindVar(aVarName,ptr))
    {
        TLex lex(ptr);
        if (lex.Val(number)==KErrNone)
        {
            aVersion.iMajor = number;
            aVersion.iMinor = GetNextVersionPart(lex);
            aVersion.iBuild = GetNextVersionPart(lex);
            // Return OK even if only one number was found.
            return(ETrue);
        }
    }
    return(EFalse);
}
Exemplo n.º 30
0
void CConsole::SetStringVar(char* pVarName, char* pString)
{
	char varName[100];
	strcpy(varName, pVarName);
	consoleVarStruct* ConVar = FindVar(varName);
	if (ConVar != NULL)
	{
		if (ConVar->varType == CONSOLE_VARTYPE_STRING)
		{
			if (ConVar->varValue != NULL)
				delete [] ConVar->varValue;

			char* str = new char[strlen(pString)+1];
			strcpy(str, pString);
			ConVar->varValue = str;
		}
	}
}