]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2004-01-05 11:57:38 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Mon, 5 Jan 2004 11:57:38 +0000 (11:57 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Mon, 5 Jan 2004 11:57:38 +0000 (11:57 +0000)
added %y tokens to make the Evaluator useable

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

Makefile.am
Makefile.in
expr.c [new file with mode: 0644]
expr.h [new file with mode: 0644]
parser.c
parser.h
processor.c

index 76dfc64c5d338cfbfc11b7c8dc8f95400a83db47..9dbe6a6dfa7382048ce0c506b2f759fca5ff956c 100644 (file)
@@ -32,6 +32,7 @@ dvb.c dvb.h \
 filter.c filter.h \
 widget.c widget.h \
 exec.c exec.h \
+expr.c expr.h \
 mail2.c \
 socket.c socket.h \
 imon.c imon.h
index 18a96430a7701c6d378060c472b9aae03748f449..08073670c4d9519eacce43d30ee1374da3be5530 100644 (file)
@@ -101,7 +101,7 @@ AM_CFLAGS = $(X_CFLAGS) -D_GNU_SOURCE -Wall
 lcd4linux_LDFLAGS = $(X_LIBS)
 lcd4linux_LDADD = liblcd4linux.la @DRVLIBS@ 
 
-lcd4linux_SOURCES =  lcd4linux.c pid.c pid.h parser.c parser.h processor.c processor.h evaluator.c evaluator.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_xmms.c system.c system.h isdn.c isdn.h wifi.c wifi.h mail.c mail.h seti.c seti.h battery.c battery.h dvb.c dvb.h filter.c filter.h widget.c widget.h exec.c exec.h mail2.c socket.c socket.h imon.c imon.h
+lcd4linux_SOURCES =  lcd4linux.c pid.c pid.h parser.c parser.h processor.c processor.h evaluator.c evaluator.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_xmms.c system.c system.h isdn.c isdn.h wifi.c wifi.h mail.c mail.h seti.c seti.h battery.c battery.h dvb.c dvb.h filter.c filter.h widget.c widget.h exec.c exec.h expr.c expr.h mail2.c socket.c socket.h imon.c imon.h
 
 
 liblcd4linux_la_DEPENDENCIES = @DRIVERS@
@@ -141,8 +141,8 @@ processor.$(OBJEXT) evaluator.$(OBJEXT) plugin.$(OBJEXT) \
 plugin_math.$(OBJEXT) plugin_string.$(OBJEXT) plugin_xmms.$(OBJEXT) \
 system.$(OBJEXT) isdn.$(OBJEXT) wifi.$(OBJEXT) mail.$(OBJEXT) \
 seti.$(OBJEXT) battery.$(OBJEXT) dvb.$(OBJEXT) filter.$(OBJEXT) \
-widget.$(OBJEXT) exec.$(OBJEXT) mail2.$(OBJEXT) socket.$(OBJEXT) \
-imon.$(OBJEXT)
+widget.$(OBJEXT) exec.$(OBJEXT) expr.$(OBJEXT) mail2.$(OBJEXT) \
+socket.$(OBJEXT) imon.$(OBJEXT)
 lcd4linux_DEPENDENCIES =  liblcd4linux.la
 CFLAGS = @CFLAGS@
 COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -164,7 +164,7 @@ DEP_FILES =  .deps/BeckmannEgle.P .deps/Crystalfontz.P .deps/Cwlinux.P \
 .deps/MilfordInstruments.P .deps/PalmPilot.P .deps/Raster.P .deps/SIN.P \
 .deps/Skeleton.P .deps/T6963.P .deps/Text.P .deps/USBLCD.P \
 .deps/XWindow.P .deps/bar.P .deps/battery.P .deps/cfg.P .deps/debug.P \
-.deps/display.P .deps/dvb.P .deps/evaluator.P .deps/exec.P \
+.deps/display.P .deps/dvb.P .deps/evaluator.P .deps/exec.P .deps/expr.P \
 .deps/filter.P .deps/fontmap.P .deps/icon.P .deps/imon.P .deps/isdn.P \
 .deps/lcd4linux.P .deps/lock.P .deps/mail.P .deps/mail2.P \
 .deps/parport.P .deps/parser.P .deps/pid.P .deps/pixmap.P \
diff --git a/expr.c b/expr.c
new file mode 100644 (file)
index 0000000..87d370b
--- /dev/null
+++ b/expr.c
@@ -0,0 +1,84 @@
+/* $Id: expr.c,v 1.1 2004/01/05 11:57:38 reinelt Exp $
+ *
+ * expr ('y*') functions
+ * This is only a workaround to make the Evaluator usable until
+ * it's fully integrated into lcd4linux.
+ *
+ * Copyright 2004 Michael Reinelt <reinelt@eunet.at>
+ *
+ * This file is part of LCD4Linux.
+ *
+ * LCD4Linux is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * LCD4Linux is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: expr.c,v $
+ * Revision 1.1  2004/01/05 11:57:38  reinelt
+ * added %y tokens to make the Evaluator useable
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <errno.h>
+#define IN_EXPR
+#include "expr.h"
+#include "plugin.h"
+#include "debug.h"
+#include "cfg.h"
+
+
+int Expr(int index, char result[EXPR_TXT_LEN], double *val)
+{
+  RESULT Result = {0, 0.0, NULL};
+  static int errs[EXPRS+1];
+  char *expression;
+  char yn[4];
+  
+  if (index < 0 || index > EXPRS)
+    return -1; 
+  
+  if (errs[index])
+    return -1;
+
+  sprintf(yn, "y%d", index);
+  expression = cfg_get(yn,NULL);
+                                           
+  if (!expression || !*expression) {
+    error("Empty expression for 'y%d'", index);
+    errs[index]++;
+    return -1;
+  }
+
+  Eval(expression, &Result);
+  strcpy(result, R2S(&Result));
+  
+  debug("%s: <%s> = '%s'",yn, expression, result);
+
+  if (isdigit(*result)) {
+    double max, min;
+    *val = atof(result);
+    sprintf(yn, "Max_y%d", index);
+    max = atof(cfg_get(yn,"100"));
+    sprintf(yn, "Min_y%d", index);
+    min = atof(cfg_get(yn,"0"));
+    if (max != min)
+      *val = (*val - min)/(max - min);
+  }
+  return 0;
+}
+
diff --git a/expr.h b/expr.h
new file mode 100644 (file)
index 0000000..ef527c3
--- /dev/null
+++ b/expr.h
@@ -0,0 +1,49 @@
+/* $Id: expr.h,v 1.1 2004/01/05 11:57:38 reinelt Exp $
+ *
+ * expr ('y*') functions
+ * This is only a workaround to make the Evaluator usable until
+ * it's fully integrated into lcd4linux.
+ *
+ * Copyright 2004 Michael Reinelt <reinelt@eunet.at>
+ *
+ * This file is part of LCD4Linux.
+ *
+ * LCD4Linux is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * LCD4Linux is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: expr.h,v $
+ * Revision 1.1  2004/01/05 11:57:38  reinelt
+ * added %y tokens to make the Evaluator useable
+ *
+ */
+
+#ifndef _EXPR_H
+#define _EXPR_H_
+
+#define EXPRS 9
+#define EXPR_TXT_LEN 256
+
+#ifdef IN_EXPR
+  #define EXTERN extern
+#else
+  #define EXTERN
+#endif
+
+EXTERN struct { char s[EXPR_TXT_LEN]; double val; } expr[EXPRS+1];
+
+int Expr (int index, char txt[EXPR_TXT_LEN], double *val);
+
+
+#endif
index cda4d6347869303ccd7cca6384d441e4c2d0233f..47f94826235ec8efe1c7ec4e398aa2dba6c9274f 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1,4 +1,4 @@
-/* $Id: parser.c,v 1.23 2003/11/11 04:40:20 reinelt Exp $
+/* $Id: parser.c,v 1.24 2004/01/05 11:57:38 reinelt Exp $
  *
  * row definition parser
  *
@@ -22,6 +22,9 @@
  *
  *
  * $Log: parser.c,v $
+ * Revision 1.24  2004/01/05 11:57:38  reinelt
+ * added %y tokens to make the Evaluator useable
+ *
  * Revision 1.23  2003/11/11 04:40:20  reinelt
  * WIFI patch from Xavier Vello
  *
@@ -201,6 +204,7 @@ static SYMTAB Symtab[] = {{ "%",  T_PERCENT,    C_GENERIC, 0 },
                          { "u*", T_MAIL_UNSEEN,C_MAIL,    0 },
                          { "s*", T_SENSOR,     C_SENSOR,  1 },
                          { "x*", T_EXEC,       C_EXEC,    1 },
+                         { "y*", T_EXPR,       C_EXPR,    1 },
                          { "jc", T_IMON_CPU,   C_IMON,    1 },
                          { "jv", T_IMON_VER,   C_IMON,    0 },
                          { "jd", T_IMON_DATE,  C_IMON,    0 },
index 1a4de9511024e72d9fd70e1a74f35d8856fd10db..05ac93d69e4e8dc9a8d6f36be190d37400e7b815 100644 (file)
--- a/parser.h
+++ b/parser.h
@@ -1,4 +1,4 @@
-/* $Id: parser.h,v 1.16 2003/11/11 04:40:20 reinelt Exp $
+/* $Id: parser.h,v 1.17 2004/01/05 11:57:38 reinelt Exp $
  *
  * row definition parser
  *
@@ -22,6 +22,9 @@
  *
  *
  * $Log: parser.h,v $
+ * Revision 1.17  2004/01/05 11:57:38  reinelt
+ * added %y tokens to make the Evaluator useable
+ *
  * Revision 1.16  2003/11/11 04:40:20  reinelt
  * WIFI patch from Xavier Vello
  *
@@ -109,6 +112,7 @@ typedef enum {
   T_MAIL, T_MAIL_UNSEEN,
   T_SENSOR,
   T_EXEC,
+  T_EXPR,
   T_IMON_CPU, T_IMON_VER, T_IMON_DATE, T_IMON_TIME, T_IMON_RIN, T_IMON_ROUT,
   T_IMON_STATUS, T_IMON_PHONE, T_IMON_IP, T_IMON_OTIME, T_IMON_CHARGE,
   T_TELMON_NUMBER, T_TELMON_MSN, T_TELMON_TIME, T_TELMON_DATE
@@ -116,7 +120,7 @@ typedef enum {
 
 typedef enum {
   C_GENERIC, C_MEM, C_LOAD, C_CPU, C_DISK, C_ETH, C_PPP, C_ISDN, C_WIFI, C_SETI, C_BATT, C_DVB,
-  C_MAIL, C_SENSOR, C_EXEC, C_IMON, C_TELMON
+  C_MAIL, C_SENSOR, C_EXEC, C_EXPR, C_IMON, C_TELMON
 } CLASS;
 
 char *parse_row (char *string, int supported_bars, int usage[]);
index 04f7cae6dc35d78cf7cac229bbe00ade099e62f3..dc23cbe0a211796c91b2e5d3310a23f48d137120 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: processor.c,v 1.51 2003/11/24 11:34:54 reinelt Exp $
+/* $Id: processor.c,v 1.52 2004/01/05 11:57:38 reinelt Exp $
  *
  * main data processing
  *
@@ -22,6 +22,9 @@
  *
  *
  * $Log: processor.c,v $
+ * Revision 1.52  2004/01/05 11:57:38  reinelt
+ * added %y tokens to make the Evaluator useable
+ *
  * Revision 1.51  2003/11/24 11:34:54  reinelt
  *
  * 'Fixed' Rows which do not scroll by Lars Kempe
 #include "dvb.h"
 #include "seti.h"
 #include "exec.h"
+#include "expr.h"
 #include "imon.h"
 
 #define ROWS 64
@@ -392,6 +396,9 @@ static double query (int token)
   case T_EXEC:
     return exec[(token>>8)-'0'].val;
 
+  case T_EXPR:
+    return expr[(token>>8)-'0'].val;
+
   case T_IMON_CPU:
     return imon.cpu;
     
@@ -650,6 +657,11 @@ static void print_token (int token, char **p, char *start)
     *p+=sprintf (*p, "%.*s",cols-(int)(*p-start), exec[i].s);
     break;
     
+  case T_EXPR:
+    i = (token>>8)-'0';
+    *p+=sprintf (*p, "%.*s",cols-(int)(*p-start), expr[i].s);
+    break;
+    
   case T_IMON_VER:
     *p+=sprintf (*p, "%s", ImonVer());
     break;
@@ -816,6 +828,12 @@ static void collect_data (void)
     }
   }
 
+  for (i=0; i<=EXPRS; i++) {
+    if (token_usage[T_EXPR]&(1<<i)) {
+      Expr (i, expr[i].s, &exec[i].val);
+    }
+  }
+
 }