aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_cfg.c
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2005-05-08 04:32:45 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2005-05-08 04:32:45 +0000
commitdbf5d92605a9db10e3e3cb154d03a515c5d5c5af (patch)
tree501d5dda3ce90fe924b893e487d9ef9f0683382b /plugin_cfg.c
parenta1c471e9fb7cadb68bb182ab2e9715a0aa092386 (diff)
downloadlcd4linux-dbf5d92605a9db10e3e3cb154d03a515c5d5c5af.tar.gz
[lcd4linux @ 2005-05-08 04:32:43 by reinelt]
CodingStyle added and applied git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@547 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to 'plugin_cfg.c')
-rw-r--r--plugin_cfg.c149
1 files changed, 77 insertions, 72 deletions
diff --git a/plugin_cfg.c b/plugin_cfg.c
index 2996045..323c04d 100644
--- a/plugin_cfg.c
+++ b/plugin_cfg.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_cfg.c,v 1.13 2005/03/30 04:57:50 reinelt Exp $
+/* $Id: plugin_cfg.c,v 1.14 2005/05/08 04:32:44 reinelt Exp $
*
* plugin for config file access
*
@@ -23,6 +23,9 @@
*
*
* $Log: plugin_cfg.c,v $
+ * Revision 1.14 2005/05/08 04:32:44 reinelt
+ * CodingStyle added and applied
+ *
* Revision 1.13 2005/03/30 04:57:50 reinelt
* Evaluator speedup: use bsearch for finding functions and variables
*
@@ -111,89 +114,91 @@
#endif
-static void load_variables (void)
+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);
- }
+ 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;
}
- l=p?p+1:NULL;
- }
- free (list);
-
+ free(list);
+
}
-static void my_cfg (RESULT *result, const int argc, RESULT *argv[])
+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 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)
+int plugin_init_cfg(void)
{
- /* load "Variables" section from cfg */
- load_variables();
+ /* load "Variables" section from cfg */
+ load_variables();
+
+ /* register plugin */
+ AddFunction("cfg", -1, my_cfg);
- /* register plugin */
- AddFunction ("cfg", -1, my_cfg);
-
- return 0;
+ return 0;
}
-void plugin_exit_cfg(void)
+void plugin_exit_cfg(void)
{
- /* empty */
+ /* empty */
}