aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_cfg.c
blob: e3fa895304a88f9ed3c482d584def61d39de692e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* $Id$
 * $URL$
 *
 * plugin for config file access
 *
 * Copyright (C) 2003, 2004 Michael Reinelt <michael@reinelt.co.at>
 * Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
 *
 * 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.
 *
 */

/* 
 * exported functions:
 *
 * int plugin_init_cfg (void)
 *  adds cfg() function for config access
 *  initializes variables from the config file
 *
 */


#include "config.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "debug.h"
#include "evaluator.h"
#include "plugin.h"
#include "cfg.h"

#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif


static void load_variables(void)
{
    char *section = "Variables";
    char *list, *l, *p;
    char *expression;
    void *tree;
    RESULT result = { 0, 0, 0, NULL };

    list = cfg_list(section);
    l = list;
    while (l != NULL) {
	while (*l == '|')
	    l++;
	if ((p = strchr(l, '|')) != NULL)
	    *p = '\0';
	if (strchr(l, '.') != NULL || strchr(l, ':') != 0) {
	    error("ignoring variable '%s' from %s: structures not allowed", l, cfg_source());
	} else {
	    expression = cfg_get_raw(section, l, "");
	    if (expression != NULL && *expression != '\0') {
		tree = NULL;
		if (Compile(expression, &tree) == 0 && Eval(tree, &result) == 0) {
		    SetVariable(l, &result);
		    debug("Variable %s = '%s' (%g)", l, R2S(&result), R2N(&result));
		    DelResult(&result);
		} else {
		    error("error evaluating variable '%s' from %s", list, cfg_source());
		}
		DelTree(tree);
	    }
	}
	l = p ? p + 1 : NULL;
    }
    free(list);

}


static void my_cfg(RESULT * result, const int argc, RESULT * argv[])
{
    int i, len;
    char *value;
    char *buffer;

    /* calculate key length */
    len = 0;
    for (i = 0; i < argc; i++) {
	len += strlen(R2S(argv[i])) + 1;
    }

    /* allocate key buffer */
    buffer = malloc(len + 1);

    /* prepare key buffer */
    *buffer = '\0';
    for (i = 0; i < argc; i++) {
	strcat(buffer, ".");
	strcat(buffer, R2S(argv[i]));
    }

    /* buffer starts with '.', so cut off first char */
    value = cfg_get("", buffer + 1, "");

    /* store result */
    SetResult(&result, R_STRING, value);

    /* free buffer again */
    free(buffer);

    free(value);
}


int plugin_init_cfg(void)
{
    /* load "Variables" section from cfg */
    load_variables();

    /* register plugin */
    AddFunction("cfg", -1, my_cfg);

    return 0;
}

void plugin_exit_cfg(void)
{
    /* empty */
}
0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* config.h.in.  Generated from configure.in by autoheader.  */

/* Define to 1 if the `closedir' function returns void instead of `int'. */
#undef CLOSEDIR_VOID

/* Found some version of curses that we're going to use */
#undef HAS_CURSES

/* Define to 1 if you have the <arpa/inet.h> header file. */
#undef HAVE_ARPA_INET_H

/* Define to 1 if you have the <asm/io.h> header file. */
#undef HAVE_ASM_IO_H

/* Define to 1 if you have the <asm/types.h> header file. */
#undef HAVE_ASM_TYPES_H

/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
   */
#undef HAVE_DIRENT_H

/* Define to 1 if you have the `dup2' function. */
#undef HAVE_DUP2

/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H

/* Define to 1 if you have the `floor' function. */
#undef HAVE_FLOOR

/* Define to 1 if you have the `fork' function. */
#undef HAVE_FORK

/* Define to 1 if you have the <ftdi.h> header file. */
#undef HAVE_FTDI_H

/* Define to 1 if you have the <gd/gd.h> header file. */
#undef HAVE_GD_GD_H

/* Define to 1 if you have the <gd.h> header file. */
#undef HAVE_GD_H

/* Define to 1 if you have the `gethostbyname' function. */
#undef HAVE_GETHOSTBYNAME

/* Define to 1 if you have the `gettimeofday' function. */
#undef HAVE_GETTIMEOFDAY

/* Define if you have the iconv() function and it works. */
#undef HAVE_ICONV

/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H

