From f2b964cb65e88fb238df3b562e8edfb0b9243489 Mon Sep 17 00:00:00 2001 From: reinelt Date: Sun, 19 Feb 2006 15:42:19 +0000 Subject: [lcd4linux @ 2006-02-19 15:42:18 by reinelt] file plugin from Chris Maj git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@640 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- Makefile.am | 1 + Makefile.in | 25 ++++++------- config.h.in | 3 ++ configure | 12 +++++++ plugin.c | 13 ++++++- plugin_file.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins.m4 | 8 +++++ 7 files changed, 162 insertions(+), 13 deletions(-) create mode 100644 plugin_file.c diff --git a/Makefile.am b/Makefile.am index dc86bb0..32ec063 100644 --- a/Makefile.am +++ b/Makefile.am @@ -93,6 +93,7 @@ plugin_cpuinfo.c \ plugin_diskstats.c \ plugin_dvb.c \ plugin_exec.c \ +plugin_file.c \ plugin_i2c_sensors.c \ plugin_imon.c \ plugin_isdn.c \ diff --git a/Makefile.in b/Makefile.in index a24c831..0922e78 100644 --- a/Makefile.in +++ b/Makefile.in @@ -104,7 +104,7 @@ lcd4linux_DEPENDENCIES = @DRIVERS@ @PLUGINS@ lcd4linux_SOURCES = lcd4linux.c cfg.c cfg.h debug.c debug.h drv.c drv.h evaluator.c evaluator.h hash.c hash.h layout.c layout.h pid.c pid.h timer.c timer.h thread.c thread.h udelay.c udelay.h qprintf.c qprintf.h rgb.c rgb.h widget.c widget.h widget_text.c widget_text.h widget_bar.c widget_bar.h widget_icon.c widget_icon.h widget_image.c widget_image.h widget_timer.c widget_timer.h widget_gpo.c widget_gpo.h plugin.c plugin.h plugin_cfg.c plugin_math.c plugin_string.c plugin_test.c plugin_time.c -EXTRA_lcd4linux_SOURCES = drv_generic_text.c drv_generic_text.h drv_generic_graphic.c drv_generic_graphic.h drv_generic_gpio.c drv_generic_gpio.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h drv_generic_i2c.c drv_generic_i2c.h drv_BeckmannEgle.c drv_BWCT.c drv_Crystalfontz.c drv_Curses.c drv_Cwlinux.c drv_G15.c drv_HD44780.c drv_Image.c drv_LCD2USB.c drv_LCDLinux.c drv_LCDTerm.c drv_LPH7508.c drv_LUIse.c drv_M50530.c drv_MatrixOrbital.c drv_MilfordInstruments.c drv_Noritake.c drv_NULL.c drv_RouterBoard.c drv_Sample.c drv_serdisplib.c drv_SimpleLCD.c drv_T6963.c drv_Trefon.c drv_USBLCD.c drv_WincorNixdorf.c drv_X11.c font_6x8.h lcd4linux_i2c.h plugin_apm.c plugin_cpuinfo.c plugin_diskstats.c plugin_dvb.c plugin_exec.c plugin_i2c_sensors.c plugin_imon.c plugin_isdn.c plugin_loadavg.c plugin_meminfo.c plugin_mysql.c plugin_netdev.c plugin_pop3.c plugin_ppp.c plugin_proc_stat.c plugin_python.c plugin_sample.c plugin_seti.c plugin_statfs.c plugin_uname.c plugin_uptime.c plugin_wireless.c plugin_xmms.c +EXTRA_lcd4linux_SOURCES = drv_generic_text.c drv_generic_text.h drv_generic_graphic.c drv_generic_graphic.h drv_generic_gpio.c drv_generic_gpio.h drv_generic_serial.c drv_generic_serial.h drv_generic_parport.c drv_generic_parport.h drv_generic_i2c.c drv_generic_i2c.h drv_BeckmannEgle.c drv_BWCT.c drv_Crystalfontz.c drv_Curses.c drv_Cwlinux.c drv_G15.c drv_HD44780.c drv_Image.c drv_LCD2USB.c drv_LCDLinux.c drv_LCDTerm.c drv_LPH7508.c drv_LUIse.c drv_M50530.c drv_MatrixOrbital.c drv_MilfordInstruments.c drv_Noritake.c drv_NULL.c drv_RouterBoard.c drv_Sample.c drv_serdisplib.c drv_SimpleLCD.c drv_T6963.c drv_Trefon.c drv_USBLCD.c drv_WincorNixdorf.c drv_X11.c font_6x8.h lcd4linux_i2c.h plugin_apm.c plugin_cpuinfo.c plugin_diskstats.c plugin_dvb.c plugin_exec.c plugin_file.c plugin_i2c_sensors.c plugin_imon.c plugin_isdn.c plugin_loadavg.c plugin_meminfo.c plugin_mysql.c plugin_netdev.c plugin_pop3.c plugin_ppp.c plugin_proc_stat.c plugin_python.c plugin_sample.c plugin_seti.c plugin_statfs.c plugin_uname.c plugin_uptime.c plugin_wireless.c plugin_xmms.c EXTRA_DIST = lcd4linux.conf.sample lcd4kde.conf lcd4linux.kdelnk lcd4linux.xpm lcd4linux.lsm curses.m4 AUTHORS CREDITS FAQ NEWS TODO README README.Drivers README.Plugins README.KDE plugin_sample.c @@ -158,17 +158,18 @@ DEP_FILES = .deps/cfg.P .deps/debug.P .deps/drv.P .deps/drv_BWCT.P \ .deps/hash.P .deps/layout.P .deps/lcd4linux.P .deps/pid.P \ .deps/plugin.P .deps/plugin_apm.P .deps/plugin_cfg.P \ .deps/plugin_cpuinfo.P .deps/plugin_diskstats.P .deps/plugin_dvb.P \ -.deps/plugin_exec.P .deps/plugin_i2c_sensors.P .deps/plugin_imon.P \ -.deps/plugin_isdn.P .deps/plugin_loadavg.P .deps/plugin_math.P \ -.deps/plugin_meminfo.P .deps/plugin_mysql.P .deps/plugin_netdev.P \ -.deps/plugin_pop3.P .deps/plugin_ppp.P .deps/plugin_proc_stat.P \ -.deps/plugin_python.P .deps/plugin_sample.P .deps/plugin_seti.P \ -.deps/plugin_statfs.P .deps/plugin_string.P .deps/plugin_test.P \ -.deps/plugin_time.P .deps/plugin_uname.P .deps/plugin_uptime.P \ -.deps/plugin_wireless.P .deps/plugin_xmms.P .deps/qprintf.P .deps/rgb.P \ -.deps/thread.P .deps/timer.P .deps/udelay.P .deps/widget.P \ -.deps/widget_bar.P .deps/widget_gpo.P .deps/widget_icon.P \ -.deps/widget_image.P .deps/widget_text.P .deps/widget_timer.P +.deps/plugin_exec.P .deps/plugin_file.P .deps/plugin_i2c_sensors.P \ +.deps/plugin_imon.P .deps/plugin_isdn.P .deps/plugin_loadavg.P \ +.deps/plugin_math.P .deps/plugin_meminfo.P .deps/plugin_mysql.P \ +.deps/plugin_netdev.P .deps/plugin_pop3.P .deps/plugin_ppp.P \ +.deps/plugin_proc_stat.P .deps/plugin_python.P .deps/plugin_sample.P \ +.deps/plugin_seti.P .deps/plugin_statfs.P .deps/plugin_string.P \ +.deps/plugin_test.P .deps/plugin_time.P .deps/plugin_uname.P \ +.deps/plugin_uptime.P .deps/plugin_wireless.P .deps/plugin_xmms.P \ +.deps/qprintf.P .deps/rgb.P .deps/thread.P .deps/timer.P .deps/udelay.P \ +.deps/widget.P .deps/widget_bar.P .deps/widget_gpo.P \ +.deps/widget_icon.P .deps/widget_image.P .deps/widget_text.P \ +.deps/widget_timer.P SOURCES = $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES) OBJECTS = $(lcd4linux_OBJECTS) diff --git a/config.h.in b/config.h.in index d8a48e7..c2c36c3 100644 --- a/config.h.in +++ b/config.h.in @@ -266,6 +266,9 @@ /* exec plugin */ #undef PLUGIN_EXEC +/* file plugin */ +#undef PLUGIN_FILE + /* i2c sensors plugin */ #undef PLUGIN_I2C_SENSORS diff --git a/configure b/configure index 24a0305..e91a58a 100755 --- a/configure +++ b/configure @@ -6793,6 +6793,7 @@ echo "$as_me: error: run ./configure --with-plugins=..." >&2;} PLUGIN_DISKSTATS="yes" PLUGIN_DVB="yes" PLUGIN_EXEC="yes" + PLUGIN_FILE="yes" PLUGIN_I2C_SENSORS="yes" PLUGIN_IMON="yes" PLUGIN_ISDN="yes" @@ -6827,6 +6828,9 @@ echo "$as_me: error: run ./configure --with-plugins=..." >&2;} exec) PLUGIN_EXEC=$val ;; + file) + PLUGIN_FILE=$val + ;; i2c_sensors) PLUGIN_I2C_SENSORS=$val ;; @@ -7086,6 +7090,14 @@ cat >>confdefs.h <<\_ACEOF #define PLUGIN_EXEC 1 _ACEOF +fi +if test "$PLUGIN_FILE" = "yes"; then + PLUGINS="$PLUGINS plugin_file.o" + +cat >>confdefs.h <<\_ACEOF +#define PLUGIN_FILE 1 +_ACEOF + fi if test "$PLUGIN_I2C_SENSORS" = "yes"; then PLUGINS="$PLUGINS plugin_i2c_sensors.o" diff --git a/plugin.c b/plugin.c index 961b1fa..b68ede1 100644 --- a/plugin.c +++ b/plugin.c @@ -1,4 +1,4 @@ -/* $Id: plugin.c,v 1.39 2005/11/04 04:53:10 reinelt Exp $ +/* $Id: plugin.c,v 1.40 2006/02/19 15:42:19 reinelt Exp $ * * plugin handler for the Evaluator * @@ -23,6 +23,9 @@ * * * $Log: plugin.c,v $ + * Revision 1.40 2006/02/19 15:42:19 reinelt + * file plugin from Chris Maj + * * Revision 1.39 2005/11/04 04:53:10 reinelt * sample plugin activated * @@ -227,6 +230,8 @@ int plugin_init_dvb(void); void plugin_exit_dvb(void); int plugin_init_exec(void); void plugin_exit_exec(void); +int plugin_init_file(void); +void plugin_exit_file(void); int plugin_init_i2c_sensors(void); void plugin_exit_i2c_sensors(void); int plugin_init_imon(void); @@ -288,6 +293,9 @@ int plugin_init(void) #ifdef PLUGIN_EXEC plugin_init_exec(); #endif +#ifdef PLUGIN_FILE + plugin_init_file(); +#endif #ifdef PLUGIN_I2C_SENSORS plugin_init_i2c_sensors(); #endif @@ -364,6 +372,9 @@ void plugin_exit(void) #ifdef PLUGIN_EXEC plugin_exit_exec(); #endif +#ifdef PLUGIN_FILE + plugin_exit_file(); +#endif #ifdef PLUGIN_I2C_SENSORS plugin_exit_i2c_sensors(); #endif diff --git a/plugin_file.c b/plugin_file.c new file mode 100644 index 0000000..24ac815 --- /dev/null +++ b/plugin_file.c @@ -0,0 +1,113 @@ +/* $Id: plugin_file.c,v 1.1 2006/02/19 15:42:19 reinelt Exp $ + * + * plugin to perform simple file operations + * + * Copyright (C) 2006 Chris Maj + * Copyright (C) 2006 The LCD4Linux Team + * + * 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: plugin_file.c,v $ + * Revision 1.1 2006/02/19 15:42:19 reinelt + * file plugin from Chris Maj + * + */ + +/* + * exported functions: + * + * int plugin_init_file (void) + * adds various functions + * + */ + + +/* define the include files you need */ +#include "config.h" + +#include +#include + +/* these should always be included */ +#include "debug.h" +#include "plugin.h" + +#ifdef WITH_DMALLOC +#include +#endif + + +/* function 'readline' */ +/* takes two arguments, file name and line number */ +/* returns text of that line */ + +static void my_readline(RESULT * result, RESULT * arg1, RESULT * arg2) +{ + char value[80], val2[80]; + char *pos; + FILE *fp; + int reqline, i, size; + + reqline = R2N(arg2); + fp = fopen(R2S(arg1), "r"); + if (!fp) { + error("readline couldn't open file '%s'", R2S(arg1)); + } else { + i = 0; + while (!feof(fp) && i < reqline) { + fgets(val2, sizeof(val2), fp); + size = strcspn(val2, "\n"); + strncpy(value, val2, size); + value[size] = '\0'; + pos = strchr(val2, '\n'); + /* more than 80 chars, chew up rest of line */ + while (!pos) { + fgets(val2, sizeof(val2), fp); + pos = strchr(val2, '\n'); + } + i++; + } + fclose(fp); + if (i < reqline) { + error("readline requested line %d but file only had %d lines", reqline, i); + value[0] = '\0'; + } + } + + /* store result */ + SetResult(&result, R_STRING, &value); +} + +/* plugin initialization */ +/* MUST NOT be declared 'static'! */ +int plugin_init_file(void) +{ + + /* register all our cool functions */ + /* the second parameter is the number of arguments */ + /* -1 stands for variable argument list */ + AddFunction("file::readline", 2, my_readline); + + return 0; +} + +void plugin_exit_file(void) +{ + /* free any allocated memory */ + /* close filedescriptors */ +} diff --git a/plugins.m4 b/plugins.m4 index 3d5dc7a..65f641b 100644 --- a/plugins.m4 +++ b/plugins.m4 @@ -54,6 +54,7 @@ for plugin in $plugins; do PLUGIN_DISKSTATS="yes" PLUGIN_DVB="yes" PLUGIN_EXEC="yes" + PLUGIN_FILE="yes" PLUGIN_I2C_SENSORS="yes" PLUGIN_IMON="yes" PLUGIN_ISDN="yes" @@ -88,6 +89,9 @@ for plugin in $plugins; do exec) PLUGIN_EXEC=$val ;; + file) + PLUGIN_FILE=$val + ;; i2c_sensors) PLUGIN_I2C_SENSORS=$val ;; @@ -174,6 +178,10 @@ if test "$PLUGIN_EXEC" = "yes"; then PLUGINS="$PLUGINS plugin_exec.o" AC_DEFINE(PLUGIN_EXEC,1,[exec plugin]) fi +if test "$PLUGIN_FILE" = "yes"; then + PLUGINS="$PLUGINS plugin_file.o" + AC_DEFINE(PLUGIN_FILE,1,[file plugin]) +fi if test "$PLUGIN_I2C_SENSORS" = "yes"; then PLUGINS="$PLUGINS plugin_i2c_sensors.o" AC_DEFINE(PLUGIN_I2C_SENSORS,1,[i2c sensors plugin]) -- cgit v1.2.3