From ceb6fc010ee9f4fadbcbf3e3cdc481ec505cdc32 Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 20 Jan 2007 06:37:35 +0000 Subject: dynamic properties for bars; new 'property_valid()' helper git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@749 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- property.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'property.c') diff --git a/property.c b/property.c index fa08c61..6b58e29 100644 --- a/property.c +++ b/property.c @@ -64,7 +64,10 @@ void property_load(const char *section, const char *name, const char *defval, PROPERTY * prop) { + char *expression; + /* initialize structure */ + prop->valid = 0; prop->name = NULL; prop->expression = NULL; prop->compiled = NULL; @@ -74,7 +77,16 @@ void property_load(const char *section, const char *name, const char *defval, PR prop->name = strdup(name); /* load expression from config, but do not evaluate it */ - prop->expression = cfg_get_raw(section, name, defval); + expression = cfg_get_raw(section, name, NULL); + + if (expression == NULL) { + if (defval != NULL && *defval != '\0') + debug("Notice: using default value <%s> for property '%s.%s'", defval, section, name); + prop->expression = (char *) defval; + } else { + prop->valid = 1; + prop->expression = expression; + } /* pre-compile the expression */ Compile(prop->expression, &prop->compiled); @@ -82,13 +94,18 @@ void property_load(const char *section, const char *name, const char *defval, PR } +int property_valid(PROPERTY * prop) +{ + return prop->valid; +} + + int property_eval(PROPERTY * prop) { RESULT old; - int update = 1; + int update; /* this is a bit ugly: we need to remember the old value */ - old.type = prop->result.type; old.size = prop->result.size; old.number = prop->result.number; @@ -97,10 +114,11 @@ int property_eval(PROPERTY * prop) DelResult(&prop->result); Eval(prop->compiled, &prop->result); + /* check if property value has changed */ + update = 1; if (prop->result.type & R_NUMBER && old.type & R_NUMBER && prop->result.number == old.number) { update = 0; } - if (prop->result.type & R_STRING && old.type & R_STRING && prop->result.size == old.size) { if (prop->result.string == NULL && old.string == NULL) { update = 0; -- cgit v1.2.3