aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-11-24 16:43:35 +0100
committerFederico Angelilli <code@fedang.net>2024-11-24 16:43:35 +0100
commit30020a08392c959505bd27388564f7436a04bace (patch)
tree2cfdeb4da789c71e3400e05caf353fe0307a6836 /src/config.c
parent441c0b974d00c01fccbce4ebed61711b7b0eeec7 (diff)
Change action syntax
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/config.c b/src/config.c
index 619d95c..f76065c 100644
--- a/src/config.c
+++ b/src/config.c
@@ -432,14 +432,25 @@ 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)
+static config_status_t config_read_action(action_t *action, const char *section, const char *key, const char *value)
{
+ action_type_t type;
+
+ if (!strcmp(key, "target"))
+ type = ACTION_TARGET;
+ else if (!strncmp(key, "set-", 4))
+ type = ACTION_SET_PAIR;
+ else if (!strcmp(key, "run-script"))
+ type = ACTION_RUN_SCRIPT;
+ else
+ return CONFIG_UNKNOWN;
+
action->parts = realloc(action->parts, ++action->length * sizeof(action_part_t));
assert(action->parts != NULL);
+ action->parts[action->length - 1].type = type;
action->parts[action->length - 1].key = strcopy(key);
- action->parts[action->length - 1].value = strcopy(key);
+ action->parts[action->length - 1].value = strcopy(value);
return CONFIG_SUCCESS;
}
@@ -484,10 +495,16 @@ int config_read(config_t *config, FILE *file)
if (section != NULL) {
if (!strncmp(section, "block.", 6)) {
char *label = strcopy(section + 6);
- if (label == NULL || *label == '\0' || !strcmp(label, "bar")) {
+ if (label == NULL || *label == '\0') {
+ ++errors;
+ log_value_error("Block section must have a non-empty label",
+ "s:section", section,
+ "i:line", ini.line);
+ } else if (!strcmp(label, "bar") || !strcmp(label, "default")) {
++errors;
- log_value_error("Block section must have a valid label",
+ log_value_error("Block section must have a non-reserved label",
"s:section", section,
+ "s:label", label,
"i:line", ini.line);
} else {
for (size_t i = 0; i < config->n_blocks; i++) {
@@ -495,6 +512,7 @@ int config_read(config_t *config, FILE *file)
++errors;
log_value_error("Block section must have a unique label",
"s:section", section,
+ "s:label", label,
"i:line", ini.line);
}
}
@@ -539,7 +557,7 @@ int config_read(config_t *config, FILE *file)
if (label == NULL || *label == '\0') {
++errors;
- log_value_error("Action section must have a valid label",
+ log_value_error("Action section must have a non-empty label",
"s:section", section,
"i:line", ini.line);
} else {
@@ -579,7 +597,7 @@ int config_read(config_t *config, FILE *file)
if (!bar_section && block == NULL && action == NULL)
goto skip_pair;
- const char *type;
+ const char *type = "none";
config_status_t status;
if (bar_section) {
@@ -595,7 +613,7 @@ int config_read(config_t *config, FILE *file)
}
if (action != NULL) {
- status = config_read_action(action, &type, section, key, value);
+ status = config_read_action(action, section, key, value);
}
switch (status) {