]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2003-10-11 06:01:52 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sat, 11 Oct 2003 06:01:53 +0000 (06:01 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sat, 11 Oct 2003 06:01:53 +0000 (06:01 +0000)
renamed expression.{c,h} to client.{c,h}
added config file client
new functions 'AddNumericVariable()' and 'AddStringVariable()'
new parameter '-i' for interactive mode

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

12 files changed:
Makefile.am
Makefile.in
cfg.c
client.c [new file with mode: 0644]
client.h [new file with mode: 0644]
config.guess
config.sub
evaluator.c
evaluator.h
expression.c [deleted file]
expression.h [deleted file]
lcd4linux.c

index eebbefa06eb5aba8c2ed7cbae70a88ba14a71277..e5b17f2fac35371ac2d896e66b3c2763e60f15b2 100644 (file)
@@ -18,7 +18,7 @@ pid.c pid.h \
 parser.c parser.h \
 processor.c processor.h \
 evaluator.c evaluator.h \
-expression.c expression.h \
+client.c client.h \
 system.c system.h \
 isdn.c isdn.h \
 mail.c mail.h \
index eba9f09adaf929c3ea1409c8276d240d5d35313b..215a70bcb0a6981302c7a274bb58478e92743941 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 expression.c expression.h system.c system.h isdn.c isdn.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
+lcd4linux_SOURCES =  lcd4linux.c pid.c pid.h parser.c parser.h processor.c processor.h evaluator.c evaluator.h client.c client.h system.c system.h isdn.c isdn.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
 
 
 liblcd4linux_la_DEPENDENCIES = @DRIVERS@
@@ -137,7 +137,7 @@ bin_PROGRAMS =  lcd4linux$(EXEEXT)
 PROGRAMS =  $(bin_PROGRAMS)
 
 lcd4linux_OBJECTS =  lcd4linux.$(OBJEXT) pid.$(OBJEXT) parser.$(OBJEXT) \
-processor.$(OBJEXT) evaluator.$(OBJEXT) expression.$(OBJEXT) \
+processor.$(OBJEXT) evaluator.$(OBJEXT) client.$(OBJEXT) \
 system.$(OBJEXT) isdn.$(OBJEXT) mail.$(OBJEXT) seti.$(OBJEXT) \
 battery.$(OBJEXT) dvb.$(OBJEXT) filter.$(OBJEXT) widget.$(OBJEXT) \
 exec.$(OBJEXT) mail2.$(OBJEXT) socket.$(OBJEXT)
@@ -161,10 +161,10 @@ DEP_FILES =  .deps/BeckmannEgle.P .deps/Crystalfontz.P .deps/Cwlinux.P \
 .deps/HD44780.P .deps/M50530.P .deps/MatrixOrbital.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/expression.P .deps/filter.P .deps/fontmap.P .deps/icon.P \
-.deps/isdn.P .deps/lcd4linux.P .deps/lock.P .deps/mail.P .deps/mail2.P \
+.deps/XWindow.P .deps/bar.P .deps/battery.P .deps/cfg.P .deps/client.P \
+.deps/debug.P .deps/display.P .deps/dvb.P .deps/evaluator.P \
+.deps/exec.P .deps/filter.P .deps/fontmap.P .deps/icon.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 \
 .deps/processor.P .deps/seti.P .deps/socket.P .deps/system.P \
 .deps/udelay.P .deps/widget.P
diff --git a/cfg.c b/cfg.c
index e9b9f1aece5b974cdea123be96de8deda59ea7f1..ad7c52adb081546f11c845d8d5c85fe99bbfdaa1 100644 (file)
--- a/cfg.c
+++ b/cfg.c
@@ -1,4 +1,4 @@
-/* $Id: cfg.c,v 1.17 2003/10/05 17:58:50 reinelt Exp $^
+/* $Id: cfg.c,v 1.18 2003/10/11 06:01:52 reinelt Exp $^
  *
  * config file stuff
  *
  *
  *
  * $Log: cfg.c,v $
+ * Revision 1.18  2003/10/11 06:01:52  reinelt
+ *
+ * renamed expression.{c,h} to client.{c,h}
+ * added config file client
+ * new functions 'AddNumericVariable()' and 'AddStringVariable()'
+ * new parameter '-i' for interactive mode
+ *
  * Revision 1.17  2003/10/05 17:58:50  reinelt
  * libtool junk; copyright messages cleaned up
  *
 
 #include "debug.h"
 #include "cfg.h"
-
+#include "client.h"
 
 typedef struct {
   char *key;
@@ -308,6 +315,13 @@ static int check_cfg_source(char *file)
 }
 
 
+static void cfg_client (RESULT *result, RESULT *arg1)
+{
+  char *value=cfg_get(R2S(arg1), "");
+  SetResult(&result, R_STRING, value); 
+}
+
+
 int l4l_cfg_init (char *file)
 {
   FILE *stream;
@@ -350,6 +364,10 @@ int l4l_cfg_init (char *file)
     cfg_add (line, p, 0);
   }
   fclose (stream);
+
+  // register as a client
+  AddFunction ("cfg", 1, cfg_client);
+
   return 0;
 }
 
diff --git a/client.c b/client.c
new file mode 100644 (file)
index 0000000..bdfcbcb
--- /dev/null
+++ b/client.c
@@ -0,0 +1,156 @@
+/* $Id: client.c,v 1.1 2003/10/11 06:01:52 reinelt Exp $
+ *
+ * client function handling
+ *
+ * Copyright 2003 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: client.c,v $
+ * Revision 1.1  2003/10/11 06:01:52  reinelt
+ *
+ * renamed expression.{c,h} to client.{c,h}
+ * added config file client
+ * new functions 'AddNumericVariable()' and 'AddStringVariable()'
+ * new parameter '-i' for interactive mode
+ *
+ * Revision 1.3  2003/10/06 05:51:15  reinelt
+ * functions: min(), max()
+ *
+ * Revision 1.2  2003/10/06 05:47:27  reinelt
+ * operators: ==, \!=, <=, >=
+ *
+ * Revision 1.1  2003/10/06 04:34:06  reinelt
+ * expression evaluator added
+ *
+ */
+
+/* 
+ * exported functions:
+ *
+ * int Client_init (void)
+ *  initializes the expression evaluator
+ *  adds some handy constants and functions
+ *
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+
+#include "debug.h"
+#include "client.h"
+
+
+
+static void my_sqrt (RESULT *result, RESULT *arg1)
+{
+  double value=sqrt(R2N(arg1));
+  SetResult(&result, R_NUMBER, &value); 
+}
+
+static void my_exp (RESULT *result, RESULT *arg1)
+{
+  double value=exp(R2N(arg1));
+  SetResult(&result, R_NUMBER, &value); 
+}
+
+static void my_ln (RESULT *result, RESULT *arg1)
+{
+  double value=log(R2N(arg1));
+  SetResult(&result, R_NUMBER, &value); 
+}
+
+static void my_log (RESULT *result, RESULT *arg1)
+{
+  double value=log10(R2N(arg1));
+  SetResult(&result, R_NUMBER, &value); 
+}
+
+static void my_sin (RESULT *result, RESULT *arg1)
+{
+  double value=sin(R2N(arg1));
+  SetResult(&result, R_NUMBER, &value); 
+}
+
+static void my_cos (RESULT *result, RESULT *arg1)
+{
+  double value=cos(R2N(arg1));
+  SetResult(&result, R_NUMBER, &value); 
+}
+
+static void my_tan (RESULT *result, RESULT *arg1)
+{
+  double value=tan(R2N(arg1));
+  SetResult(&result, R_NUMBER, &value); 
+}
+
+
+static void my_min (RESULT *result, RESULT *arg1, RESULT *arg2)
+{
+  double a1=R2N(arg1);
+  double a2=R2N(arg2);
+  double value=a1<a2?a1:a2;
+  SetResult(&result, R_NUMBER, &value); 
+}
+
+static void my_max (RESULT *result, RESULT *arg1, RESULT *arg2)
+{
+  double a1=R2N(arg1);
+  double a2=R2N(arg2);
+  double value=a1>a2?a1:a2;
+  SetResult(&result, R_NUMBER, &value); 
+}
+
+
+static void my_strlen (RESULT *result, RESULT *arg1)
+{
+  double value=strlen(R2S(arg1));
+  SetResult(&result, R_NUMBER, &value); 
+}
+
+
+int client_init (void)
+{
+  // set some handy constants
+  AddNumericVariable ("Pi", M_PI);
+  AddNumericVariable ("e",  M_E);
+  
+  // register some basic math functions
+  AddFunction ("sqrt", 1, my_sqrt);
+  AddFunction ("exp",  1, my_exp);
+  AddFunction ("ln",   1, my_ln);
+  AddFunction ("log",  1, my_log);
+  AddFunction ("sin",  1, my_sin);
+  AddFunction ("cos",  1, my_cos);
+  AddFunction ("tan",  1, my_tan);
+  
+  // min, max
+  AddFunction ("min",  2, my_min);
+  AddFunction ("max",  2, my_max);
+
+  // register some basic string functions
+  AddFunction ("strlen", 1, my_strlen);
+
+  
+  return 0;
+}
+
+
diff --git a/client.h b/client.h
new file mode 100644 (file)
index 0000000..6956227
--- /dev/null
+++ b/client.h
@@ -0,0 +1,45 @@
+/* $Id: client.h,v 1.1 2003/10/11 06:01:52 reinelt Exp $
+ *
+ * client function handling
+ *
+ * Copyright 2003 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: client.h,v $
+ * Revision 1.1  2003/10/11 06:01:52  reinelt
+ *
+ * renamed expression.{c,h} to client.{c,h}
+ * added config file client
+ * new functions 'AddNumericVariable()' and 'AddStringVariable()'
+ * new parameter '-i' for interactive mode
+ *
+ * Revision 1.1  2003/10/06 04:34:06  reinelt
+ * expression evaluator added
+ *
+ */
+
+
+#include "evaluator.h"
+
+#ifndef _CLIENT_H_
+#define _CLIENT_H_
+
+int client_init (void);
+
+#endif
index 0e30d56e94e09336675d596da079d04cc520d257..11271623bbd264b4e32e6ea38bd50497b50e6f86 100755 (executable)
@@ -3,7 +3,7 @@
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
 #   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
-timestamp='2003-07-02'
+timestamp='2003-10-07'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -734,7 +734,7 @@ EOF
        echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
        exit 0 ;;
     *:UNICOS/mp:*:*)
