static int64_t _find_config_int64(const struct config_node *cn1, const struct config_node *cn2, const char *path, int64_t fail) { const struct config_node *n = _find_first_config_node(cn1, cn2, path); if (n && n->v && n->v->type == CFG_INT) { log_very_verbose("Setting %s to %" PRId64, path, n->v->v.i); return n->v->v.i; } log_very_verbose("%s not found in config: defaulting to %" PRId64, path, fail); return fail; }
static const char *_find_config_str(const struct config_node *cn1, const struct config_node *cn2, const char *path, const char *fail) { const struct config_node *n = _find_first_config_node(cn1, cn2, path); /* Empty strings are ignored */ if ((n && n->v && n->v->type == CFG_STRING) && (*n->v->v.str)) { log_very_verbose("Setting %s to %s", path, n->v->v.str); return n->v->v.str; } if (fail) log_very_verbose("%s not found in config: defaulting to %s", path, fail); return fail; }
static float _find_config_float(const struct config_node *cn1, const struct config_node *cn2, const char *path, float fail) { const struct config_node *n = _find_first_config_node(cn1, cn2, path); if (n && n->v && n->v->type == CFG_FLOAT) { log_very_verbose("Setting %s to %f", path, n->v->v.r); return n->v->v.r; } log_very_verbose("%s not found in config: defaulting to %f", path, fail); return fail; }
static int _find_config_bool(const struct config_node *cn1, const struct config_node *cn2, const char *path, int fail) { const struct config_node *n = _find_first_config_node(cn1, cn2, path); const struct config_value *v; if (!n) return fail; v = n->v; switch (v->type) { case CFG_INT: return v->v.i ? 1 : 0; case CFG_STRING: return _str_to_bool(v->v.str, fail); } return fail; }
const struct config_node *find_config_tree_node(struct cmd_context *cmd, const char *path) { return _find_first_config_node(cmd->cft_override ? cmd->cft_override->root : NULL, cmd->cft->root, path); }
const struct dm_config_node *dm_config_tree_find_node(const struct dm_config_tree *cft, const char *path) { return _find_first_config_node(cft, path); }