1 /* evaluate.h (C) 2000-2002 Kyzer/CSG. */
2 /* Released under the terms of the GNU General Public Licence version 2. */
3 /* http://www.kyzer.me.uk/code/evaluate/ */
13 long ival
; /* if type = T_INT, this is the result */
14 double rval
; /* if type = T_REAL, this is the result */
15 char type
; /* either T_INT or T_REAL */
20 struct var
*next
; /* next variable in table or NULL */
21 struct val val
; /* value of variable */
22 char *name
; /* name of variable */
27 struct var
*first
; /* first entry in variable table */
31 /* creates a new variable table (NULL if no memory) */
32 struct vartable
*create_vartable(void);
34 /* frees a variable table */
35 void free_vartable(struct vartable
*vt
);
37 /* gets a variable from a variable table (NULL if not found) */
38 struct var
*get_var(struct vartable
*vt
, char *name
);
40 /* puts a variable into a variable table (NULL if no memory) */
41 struct var
*put_var(struct vartable
*vt
, char *name
, struct val
*value
);
44 typedef struct val
*(*get_var_cb_t
)(char*, struct val
*);
45 typedef struct val
*(*get_func_result_cb_t
)(char*, struct val
*, struct val
*);
46 void eval_set_cb_get_var(get_var_cb_t cb
);
47 void eval_set_cb_get_func_result(get_func_result_cb_t cb
);
49 /* THE FUNCTION YOU WANT TO CALL */
51 /* given a string to evaluate (not NULL), a result to put the answer in
52 * (not NULL) and optionally your own variable table (NULL for 'internal
53 * only' vartable), will return an error code (and result, etc)
55 int evaluate(char *eval
, struct val
*result
, struct vartable
*variables
);
58 #define RESULT_OK 0 /* all OK */
59 #define ERROR_SYNTAX 2 /* invalid expression */
60 #define ERROR_VARNOTFOUND 3 /* variable not found */
61 #define ERROR_FUNCNOTFOUND 4 /* function not found */
62 #define ERROR_NOMEM 8 /* not enough memory available */
63 #define ERROR_DIV0 9 /* division by zero */
64 #define ERROR_BUSY 10 /* busy now */
70 #define USE_MATH_LIB 0
72 #define MEM_LOW_FOOTPRINT 1
73 #define VAR_FROM_ENV 0