/* Define to 1 if you have the `m' library (-lm). */
#undef HAVE_LIBM

/* Define to 1 if you have the <linux/dvb/frontend.h> header file. */
#undef HAVE_LINUX_DVB_FRONTEND_H

/* Define to 1 if you have the <linux/errno.h> header file. */
#undef HAVE_LINUX_ERRNO_H

/* Define to 1 if you have the <linux/hd44780.h> header file. */
#undef HAVE_LINUX_HD44780_H

/* Define to 1 if you have the <linux/isdn.h> header file. */
#undef HAVE_LINUX_ISDN_H

/* Define to 1 if you have the <linux/lcd-linux.h> header file. */
#undef HAVE_LINUX_LCD_LINUX_H

/* Define to 1 if you have the <linux/parport.h> header file. */
#undef HAVE_LINUX_PARPORT_H

/* Define to 1 if you have the <linux/ppdev.h> header file. */
#undef HAVE_LINUX_PPDEV_H

/* Define to 1 if you have the <linux/wireless.h> header file. */
#undef HAVE_LINUX_WIRELESS_H

/* Define to 1 if you have the <luise.h> header file. */
#undef HAVE_LUISE_H

/* Define to 1 if you have the `memmove' function. */
#undef HAVE_MEMMOVE

/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H

/* Define to 1 if you have the `memset' function. */
#undef HAVE_MEMSET

/* Define to 1 if you have the <mysql/mysql.h> header file. */
#undef HAVE_MYSQL_MYSQL_H

/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#undef HAVE_NDIR_H

/* Define to 1 if you have the <netdb.h> header file. */
#undef HAVE_NETDB_H

/* Define to 1 if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H

/* Define to 1 if you have the <net/if_ppp.h> header file. */
#undef HAVE_NET_IF_PPP_H

/* Define to 1 if you have the <nmeap.h> header file. */
#undef HAVE_NMEAP_H

/* Define to 1 if you have the `pow' function. */
#undef HAVE_POW

/* Define to 1 if you have the `putenv' function. */
#undef HAVE_PUTENV

/* Define to 1 if you have the `regcomp' function. */
#undef HAVE_REGCOMP

/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT

/* Define to 1 if you have the <serdisplib/serdisp.h> header file. */
#undef HAVE_SERDISPLIB_SERDISP_H

/* Define to 1 if you have the `socket' function. */
#undef HAVE_SOCKET

/* Define to 1 if you have the `sqrt' function. */
#undef HAVE_SQRT

/* Define to 1 if you have the <st2205.h> header file. */
#undef HAVE_ST2205_H

/* Define to 1 if `stat' has the bug that it succeeds when given the
   zero-length file name argument. */
#undef HAVE_STAT_EMPTY_STRING_BUG

/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H

/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H

/* Define to 1 if you have the `strcasecmp' function. */
#undef HAVE_STRCASECMP

/* Define to 1 if you have the `strchr' function. */
#undef HAVE_STRCHR

/* Define to 1 if you have the `strcspn' function. */
#undef HAVE_STRCSPN

/* Define to 1 if you have the `strdup' function. */
#undef HAVE_STRDUP

/* Define to 1 if you have the `strerror' function. */
#undef HAVE_STRERROR

/* Define to 1 if you have the `strftime' function. */
#undef HAVE_STRFTIME

/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H

/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H

/* Define to 1 if you have the `strncasecmp' function. */
#undef HAVE_STRNCASECMP

/* Define to 1 if you have the `strndup' function. */
#undef HAVE_STRNDUP

/* Define to 1 if you have the `strpbrk' function. */
#undef HAVE_STRPBRK

/* Define to 1 if you have the `strrchr' function. */
#undef HAVE_STRRCHR

/* Define to 1 if you have the `strstr' function. */
#undef HAVE_STRSTR

/* Define to 1 if you have the `strtol' function. */
#undef HAVE_STRTOL

/* Define to 1 if you have the `strtoul' function. */
#undef HAVE_STRTOUL

/* Define to 1 if you have the <syslog.h> header file. */
#undef HAVE_SYSLOG_H

/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
   */
#undef HAVE_SYS_DIR_H

/* Define to 1 if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H

/* Define to 1 if you have the <sys/io.h> header file. */
#undef HAVE_SYS_IO_H

