diff --git a/config-verify.c b/config-verify.c index 8ff2008..41407ec 100644 --- a/config-verify.c +++ b/config-verify.c @@ -341,8 +341,10 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } + assert(info->verify_conf != NULL); + chain_push(chain, mod_name); - if (!conf_verify_dict(chain, values, info->attrs)) + if (!info->verify_conf(chain, values)) return false; chain_pop(chain); diff --git a/module.h b/module.h index 48dcfc1..38bd48f 100644 --- a/module.h +++ b/module.h @@ -12,9 +12,9 @@ struct bar; struct module; struct module_info { + bool (*verify_conf)(keychain_t *chain, const struct yml_node *node); struct module *(*from_conf)(const struct yml_node *node, const struct font *parent_font); - const struct attr_info attrs[]; }; struct module_run_context { diff --git a/modules/alsa.c b/modules/alsa.c index a6044c6..ebb4343 100644 --- a/modules/alsa.c +++ b/modules/alsa.c @@ -280,13 +280,21 @@ from_conf(const struct yml_node *node, const struct font *parent_font) conf_to_particle(content, parent_font)); } -const struct module_info plugin_info = { - .from_conf = &from_conf, - .attrs = { +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) +{ + static const struct attr_info attrs[] = { {"card", true, &conf_verify_string}, {"mixer", true, &conf_verify_string}, {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, {NULL, false, NULL} - }, + }; + + return conf_verify_dict(chain, node, attrs); +} + +const struct module_info plugin_info = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, }; diff --git a/modules/backlight.c b/modules/backlight.c index 73f6e3e..2df38ea 100644 --- a/modules/backlight.c +++ b/modules/backlight.c @@ -224,12 +224,20 @@ from_conf(const struct yml_node *node, const struct font *parent_font) yml_value_as_string(name), conf_to_particle(c, parent_font)); } -const struct module_info plugin_info = { - .from_conf = &from_conf, - .attrs = { +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) +{ + static const struct attr_info attrs[] = { {"name", true, &conf_verify_string}, {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, - {NULL, false, NULL}, - }, + {NULL, false, NULL} + }; + + return conf_verify_dict(chain, node, attrs); +} + +const struct module_info plugin_info = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, }; diff --git a/modules/battery.c b/modules/battery.c index 41594e8..600122c 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -356,13 +356,21 @@ from_conf(const struct yml_node *node, const struct font *parent_font) poll_interval != NULL ? yml_value_as_int(poll_interval) : 60); } -const struct module_info plugin_info = { - .from_conf = &from_conf, - .attrs = { +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) +{ + static const struct attr_info attrs[] = { {"name", true, &conf_verify_string}, {"poll-interval", false, &conf_verify_int}, {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, - {NULL, false, NULL}, - }, + {NULL, false, NULL} + }; + + return conf_verify_dict(chain, node, attrs); +} + +const struct module_info plugin_info = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, }; diff --git a/modules/clock.c b/modules/clock.c index 7cfbf2b..c538b5a 100644 --- a/modules/clock.c +++ b/modules/clock.c @@ -107,13 +107,21 @@ from_conf(const struct yml_node *node, const struct font *parent_font) time_format != NULL ? yml_value_as_string(time_format) : "%H:%M"); } -const struct module_info plugin_info = { - .from_conf = &from_conf, - .attrs = { +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) +{ + static const struct attr_info attrs[] = { {"date-format", false, &conf_verify_string}, {"time-format", false, &conf_verify_string}, {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, - {NULL, false, NULL}, - }, + {NULL, false, NULL} + }; + + return conf_verify_dict(chain, node, attrs); +} + +const struct module_info plugin_info = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, }; diff --git a/modules/i3.c b/modules/i3.c index db46e3a..e71828c 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -701,14 +701,22 @@ verify_content(keychain_t *chain, const struct yml_node *node) return true; } -const struct module_info plugin_info = { - .from_conf = &from_conf, - .attrs = { +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) +{ + static const struct attr_info attrs[] = { {"spacing", false, &conf_verify_int}, {"left-spacing", false, &conf_verify_int}, {"right-spacing", false, &conf_verify_int}, {"content", true, &verify_content}, {"anchors", false, NULL}, - {NULL, false, NULL}, - }, + {NULL, false, NULL} + }; + + return conf_verify_dict(chain, node, attrs); +} + +const struct module_info plugin_info = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, }; diff --git a/modules/label.c b/modules/label.c index 485a663..1f5a46a 100644 --- a/modules/label.c +++ b/modules/label.c @@ -53,11 +53,19 @@ from_conf(const struct yml_node *node, const struct font *parent_font) return label_new(conf_to_particle(c, parent_font)); } -const struct module_info plugin_info = { - .from_conf = &from_conf, - .attrs = { +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) +{ + static const struct attr_info attrs[] = { {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, - {NULL, false, NULL}, - }, + {NULL, false, NULL} + }; + + return conf_verify_dict(chain, node, attrs); +} + +const struct module_info plugin_info = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, }; diff --git a/modules/mpd.c b/modules/mpd.c index 0bcbdd9..c6472de 100644 --- a/modules/mpd.c +++ b/modules/mpd.c @@ -491,13 +491,21 @@ from_conf(const struct yml_node *node, const struct font *parent_font) conf_to_particle(c, parent_font)); } -const struct module_info plugin_info = { - .from_conf = &from_conf, - .attrs = { +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) +{ + static const struct attr_info attrs[] = { {"host", true, &conf_verify_string}, {"port", false, &conf_verify_int}, {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, - {NULL, false, NULL}, - }, + {NULL, false, NULL} + }; + + return conf_verify_dict(chain, node, attrs); +} + +const struct module_info plugin_info = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, }; diff --git a/modules/network.c b/modules/network.c index 6761226..7df8233 100644 --- a/modules/network.c +++ b/modules/network.c @@ -543,12 +543,20 @@ from_conf(const struct yml_node *node, const struct font *parent_font) yml_value_as_string(name), conf_to_particle(content, parent_font)); } -const struct module_info plugin_info = { - .from_conf = &from_conf, - .attrs = { +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) +{ + static const struct attr_info attrs[] = { {"name", true, &conf_verify_string}, {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, - {NULL, false, NULL}, - }, + {NULL, false, NULL} + }; + + return conf_verify_dict(chain, node, attrs); +} + +const struct module_info plugin_info = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, }; diff --git a/modules/removables.c b/modules/removables.c index 5cf7dc9..a788541 100644 --- a/modules/removables.c +++ b/modules/removables.c @@ -577,14 +577,22 @@ from_conf(const struct yml_node *node, const struct font *parent_font) conf_to_particle(content, parent_font), left, right); } -const struct module_info plugin_info = { - .from_conf = &from_conf, - .attrs = { +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) +{ + static const struct attr_info attrs[] = { {"spacing", false, &conf_verify_int}, {"left-spacing", false, &conf_verify_int}, {"right-spacing", false, &conf_verify_int}, {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, - {NULL, false, NULL}, - }, + {NULL, false, NULL} + }; + + return conf_verify_dict(chain, node, attrs); +} + +const struct module_info plugin_info = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, }; diff --git a/modules/xkb.c b/modules/xkb.c index 1a00399..a373801 100644 --- a/modules/xkb.c +++ b/modules/xkb.c @@ -459,11 +459,19 @@ from_conf(const struct yml_node *node, const struct font *parent_font) return xkb_new(conf_to_particle(c, parent_font)); } -const struct module_info plugin_info = { - .from_conf = &from_conf, - .attrs = { +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) +{ + static const struct attr_info attrs[] = { {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, - {NULL, false, NULL}, - }, + {NULL, false, NULL} + }; + + return conf_verify_dict(chain, node, attrs); +} + +const struct module_info plugin_info = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, }; diff --git a/modules/xwindow.c b/modules/xwindow.c index 6400a1e..c91908d 100644 --- a/modules/xwindow.c +++ b/modules/xwindow.c @@ -321,11 +321,19 @@ from_conf(const struct yml_node *node, const struct font *parent_font) return xwindow_new(conf_to_particle(c, parent_font)); } -const struct module_info plugin_info = { - .from_conf = &from_conf, - .attrs = { +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) +{ + static const struct attr_info attrs[] = { {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, - {NULL, false, NULL}, - }, + {NULL, false, NULL} + }; + + return conf_verify_dict(chain, node, attrs); +} + +const struct module_info plugin_info = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, };