config: conf_verify_dict() now assumes attr list is NULL-terminated

This commit is contained in:
Daniel Eklöf 2019-01-13 11:37:05 +01:00
parent 2df419efc2
commit 71515e4079
21 changed files with 22 additions and 34 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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[];
};

View file

@ -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},

View file

@ -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},

View file

@ -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},

View file

@ -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},

View file

@ -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},

View file

@ -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},

View file

@ -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},

View file

@ -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},

View file

@ -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},

View file

@ -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},

View file

@ -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},

View file

@ -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

View file

@ -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,
},

View file

@ -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},

View file

@ -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},

View file

@ -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},

View file

@ -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},

View file

@ -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},