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 --- widget_bar.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'widget_bar.c') diff --git a/widget_bar.c b/widget_bar.c index 97bcaca..a3d4435 100644 --- a/widget_bar.c +++ b/widget_bar.c @@ -1,4 +1,4 @@ -/* $Id: widget_bar.c,v 1.8 2004/03/03 03:47:04 reinelt Exp $ +/* $Id: widget_bar.c,v 1.9 2004/03/06 20:31:16 reinelt Exp $ * * bar widget handling * @@ -21,6 +21,12 @@ * * * $Log: widget_bar.c,v $ + * Revision 1.9 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.8 2004/03/03 03:47:04 reinelt * big patch from Martin Hejl: * - use qprintf() where appropriate @@ -94,22 +100,22 @@ void widget_bar_update (void *Self) // evaluate expressions val1 = 0.0; - if (Bar->expression1!=NULL && *Bar->expression1!='\0') { - Eval(Bar->expression1, &result); + if (Bar->tree1 != NULL) { + Eval(Bar->tree1, &result); val1 = R2N(&result); DelResult(&result); } val2 = val1; - if (Bar->expression2!=NULL && *Bar->expression2!='\0') { - Eval(Bar->expression2, &result); + if (Bar->tree2!=NULL) { + Eval(Bar->tree2, &result); val2 = R2N(&result); DelResult(&result); } // minimum: if expression is empty, do auto-scaling - if (Bar->expr_min!=NULL && *Bar->expr_min!='\0') { - Eval(Bar->expr_min, &result); + if (Bar->tree_min!=NULL) { + Eval(Bar->tree_min, &result); min = R2N(&result); DelResult(&result); } else { @@ -119,8 +125,8 @@ void widget_bar_update (void *Self) } // maximum: if expression is empty, do auto-scaling - if (Bar->expr_max!=NULL && *Bar->expr_max!='\0') { - Eval(Bar->expr_max, &result); + if (Bar->tree_max!=NULL) { + Eval(Bar->tree_max, &result); max = R2N(&result); DelResult(&result); } else { @@ -147,7 +153,6 @@ void widget_bar_update (void *Self) } - int widget_bar_init (WIDGET *Self) { char *section; char *c; @@ -176,6 +181,12 @@ int widget_bar_init (WIDGET *Self) Bar->expr_min = cfg_get_raw (section, "min", NULL); Bar->expr_max = cfg_get_raw (section, "max", NULL); + // compile all expressions + Compile (Bar->expression1, &Bar->tree1); + Compile (Bar->expression2, &Bar->tree2); + Compile (Bar->expr_min, &Bar->tree_min); + Compile (Bar->expr_max, &Bar->tree_max); + // bar length, default 1 cfg_number (section, "length", 1, 0, 99999, &(Bar->length)); -- cgit v1.2.3