aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/config.c b/src/config.c
index 5af05f7..d636c31 100644
--- a/src/config.c
+++ b/src/config.c
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <limits.h>
#include <string.h>
+#include <assert.h>
#include "any_log.h"
#include "config.h"
@@ -37,6 +38,8 @@ static const config_entry_t bar_entries[] = {
};
static const config_entry_t block_entries[] = {
+ { "type", CONFIG_INT, offsetof(block_t, type) },
+ { "text", CONFIG_STRING, offsetof(block_t, text.text) },
{ 0 },
};
@@ -156,7 +159,7 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l
const char *types[] = {
"string",
"integer",
- "positive integer",
+ "unsigned integer",
"double float",
};
@@ -178,35 +181,35 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l
case CONFIG_STRING:
// NOTE: The previous string is freed by config_read_string
if (config_read_string(value, (char **)result)) {
- log_debug("Config '%s' set to '%s'", key, *(char **)result);
+ log_debug("Set '%s.%s' to '%s'", section, key, *(char **)result);
return true;
}
break;
case CONFIG_INT:
if (config_read_int(value, (int *)result)) {
- log_debug("Config '%s' set to '%d'", key, *(int *)result);
+ log_debug("Set '%s.%s' to '%d'", section, key, *(int *)result);
return true;
}
break;
case CONFIG_UINT:
if (config_read_uint(value, (unsigned int *)result)) {
- log_debug("Config '%s' set to '%u'", key, *(unsigned int *)result);
+ log_debug("Set '%s.%s' to '%u'", section, key, *(unsigned int *)result);
return true;
}
break;
case CONFIG_DOUBLE:
if (config_read_double(value, (double *)result)) {
- log_debug("Config '%s' set to '%lf'", key, *(double *)result);
+ log_debug("Set '%s.%s' to '%lf'", section, key, *(double *)result);
return true;
}
break;
case CONFIG_BOOL:
if (config_read_bool(value, (bool *)result)) {
- log_debug("Config '%s' set to '%s'", key, *(bool *)result ? "true" : "false");
+ log_debug("Set '%s.%s' to '%s'", section, key, *(bool *)result ? "true" : "false");
return true;
}
break;
@@ -214,7 +217,7 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l
case CONFIG_COLOR:
if (config_read_color(value, (color_t *)result)) {
char *color = color_to_string((color_t *)result);
- log_debug("Config '%s' set to '%s'", key, color);
+ log_debug("Set '%s.%s' to '%s'", section, key, color);
free(color);
return true;
}
@@ -281,6 +284,9 @@ void config_read(config_t *config, FILE *file)
if (section != NULL) {
if (!strncmp(section, "block.", 6)) {
entries = block_entries;
+ config->blocks = realloc(config->blocks, ++config->n_blocks * sizeof(block_t));
+ assert(config->blocks != NULL);
+ result = &config->blocks[config->n_blocks - 1];
} else if (!strcmp(section, "bar")) {
entries = bar_entries;
result = config;