-       echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 
+       echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
        exit 0 ;;
     F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
        FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
@@ -751,7 +751,7 @@ EOF
     *:BSD/OS:*:*)
        echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
        exit 0 ;;
-    *:FreeBSD:*:*|*:GNU/FreeBSD:*:*)
+    *:FreeBSD:*:*)
        # Determine whether the default compiler uses glibc.
        eval $set_cc_for_build
        sed 's/^        //' << EOF >$dummy.c
@@ -763,7 +763,7 @@ EOF
        #endif
 EOF
        eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
-       # GNU/FreeBSD systems have a "k" prefix to indicate we are using
+       # GNU/KFreeBSD systems have a "k" prefix to indicate we are using
        # FreeBSD's kernel, but not the complete OS.
        case ${LIBC} in gnu) kernel_only='k' ;; esac
        echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC}
@@ -799,8 +799,13 @@ EOF
        echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
        exit 0 ;;
     *:GNU:*:*)
+       # the GNU system
        echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
        exit 0 ;;
+    *:GNU/*:*:*)
+       # other systems with GNU libc and userland
+       echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
+       exit 0 ;;
     i*86:Minix:*:*)
        echo ${UNAME_MACHINE}-pc-minix
        exit 0 ;;
@@ -948,6 +953,9 @@ EOF
        LIBC=gnuaout
        #endif
        #endif
+       #ifdef __dietlibc__
+       LIBC=dietlibc
+       #endif
 EOF
        eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
        test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0
@@ -1049,7 +1057,7 @@ EOF
        exit 0 ;;
     M68*:*:R3V[567]*:*)
        test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
-    3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0)
+    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0)
        OS_REL=''
        test -r /etc/.relid \
        && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
@@ -1164,7 +1172,7 @@ EOF
     *:QNX:*:4*)
        echo i386-pc-qnx
        exit 0 ;;
-    NSR-[DGKLNPTVW]:NONSTOP_KERNEL:*:*)
+    NSR-[DGKLNPTVWY]:NONSTOP_KERNEL:*:*)
        echo nsr-tandem-nsk${UNAME_RELEASE}
        exit 0 ;;
     *:NonStop-UX:*:*)
index 6eea72728397be8ff2576ff2874998620dd1a617..79657cd182242a10caec0d995dabbc673fc3970e 100755 (executable)
@@ -3,7 +3,7 @@
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
 #   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
-timestamp='2003-07-17'
+timestamp='2003-10-07'
 
 # This file is (in principle) common to ALL GNU software.
 # The presence of a machine in this file suggests that SOME GNU software
@@ -118,7 +118,7 @@ esac
 # Here we must recognize all the valid KERNEL-OS combinations.
 maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
 case $maybe_os in
-  nto-qnx* | linux-gnu* | kfreebsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
+  nto-qnx* | linux-gnu* | linux-dietlibc | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
     os=-$maybe_os
     basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
     ;;
@@ -248,6 +248,7 @@ case $basic_machine in
        | mipsisa32 | mipsisa32el \
        | mipsisa32r2 | mipsisa32r2el \
        | mipsisa64 | mipsisa64el \
+       | mipsisa64r2 | mipsisa64r2el \
        | mipsisa64sb1 | mipsisa64sb1el \
        | mipsisa64sr71k | mipsisa64sr71kel \
        | mipstx39 | mipstx39el \
@@ -320,6 +321,7 @@ case $basic_machine in
        | mipsisa32-* | mipsisa32el-* \
        | mipsisa32r2-* | mipsisa32r2el-* \
        | mipsisa64-* | mipsisa64el-* \
+       | mipsisa64r2-* | mipsisa64r2el-* \
        | mipsisa64sb1-* | mipsisa64sb1el-* \
        | mipsisa64sr71k-* | mipsisa64sr71kel-* \
        | mipstx39-* | mipstx39el-* \
@@ -1129,7 +1131,7 @@ case $os in
              | -aos* \
              | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
              | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
-             | -hiux* | -386bsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \
+             | -hiux* | -386bsd* | -knetbsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \
              | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
              | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
              | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
@@ -1165,6 +1167,9 @@ case $os in
        -mac*)
                os=`echo $os | sed -e 's|mac|macos|'`
                ;;
+       -linux-dietlibc)
+               os=-linux-dietlibc
+               ;;
        -linux*)
                os=`echo $os | sed -e 's|linux|linux-gnu|'`
                ;;
index 995b61a638c5cd275893fb8c1b9a7f436d88c510..ac5bd935ee33e3b66cdeeedf6422c5d714a1638b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: evaluator.c,v 1.2 2003/10/06 05:47:27 reinelt Exp $
+/* $Id: evaluator.c,v 1.3 2003/10/11 06:01:52 reinelt Exp $
  *
  * expression evaluation
  *
  * FIXME: GPL or not GPL????
  *
  * $Log: evaluator.c,v $
+ * Revision 1.3  2003/10/11 06:01:52  reinelt
+ *
+ * renamed expression.{c,h} to client.{c,h}
+ * added config file client
+ * new functions 'AddNumericVariable()' and 'AddStringVariable()'
+ * new parameter '-i' for interactive mode
+ *
  * Revision 1.2  2003/10/06 05:47:27  reinelt
  * operators: ==, \!=, <=, >=
  *
 /* 
  * exported functions:
  *
- * int AddConstant (char *name, double value)
+ * int AddNumericVariable(char *name, double value)
+ *   adds a numerical variable to the evaluator
+ *
+ * int AddStringVariable(char *name, char *value)
  *   adds a numerical variable to the evaluator
  *
  * int AddFunction (char *name, int args, void (*func)())
@@ -339,18 +349,6 @@ static int SetVariable (char *name, RESULT *value)
 }
 
 
-int AddConstant (char *name, double value)
-{
-  RESULT result;
-  
-  result.type=R_NUMBER;
-  result.number=value;
-  result.string=NULL;
-  
-  return SetVariable (name, &result);
-}
-
-
 // bsearch compare function for functions 
 static int f_lookup (const void *a, const void *b)
 {
@@ -369,33 +367,6 @@ static int f_sort (const void *a, const void *b)
 }
 
 
-int AddFunction (char *name, int args, void (*func)())
-{
-  FUNCTION *F;
-
-  F=bsearch(name, Function, nFunction, sizeof(FUNCTION), f_lookup);
-  if (F!=NULL) {
-    if (F->name) free (F->name);
-    F->name=strdup(name);
-    F->args=args;
-    F->func=func;
-    return 1;
-  }
-  
-  // Fixme: we append the func at the end and re-sort
-  // the whole array! This should be optimized...
-  nFunction++;
-  Function=realloc(Function, nFunction*sizeof(FUNCTION));
-  Function[nFunction-1].name=strdup(name);
-  Function[nFunction-1].args=args;
-  Function[nFunction-1].func=func;
-  qsort(Function, nFunction, sizeof(FUNCTION), f_sort);
-
-  return 0;
-}
-
-
-
 // Prototypes
 static void Level01  (RESULT *result);
 static void Level02  (RESULT *result);
@@ -749,6 +720,56 @@ static void Level11 (RESULT *result)
 }
 
 
+int AddNumericVariable (char *name, double value)
+{
+  RESULT result;
+  
+  result.type=R_NUMBER;
+  result.number=value;
+  result.string=NULL;
+  
+  return SetVariable (name, &result);
+}
+
+
+int AddStringVariable (char *name, char *value)
+{
+  RESULT result;
+  
+  result.type=R_STRING;
+  result.number=0.0;
+  result.string=strdup(value);
+  
+  return SetVariable (name, &result);
+}
+
+
+int AddFunction (char *name, int args, void (*func)())
+{
+  FUNCTION *F;
+
+  F=bsearch(name, Function, nFunction, sizeof(FUNCTION), f_lookup);
+  if (F!=NULL) {
+    if (F->name) free (F->name);
+    F->name=strdup(name);
+    F->args=args;
+    F->func=func;
+    return 1;
+  }
+  
+  // Fixme: we append the func at the end and re-sort
+  // the whole array! This should be optimized...
+  nFunction++;
+  Function=realloc(Function, nFunction*sizeof(FUNCTION));
+  Function[nFunction-1].name=strdup(name);
+  Function[nFunction-1].args=args;
+  Function[nFunction-1].func=func;
+  qsort(Function, nFunction, sizeof(FUNCTION), f_sort);
+
+  return 0;
+}
+
+
 int Eval (char* expression, RESULT *result)
 {
   int err;
@@ -766,5 +787,3 @@ int Eval (char* expression, RESULT *result)
   if (*Token!='\0') ERROR (E_SYNTAX);
   return 0;
 }
-
-
index 661b967575545a248aacf692261db64eafe6fe76..f15ee3290f85cf6e31ad62759cd3469527bb5365 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: evaluator.h,v 1.1 2003/10/06 04:34:06 reinelt Exp $
+/* $Id: evaluator.h,v 1.2 2003/10/11 06:01:53 reinelt Exp $
  *
  * expression evaluation
  *
  * FIXME: GPL or not GPL????
  *
  * $Log: evaluator.h,v $
+ * Revision 1.2  2003/10/11 06:01:53  reinelt
+ *
+ * renamed expression.{c,h} to client.{c,h}
+ * added config file client
+ * new functions 'AddNumericVariable()' and 'AddStringVariable()'
+ * new parameter '-i' for interactive mode
+ *
  * Revision 1.1  2003/10/06 04:34:06  reinelt
  * expression evaluator added
  *
@@ -77,8 +84,9 @@ typedef struct {
 #define E_EMPTY   8 /* Empty expression */
 
 
