]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2004-01-12 03:51:01 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Mon, 12 Jan 2004 03:51:01 +0000 (03:51 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Mon, 12 Jan 2004 03:51:01 +0000 (03:51 +0000)
evaluating the 'Variables' section in the config file

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@307 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

evaluator.c
evaluator.h
expr.c
layout.c
lcd4linux.c

index 2b84dd65de31fe76c5c28a2b186d518dbc28d3d3..ce0623dc4ed4ca8a1db26a985687313e0a7f2b20 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: evaluator.c,v 1.7 2004/01/07 10:15:41 reinelt Exp $
+/* $Id: evaluator.c,v 1.8 2004/01/12 03:51:01 reinelt Exp $
  *
  * expression evaluation
  *
@@ -10,6 +10,9 @@
  * FIXME: GPL or not GPL????
  *
  * $Log: evaluator.c,v $
+ * Revision 1.8  2004/01/12 03:51:01  reinelt
+ * evaluating the 'Variables' section in the config file
+ *
  * Revision 1.7  2004/01/07 10:15:41  reinelt
  * small glitch in evaluator fixed
  * made config table sorted and access with bsearch(),
 /* 
  * exported functions:
  *
+ * void DelResult (RESULT *result)
+ *   sets a result to none
+ *   frees a probably allocated memory
+ *
+ * int SetVariable (char *name, RESULT *value)
+ *   adds a generic variable to the evaluator
+ *
  * int AddNumericVariable(char *name, double value)
  *   adds a numerical variable to the evaluator
  *
@@ -168,7 +178,7 @@ char* ErrMsg[] = {
 
 
 
-static void DelResult (RESULT *result)
+void DelResult (RESULT *result)
 {
   result->type=0;
   result->number=0.0;
@@ -348,7 +358,7 @@ static int GetVariable (char *name, RESULT *value)
 }
 
 
-static int SetVariable (char *name, RESULT *value)
+int SetVariable (char *name, RESULT *value)
 {
   VARIABLE *V;
 
@@ -819,7 +829,7 @@ int Eval (char* expression, RESULT *result)
   int i, err;
   
   if ((err=setjmp(jb))) {
-    error ("Error: %s in expression <%s>", ErrMsg[err], expression);
+    error ("Evaluator: %s in expression <%s>", ErrMsg[err], expression);
     return -1;
   }
   
@@ -830,7 +840,7 @@ int Eval (char* expression, RESULT *result)
     // sanity check: two functions with the same name?
     for (i=1; i<nFunction; i++) {
       if (strcmp(Function[i].name, Function[i-1].name)==0) {
-       error ("internal error: Function '%s' defined twice!", Function[i].name);
+       error ("Evaluator: internal error: Function '%s' defined twice!", Function[i].name);
       }
     }
   }
index f15ee3290f85cf6e31ad62759cd3469527bb5365..9ace1028ea01ac1cb2eb89a409c1605059a3fbf9 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: evaluator.h,v 1.2 2003/10/11 06:01:53 reinelt Exp $
+/* $Id: evaluator.h,v 1.3 2004/01/12 03:51:01 reinelt Exp $
  *
  * expression evaluation
  *
@@ -10,6 +10,9 @@
  * FIXME: GPL or not GPL????
  *
  * $Log: evaluator.h,v $
+ * Revision 1.3  2004/01/12 03:51:01  reinelt
+ * evaluating the 'Variables' section in the config file
+ *
  * Revision 1.2  2003/10/11 06:01:53  reinelt
  *
  * renamed expression.{c,h} to client.{c,h}
@@ -84,6 +87,8 @@ typedef struct {
 #define E_EMPTY   8 /* Empty expression */
 
 
+void DelResult         (RESULT *result);
+int SetVariable        (char *name, RESULT *value);
 int AddNumericVariable (char *name, double value);
 int AddStringVariable  (char *name, char *value);
 int AddFunction        (char *name, int args, void (*func)());
diff --git a/expr.c b/expr.c
index 2464a99b8afe3311a8326623e7eeb32c1970ef06..1b1c5b74f5954fc03f3011213dbfda5849f8cddf 100644 (file)
--- a/expr.c
+++ b/expr.c
@@ -1,4 +1,4 @@
-/* $Id: expr.c,v 1.2 2004/01/09 04:16:06 reinelt Exp $
+/* $Id: expr.c,v 1.3 2004/01/12 03:51:01 reinelt Exp $
  *
  * expr ('y*') functions
  * This is only a workaround to make the Evaluator usable until
@@ -24,6 +24,9 @@
  *
  *
  * $Log: expr.c,v $
+ * Revision 1.3  2004/01/12 03:51:01  reinelt
+ * evaluating the 'Variables' section in the config file
+ *
  * Revision 1.2  2004/01/09 04:16:06  reinelt
  * added 'section' argument to cfg_get(), but NULLed it on all calls by now.
  *
@@ -45,9 +48,9 @@
 #include "cfg.h"
 
 
-int Expr(int index, char result[EXPR_TXT_LEN], double *val)
+int Expr(int index, char string[EXPR_TXT_LEN], double *val)
 {
-  RESULT Result = {0, 0.0, NULL};
+  RESULT result = {0, 0.0, NULL};
   static int errs[EXPRS+1];
   char *expression;
   char yn[4];
@@ -67,14 +70,14 @@ int Expr(int index, char result[EXPR_TXT_LEN], double *val)
     return -1;
   }
 
-  Eval(expression, &Result);
-  strcpy(result, R2S(&Result));
+  Eval(expression, &result);
+  strcpy(string, R2S(&result));
   
   debug("%s: <%s> = '%s'",yn, expression, result);
 
-  if (isdigit(*result)) {
+  if (isdigit(*string)) {
     double max, min;
-    *val = atof(result);
+    *val = atof(string);
     sprintf(yn, "Max_y%d", index);
     max = atof(cfg_get(NULL, yn, "100"));
     sprintf(yn, "Min_y%d", index);
@@ -82,6 +85,9 @@ int Expr(int index, char result[EXPR_TXT_LEN], double *val)
     if (max != min)
       *val = (*val - min)/(max - min);
   }
+
+  DelResult (&result);
+
   return 0;
 }
 
index 13d05f95cbd5b18d217ae61818327daa3110bbd4..5ea84ca1abc91958666902761650beda8fc0ace8 100644 (file)
--- a/layout.c
+++ b/layout.c
@@ -1,4 +1,4 @@
-/* $Id: layout.c,v 1.3 2004/01/11 18:26:02 reinelt Exp $
+/* $Id: layout.c,v 1.4 2004/01/12 03:51:01 reinelt Exp $
  *
  * new layouter framework
  *
@@ -23,6 +23,9 @@
  *
  *
  * $Log: layout.c,v $
+ * Revision 1.4  2004/01/12 03:51:01  reinelt
+ * evaluating the 'Variables' section in the config file
+ *
  * Revision 1.3  2004/01/11 18:26:02  reinelt
  * further widget and layout processing
  *
@@ -54,6 +57,7 @@
 
 #include "debug.h"
 #include "cfg.h"
+#include "widget.h"
 #include "layout.h"
 
 
index 255d94a82b5c292b50ab0faa5c1b86f42c8a133a..a69e54648670eed7d9211b6a033be2de82906d0f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: lcd4linux.c,v 1.58 2004/01/10 20:22:33 reinelt Exp $
+/* $Id: lcd4linux.c,v 1.59 2004/01/12 03:51:01 reinelt Exp $
  *
  * LCD4Linux
  *
@@ -22,6 +22,9 @@
  *
  *
  * $Log: lcd4linux.c,v $
+ * Revision 1.59  2004/01/12 03:51:01  reinelt
+ * evaluating the 'Variables' section in the config file
+ *
  * Revision 1.58  2004/01/10 20:22:33  reinelt
  * added new function 'cfg_list()' (not finished yet)
  * added layout.c (will replace processor.c someday)
@@ -564,6 +567,7 @@ int main (int argc, char *argv[])
        } else if (result.type==R_STRING) {
          printf ("'%s'\n", R2S(&result));
        }
+       DelResult (&result);
       }
       printf("eval> ");
     }