Ejemplo n.º 1
0
/**
\brief Gets a variable value.
\param Name The name of the variable.
\param [out] Value This function can get the variable value. If this value is null, it is ignored.
\param [out] Size This function can get the variable size. If this value is null, it is ignored.
\param [out] Type This function can get the variable type. If this value is null, it is ignored.
\return true if the variable was found and the optional values were retrieved successfully, false otherwise.
*/
bool varget(const char* Name, VAR_VALUE* Value, int* Size, VAR_TYPE* Type)
{
    SHARED_ACQUIRE(LockVariables);

    String name_;
    if(*Name != '$')
        name_ = "$";
    name_ += Name;
    auto found = variables.find(name_);
    if(found == variables.end()) //not found
        return false;
    if(found->second.alias.length())
    {
        // Release the lock (potential deadlock here)
        SHARED_RELEASE();

        return varget(found->second.alias.c_str(), Value, Size, Type);
    }
    if(Type)
        *Type = found->second.type;
    if(Size)
        *Size = found->second.value.size;
    if(Value)
        *Value = found->second.value;
    return true;
}
Ejemplo n.º 2
0
static bool scriptinternalbranch(SCRIPTBRANCHTYPE type) //determine if we should jump
{
    uint ezflag = 0;
    uint bsflag = 0;
    varget("$_EZ_FLAG", &ezflag, 0, 0);
    varget("$_BS_FLAG", &bsflag, 0, 0);
    bool bJump = false;
    switch(type)
    {
    case scriptcall:
    case scriptjmp:
        bJump = true;
        break;
    case scriptjnejnz: //$_EZ_FLAG=0
        if(!ezflag)
            bJump = true;
        break;
    case scriptjejz: //$_EZ_FLAG=1
        if(ezflag)
            bJump = true;
        break;
    case scriptjbjl: //$_BS_FLAG=0 and $_EZ_FLAG=0 //below, not equal
        if(!bsflag && !ezflag)
            bJump = true;
        break;
    case scriptjajg: //$_BS_FLAG=1 and $_EZ_FLAG=0 //above, not equal
        if(bsflag && !ezflag)
            bJump = true;
        break;
    case scriptjbejle: //$_BS_FLAG=0 or $_EZ_FLAG=1
        if(!bsflag || ezflag)
            bJump = true;
        break;
    case scriptjaejge: //$_BS_FLAG=1 or $_EZ_FLAG=1
        if(bsflag || ezflag)
            bJump = true;
        break;
    default:
        bJump = false;
        break;
    }
    return bJump;
}
Ejemplo n.º 3
0
/**
\brief Gets a variable value.
\param Name The name of the variable.
\param [out] String This function can get the variable value. If this value is null, it is ignored.
\param [out] Size This function can get the variable size. If this value is null, it is ignored.
\param [out] Type This function can get the variable type. If this value is null, it is ignored.
\return true if the variable was found and the optional values were retrieved successfully, false otherwise.
*/
bool varget(const char* Name, char* String, int* Size, VAR_TYPE* Type)
{
    VAR_VALUE varvalue;
    int varsize;
    VAR_TYPE vartype;
    if(!varget(Name, &varvalue, &varsize, &vartype) || varvalue.type != VAR_STRING)
        return false;
    if(Size)
        *Size = varsize;
    if(Type)
        *Type = vartype;
    if(String)
        memcpy(String, varvalue.u.data->data(), varsize);
    return true;
}
Ejemplo n.º 4
0
/**
\brief Gets a variable value.
\param Name The name of the variable.
\param [out] Value This function can get the variable value. If this value is null, it is ignored.
\param [out] Size This function can get the variable size. If this value is null, it is ignored.
\param [out] Type This function can get the variable type. If this value is null, it is ignored.
\return true if the variable was found and the optional values were retrieved successfully, false otherwise.
*/
bool varget(const char* Name, duint* Value, int* Size, VAR_TYPE* Type)
{
    VAR_VALUE varvalue;
    int varsize;
    VAR_TYPE vartype;
    if(!varget(Name, &varvalue, &varsize, &vartype) || varvalue.type != VAR_UINT)
        return false;
    if(Size)
        *Size = varsize;
    if(Type)
        *Type = vartype;
    if(Value)
        *Value = varvalue.u.value;
    return true;
}
Ejemplo n.º 5
0
static const char *
search_helper( 
	   const char *target,
	   time_t	*time,
	   LIST *(*varget)( const char*, void* ),
	   void *userData,
	   int uncached )
{
	PATHNAME f[1];
	LIST	*varlist;
	char	buf[ MAXJPATH ];
#ifdef OPT_PATH_BINDING_EXT
	PATHNAME bf[1];
#endif
	
	/* Parse the filename */
	
	path_parse( target, f );
	
	f->f_grist.ptr = 0;
	f->f_grist.len = 0;
	
#ifdef OPT_PATH_BINDING_EXT
	if ( list_first(varlist = varget( "BINDING", userData )) )
	{
		path_parse( list_value(list_first(varlist)), bf );
		
		f->f_dir = bf->f_dir;
		f->f_base = bf->f_base;
		f->f_suffix = bf->f_suffix;
	}
#endif
	
	if( list_first(varlist = varget( "LOCATE", userData )) )
	{
		f->f_root.ptr = list_value(list_first(varlist));
		f->f_root.len = (int)(strlen( list_value(list_first(varlist)) ));
		
#ifdef OPT_ROOT_PATHS_AS_ABSOLUTE_EXT
		path_build( f, buf, 1, 1 );
#else
		path_build( f, buf, 1 );
#endif
		
		if( DEBUG_SEARCH )
			printf( "locate %s: %s\n", target, buf );
		
		if ( uncached )
		{
			file_time( buf, time );
		}
		else
		{
			timestamp( buf, time, 0 );
		}
		
		return newstr( buf );
	}
	else if( list_first(varlist = varget( "SEARCH", userData )) )
	{
		LIST *searchextensionslist;
		LISTITEM* var = list_first(varlist);
		while( var )
		{
			f->f_root.ptr = list_value(var);
			f->f_root.len = (int)(strlen( list_value(var) ));
			
#ifdef OPT_ROOT_PATHS_AS_ABSOLUTE_EXT
			path_build( f, buf, 1, 1 );
#else
			path_build( f, buf, 1 );
#endif
			
			if( DEBUG_SEARCH )
				printf( "search %s: %s\n", target, buf );
			
			if ( uncached )
			{
				file_time( buf, time );
			}
			else
			{
				timestamp( buf, time, 0 );
			}
			
			if( *time )
				return newstr( buf );
			
			var = list_next( var );
		}
		
		searchextensionslist = varget( "SEARCH_EXTENSIONS", userData );
		if ( list_first(searchextensionslist) )
		{
			LISTITEM* ext = list_first(searchextensionslist);
			for ( ; ext; ext = list_next(ext) )
			{
				LISTITEM* var = list_first(varlist);
				while( var )
				{
					f->f_root.ptr = list_value(var);
					f->f_root.len = (int)(strlen( list_value(var) ));
					
#ifdef OPT_ROOT_PATHS_AS_ABSOLUTE_EXT
					strcpy( path_build( f, buf, 1, 1 ), list_value(ext) );
#else
					strcpy( path_build( f, buf, 1 ), list_value(ext) );
#endif
					
					if( DEBUG_SEARCH )
						printf( "search %s: %s\n", target, buf );
					
					if ( uncached )
					{
						file_time( buf, time );
					}
					else
					{
						timestamp( buf, time, 0 );
					}
					
					if( *time )
						return newstr( buf );
					
					var = list_next( var );
				}
			}
		}			
	}
	
	/* Look for the obvious */
	/* This is a questionable move.  Should we look in the */
	/* obvious place if SEARCH is set? */
	
	f->f_root.ptr = 0;
	f->f_root.len = 0;
	
#ifdef OPT_ROOT_PATHS_AS_ABSOLUTE_EXT
	path_build( f, buf, 1, 1 );
#else
	path_build( f, buf, 1 );
#endif
	
	if( DEBUG_SEARCH )
		printf( "search %s: %s\n", target, buf );
	
	if ( uncached )
	{
		file_time( buf, time );
	}
	else
	{
		timestamp( buf, time, 0 );
	}
	
	return newstr( buf );
}