zabbix-agent2/src/libs/zbxeval/misc.c
/******************************************************************************
 *                                                                            *
 * Function: zbx_eval_compose_expression                                      *
 *                                                                            *
 * Purpose: compose expression by replacing processed tokens (with values) in *
 *          the original expression                                           *
 *                                                                            *
 * Parameters: ctx        - [IN] the evaluation context                       *
 *             expression - [OUT] the composed expression                     *
 *                                                                            *
 ******************************************************************************/
zbx_eval_compose_expression

Purpose: compose expression by replacing processed tokens (with values) in
the original expression

Parameters: ctx        - [IN] the evaluation context
expression - [OUT] the composed expression
zbx_eval_compose_expression Purpose : compose expression by replacing processed tokens ( with values ) in the original expression Parameters : ctx - [ IN ] the evaluation context expression - [ OUT ] the composed expression
void	zbx_eval_compose_expression(const zbx_eval_context_t *ctx, char **expression)
{
	zbx_vector_ptr_t	tokens;
	const zbx_eval_token_t	*token;
	int			i;
	size_t			pos = 0, expression_alloc = 0, expression_offset = 0;
	if (2 == ctx->stack.values_num && ZBX_EVAL_TOKEN_EXCEPTION == ctx->stack.values[1].type)
	{
		zbx_strcpy_alloc(expression, &expression_alloc, &expression_offset, "throw(");
		eval_token_print_alloc(ctx, expression, &expression_alloc, &expression_offset, &ctx->stack.values[0]);
		zbx_chrcpy_alloc(expression, &expression_alloc, &expression_offset, ')');
		return;
	}
	zbx_vector_ptr_create(&tokens);
	for (i = 0; i < ctx->stack.values_num; i++)
	{
		if (ZBX_VARIANT_NONE != ctx->stack.values[i].value.type)
			zbx_vector_ptr_append(&tokens, &ctx->stack.values[i]);
	}
	zbx_vector_ptr_sort(&tokens, compare_tokens_by_loc);
	for (i = 0; i < tokens.values_num; i++)
	{
		token = (const zbx_eval_token_t *)tokens.values[i];
		if (0 != token->loc.l)
		{
			zbx_strncpy_alloc(expression, &expression_alloc, &expression_offset, ctx->expression + pos,
					token->loc.l - pos);
		}
		pos = token->loc.r + 1;
		eval_token_print_alloc(ctx, expression, &expression_alloc, &expression_offset, token);
	}
	if ('\0' != ctx->expression[pos])
		zbx_strcpy_alloc(expression, &expression_alloc, &expression_offset, ctx->expression + pos);
	zbx_vector_ptr_destroy(&tokens);
}
void zbx_eval_compose_expression ( const zbx_eval_context_t * ctx , char * * expression ) { zbx_vector_ptr_t tokens ; const zbx_eval_token_t * token ; int i ; size_t pos = 0 , expression_alloc = 0 , expression_offset = 0 ; if ( 2 == ctx -> stack . values_num && ZBX_EVAL_TOKEN_EXCEPTION == ctx -> stack . values [ 1 ] . type ) { zbx_strcpy_alloc ( expression , & expression_alloc , & expression_offset , " " ) ; eval_token_print_alloc ( ctx , expression , & expression_alloc , & expression_offset , & ctx -> stack . values [ 0 ] ) ; zbx_chrcpy_alloc ( expression , & expression_alloc , & expression_offset , ' ' ) ; return ; } zbx_vector_ptr_create ( & tokens ) ; for ( i = 0 ; i < ctx -> stack . values_num ; i ++ ) { if ( ZBX_VARIANT_NONE != ctx -> stack . values [ i ] . value . type ) zbx_vector_ptr_append ( & tokens , & ctx -> stack . values [ i ] ) ; } zbx_vector_ptr_sort ( & tokens , compare_tokens_by_loc ) ; for ( i = 0 ; i < tokens . values_num ; i ++ ) { token = ( const zbx_eval_token_t * ) tokens . values [ i ] ; if ( 0 != token -> loc . l ) { zbx_strncpy_alloc ( expression , & expression_alloc , & expression_offset , ctx -> expression + pos , token -> loc . l - pos ) ; } pos = token -> loc . r + 1 ; eval_token_print_alloc ( ctx , expression , & expression_alloc , & expression_offset , token ) ; } if ( ' \0 ' != ctx -> expression [ pos ] ) zbx_strcpy_alloc ( expression , & expression_alloc , & expression_offset , ctx -> expression + pos ) ; zbx_vector_ptr_destroy ( & tokens ) ; }
Function: zbx_eval_compose_expression                                      
                                                                            
 Purpose: compose expression by replacing processed tokens (with values) in 
          the original expression                                           
                                                                            
 Parameters: ctx        - [IN] the evaluation context                       
             expression - [OUT] the composed expression
Function : zbx_eval_compose_expression Purpose : compose expression by replacing processed tokens ( with values ) in the original expression Parameters : ctx - [ IN ] the evaluation context expression - [ OUT ] the composed expression
/* Handle exceptions that are set when expression evaluation failed.     */ /* Exception stack consists of two tokens - error message and exception. */