Drop main() prototype. Syncs with NetBSD-8
[minix.git] / minix / lib / libmagicrt / include / magic_eval_lib.h
blobd2ce30c54d639e3f66d875e3973494c388429f03
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/ */
5 #include <stddef.h>
6 #include <stdlib.h>
8 #define T_INT 0
9 #define T_REAL 1
11 /* value */
12 struct val {
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 */
18 /* variable */
19 struct var {
20 struct var *next; /* next variable in table or NULL */
21 struct val val; /* value of variable */
22 char *name; /* name of variable */
25 /* variable table */
26 struct vartable {
27 struct var *first; /* first entry in variable table */
28 struct memh *mh;
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);
43 /* callbacks */
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);
57 /* errors */
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 */
66 /* configuration */
67 #define TOKEN_DEBUG 0
68 #define EVAL_DEBUG 0
69 #define EVAL_MALLOC 0
70 #define USE_MATH_LIB 0
71 #define MEM_DEBUG 0
72 #define MEM_LOW_FOOTPRINT 1
73 #define VAR_FROM_ENV 0