config: verify: break out err_prefix(), and rename

This commit is contained in:
Daniel Eklöf 2019-01-12 12:11:59 +01:00
parent 550d4ad534
commit d2af5b2c84
2 changed files with 30 additions and 27 deletions

View file

@ -13,8 +13,8 @@
#include "modules/battery/battery.h"
#include "modules/clock/clock.h"
static const char *
err_prefix(const keychain_t *chain, const struct yml_node *node)
const char *
conf_err_prefix(const keychain_t *chain, const struct yml_node *node)
{
static char msg[4096];
int idx = 0;
@ -35,7 +35,7 @@ conf_verify_string(keychain_t *chain, const struct yml_node *node)
{
const char *s = yml_value_as_string(node);
if (s == NULL) {
LOG_ERR("%s: value must be a string", err_prefix(chain, node));
LOG_ERR("%s: value must be a string", conf_err_prefix(chain, node));
return false;
}
@ -49,7 +49,7 @@ conf_verify_int(keychain_t *chain, const struct yml_node *node)
return true;
LOG_ERR("%s: value is not an integer: '%s'",
err_prefix(chain, node), yml_value_as_string(node));
conf_err_prefix(chain, node), yml_value_as_string(node));
return false;
}
@ -59,7 +59,7 @@ conf_verify_enum(keychain_t *chain, const struct yml_node *node,
{
const char *s = yml_value_as_string(node);
if (s == NULL) {
LOG_ERR("%s: value must be a string", err_prefix(chain, node));
LOG_ERR("%s: value must be a string", conf_err_prefix(chain, node));
return false;
}
@ -68,7 +68,7 @@ conf_verify_enum(keychain_t *chain, const struct yml_node *node,
return true;
}
LOG_ERR("%s: value must be one of:", err_prefix(chain, node));
LOG_ERR("%s: value must be one of:", conf_err_prefix(chain, node));
for (size_t i = 0; i < count; i++)
LOG_ERR(" %s", values[i]);
@ -80,7 +80,7 @@ conf_verify_dict(keychain_t *chain, const struct yml_node *node,
const struct attr_info info[], size_t count)
{
if (!yml_is_dict(node)) {
LOG_ERR("%s: must be a dictionary", err_prefix(chain, node));
LOG_ERR("%s: must be a dictionary", conf_err_prefix(chain, node));
return false;
}
@ -93,7 +93,7 @@ conf_verify_dict(keychain_t *chain, const struct yml_node *node,
{
const char *key = yml_value_as_string(it.key);
if (key == NULL) {
LOG_ERR("%s: key must be a string", err_prefix(chain, it.key));
LOG_ERR("%s: key must be a string", conf_err_prefix(chain, it.key));
return false;
}
@ -107,7 +107,7 @@ conf_verify_dict(keychain_t *chain, const struct yml_node *node,
}
if (attr == NULL) {
LOG_ERR("%s: invalid key: %s", err_prefix(chain, it.key), key);
LOG_ERR("%s: invalid key: %s", conf_err_prefix(chain, it.key), key);
return false;
}
@ -123,7 +123,7 @@ conf_verify_dict(keychain_t *chain, const struct yml_node *node,
if (!info[i].required || exists[i])
continue;
LOG_ERR("%s: missing required key: %s", err_prefix(chain, node), info[i].name);
LOG_ERR("%s: missing required key: %s", conf_err_prefix(chain, node), info[i].name);
return false;
}
@ -135,7 +135,7 @@ conf_verify_color(keychain_t *chain, const struct yml_node *node)
{
const char *s = yml_value_as_string(node);
if (s == NULL) {
LOG_ERR("%s: value must be a string", err_prefix(chain, node));
LOG_ERR("%s: value must be a string", conf_err_prefix(chain, node));
return false;
}
@ -144,7 +144,7 @@ conf_verify_color(keychain_t *chain, const struct yml_node *node)
if (strlen(s) != 8 || v != 4) {
LOG_ERR("%s: value must be a color ('rrggbbaa', e.g ff00ffff)",
err_prefix(chain, node));
conf_err_prefix(chain, node));
return false;
}
@ -168,7 +168,7 @@ static bool
verify_decoration_stack(keychain_t *chain, const struct yml_node *node)
{
if (!yml_is_list(node)) {
LOG_ERR("%s: must be a list of decorations", err_prefix(chain, node));
LOG_ERR("%s: must be a list of decorations", conf_err_prefix(chain, node));
return false;
}
@ -190,7 +190,7 @@ verify_decoration(keychain_t *chain, const struct yml_node *node)
if (yml_dict_length(node) != 1) {
LOG_ERR("%s: decoration must be a dictionary with a single key; "
"the name of the particle", err_prefix(chain, node));
"the name of the particle", conf_err_prefix(chain, node));
return false;
}
@ -200,7 +200,7 @@ verify_decoration(keychain_t *chain, const struct yml_node *node)
const char *deco_name = yml_value_as_string(deco);
if (deco_name == NULL) {
LOG_ERR("%s: decoration name must be a string", err_prefix(chain, deco));
LOG_ERR("%s: decoration name must be a string", conf_err_prefix(chain, deco));
return false;
}
@ -243,7 +243,7 @@ verify_decoration(keychain_t *chain, const struct yml_node *node)
}
LOG_ERR(
"%s: invalid decoration name: %s", err_prefix(chain, deco), deco_name);
"%s: invalid decoration name: %s", conf_err_prefix(chain, deco), deco_name);
return false;
}
@ -269,7 +269,7 @@ verify_map_values(keychain_t *chain, const struct yml_node *node)
if (!yml_is_dict(node)) {
LOG_ERR(
"%s: must be a dictionary of workspace-name: particle mappings",
err_prefix(chain, node));
conf_err_prefix(chain, node));
return false;
}
@ -279,8 +279,7 @@ verify_map_values(keychain_t *chain, const struct yml_node *node)
{
const char *key = yml_value_as_string(it.key);
if (key == NULL) {
LOG_ERR("%s: key must be a string (a i3 workspace name)",
err_prefix(chain, it.key));
LOG_ERR("%s: key must be a string", conf_err_prefix(chain, it.key));
return false;
}
@ -300,7 +299,7 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
if (yml_dict_length(node) != 1) {
LOG_ERR("%s: particle must be a dictionary with a single key; "
"the name of the particle", err_prefix(chain, node));
"the name of the particle", conf_err_prefix(chain, node));
return false;
}
@ -310,7 +309,7 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
const char *particle_name = yml_value_as_string(particle);
if (particle_name == NULL) {
LOG_ERR("%s: particle name must be a string", err_prefix(chain, particle));
LOG_ERR("%s: particle name must be a string", conf_err_prefix(chain, particle));
return false;
}
@ -396,7 +395,7 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
}
LOG_ERR(
"%s: invalid particle name: %s", err_prefix(chain, particle), particle_name);
"%s: invalid particle name: %s", conf_err_prefix(chain, particle), particle_name);
return false;
}
@ -409,7 +408,7 @@ conf_verify_particle(keychain_t *chain, const struct yml_node *node)
return verify_list_items(chain, node);
else {
LOG_ERR("%s: particle must be either a dictionary or a list",
err_prefix(chain, node));
conf_err_prefix(chain, node));
return false;
}
}
@ -449,7 +448,7 @@ verify_module(keychain_t *chain, const struct yml_node *node)
{
if (!yml_is_dict(node) || yml_dict_length(node) != 1) {
LOG_ERR("%s: module must be a dictionary with a single key; "
"the name of the module", err_prefix(chain, node));
"the name of the module", conf_err_prefix(chain, node));
return false;
}
@ -459,7 +458,7 @@ verify_module(keychain_t *chain, const struct yml_node *node)
const char *mod_name = yml_value_as_string(module);
if (mod_name == NULL) {
LOG_ERR("%s: module name must be a string", err_prefix(chain, module));
LOG_ERR("%s: module name must be a string", conf_err_prefix(chain, module));
return false;
}
@ -562,7 +561,7 @@ verify_module(keychain_t *chain, const struct yml_node *node)
return true;
}
LOG_ERR("%s: invalid module name: %s", err_prefix(chain, module), mod_name);
LOG_ERR("%s: invalid module name: %s", conf_err_prefix(chain, module), mod_name);
return false;
}
@ -570,7 +569,7 @@ static bool
verify_module_list(keychain_t *chain, const struct yml_node *node)
{
if (!yml_is_list(node)) {
LOG_ERR("%s: must be a list of modules", err_prefix(chain, node));
LOG_ERR("%s: must be a list of modules", conf_err_prefix(chain, node));
return false;
}

View file

@ -26,6 +26,10 @@ chain_pop(keychain_t *chain)
tll_pop_back(*chain);
}
const char *conf_err_prefix(
const keychain_t *chain, const struct yml_node *node);
bool conf_verify_string(keychain_t *chain, const struct yml_node *node);
bool conf_verify_int(keychain_t *chain, const struct yml_node *node);