aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c56
1 files changed, 44 insertions, 12 deletions
diff --git a/src/config.c b/src/config.c
index 54d32eb..8955359 100644
--- a/src/config.c
+++ b/src/config.c
@@ -37,15 +37,16 @@ static const config_entry_t effect_entries[] = {
};
static const config_entry_t block_entries[] = {
- { "hidden", CONFIG_BOOL, NULL, offsetof(block_t, hidden) },
- { "color", CONFIG_COLOR, NULL, offsetof(block_t, color) },
- { "line-color", CONFIG_COLOR, NULL, offsetof(block_t, line_color) },
- { "line-width", CONFIG_UINT, NULL, offsetof(block_t, line_width) },
- { "x-padding", CONFIG_UINT, NULL, offsetof(block_t, x_padding) },
- { "y-padding", CONFIG_UINT, NULL, offsetof(block_t, y_padding) },
- { "min-width", CONFIG_UINT, NULL, offsetof(block_t, min_width) },
- { "max-width", CONFIG_UINT, NULL, offsetof(block_t, max_width) },
- { "interval", CONFIG_TIME, NULL, offsetof(block_t, update_interval) },
+ { "hidden", CONFIG_BOOL, NULL, offsetof(block_t, hidden) },
+ { "color", CONFIG_COLOR, NULL, offsetof(block_t, color) },
+ { "line-color", CONFIG_COLOR, NULL, offsetof(block_t, line_color) },
+ { "line-width", CONFIG_UINT, NULL, offsetof(block_t, line_width) },
+ { "x-padding", CONFIG_UINT, NULL, offsetof(block_t, x_padding) },
+ { "y-padding", CONFIG_UINT, NULL, offsetof(block_t, y_padding) },
+ { "min-width", CONFIG_UINT, NULL, offsetof(block_t, min_width) },
+ { "max-width", CONFIG_UINT, NULL, offsetof(block_t, max_width) },
+ { "interval", CONFIG_TIME, NULL, offsetof(block_t, update_interval) },
+ { "effect", CONFIG_STRING, NULL, offsetof(block_t, info) },
{ 0 },
};
@@ -479,7 +480,7 @@ void config_read(config_t *config, FILE *file)
assert(config->infos != NULL);
info = &config->infos[config->n_infos - 1];
- char *label = strcopy(section + 6);
+ char *label = strcopy(section + 7);
if (label == NULL || *label == '\0') {
++errors;
log_value_error("Effect section must have a valid label",
@@ -628,9 +629,35 @@ skip_pair:
log_panic("Config file contained %d errors", n_errors);
}
+static bool config_resolve_effect(config_t *config, block_t *block)
+{
+ if (block->info == NULL)
+ return true;
+
+ char *effect = (void *)block->info;
+ block->info = NULL;
+
+ for (size_t i = 0; i < config->n_infos; i++) {
+ if (!strcmp(effect, config->infos[i].label)) {
+ block->info = &config->infos[i];
+ free(effect);
+ return true;
+ }
+ }
+
+
+ log_error("Effect '%s' not found", effect);
+ free(effect);
+ return false;
+}
+
static bool config_resolve_children(config_t *config, block_t *block)
{
block->resolved = true;
+
+ if (!config_resolve_effect(config, block))
+ return false;
+
if (block->type == BLOCK_TEXT)
return true;
@@ -655,23 +682,28 @@ static bool config_resolve_children(config_t *config, block_t *block)
if (!strcmp(children[i], config->blocks[j].label)) {
if (config->blocks[j].resolved) {
log_error("Block '%s' can only be referenced by one block", config->blocks[j].label);
+ strvfree(children);
return false;
}
- log_debug("Block '%s' is parent of '%s'", block->label, config->blocks[j].label);
block->group.children[i] = &config->blocks[j];
+ log_debug("Block '%s' is parent of '%s'", block->label, config->blocks[j].label);
- if (!config_resolve_children(config, &config->blocks[j]))
+ if (!config_resolve_children(config, &config->blocks[j])) {
+ strvfree(children);
return false;
+ }
goto next;
}
}
+ strvfree(children);
log_error("Block '%s' not found", children[i]);
return false;
next:
}
+ strvfree(children);
return true;
}