diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/blocks/info.h | 2 | ||||
| -rw-r--r-- | src/blocks/ram.c | 22 | ||||
| -rw-r--r-- | src/config.c | 20 |
3 files changed, 37 insertions, 7 deletions
diff --git a/src/blocks/info.h b/src/blocks/info.h index c5ea38e..2b42c72 100644 --- a/src/blocks/info.h +++ b/src/blocks/info.h @@ -7,4 +7,6 @@ extern const config_block_t block_text_info; extern const config_block_t block_group_info; +extern const config_block_t block_ram_info; + #endif diff --git a/src/blocks/ram.c b/src/blocks/ram.c new file mode 100644 index 0000000..2190b20 --- /dev/null +++ b/src/blocks/ram.c @@ -0,0 +1,22 @@ +#include "info.h" + +static bool block_ram_apply(block_t *block, void *result) +{ + return true; +} + +static const config_entry_t block_ram_entries[] = { + { "text", CONFIG_STRING, offsetof(block_t, text.text) }, + { "text-color", CONFIG_COLOR, offsetof(block_t, text.text_color) }, + { "text-size", CONFIG_INT, offsetof(block_t, text.text_size) }, + { 0 }, +}; + +const config_block_t block_ram_info = { + .type_name = "ram", + .type_size = 0, + .base = { 0 }, + .entries = block_ram_entries, + .apply = block_ram_apply, +}; + diff --git a/src/config.c b/src/config.c index ff587da..cfeb70f 100644 --- a/src/config.c +++ b/src/config.c @@ -277,14 +277,13 @@ void config_read(config_t *config, FILE *file) block = &config->blocks[config->n_blocks - 1]; char *label = strcopy(section + 6); - if (*label == '\0') { + if (label == NULL || *label == '\0') { ++errors; log_value_error("Block section must have a non-empty label", "s:section", section, "i:line", ini.line); free(label); - } else - block->label = label; + } if ((key = any_ini_stream_next_key(&ini)) == NULL || strcmp(key, "type")) { ++errors; @@ -309,6 +308,7 @@ void config_read(config_t *config, FILE *file) const config_block_t block_infos[] = { block_text_info, block_group_info, + block_ram_info, { 0 } }; @@ -316,10 +316,14 @@ void config_read(config_t *config, FILE *file) if (strcmp(block_infos[i].type_name, value)) continue; info = &block_infos[i]; - memcpy(block, &info->base, sizeof(block_t)); - block->info = result = !strcmp(value, "text") - ? block - : malloc(info->type_size); + block_copy(block, &info->base); + free(block->label); + block->label = label; + + if (info->type_size == 0) + result = block; + else + block->info = result = malloc(info->type_size); goto skip_pair; } @@ -410,7 +414,9 @@ void config_resolve(config_t *config, block_t *block) { int errors = 0; + block->label = strcopy("main"); block->type = BLOCK_GROUP; + block->group.spacing = 10; block->group.n_children = config->n_blocks; block->group.children = malloc(config->n_blocks * sizeof(block_t *)); |
