forked from external/yambar
config: conf_verify_dict() now assumes attr list is NULL-terminated
This commit is contained in:
parent
2df419efc2
commit
71515e4079
21 changed files with 22 additions and 34 deletions
|
@ -73,13 +73,18 @@ conf_verify_enum(keychain_t *chain, const struct yml_node *node,
|
||||||
|
|
||||||
bool
|
bool
|
||||||
conf_verify_dict(keychain_t *chain, const struct yml_node *node,
|
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)) {
|
if (!yml_is_dict(node)) {
|
||||||
LOG_ERR("%s: must be a dictionary", conf_err_prefix(chain, node));
|
LOG_ERR("%s: must be a dictionary", conf_err_prefix(chain, node));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Count the attributes */
|
||||||
|
size_t count = 0;
|
||||||
|
for (; info[count].name != NULL; count++)
|
||||||
|
;
|
||||||
|
|
||||||
bool exists[count];
|
bool exists[count];
|
||||||
memset(exists, 0, sizeof(exists));
|
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[] = {
|
static const struct attr_info attrs[] = {
|
||||||
{"family", true, &conf_verify_string},
|
{"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
|
static bool
|
||||||
|
@ -206,11 +212,13 @@ conf_verify_decoration(keychain_t *chain, const struct yml_node *node)
|
||||||
|
|
||||||
static const struct attr_info background[] = {
|
static const struct attr_info background[] = {
|
||||||
{"color", true, &conf_verify_color},
|
{"color", true, &conf_verify_color},
|
||||||
|
{NULL, false, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct attr_info underline[] = {
|
static const struct attr_info underline[] = {
|
||||||
{"size", true, &conf_verify_int},
|
{"size", true, &conf_verify_int},
|
||||||
{"color", true, &conf_verify_color},
|
{"color", true, &conf_verify_color},
|
||||||
|
{NULL, false, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct {
|
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)
|
if (strcmp(decos[i].name, deco_name) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!conf_verify_dict(chain_push(chain, deco_name),
|
chain_push(chain, deco_name);
|
||||||
values, decos[i].attrs, decos[i].count))
|
if (!conf_verify_dict(chain, values, decos[i].attrs))
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
chain_pop(chain);
|
chain_pop(chain);
|
||||||
return true;
|
return true;
|
||||||
|
@ -286,8 +292,8 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!conf_verify_dict(chain_push(chain, particle_name), values,
|
chain_push(chain, particle_name);
|
||||||
info->attrs, info->attr_count))
|
if (!conf_verify_dict(chain, values, info->attrs))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
chain_pop(chain);
|
chain_pop(chain);
|
||||||
|
@ -335,8 +341,8 @@ verify_module(keychain_t *chain, const struct yml_node *node)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!conf_verify_dict(chain_push(chain, mod_name), values,
|
chain_push(chain, mod_name);
|
||||||
info->attrs, info->attr_count))
|
if (!conf_verify_dict(chain, values, info->attrs))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
chain_pop(chain);
|
chain_pop(chain);
|
||||||
|
@ -368,9 +374,10 @@ verify_bar_border(keychain_t *chain, const struct yml_node *node)
|
||||||
static const struct attr_info attrs[] = {
|
static const struct attr_info attrs[] = {
|
||||||
{"width", true, &conf_verify_int},
|
{"width", true, &conf_verify_int},
|
||||||
{"color", true, &conf_verify_color},
|
{"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
|
static bool
|
||||||
|
@ -409,9 +416,11 @@ conf_verify_bar(const struct yml_node *bar)
|
||||||
{"left", false, &verify_module_list},
|
{"left", false, &verify_module_list},
|
||||||
{"center", false, &verify_module_list},
|
{"center", false, &verify_module_list},
|
||||||
{"right", 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);
|
tll_free(chain);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
bool conf_verify_enum(keychain_t *chain, const struct yml_node *node,
|
||||||
const char *values[], size_t count);
|
const char *values[], size_t count);
|
||||||
bool conf_verify_dict(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[]); /* NULL-terminated list */
|
||||||
|
|
||||||
bool conf_verify_color(keychain_t *chain, const struct yml_node *node);
|
bool conf_verify_color(keychain_t *chain, const struct yml_node *node);
|
||||||
bool conf_verify_font(keychain_t *chain, const struct yml_node *node);
|
bool conf_verify_font(keychain_t *chain, const struct yml_node *node);
|
||||||
|
|
2
module.h
2
module.h
|
@ -14,8 +14,6 @@ struct module;
|
||||||
struct module_info {
|
struct module_info {
|
||||||
struct module *(*from_conf)(const struct yml_node *node,
|
struct module *(*from_conf)(const struct yml_node *node,
|
||||||
const struct font *parent_font);
|
const struct font *parent_font);
|
||||||
|
|
||||||
size_t attr_count; /* TODO: remove, NULL-terminate attr list instead */
|
|
||||||
const struct attr_info attrs[];
|
const struct attr_info attrs[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -282,7 +282,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
const struct module_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = 4,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"card", true, &conf_verify_string},
|
{"card", true, &conf_verify_string},
|
||||||
{"mixer", true, &conf_verify_string},
|
{"mixer", true, &conf_verify_string},
|
||||||
|
|
|
@ -226,7 +226,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
const struct module_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = 3,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"name", true, &conf_verify_string},
|
{"name", true, &conf_verify_string},
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
|
|
|
@ -358,7 +358,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
const struct module_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = 4,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"name", true, &conf_verify_string},
|
{"name", true, &conf_verify_string},
|
||||||
{"poll-interval", false, &conf_verify_int},
|
{"poll-interval", false, &conf_verify_int},
|
||||||
|
|
|
@ -109,7 +109,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
const struct module_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = 4,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"date-format", false, &conf_verify_string},
|
{"date-format", false, &conf_verify_string},
|
||||||
{"time-format", false, &conf_verify_string},
|
{"time-format", false, &conf_verify_string},
|
||||||
|
|
|
@ -703,7 +703,6 @@ verify_content(keychain_t *chain, const struct yml_node *node)
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
const struct module_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = 5,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"spacing", false, &conf_verify_int},
|
{"spacing", false, &conf_verify_int},
|
||||||
{"left-spacing", false, &conf_verify_int},
|
{"left-spacing", false, &conf_verify_int},
|
||||||
|
|
|
@ -55,7 +55,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
const struct module_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = 2,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"anchors", false, NULL},
|
||||||
|
|
|
@ -493,7 +493,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
const struct module_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = 4,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"host", true, &conf_verify_string},
|
{"host", true, &conf_verify_string},
|
||||||
{"port", false, &conf_verify_int},
|
{"port", false, &conf_verify_int},
|
||||||
|
|
|
@ -545,7 +545,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
const struct module_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = 3,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"name", true, &conf_verify_string},
|
{"name", true, &conf_verify_string},
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
|
|
|
@ -579,7 +579,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
const struct module_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = 5,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"spacing", false, &conf_verify_int},
|
{"spacing", false, &conf_verify_int},
|
||||||
{"left-spacing", false, &conf_verify_int},
|
{"left-spacing", false, &conf_verify_int},
|
||||||
|
|
|
@ -461,7 +461,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
const struct module_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = 2,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"anchors", false, NULL},
|
||||||
|
|
|
@ -323,7 +323,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||||
|
|
||||||
const struct module_info plugin_info = {
|
const struct module_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = 2,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"anchors", false, NULL},
|
||||||
|
|
|
@ -18,8 +18,6 @@ struct particle_info {
|
||||||
const struct font *parent_font,
|
const struct font *parent_font,
|
||||||
int left_margin, int right_margin,
|
int left_margin, int right_margin,
|
||||||
const char *on_click_template);
|
const char *on_click_template);
|
||||||
|
|
||||||
size_t attr_count; /* TODO: reomve, NULL-terminate attr list instead */
|
|
||||||
const struct attr_info attrs[];
|
const struct attr_info attrs[];
|
||||||
|
|
||||||
#define PARTICLE_COMMON_ATTRS_COUNT 5
|
#define PARTICLE_COMMON_ATTRS_COUNT 5
|
||||||
|
|
|
@ -50,7 +50,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
|
|
||||||
const struct particle_info plugin_info = {
|
const struct particle_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = PARTICLE_COMMON_ATTRS_COUNT + 0,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
PARTICLE_COMMON_ATTRS,
|
PARTICLE_COMMON_ATTRS,
|
||||||
},
|
},
|
||||||
|
|
|
@ -200,7 +200,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
|
|
||||||
const struct particle_info plugin_info = {
|
const struct particle_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = PARTICLE_COMMON_ATTRS_COUNT + 4,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"items", true, &conf_verify_particle_list_items},
|
{"items", true, &conf_verify_particle_list_items},
|
||||||
{"spacing", false, &conf_verify_int},
|
{"spacing", false, &conf_verify_int},
|
||||||
|
|
|
@ -230,7 +230,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
|
|
||||||
const struct particle_info plugin_info = {
|
const struct particle_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = PARTICLE_COMMON_ATTRS_COUNT + 3,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"tag", true, &conf_verify_string},
|
{"tag", true, &conf_verify_string},
|
||||||
{"values", true, &verify_map_values},
|
{"values", true, &verify_map_values},
|
||||||
|
|
|
@ -259,7 +259,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
|
|
||||||
const struct particle_info plugin_info = {
|
const struct particle_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = PARTICLE_COMMON_ATTRS_COUNT + 7,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"tag", true, &conf_verify_string},
|
{"tag", true, &conf_verify_string},
|
||||||
{"length", true, &conf_verify_int},
|
{"length", true, &conf_verify_int},
|
||||||
|
|
|
@ -180,7 +180,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
|
|
||||||
const struct particle_info plugin_info = {
|
const struct particle_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = PARTICLE_COMMON_ATTRS_COUNT + 2,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"tag", true, &conf_verify_string},
|
{"tag", true, &conf_verify_string},
|
||||||
{"items", true, &conf_verify_particle_list_items},
|
{"items", true, &conf_verify_particle_list_items},
|
||||||
|
|
|
@ -173,7 +173,6 @@ from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
|
|
||||||
const struct particle_info plugin_info = {
|
const struct particle_info plugin_info = {
|
||||||
.from_conf = &from_conf,
|
.from_conf = &from_conf,
|
||||||
.attr_count = PARTICLE_COMMON_ATTRS_COUNT + 4,
|
|
||||||
.attrs = {
|
.attrs = {
|
||||||
{"text", true, &conf_verify_string},
|
{"text", true, &conf_verify_string},
|
||||||
{"max", false, &conf_verify_int},
|
{"max", false, &conf_verify_int},
|
||||||
|
|
Loading…
Add table
Reference in a new issue