From 441c0b974d00c01fccbce4ebed61711b7b0eeec7 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Sun, 24 Nov 2024 16:13:20 +0100 Subject: Start performing actions --- src/action.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/action.c') diff --git a/src/action.c b/src/action.c index c8ccee1..2ceae9b 100644 --- a/src/action.c +++ b/src/action.c @@ -3,6 +3,7 @@ #include "action.h" #include "block.h" +#include "any_log.h" void action_perform(action_t *action, block_t *block, config_t *config) { @@ -13,9 +14,15 @@ void action_perform(action_t *action, block_t *block, config_t *config) if (strncmp(key, "block.", 6)) abort(); + int sep = 6; + while (key[sep] != '.' && key[sep] != '\0') sep++; + + if (key[sep] == '\0') abort(); + block_t *target = NULL; for (size_t i = 0; i < config->n_blocks; i++) { - if (!strcmp(key + 6, config->blocks[i]->label)) { + size_t length = strlen(config->blocks[i]->label); + if (length == (sep - 6) && !strncmp(key + 6, config->blocks[i]->label, length)) { target = config->blocks[i]; break; } @@ -24,8 +31,15 @@ void action_perform(action_t *action, block_t *block, config_t *config) if (target == NULL) abort(); + if (target->scheme->change_fn == NULL) { + log_warn("Block '%s' does not support changing values", target->label); + continue; + } + block_change(target, key, value); } + + log_debug("Performed action '%s'", action->label); } int action_validate(action_t *action, config_t *config) @@ -42,4 +56,5 @@ void action_free(action_t *action) } free(action->parts); + free(action->label); } -- cgit v1.2.3