source/MQTTCfgParser.c
/**
 * @brief extracts tokens from the input buffer , copy into the token buffer and returns its
 * size at tokensize
 *
 * @param[in] buffer
 *            The input buffer
 * @param[in] idxAtBuffer
 *            The index from which we have to look after tokens
 * @param[in] bufSize
 *            The size of the input buffer (param one)
 * @param[out] token
 *            The buffer that will contain the token (must be different to NULL )
 * @param[in] expTokenType
 *            expected token type awaited from attribute parser
 *
 * @param[out] tokenSize
 *            The pointer to the variable that receive the size of the buffer
 *
 * @return the TOKEN types found (TOKEN_TYPE_UNKNOWN is EOF)
 */
@brief extracts tokens from the input buffer , copy into the token buffer and returns its
size at tokensize



@param[out] tokenSize
The pointer to the variable that receive the size of the buffer

@return the TOKEN types found (TOKEN_TYPE_UNKNOWN is EOF)
@brief extracts tokens from the input buffer copy into the token buffer and returns its size at tokensize @param [ out ] tokenSize The pointer to the variable that receive the size of the buffer @return the TOKEN types found ( TOKEN_TYPE_UNKNOWN is EOF )
static TokensType_T GetToken(const char *buffer, uint16_t *idxAtBuffer,
		uint16_t bufSize, char *token, uint16_t *tokenSize,
		States_T expTokenType) {
	TokensType_T Result = TOKEN_TYPE_UNKNOWN;
	memset(token, 0, *tokenSize);
	uint8_t index = UINT8_C(0);
	const char *skipSet =
			(expTokenType == STAT_EXP_ATT_VALUE) ? CFG_SPACE : CFG_WHITESPACE;
	while ((*idxAtBuffer < bufSize)
			&& (NULL != strchr(skipSet, buffer[*idxAtBuffer]))) {
		*idxAtBuffer = *idxAtBuffer + 1;
	}
	if (expTokenType == STAT_EXP_ATT_NAME) {
		while (buffer[*idxAtBuffer] == '#') 
		{
			while ((buffer[*idxAtBuffer] != '\n')
					&& (buffer[*idxAtBuffer] != '\r') && (*idxAtBuffer < bufSize)) 
			{
				*idxAtBuffer = *idxAtBuffer + 1;
			}
			while ((*idxAtBuffer < bufSize)
					&& (NULL != strchr(CFG_WHITESPACE, buffer[*idxAtBuffer]))) {
				*idxAtBuffer = *idxAtBuffer + 1;
			}
		}
	}
	if (buffer[*idxAtBuffer] == '=') {
		token[index] = '=';
		*idxAtBuffer = *idxAtBuffer + 1;
		index = index + 1;
		Result = TOKEN_EQUAL;
	} else {
		if (expTokenType == STAT_EXP_ATT_VALUE) {
			while ((buffer[*idxAtBuffer] != '\r')
					&& (buffer[*idxAtBuffer] != '\n')
					&& (buffer[*idxAtBuffer] != '\t')
					&& (*idxAtBuffer < bufSize)) {
				if (index < *tokenSize - 1) {
					token[index] = buffer[*idxAtBuffer];
					*idxAtBuffer = *idxAtBuffer + 1;
					index = index + 1;
				}
			};
		} else {
			while ((buffer[*idxAtBuffer] != '\r')
					&& (buffer[*idxAtBuffer] != '\n')
					&& (buffer[*idxAtBuffer] != '\t')
					&& (buffer[*idxAtBuffer] != ' ')
					&& (buffer[*idxAtBuffer] != '=') && (*idxAtBuffer < bufSize)) {
				if (index < *tokenSize - 1) {
					token[index] = buffer[*idxAtBuffer];
					*idxAtBuffer = *idxAtBuffer + 1;
					index = index + 1;
				}
			};
		}
		for (uint8_t ConfigIndex = UINT8_C(0); ConfigIndex < ATT_IDX_SIZE;
				ConfigIndex++) {
			if (0 == strcmp(token, ConfigStructure[ConfigIndex].attName)) {
				Result = TOKEN_ATT_NAME;
				break;
			}
		}
		if ((index > 0) && (TOKEN_TYPE_UNKNOWN == Result)) {
			Result = TOKEN_VALUE;
		}
	}
	if ((index == 0) && (TOKEN_TYPE_UNKNOWN == Result)) 
	{
		Result = TOKEN_EOF;
	}
	return (Result);
}
static TokensType_T GetToken ( const char * buffer , uint16_t * idxAtBuffer , uint16_t bufSize , char * token , uint16_t * tokenSize , States_T expTokenType ) { TokensType_T Result = TOKEN_TYPE_UNKNOWN ; memset ( token , 0 , * tokenSize ) ; uint8_t index = UINT8_C ( 0 ) ; const char * skipSet = ( expTokenType == STAT_EXP_ATT_VALUE ) ? CFG_SPACE : CFG_WHITESPACE ; while ( ( * idxAtBuffer < bufSize ) && ( NULL != strchr ( skipSet , buffer [ * idxAtBuffer ] ) ) ) { * idxAtBuffer = * idxAtBuffer + 1 ; } if ( expTokenType == STAT_EXP_ATT_NAME ) { while ( buffer [ * idxAtBuffer ] == ' ' ) { while ( ( buffer [ * idxAtBuffer ] != ' \n ' ) && ( buffer [ * idxAtBuffer ] != ' \r ' ) && ( * idxAtBuffer < bufSize ) ) { * idxAtBuffer = * idxAtBuffer + 1 ; } while ( ( * idxAtBuffer < bufSize ) && ( NULL != strchr ( CFG_WHITESPACE , buffer [ * idxAtBuffer ] ) ) ) { * idxAtBuffer = * idxAtBuffer + 1 ; } } } if ( buffer [ * idxAtBuffer ] == ' ' ) { token [ index ] = ' ' ; * idxAtBuffer = * idxAtBuffer + 1 ; index = index + 1 ; Result = TOKEN_EQUAL ; } else { if ( expTokenType == STAT_EXP_ATT_VALUE ) { while ( ( buffer [ * idxAtBuffer ] != ' \r ' ) && ( buffer [ * idxAtBuffer ] != ' \n ' ) && ( buffer [ * idxAtBuffer ] != ' \t ' ) && ( * idxAtBuffer < bufSize ) ) { if ( index < * tokenSize - 1 ) { token [ index ] = buffer [ * idxAtBuffer ] ; * idxAtBuffer = * idxAtBuffer + 1 ; index = index + 1 ; } } ; } else { while ( ( buffer [ * idxAtBuffer ] != ' \r ' ) && ( buffer [ * idxAtBuffer ] != ' \n ' ) && ( buffer [ * idxAtBuffer ] != ' \t ' ) && ( buffer [ * idxAtBuffer ] != ' ' ) && ( buffer [ * idxAtBuffer ] != ' ' ) && ( * idxAtBuffer < bufSize ) ) { if ( index < * tokenSize - 1 ) { token [ index ] = buffer [ * idxAtBuffer ] ; * idxAtBuffer = * idxAtBuffer + 1 ; index = index + 1 ; } } ; } for ( uint8_t ConfigIndex = UINT8_C ( 0 ) ; ConfigIndex < ATT_IDX_SIZE ; ConfigIndex ++ ) { if ( 0 == strcmp ( token , ConfigStructure [ ConfigIndex ] . attName ) ) { Result = TOKEN_ATT_NAME ; break ; } } if ( ( index > 0 ) && ( TOKEN_TYPE_UNKNOWN == Result ) ) { Result = TOKEN_VALUE ; } } if ( ( index == 0 ) && ( TOKEN_TYPE_UNKNOWN == Result ) ) { Result = TOKEN_EOF ; } return ( Result ) ; }
@brief extracts tokens from the input buffer , copy into the token buffer and returns its
 size at tokensize
@brief extracts tokens from the input buffer copy into the token buffer and returns its size at tokensize
/* erase the OUTPUT token buffer*/ /* don't skip line end if next token is STAT_EXP_ATT_VALUE */ /* support empty attribute values to deleted compiled defaults */ /* Bypass all chars in skip set */ // Handling in-line comments for key value pair in the configuration file // skip to EOL if since Start of comment tag '#' was found /* is the next char the EQUAL sign */ /* YES */ /* No , its a string ...*/ /* Is this string is a known string ,i.e. attribute name ?*/ /* The string is not known one, so it's a value */ /* At this point nothing has been found ! */ /* (index == 0) check was added due to :Warning 438: Last value assigned to variable 'index' (defined at line 218) not used*/