/* $Id: plugin_cfg.c 840 2007-09-09 12:17:42Z michael $ * $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/plugin_cfg.c $ * * plugin for config file access * * Copyright (C) 2003, 2004 Michael Reinelt * Copyright (C) 2004 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. * */ /* * exported functions: * * int plugin_init_cfg (void) * adds cfg() function for config access * initializes variables from the config file * */ #include "config.h" #include #include #include #include "debug.h" #include "evaluator.h" #include "plugin.h" #include "cfg.h" #ifdef WITH_DMALLOC #include #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 */ } class='insertions'>+1 2010-03-16update debian/changelogReinhard Tartler1-0/+6 2010-03-16rerun autoreconfReinhard Tartler9-8343/+5554 2010-03-16make configure.in reference the now renamed ax_python_devel.m4Reinhard Tartler1-1/+1 2010-03-16disable switch --disable-mpd, it is not recognized anywaysReinhard Tartler1-1/+0 2010-03-16don't include LOCALMODLIBS for linking. it was empty for python 2.5, and are ...Reinhard Tartler1-1/+1 2010-03-16update ac_python_devel.m4 from upstream, has been renamed now to ax_python_develReinhard Tartler1-3/+8 2010-02-28fix typo, don't disable python supportReinhard Tartler1-1/+1 2010-02-28Allow user control over lcd4linux args, Reinhard Tartler2-1/+6 2010-02-28clarify copyright notice, reported by lintianReinhard Tartler1-1/+1 2010-02-28bump standards version to 3.8.4.Reinhard Tartler2-2/+3 2010-02-28bump debhelper compat level to 7Reinhard Tartler3-3/+4 2010-02-28disable mpd plugin. According to bugreports, it makes lcd4linuxReinhard Tartler3-3/+6 2010-02-28prefer multiline dependsReinhard Tartler1-1/+9 2010-02-28update config.guess && config.sub, Closes: #542077Reinhard Tartler3-405/+624 2010-02-28update ac_python_devel.m4 from autoconf-archive package. This allowsReinhard Tartler2-66/+199 2010-02-28Add $remote-fs dependencies to init script. Reported by lintian.Reinhard Tartler2-2/+8 2008-01-10oops. fix version numberReinhard Tartler1-1/+1 2008-01-10* add Vcs-Bzr and Homepage header.Reinhard Tartler2-1/+4 2008-01-10* bump to standards version 3.7.3 (no changes needed)Reinhard Tartler2-2/+3 2008-01-10new upload to unstableReinhard Tartler1-0/+9 2008-01-10import commit 809 from trunk to fix http://bugs.debian.org/cgi-bin/bugreport....Reinhard Tartler4-255/+12 2007-04-05missing depends in LSB init stanzaReinhard Tartler1-0/+2 2007-04-05* new upstream tarball no longer contains a debian/ directory at allReinhard Tartler1-1/+3 2007-04-30new upstream versionReinhard Tartler63-4596/+7100 2007-04-05* add LSB keyword sectionReinhard Tartler2-1/+12 2007-04-05mark new upload in debian/changelogReinhard Tartler1-0/+6 2007-04-05import new upstreamReinhard Tartler162-10578/+5766 2007-04-05improvements to the manpageReinhard Tartler1-2/+6 2006-08-27update config.guess and .subReinhard Tartler2-350/+450 2006-08-27install new manpageReinhard Tartler2-2/+3