aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-11-24 15:14:05 +0100
committerFederico Angelilli <code@fedang.net>2024-11-24 15:14:05 +0100
commitab8a774df0ebc88c4b16377547366b01134b041c (patch)
tree0d34c311276c271e16fe9d8ef842fc960bda8334 /src/config.c
parentb260d5beb9fab0c39f18be677e70b35e988d3c1d (diff)
Add actions
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c58
1 files changed, 57 insertions, 1 deletions
diff --git a/src/config.c b/src/config.c
index 13addef..d20aebe 100644
--- a/src/config.c
+++ b/src/config.c
@@ -9,7 +9,7 @@
#include "config.h"
#include "util.h"
#include "block.h"
-#include "block.h"
+#include "action.h"
#define ANY_INI_IMPLEMENT
#include "any_ini.h"
@@ -431,6 +431,18 @@ static block_t *config_alloc_block(config_t *config, const block_scheme_t *schem
return block;
}
+static config_status_t config_read_action(action_t *action, const char **type,
+ const char *section, const char *key, const char *value)
+{
+ action->parts = realloc(action->parts, ++action->length * sizeof(action_part_t));
+ assert(action->parts != NULL);
+
+ action->parts[action->length - 1].key = strcopy(key);
+ action->parts[action->length - 1].value = strcopy(key);
+
+ return CONFIG_SUCCESS;
+}
+
// TODO: More robust way to define defaults
void config_init(config_t *config)
{
@@ -463,6 +475,8 @@ int config_read(config_t *config, FILE *file)
int errors = 0;
bool bar_section = false;
+ action_t *action = NULL;
+
const block_scheme_t *scheme = NULL;
block_t *block = NULL;
@@ -519,6 +533,32 @@ int config_read(config_t *config, FILE *file)
"i:line", ini.line);
goto skip_pair;
+ } else if (!strncmp(section, "action.", 7)) {
+ char *label = strcopy(section + 7);
+
+ if (label == NULL || *label == '\0') {
+ ++errors;
+ log_value_error("Action section must have a valid label",
+ "s:section", section,
+ "i:line", ini.line);
+ } else {
+ for (size_t i = 0; i < config->n_actions; i++) {
+ if (!strcmp(label, config->actions[i].label)) {
+ ++errors;
+ log_value_error("Action section must have a unique label",
+ "s:section", section,
+ "i:line", ini.line);
+ }
+ }
+ }
+
+ config->actions = realloc(config->actions, ++config->n_actions * sizeof(action_t));
+ assert(config->actions != NULL);
+
+ action = &config->actions[config->n_actions - 1];
+ memset(action, 0, sizeof(action_t));
+ action->label = label;
+
} else if (!strcmp(section, "bar")) {
bar_section = true;
} else
@@ -552,6 +592,10 @@ int config_read(config_t *config, FILE *file)
status = config_read_block(scheme, block, &type, section, key, value);
}
+ if (action != NULL) {
+ status = config_read_action(action, &type, section, key, value);
+ }
+
switch (status) {
case CONFIG_SUCCESS:
break;
@@ -613,6 +657,15 @@ int config_validate(config_t *config)
block->validated = tmp == 0;
}
+ // Validate actions
+ // NOTE: Maybe move this after the config is resolved?
+ //
+ for (size_t i = 0; i < config->n_actions; i++) {
+ action_t *action = &config->actions[i];
+ log_debug("Validating 'action.%s'", action->label);
+ errors += action_validate(action, config);
+ }
+
return errors;
}
@@ -694,6 +747,9 @@ void config_free(config_t *config)
for (size_t i = 0; i < config->n_blocks; i++)
block_free(config->blocks[i]);
+ for (size_t i = 0; i < config->n_actions; i++)
+ action_free(&config->actions[i]);
+
gradient_free(&config->background);
free(config->blocks);