From 4639c081cd5ebff1e689ce6f41d9c78220042808 Mon Sep 17 00:00:00 2001 From: erg Date: Tue, 23 Jun 2009 15:27:01 +0000 Subject: [PATCH] Fix libexpr to be re-usable. --- lib/expr/exeval.c | 5 ++++- lib/expr/exgram.h | 8 ++++++++ lib/expr/expr.h | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/expr/exeval.c b/lib/expr/exeval.c index 8c61786d8..5badc1c8b 100644 --- a/lib/expr/exeval.c +++ b/lib/expr/exeval.c @@ -873,7 +873,10 @@ static Extype_t eval(Expr_t * ex, register Exnode_t * expr, void *env) return v; case EXIT: v = eval(ex, x, env); - exit((int) v.integer); + if (ex->disc->exitf) + (*ex->disc->exitf) (ex, env, (int)v.integer); + else + exit((int) v.integer); /*NOTREACHED*/ v.integer = -1; return v; case IF: diff --git a/lib/expr/exgram.h b/lib/expr/exgram.h index 4e4859e19..6fdf48958 100644 --- a/lib/expr/exgram.h +++ b/lib/expr/exgram.h @@ -881,6 +881,14 @@ extern "C" { return 0; } +/* + * clear global state of stale pointers + */ + + void + exinit() { + memset (&expr, 0, sizeof(Expr_t)); + } /* * compile the expression in [sf]p */ diff --git a/lib/expr/expr.h b/lib/expr/expr.h index 43f14fc17..8320c7e67 100644 --- a/lib/expr/expr.h +++ b/lib/expr/expr.h @@ -126,6 +126,7 @@ extern "C" { typedef int (*Exerror_f) (Expr_t *, Exdisc_t *, int, const char *, ...); + typedef void (*Exexit_f) (Expr_t *, Exdisc_t *, int); typedef struct { /* user defined member type */ Sflong_t number; @@ -237,6 +238,8 @@ extern "C" { /* set value function */ int (*matchf) (Expr_t *, Exnode_t *, const char *, Exnode_t *, const char *, void *, Exdisc_t *); + /* exit function */ + Exexit_f exitf; int *types; void *user; }; @@ -310,6 +313,7 @@ extern "C" { extern char *extype(int); extern Extype_t exzero(int); extern char *exopname(int); + extern void exinit(); extern char *extypename(Expr_t * p, int); extern int exisAssign(Exnode_t *); -- 2.40.0