/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
   */
#undef HAVE_SYS_NDIR_H

/* Define to 1 if you have the <sys/select.h> header file. */
#undef HAVE_SYS_SELECT_H

/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H

/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H

/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H

/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H

/* Define to 1 if you have the <sys/vfs.h> header file. */
#undef HAVE_SYS_VFS_H

/* Define to 1 if you have the <termios.h> header file. */
#undef HAVE_TERMIOS_H

/* Define to 1 if you have the `uname' function. */
#undef HAVE_UNAME

/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H

/* Define to 1 if you have the <usb.h> header file. */
#undef HAVE_USB_H

/* Define to 1 if you have the `vfork' function. */
#undef HAVE_VFORK

/* Define to 1 if you have the <vfork.h> header file. */
#undef HAVE_VFORK_H

/* Define to 1 if `fork' works. */
#undef HAVE_WORKING_FORK

/* Define to 1 if `vfork' works. */
#undef HAVE_WORKING_VFORK

/* Define to 1 if you have the <X11/Xlib.h> header file. */
#undef HAVE_X11_XLIB_H

/* Define to 1 if you have the <X11/Xutil.h> header file. */
#undef HAVE_X11_XUTIL_H

/* Define as const if the declaration of iconv() needs const. */
#undef ICONV_CONST

/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
   slash. */
#undef LSTAT_FOLLOWS_SLASHED_SYMLINK

/* Set to reflect version of ncurses */
#undef NCURSES_970530

/* If you Curses does not have color define this one */
#undef NO_COLOR_CURSES

/* Name of package */
#undef PACKAGE

/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT

/* Define to the full name of this package. */
#undef PACKAGE_NAME

/* Define to the full name and version of this package. */
#undef PACKAGE_STRING

/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME

/* Define to the version of this package. */
#undef PACKAGE_VERSION

/* apm plugin */
#undef PLUGIN_APM

/* asterisk plugin */
#undef PLUGIN_ASTERISK

/* button_exec plugin */
#undef PLUGIN_BUTTON_EXEC

/* cpuinfo plugin */
#undef PLUGIN_CPUINFO

/* diskstats plugin */
#undef PLUGIN_DISKSTATS

/* dvb plugin */
#undef PLUGIN_DVB

/* exec plugin */
#undef PLUGIN_EXEC

/* fifo plugin */
#undef PLUGIN_FIFO

/* file plugin */
#undef PLUGIN_FILE

/* gps plugin */
#undef PLUGIN_GPS

/* hddtemp plugin */
#undef PLUGIN_HDDTEMP

/* i2c sensors plugin */
#undef PLUGIN_I2C_SENSORS

/* iconv charset converter plugin */
#undef PLUGIN_ICONV

/* imon plugin */
#undef PLUGIN_IMON

/* ISDN plugin */
#undef PLUGIN_ISDN

/* kvv plugin */
#undef PLUGIN_KVV

/* loadavg plugin */
#undef PLUGIN_LOADAVG

/* meminfo plugin */
#undef PLUGIN_MEMINFO

/* mpd plugin */
#undef PLUGIN_MPD

/* mysql plugin */
#undef PLUGIN_MYSQL

/* netdev plugin */
#undef PLUGIN_NETDEV

/* netinfo plugin */
#undef PLUGIN_NETINFO

/* POP3 plugin */
#undef PLUGIN_POP3

/* ppp plugin */
#undef PLUGIN_PPP

/* proc_stat plugin */
#undef PLUGIN_PROC_STAT

/* python plugin */
#undef PLUGIN_PYTHON

/* sample plugin */
#undef PLUGIN_SAMPLE

/* seti plugin */
#undef PLUGIN_SETI

/* statfs plugin */
#undef PLUGIN_STATFS

/* uname plugin */
#undef PLUGIN_UNAME

/* uptime plugin */
#undef PLUGIN_UPTIME

/* w1retap plugin */
#undef PLUGIN_W1RETAP

/* wireless plugin */
#undef PLUGIN_WIRELESS

/* xmms plugin */
#undef PLUGIN_XMMS

/* Define as the return type of signal handlers (`int' or `void'). */
#undef RETSIGTYPE

/* Define if you want to turn on SCO-specific code */
#undef SCO_FLAVOR

