4 #define EVAL_MAX_VARIABLE_NAME_LENGTH 300
6 typedef struct eval_variable {
10 struct eval_variable *next;
13 typedef struct eval_expression {
15 const char *parsed_as;
17 calculated_number *this;
21 calculated_number result;
29 // custom data to be used for looking up variables
30 struct rrdcalc *rrdcalc;
33 #define EVAL_VALUE_INVALID 0
34 #define EVAL_VALUE_NUMBER 1
35 #define EVAL_VALUE_VARIABLE 2
36 #define EVAL_VALUE_EXPRESSION 3
38 // parsing and evaluation
39 #define EVAL_ERROR_OK 0
42 #define EVAL_ERROR_MISSING_CLOSE_SUBEXPRESSION 1
43 #define EVAL_ERROR_UNKNOWN_OPERAND 2
44 #define EVAL_ERROR_MISSING_OPERAND 3
45 #define EVAL_ERROR_MISSING_OPERATOR 4
46 #define EVAL_ERROR_REMAINING_GARBAGE 5
47 #define EVAL_ERROR_IF_THEN_ELSE_MISSING_ELSE 6
50 #define EVAL_ERROR_INVALID_VALUE 101
51 #define EVAL_ERROR_INVALID_NUMBER_OF_OPERANDS 102
52 #define EVAL_ERROR_VALUE_IS_NAN 103
53 #define EVAL_ERROR_VALUE_IS_INFINITE 104
54 #define EVAL_ERROR_UNKNOWN_VARIABLE 105
56 // parse the given string as an expression and return:
57 // a pointer to an expression if it parsed OK
58 // NULL in which case the pointer to error has the error code
59 extern EVAL_EXPRESSION *expression_parse(const char *string, const char **failed_at, int *error);
61 // free all resources allocated for an expression
62 extern void expression_free(EVAL_EXPRESSION *op);
64 // convert an error code to a message
65 extern const char *expression_strerror(int error);
67 // evaluate an expression and return
68 // 1 = OK, the result is in: expression->result
69 // 2 = FAILED, the error message is in: buffer_tostring(expression->error_msg)
70 extern int expression_evaluate(EVAL_EXPRESSION *expression);
72 #endif //NETDATA_EVAL_H