aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-07-12 00:44:52 +0200
committerFederico Angelilli <code@fedang.net>2024-07-12 00:44:52 +0200
commite60937111eb8c7097e63da2bf253ea7425275636 (patch)
tree65fe41c1c2004dc4db2c3c4cc9cee7e3c85497fa /src
parente8cd9d9f83c1f48fd6f71ee7b062173436f78266 (diff)
Start parsing blocks
Diffstat (limited to 'src')
-rw-r--r--src/config.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/config.c b/src/config.c
index 77f6732..5af05f7 100644
--- a/src/config.c
+++ b/src/config.c
@@ -26,13 +26,18 @@ typedef struct {
size_t offset;
} config_entry_t;
-static const config_entry_t config_entries[] = {
+static const config_entry_t bar_entries[] = {
{ "width", CONFIG_UINT, offsetof(config_t, width) },
{ "height", CONFIG_UINT, offsetof(config_t, height) },
{ "font", CONFIG_STRING, offsetof(config_t, font) },
{ "monitor", CONFIG_STRING, offsetof(config_t, monitor) },
{ "override_redirect", CONFIG_BOOL, offsetof(config_t, override_redirect) },
{ "background", CONFIG_COLOR, offsetof(config_t, background) },
+ { 0 },
+};
+
+static const config_entry_t block_entries[] = {
+ { 0 },
};
static bool config_read_string(const char *value, char **result)
@@ -145,10 +150,9 @@ static bool config_read_color(const char *value, color_t *result)
return false;
}
-static bool config_entry(config_t *config, int line, const char *section, const char *key, const char *value)
+static bool config_read_entry(const config_entry_t *entries, void *result, int line,
+ const char *section, const char *key, const char *value)
{
- const int n_entries = sizeof(config_entries) / sizeof(config_entry_t);
-
const char *types[] = {
"string",
"integer",
@@ -156,21 +160,21 @@ static bool config_entry(config_t *config, int line, const char *section, const
"double float",
};
- for (int i = 0; i < n_entries; i++) {
- if (!strcmp(key, config_entries[i].key)) {
- bool nullable = config_entries[i].type == CONFIG_STRING;
+ for (int i = 0; entries[i].key != NULL; i++) {
+ if (!strcmp(key, entries[i].key)) {
+ bool nullable = entries[i].type == CONFIG_STRING;
if ((value == NULL || *value == '\0') && !nullable) {
log_value_error("Empty config entry",
"s:section", section,
"s:key", key,
- "s:expected_type", types[config_entries[i].type],
+ "s:expected_type", types[entries[i].type],
"i:line", line);
return false;
}
- void *result = (uint8_t *)config + config_entries[i].offset;
- switch (config_entries[i].type) {
+ result += entries[i].offset;
+ switch (entries[i].type) {
case CONFIG_STRING:
// NOTE: The previous string is freed by config_read_string
if (config_read_string(value, (char **)result)) {
@@ -224,7 +228,7 @@ static bool config_entry(config_t *config, int line, const char *section, const
"s:section", section,
"s:key", key,
"s:value", value,
- "s:expected_type", types[config_entries[i].type],
+ "s:expected_type", types[entries[i].type],
"i:line", line);
return false;
@@ -271,10 +275,18 @@ void config_read(config_t *config, FILE *file)
char *section = NULL;
do {
- bool unknown_section = section != NULL && strcmp(section, "bar");
-
- if (unknown_section)
- log_warn("Unknown section '%s'", section);
+ const config_entry_t *entries = NULL;
+ void *result = NULL;
+
+ if (section != NULL) {
+ if (!strncmp(section, "block.", 6)) {
+ entries = block_entries;
+ } else if (!strcmp(section, "bar")) {
+ entries = bar_entries;
+ result = config;
+ } else
+ log_warn("Unknown section '%s'", section);
+ }
char *key;
while ((key = any_ini_stream_next_key(&ini)) != NULL) {
@@ -286,8 +298,8 @@ void config_read(config_t *config, FILE *file)
"s:value", value,
"i:line", ini.line);
- if (!unknown_section)
- errors += !config_entry(config, ini.line, section, key, value);
+ if (entries != NULL)
+ errors += !config_read_entry(entries, result, ini.line, section, key, value);
free(key);
free(value);