aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c70
1 files changed, 9 insertions, 61 deletions
diff --git a/src/config.c b/src/config.c
index 4451341..bb9c1d2 100644
--- a/src/config.c
+++ b/src/config.c
@@ -8,25 +8,11 @@
#include "any_log.h"
#include "config.h"
#include "util.h"
+#include "block.h"
#define ANY_INI_IMPLEMENT
#include "any_ini.h"
-typedef enum {
- CONFIG_STRING,
- CONFIG_INT,
- CONFIG_UINT,
- CONFIG_DOUBLE,
- CONFIG_BOOL,
- CONFIG_COLOR,
-} config_type_t;
-
-typedef struct {
- const char *key;
- config_type_t type;
- size_t offset;
-} config_entry_t;
-
static const config_entry_t bar_entries[] = {
{ "width", CONFIG_UINT, offsetof(config_t, width) },
{ "height", CONFIG_UINT, offsetof(config_t, height) },
@@ -172,7 +158,7 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l
bool nullable = entries[i].type == CONFIG_STRING;
if ((value == NULL || *value == '\0') && !nullable) {
- log_value_error("Empty config entry",
+ log_value_error("Invalid empty entry",
"s:section", section,
"s:key", key,
"s:expected_type", types[entries[i].type],
@@ -231,7 +217,7 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l
log_panic("Unreachable");
}
- log_value_error("Invalid config entry",
+ log_value_error("Invalid entry",
"s:section", section,
"s:key", key,
"s:value", value,
@@ -242,7 +228,7 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l
}
}
- log_value_warn("Unknown config entry",
+ log_value_warn("Unknown entry",
"s:section", section,
"s:key", key,
"s:value", value,
@@ -278,19 +264,12 @@ void config_read(config_t *config, FILE *file)
const config_entry_t *entries = NULL;
void *result = NULL;
- config_section_t **section_ptr = NULL;
- size_t *section_size = NULL;
- char *section_label = NULL;
-
if (section != NULL) {
if (!strncmp(section, "block.", 6)) {
- section_ptr = &config->blocks;
- section_size = &config->n_blocks;
- section_label = strcopy(section + 6);
+ // TODO
+
} else if (!strncmp(section, "action.", 7)) {
- section_ptr = &config->actions;
- section_size = &config->n_actions;
- section_label = strcopy(section + 7);
+ // TODO
} else if (!strcmp(section, "bar")) {
entries = bar_entries;
result = config;
@@ -298,24 +277,11 @@ void config_read(config_t *config, FILE *file)
log_warn("Unknown section '%s'", section);
}
- if (section_ptr != NULL) {
- if (*section_label == '\0') {
- ++errors;
- log_value_error("Sections must have a non-empty label",
- "s:section", section,
- "i:line", ini.line);
- }
-
- *section_ptr = realloc(*section_ptr, ++(*section_size) * sizeof(config_section_t));
- assert(*section_ptr != NULL);
- (*section_ptr)[*section_size - 1].label = section_label;
- }
-
char *key;
while ((key = any_ini_stream_next_key(&ini)) != NULL) {
char *value = any_ini_stream_next_value(&ini);
- log_value_trace("Reading config entry",
+ log_value_trace("Reading entry",
"s:section", section,
"s:key", key,
"s:value", value,
@@ -340,29 +306,11 @@ void config_resolve(config_t *config, block_t *block)
int errors = 1;
if (errors > 0)
- log_panic("Failed to resolve config");
+ log_panic("Config could not be resolved");
}
void config_free(config_t *config)
{
- for (int i = 0; i < config->n_blocks; i++) {
- for (int j = 0; j < config->blocks[i].n_pairs; j++)
- pair_free(&config->blocks[i].pairs[j]);
-
- free(config->blocks[i].pairs);
- free(config->blocks[i].label);
- }
-
- for (int i = 0; i < config->n_actions; i++) {
- for (int j = 0; j < config->actions[i].n_pairs; j++)
- pair_free(&config->actions[i].pairs[j]);
-
- free(config->actions[i].pairs);
- free(config->actions[i].label);
- }
-
- free(config->blocks);
- free(config->actions);
free(config->font);
free(config->monitor);
}