Ejemplo n.º 1
0
//-------------------------------------------------------------------------
bool CIronSight::UseAlternativeIronSight() const
{
	bool weaponSupport = m_pShared->zoomParams.support_FC_IronSight;
	bool diffEnabled = g_pGameCVars->g_difficultyLevel<4 || gEnv->bMultiplayer;
	bool flagEnabled = (g_pGameCVars->g_enableAlternateIronSight)?true:false;
	bool noScope = !IsScope();
	return (diffEnabled && flagEnabled && weaponSupport);
}
Ejemplo n.º 2
0
// Get a word token
bool SqlParser::GetWordToken(Token *token)
{
	if(token == NULL)
		return false;

	int len = 0;

	const char *cur = _next_start;

	// Check for a sign for numbers in the first position (sign can go before variable name -num i.e)
	if(_remain_size > 1 && (*cur == '+' || *cur == '-') /*&& cur[1] >= '0' && cur[1] <= '9'*/ &&
		// Skip comment --
		cur[1] != '-') 
	{
		char sign = *cur;

		_remain_size--;
		len++;
		cur++;

		// Allow spaces follow the sign
		while(sign == '-' && _remain_size > 1 && *cur == ' ')
		{
			_remain_size--;
			len++;
			cur++;
		}
	}

	// Identifiers starts as a word but then there is quoted part SCHEMA."TABLE".COL i.e.
	bool partially_quoted_identifier = false;

	// Calculate the length
	while(_remain_size > 0)
	{
		// Check for a comment
		if(len == 0 && ParseComment() == true)
		{
			cur = _next_start;
			continue;
		}

		// Check whether we meet a special character allowed in identifiers
		if(strchr(g_symbols, *cur) != NULL)
		{
			// @variable in SQL Server and MySQL, :new in Oracle trigger, #temp table name in SQL Server
			// * meaning all columns, - in COBOL identifier, label : label name in DB2
			if(*cur != '_' && *cur != '.' && *cur != '@' && *cur != ':' && *cur != '#' && *cur != '*' && 
					*cur != '-' && *cur != '"' && *cur != '[' && *cur != ' ' && *cur != '&')
				break;

			// Spaces are allowed between identifier parts: table . name 
			if(*cur == ' ')
			{
				int ident_len = 0;

				for(int i = 0; i < _remain_size - 1; i++)
				{
					if(cur[i] == ' ' || cur[i] == '\t' || cur[i] == '\n' || cur[i] == '\r')
						continue;

					if(cur[i] == '.')
						ident_len = i;

					break;
				}

				// Not a multi-part identifier
				if(len == 0 || ident_len == 0)
					break;

				_remain_size -= ident_len;
				cur += ident_len;
				len += ident_len;

				continue;
			}

			// * must be after . to not confuse with multiplication operator
			if(*cur == '*' && (len == 0 || (len > 0 && cur > _start && cur[-1] != '.')))
				break;

			// Check for partially quoted identifier that starts as a word then quoted part follows
			if(*cur == '"' || *cur == '[')
			{
				if(len > 0 && cur > _start && cur[-1] == '.')
					partially_quoted_identifier = true;
				
				break;
			}

			if(*cur == ':')
			{
				// But := also means assigment in Oracle (space is not allowed between : and =)
				if((_remain_size > 1 && cur[1] == '=') ||
				  // In DB2, Teradata, MySQL : used in label, and label:BEGIN (without spaces) or 
				  // label :BEGIN is correct, but :param can be also used in scripts
				  (Source(SQL_DB2, SQL_TERADATA, SQL_MYSQL) == true && 
						IsScope(SQL_SCOPE_SELECT_STMT) == false) ||
				  // In Informix, PostgreSQL :: is data type cast operator
				  (_remain_size > 1 && cur[1] == ':') || (cur > _start && cur[-1] == ':'))
				break;
			}

			// : can follow after label in DB2
			//if(*cur == ':' && len == 0 && _remain_size > 1 && Str::IsSpace(cur[1]) == true)
			//	break;

			// & used as parameter marker in scripts i.e. SQL*Plus, must be at the first position
			if(*cur == '&' && len != 0)
				break;

			// Allow - in COBOL only
			if(*cur == '-' && _source_app != APP_COBOL && _level != LEVEL_APP)
				break;

			bool right = true;

			// @ must not be followed by a blank or delimiter
			if(*cur == '@')
			{
				// Remain size not decremented yet
				if(_remain_size == 1 || 
					(_remain_size > 1 && (cur[1] == ' ' || cur[1] == '\r' || cur[1] == '\n' || cur[1] == '\t')))
					right = false;
			}
			else
			// . is the statement delimiter in COBOL
			if(_source_app == APP_COBOL && _level == LEVEL_APP && *cur == '.')
				right = false;

			if(right == false)
				break;
		}

		_remain_size--;
		cur++;
		len++;
	}

	if(partially_quoted_identifier == true)
	{
		_remain_size += len;

		GetQuotedIdentifier(token, true);
	}
	else			
	if(len > 0)
	{
		// If a single special character was selected in the right position, but no more characters followed
		// do not return as word
		if(len == 1 && (strchr(g_symbols, *_next_start) != NULL ||
			// Also skip N'literal' in SQL Server
			(*_next_start == 'N' && _remain_size > 1 && *cur == '\'')))
		{
			_remain_size++;
			return false;
		}

		token->type = TOKEN_WORD;
		token->chr = 0;
		token->wchr = 0;
		token->str = _next_start;
		token->wstr = 0;
		token->len = len;
		token->remain_size = _remain_size;
		token->next_start = _next_start + len;

		_tokens.Add(token);

		_next_start = cur;
	}

	return (len > 0) ? true : false;
}