/* Define to the type of arg 1 for `select'. */
#undef SELECT_TYPE_ARG1

/* Define to the type of args 2, 3 and 4 for `select'. */
#undef SELECT_TYPE_ARG234

/* Define to the type of arg 5 for `select'. */
#undef SELECT_TYPE_ARG5

/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS

/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME

/* Use Ncurses? */
#undef USE_NCURSES

/* Use SunOS SysV curses? */
#undef USE_SUNOS_CURSES

/* Use SystemV curses? */
#undef USE_SYSV_CURSES

/* Version number of package */
#undef VERSION

/* Beckmann&Egle driver */
#undef WITH_BECKMANNEGLE

/* BWCT driver */
#undef WITH_BWCT

/* Crystalfontz driver */
#undef WITH_CRYSTALFONTZ

/* Curses driver */
#undef WITH_CURSES

/* CwLinux driver */
#undef WITH_CWLINUX

/* D4D driver */
#undef WITH_D4D

/* Define if using the dmalloc debugging malloc package */
#undef WITH_DMALLOC

/* Electronic Assembly RS232 graphic driver */
#undef WITH_EA232graphic

/* G-15 driver */
#undef WITH_G15

/* GD library */
#undef WITH_GD

/* HD44780 driver */
#undef WITH_HD44780

/* I2C bus driver */
#undef WITH_I2C

/* image widget */
#undef WITH_IMAGE

/* IRLCD driver */
#undef WITH_IRLCD

/* LCD2USB driver */
#undef WITH_LCD2USB

/* LCD-Linux driver */
#undef WITH_LCDLINUX

/* LCDTerm driver */
#undef WITH_LCDTERM

/* LEDMatrix driver */
#undef WITH_LEDMATRIX

/* LPH7508 driver */
#undef WITH_LPH7508

/* LUIse driver */
#undef WITH_LUISE

/* M50530 driver */
#undef WITH_M50530

/* MatrixOrbital driver */
#undef WITH_MATRIXORBITAL

/* Milford Instruments driver */
#undef WITH_MILINST

/* Noritake driver */
#undef WITH_NORITAKE

/* NULL driver */
#undef WITH_NULL

/* parport bus driver */
#undef WITH_PARPORT

/* Pertelian driver */
#undef WITH_PERTELIAN

/* PHAnderson driver */
#undef WITH_PHANDERSON

/* picoLCD driver */
#undef WITH_PICOLCD

/* picoLCDGraphic driver */
#undef WITH_PICOLCDGRAPHIC

/* PNG driver */
#undef WITH_PNG

/* PPM driver */
#undef WITH_PPM

/* RouterBoard driver */
#undef WITH_ROUTERBOARD

/* Sample driver */
#undef WITH_SAMPLE

/* serdisplib driver */
#undef WITH_SERDISPLIB

/* serial bus driver */
#undef WITH_SERIAL

/* SimpleLCD driver */
#undef WITH_SIMPLELCD

/* st2205 driver */
#undef WITH_ST2205

/* T6963 driver */
#undef WITH_T6963

/* TREFON driver */
#undef WITH_TREFON

/* ULA200 driver */
#undef WITH_ULA200

/* USBHUB driver */
#undef WITH_USBHUB

/* USBLCD driver */
#undef WITH_USBLCD

/* WincorNixdorf driver */
#undef WITH_WINCORNIXDORF

/* X11 driver */
#undef WITH_X11

/* Define to 1 if the X Window System is missing or not being used. */
#undef X_DISPLAY_MISSING

/* Define to empty if `const' does not conform to ANSI C. */
#undef const

/* Define to `int' if <sys/types.h> doesn't define. */
#undef gid_t

/* Define to `__inline__' or `__inline' if that's what the C compiler
   calls it, or to nothing if 'inline' is not supported under any name.  */
#ifndef __cplusplus
#undef inline
#endif

/* Define to `long int' if <sys/types.h> does not define. */
#undef off_t

/* Define to `int' if <sys/types.h> does not define. */
#undef pid_t

/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t

/* Define to `int' if <sys/types.h> does not define. */
#undef ssize_t

/* Define to `int' if <sys/types.h> doesn't define. */
#undef uid_t

/* Define as `fork' if `vfork' does not work. */
#undef vfork