From 71515e4079210397857221e800958356fad30ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 13 Jan 2019 11:37:05 +0100 Subject: [PATCH] config: conf_verify_dict() now assumes attr list is NULL-terminated --- config-verify.c | 33 +++++++++++++++++++++------------ config-verify.h | 2 +- module.h | 2 -- modules/alsa.c | 1 - modules/backlight.c | 1 - modules/battery.c | 1 - modules/clock.c | 1 - modules/i3.c | 1 - modules/label.c | 1 - modules/mpd.c | 1 - modules/network.c | 1 - modules/removables.c | 1 - modules/xkb.c | 1 - modules/xwindow.c | 1 - particle.h | 2 -- particles/empty.c | 1 - particles/list.c | 1 - particles/map.c | 1 - particles/progress-bar.c | 1 - particles/ramp.c | 1 - particles/string.c | 1 - 21 files changed, 22 insertions(+), 34 deletions(-) diff --git a/config-verify.c b/config-verify.c index f592520..8ff2008 100644 --- a/config-verify.c +++ b/config-verify.c @@ -73,13 +73,18 @@ conf_verify_enum(keychain_t *chain, const struct yml_node *node, bool conf_verify_dict(keychain_t *chain, const struct yml_node *node, - const struct attr_info info[], size_t count) + const struct attr_info info[]) { if (!yml_is_dict(node)) { LOG_ERR("%s: must be a dictionary", conf_err_prefix(chain, node)); return false; } + /* Count the attributes */ + size_t count = 0; + for (; info[count].name != NULL; count++) + ; + bool exists[count]; memset(exists, 0, sizeof(exists)); @@ -153,9 +158,10 @@ conf_verify_font(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"family", true, &conf_verify_string}, + {NULL, false, NULL}, }; - return conf_verify_dict(chain, node, attrs, sizeof(attrs) / sizeof(attrs[0])); + return conf_verify_dict(chain, node, attrs); } static bool @@ -206,11 +212,13 @@ conf_verify_decoration(keychain_t *chain, const struct yml_node *node) static const struct attr_info background[] = { {"color", true, &conf_verify_color}, + {NULL, false, NULL}, }; static const struct attr_info underline[] = { {"size", true, &conf_verify_int}, {"color", true, &conf_verify_color}, + {NULL, false, NULL}, }; static const struct { @@ -226,11 +234,9 @@ conf_verify_decoration(keychain_t *chain, const struct yml_node *node) if (strcmp(decos[i].name, deco_name) != 0) continue; - if (!conf_verify_dict(chain_push(chain, deco_name), - values, decos[i].attrs, decos[i].count)) - { + chain_push(chain, deco_name); + if (!conf_verify_dict(chain, values, decos[i].attrs)) return false; - } chain_pop(chain); return true; @@ -286,8 +292,8 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) return false; } - if (!conf_verify_dict(chain_push(chain, particle_name), values, - info->attrs, info->attr_count)) + chain_push(chain, particle_name); + if (!conf_verify_dict(chain, values, info->attrs)) return false; chain_pop(chain); @@ -335,8 +341,8 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - if (!conf_verify_dict(chain_push(chain, mod_name), values, - info->attrs, info->attr_count)) + chain_push(chain, mod_name); + if (!conf_verify_dict(chain, values, info->attrs)) return false; chain_pop(chain); @@ -368,9 +374,10 @@ verify_bar_border(keychain_t *chain, const struct yml_node *node) static const struct attr_info attrs[] = { {"width", true, &conf_verify_int}, {"color", true, &conf_verify_color}, + {NULL, false, NULL}, }; - return conf_verify_dict(chain, node, attrs, sizeof(attrs) / sizeof(attrs[0])); + return conf_verify_dict(chain, node, attrs); } static bool @@ -409,9 +416,11 @@ conf_verify_bar(const struct yml_node *bar) {"left", false, &verify_module_list}, {"center", false, &verify_module_list}, {"right", false, &verify_module_list}, + + {NULL, false, NULL}, }; - bool ret = conf_verify_dict(&chain, bar, attrs, sizeof(attrs) / sizeof(attrs[0])); + bool ret = conf_verify_dict(&chain, bar, attrs); tll_free(chain); return ret; } diff --git a/config-verify.h b/config-verify.h index 5bdc37c..24d0256 100644 --- a/config-verify.h +++ b/config-verify.h @@ -36,7 +36,7 @@ bool conf_verify_int(keychain_t *chain, const struct yml_node *node); bool conf_verify_enum(keychain_t *chain, const struct yml_node *node, const char *values[], size_t count); bool conf_verify_dict(keychain_t *chain, const struct yml_node *node, - const struct attr_info info[], size_t count); + const struct attr_info info[]); /* NULL-terminated list */ bool conf_verify_color(keychain_t *chain, const struct yml_node *node); bool conf_verify_font(keychain_t *chain, const struct yml_node *node); diff --git a/module.h b/module.h index 450dcd6..48dcfc1 100644 --- a/module.h +++ b/module.h @@ -14,8 +14,6 @@ struct module; struct module_info { struct module *(*from_conf)(const struct yml_node *node, const struct font *parent_font); - - size_t attr_count; /* TODO: remove, NULL-terminate attr list instead */ const struct attr_info attrs[]; }; diff --git a/modules/alsa.c b/modules/alsa.c index c8f1562..a6044c6 100644 --- a/modules/alsa.c +++ b/modules/alsa.c @@ -282,7 +282,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font) const struct module_info plugin_info = { .from_conf = &from_conf, - .attr_count = 4, .attrs = { {"card", true, &conf_verify_string}, {"mixer", true, &conf_verify_string}, diff --git a/modules/backlight.c b/modules/backlight.c index 5848640..73f6e3e 100644 --- a/modules/backlight.c +++ b/modules/backlight.c @@ -226,7 +226,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font) const struct module_info plugin_info = { .from_conf = &from_conf, - .attr_count = 3, .attrs = { {"name", true, &conf_verify_string}, {"content", true, &conf_verify_particle}, diff --git a/modules/battery.c b/modules/battery.c index b4812f0..41594e8 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -358,7 +358,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font) const struct module_info plugin_info = { .from_conf = &from_conf, - .attr_count = 4, .attrs = { {"name", true, &conf_verify_string}, {"poll-interval", false, &conf_verify_int}, diff --git a/modules/clock.c b/modules/clock.c index 8834571..7cfbf2b 100644 --- a/modules/clock.c +++ b/modules/clock.c @@ -109,7 +109,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font) const struct module_info plugin_info = { .from_conf = &from_conf, - .attr_count = 4, .attrs = { {"date-format", false, &conf_verify_string}, {"time-format", false, &conf_verify_string}, diff --git a/modules/i3.c b/modules/i3.c index 924fedb..db46e3a 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -703,7 +703,6 @@ verify_content(keychain_t *chain, const struct yml_node *node) const struct module_info plugin_info = { .from_conf = &from_conf, - .attr_count = 5, .attrs = { {"spacing", false, &conf_verify_int}, {"left-spacing", false, &conf_verify_int}, diff --git a/modules/label.c b/modules/label.c index a0553ac..485a663 100644 --- a/modules/label.c +++ b/modules/label.c @@ -55,7 +55,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font) const struct module_info plugin_info = { .from_conf = &from_conf, - .attr_count = 2, .attrs = { {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, diff --git a/modules/mpd.c b/modules/mpd.c index 7d72be1..0bcbdd9 100644 --- a/modules/mpd.c +++ b/modules/mpd.c @@ -493,7 +493,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font) const struct module_info plugin_info = { .from_conf = &from_conf, - .attr_count = 4, .attrs = { {"host", true, &conf_verify_string}, {"port", false, &conf_verify_int}, diff --git a/modules/network.c b/modules/network.c index c918291..6761226 100644 --- a/modules/network.c +++ b/modules/network.c @@ -545,7 +545,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font) const struct module_info plugin_info = { .from_conf = &from_conf, - .attr_count = 3, .attrs = { {"name", true, &conf_verify_string}, {"content", true, &conf_verify_particle}, diff --git a/modules/removables.c b/modules/removables.c index a76e001..5cf7dc9 100644 --- a/modules/removables.c +++ b/modules/removables.c @@ -579,7 +579,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font) const struct module_info plugin_info = { .from_conf = &from_conf, - .attr_count = 5, .attrs = { {"spacing", false, &conf_verify_int}, {"left-spacing", false, &conf_verify_int}, diff --git a/modules/xkb.c b/modules/xkb.c index 2e20aa0..1a00399 100644 --- a/modules/xkb.c +++ b/modules/xkb.c @@ -461,7 +461,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font) const struct module_info plugin_info = { .from_conf = &from_conf, - .attr_count = 2, .attrs = { {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, diff --git a/modules/xwindow.c b/modules/xwindow.c index 7d95023..6400a1e 100644 --- a/modules/xwindow.c +++ b/modules/xwindow.c @@ -323,7 +323,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font) const struct module_info plugin_info = { .from_conf = &from_conf, - .attr_count = 2, .attrs = { {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, diff --git a/particle.h b/particle.h index a3fcf8c..fed44ae 100644 --- a/particle.h +++ b/particle.h @@ -18,8 +18,6 @@ struct particle_info { const struct font *parent_font, int left_margin, int right_margin, const char *on_click_template); - - size_t attr_count; /* TODO: reomve, NULL-terminate attr list instead */ const struct attr_info attrs[]; #define PARTICLE_COMMON_ATTRS_COUNT 5 diff --git a/particles/empty.c b/particles/empty.c index 184ce78..4aa6294 100644 --- a/particles/empty.c +++ b/particles/empty.c @@ -50,7 +50,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font, const struct particle_info plugin_info = { .from_conf = &from_conf, - .attr_count = PARTICLE_COMMON_ATTRS_COUNT + 0, .attrs = { PARTICLE_COMMON_ATTRS, }, diff --git a/particles/list.c b/particles/list.c index 90ba4ac..c95f8d9 100644 --- a/particles/list.c +++ b/particles/list.c @@ -200,7 +200,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font, const struct particle_info plugin_info = { .from_conf = &from_conf, - .attr_count = PARTICLE_COMMON_ATTRS_COUNT + 4, .attrs = { {"items", true, &conf_verify_particle_list_items}, {"spacing", false, &conf_verify_int}, diff --git a/particles/map.c b/particles/map.c index 3e023a1..d616034 100644 --- a/particles/map.c +++ b/particles/map.c @@ -230,7 +230,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font, const struct particle_info plugin_info = { .from_conf = &from_conf, - .attr_count = PARTICLE_COMMON_ATTRS_COUNT + 3, .attrs = { {"tag", true, &conf_verify_string}, {"values", true, &verify_map_values}, diff --git a/particles/progress-bar.c b/particles/progress-bar.c index 68b0d0f..2526a49 100644 --- a/particles/progress-bar.c +++ b/particles/progress-bar.c @@ -259,7 +259,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font, const struct particle_info plugin_info = { .from_conf = &from_conf, - .attr_count = PARTICLE_COMMON_ATTRS_COUNT + 7, .attrs = { {"tag", true, &conf_verify_string}, {"length", true, &conf_verify_int}, diff --git a/particles/ramp.c b/particles/ramp.c index 2e51cb7..2d81bf1 100644 --- a/particles/ramp.c +++ b/particles/ramp.c @@ -180,7 +180,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font, const struct particle_info plugin_info = { .from_conf = &from_conf, - .attr_count = PARTICLE_COMMON_ATTRS_COUNT + 2, .attrs = { {"tag", true, &conf_verify_string}, {"items", true, &conf_verify_particle_list_items}, diff --git a/particles/string.c b/particles/string.c index d47fb93..5e3863d 100644 --- a/particles/string.c +++ b/particles/string.c @@ -173,7 +173,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font, const struct particle_info plugin_info = { .from_conf = &from_conf, - .attr_count = PARTICLE_COMMON_ATTRS_COUNT + 4, .attrs = { {"text", true, &conf_verify_string}, {"max", false, &conf_verify_int},