diff options
author | reinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2004-03-06 20:31:16 +0000 |
---|---|---|
committer | reinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2004-03-06 20:31:16 +0000 |
commit | c008748638679f10746c70a7f677c0e8906ffa9e (patch) | |
tree | e8d53c15a9184b19109453e56cf4fc8f8cfac6b0 /cfg.c | |
parent | 2f4f59ba2e28ee38f721f09ab6756fd4575b3f78 (diff) | |
download | lcd4linux-c008748638679f10746c70a7f677c0e8906ffa9e.tar.gz |
[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
Diffstat (limited to 'cfg.c')
-rw-r--r-- | cfg.c | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -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<min) { |