From c008748638679f10746c70a7f677c0e8906ffa9e Mon Sep 17 00:00:00 2001 From: reinelt Date: Sat, 6 Mar 2004 20:31:16 +0000 Subject: [lcd4linux @ 2004-03-06 20:31:16 by reinelt] Complete rewrite of the evaluator to get rid of the code from mark Morley (because of license issues). The new Evaluator does a pre-compile of expressions, and stores them in trees. Therefore it should be reasonable faster... git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@387 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- cfg.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'cfg.c') diff --git a/cfg.c b/cfg.c index dd6d2c3..0b4aec7 100644 --- a/cfg.c +++ b/cfg.c @@ -1,4 +1,4 @@ -/* $Id: cfg.c,v 1.36 2004/03/03 03:47:04 reinelt Exp $^ +/* $Id: cfg.c,v 1.37 2004/03/06 20:31:16 reinelt Exp $^ * * config file stuff * @@ -23,6 +23,12 @@ * * * $Log: cfg.c,v $ + * Revision 1.37 2004/03/06 20:31:16 reinelt + * Complete rewrite of the evaluator to get rid of the code + * from mark Morley (because of license issues). + * The new Evaluator does a pre-compile of expressions, and + * stores them in trees. Therefore it should be reasonable faster... + * * Revision 1.36 2004/03/03 03:47:04 reinelt * big patch from Martin Hejl: * - use qprintf() where appropriate @@ -471,17 +477,19 @@ char *l4l_cfg_get (char *section, char *key, char *defval) { char *expression; char *retval; + void *tree = NULL; RESULT result = {0, 0.0, NULL}; expression=cfg_lookup(section, key); if (expression!=NULL) { if (*expression=='\0') return ""; - if (Eval(expression, &result)==0) { + if (Compile(expression, &tree)==0 && Eval(tree, &result)==0) { retval=strdup(R2S(&result)); DelResult(&result); - return(retval); + return(retval); } + DelTree(tree); DelResult(&result); } if (defval) return strdup(defval); @@ -492,6 +500,7 @@ char *l4l_cfg_get (char *section, char *key, char *defval) int l4l_cfg_number (char *section, char *key, int defval, int min, int max, int *value) { char *expression; + void *tree = NULL; RESULT result = {0, 0.0, NULL}; // start with default value @@ -500,15 +509,17 @@ int l4l_cfg_number (char *section, char *key, int defval, int min, int max, int *value=defval; expression=cfg_get_raw(section, key, NULL); - if (expression==NULL) { + if (expression==NULL || *expression=='\0') { return 0; } - if (Eval(expression, &result)!=0) { + if (Compile(expression, &tree) != 0) return -1; + if (Eval(tree, &result) != 0) { DelResult(&result); return -1; } *value=R2N(&result); + DelTree (tree); DelResult(&result); if (*value