aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile.am1
-rw-r--r--Makefile.in8
-rw-r--r--expr.c84
-rw-r--r--expr.h49
-rw-r--r--parser.c6
-rw-r--r--parser.h8
-rw-r--r--processor.c20
7 files changed, 168 insertions, 8 deletions
diff --git a/Makefile.am b/Makefile.am
index 76dfc64..9dbe6a6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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
diff --git a/Makefile.in b/Makefile.in
index 18a9643..0807367 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -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
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
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
diff --git a/parser.c b/parser.c
index cda4d63..47f9482 100644
--- 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 },
diff --git a/parser.h b/parser.h
index 1a4de95..05ac93d 100644
--- 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[]);
diff --git a/processor.c b/processor.c
index 04f7cae..dc23cbe 100644
--- a/processor.c
+++ b/processor.c
@@ -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
@@ -248,6 +251,7 @@
#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);
+ }
+ }
+
}