-int AddConstant (char *name, double value);
-int AddFunction (char *name, int args, void (*func)());
+int AddNumericVariable (char *name, double value);
+int AddStringVariable  (char *name, char *value);
+int AddFunction        (char *name, int args, void (*func)());
 
 RESULT* SetResult (RESULT **result, int type, void *value);
 
diff --git a/expression.c b/expression.c
deleted file mode 100644 (file)
index 7fc15fd..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-/* $Id: expression.c,v 1.3 2003/10/06 05:51:15 reinelt Exp $
- *
- * expression handling
- *
- * Copyright 2003 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: expression.c,v $
- * Revision 1.3  2003/10/06 05:51:15  reinelt
- * functions: min(), max()
- *
- * Revision 1.2  2003/10/06 05:47:27  reinelt
- * operators: ==, \!=, <=, >=
- *
- * Revision 1.1  2003/10/06 04:34:06  reinelt
- * expression evaluator added
- *
- */
-
-/* 
- * exported functions:
- *
- * int EX_init (void)
- *  initializes the expression evaluator
- *  adds some handy constants and functions
- *
- */
-
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-
-#include "debug.h"
-#include "cfg.h"
-#include "evaluator.h"
-#include "expression.h"
-
-
-
-static void my_sqrt (RESULT *result, RESULT *arg1)
-{
-  double value=sqrt(R2N(arg1));
-  SetResult(&result, R_NUMBER, &value); 
-}
-
-static void my_exp (RESULT *result, RESULT *arg1)
-{
-  double value=exp(R2N(arg1));
-  SetResult(&result, R_NUMBER, &value); 
-}
-
-static void my_ln (RESULT *result, RESULT *arg1)
-{
-  double value=log(R2N(arg1));
-  SetResult(&result, R_NUMBER, &value); 
-}
-
-static void my_log (RESULT *result, RESULT *arg1)
-{
-  double value=log10(R2N(arg1));
-  SetResult(&result, R_NUMBER, &value); 
-}
-
-static void my_sin (RESULT *result, RESULT *arg1)
-{
-  double value=sin(R2N(arg1));
-  SetResult(&result, R_NUMBER, &value); 
-}
-
-static void my_cos (RESULT *result, RESULT *arg1)
-{
-  double value=cos(R2N(arg1));
-  SetResult(&result, R_NUMBER, &value); 
-}
-
-static void my_tan (RESULT *result, RESULT *arg1)
-{
-  double value=tan(R2N(arg1));
-  SetResult(&result, R_NUMBER, &value); 
-}
-
-
-static void my_min (RESULT *result, RESULT *arg1, RESULT *arg2)
-{
-  double a1=R2N(arg1);
-  double a2=R2N(arg2);
-  double value=a1<a2?a1:a2;
-  SetResult(&result, R_NUMBER, &value); 
-}
-
-static void my_max (RESULT *result, RESULT *arg1, RESULT *arg2)
-{
-  double a1=R2N(arg1);
-  double a2=R2N(arg2);
-  double value=a1>a2?a1:a2;
-  SetResult(&result, R_NUMBER, &value); 
-}
-
-
-static void my_strlen (RESULT *result, RESULT *arg1)
-{
-  double value=strlen(R2S(arg1));
-  SetResult(&result, R_NUMBER, &value); 
-}
-
-
-static void my_cfg (RESULT *result, RESULT *arg1)
-{
-  char *value=cfg_get(R2S(arg1), "");
-  SetResult(&result, R_STRING, value); 
-}
-
-
-int EX_init (void)
-{
-  // set some handy constants
-  AddConstant ("Pi", M_PI);
-  AddConstant ("e",  M_E);
-  
-  // register some basic math functions
-  AddFunction ("sqrt", 1, my_sqrt);
-  AddFunction ("exp",  1, my_exp);
-  AddFunction ("ln",   1, my_ln);
-  AddFunction ("log",  1, my_log);
-  AddFunction ("sin",  1, my_sin);
-  AddFunction ("cos",  1, my_cos);
-  AddFunction ("tan",  1, my_tan);
-  
-  // min, max
-  AddFunction ("min",  2, my_min);
-  AddFunction ("max",  2, my_max);
-
-  // register some basic string functions
-  AddFunction ("strlen", 1, my_strlen);
-
-  // config file access
-  AddFunction ("cfg", 1, my_cfg);
-
-  
-  return 0;
-}
-
-
-int EX_test(int argc, char* argv[])
-{
-  int ec;
-  char line[1024];
-  RESULT result = {0, 0.0, NULL};
-  
-  printf("\nEE> ");
-  for(gets(line); !feof(stdin); gets(line)) {
-    ec=Eval(line, &result);
-    if (result.type==R_NUMBER) {
-      printf ("%g\n", R2N(&result));
-    } else if (result.type==R_STRING) {
-      printf ("<%s>\n", R2S(&result));
-    }
-    printf("EE> ");
-  }
-
-  return 0;
-}
diff --git a/expression.h b/expression.h
deleted file mode 100644 (file)
index 07a53a2..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/* $Id: expression.h,v 1.1 2003/10/06 04:34:06 reinelt Exp $
- *
- * expression handling
- *
- * Copyright 2003 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: expression.h,v $
- * Revision 1.1  2003/10/06 04:34:06  reinelt
- * expression evaluator added
- *
- */
-
-
-#ifndef _EXPRESSION_H_
-#define _EXPRESSION_H_
-
-int EX_init (void);
-
-#endif
index a9be90ac7f7b69bc7f25afbd39cebce54e9cb74d..9af5a6a8f5f8db8c1d91b58f1864502dd689fc0a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: lcd4linux.c,v 1.48 2003/10/05 17:58:50 reinelt Exp $
+/* $Id: lcd4linux.c,v 1.49 2003/10/11 06:01:53 reinelt Exp $
  *
  * LCD4Linux
  *
  *
  *
  * $Log: lcd4linux.c,v $
+ * Revision 1.49  2003/10/11 06:01:53  reinelt
+ *
+ * renamed expression.{c,h} to client.{c,h}
+ * added config file client
+ * new functions 'AddNumericVariable()' and 'AddStringVariable()'
+ * new parameter '-i' for interactive mode
+ *
  * Revision 1.48  2003/10/05 17:58:50  reinelt
  * libtool junk; copyright messages cleaned up
  *
 #include "udelay.h"
 #include "display.h"
 #include "processor.h"
+#include "client.h"
 
 #define PIDFILE "/var/run/lcd4linux.pid"
 
@@ -257,6 +265,7 @@ static int got_signal=0;
 int tick, tack;
 extern char* output;
 
+
 static void usage(void)
 {
   printf ("%s\n", release);
@@ -265,9 +274,11 @@ static void usage(void)
 #ifdef USE_OLD_UDELAY
   printf ("       lcd4linux [-d]\n");
 #endif
+  printf ("       lcd4linux [-c key=value] [-i] [-f config-file] [-v]\n");
   printf ("       lcd4linux [-c key=value] [-F] [-f config-file] [-o output-file] [-q] [-v]\n");
 }
 
+
 int hello (void)
 {
   int i, x, y, flag;
@@ -304,6 +315,7 @@ int hello (void)
   return flag;
 }
 
+
 #ifdef USE_OLD_UDELAY
 void calibrate (void)
 {
@@ -322,18 +334,21 @@ void calibrate (void)
 }
 #endif
 
+
 void handler (int signal)
 {
   debug ("got signal %d", signal);
   got_signal=signal;
 }
 
+
 int main (int argc, char *argv[])
 {
   char *cfg="/etc/lcd4linux.conf";
   char *driver;
   int c;
   int quiet=0;
+  int interactive=0;
   
   // save arguments for restart
   my_argv=malloc(sizeof(char*)*(argc+1));
@@ -344,11 +359,11 @@ int main (int argc, char *argv[])
 
   running_foreground=0;
   running_background=0;
-
+  
 #ifdef USE_OLD_UDELAY
-  while ((c=getopt (argc, argv, "c:dFf:hlo:qv"))!=EOF) {
+  while ((c=getopt (argc, argv, "c:dFf:hilo:qv"))!=EOF) {
 #else
-  while ((c=getopt (argc, argv, "c:dFf:hlo:qv"))!=EOF) {
+  while ((c=getopt (argc, argv, "c:dFf:hilo:qv"))!=EOF) {
 #endif
     switch (c) {
     case 'c':
@@ -374,6 +389,9 @@ int main (int argc, char *argv[])
     case 'h':
       usage();
       exit(0);
+    case 'i':
+      interactive++;
+      break;
     case 'l':
       printf ("%s\n", release);
       lcd_list();
@@ -397,17 +415,21 @@ int main (int argc, char *argv[])
     exit(2);
   }
 
+  // do not fork in interactive mode
+  if (interactive) {
+    running_foreground=1;
+  }
+
   info ("Version " VERSION " starting");
   if (!running_foreground && (my_argv[0]==NULL || my_argv[0][0]!='/')) {
     info ("invoked without full path; restart may not work!");
   }
   
-  if (cfg_init (cfg)==-1)
+  if (client_init()==-1)
     exit (1);
   
-  // Fixme:
-  EX_init();
-  EX_test();
+  if (cfg_init(cfg)==-1)
+    exit (1);
   
   driver=cfg_get("display",NULL);
   if (driver==NULL || *driver=='\0') {
@@ -479,10 +501,31 @@ int main (int argc, char *argv[])
   signal(SIGQUIT, handler);
   signal(SIGTERM, handler);
   
-
   // process_init sets global vars tick, tack
   process_init();
-  lcd_clear(1);
+
+  // maybe go into interactive mode
+  if (interactive) {
+    char line[1024];
+    RESULT result = {0, 0.0, NULL};
+    
+    printf("\neval> ");
+    for(fgets(line, 1024, stdin); !feof(stdin); fgets(line, 1024, stdin)) {
+      if (line[strlen(line)-1]=='\n') line[strlen(line)-1]='\0';
+      Eval(line, &result);
+      if (result.type==R_NUMBER) {
+       printf ("%g\n", R2N(&result));
+      } else if (result.type==R_STRING) {
+       printf ("'%s'\n", R2S(&result));
+      }
+      printf("eval> ");
+    }
+    printf ("\n");
+    lcd_clear(1);
+    lcd_quit();
+    pid_exit(PIDFILE);
+    exit (0);
+  }
   
   if (!quiet && hello()) {
     sleep (3);