const char *dm_basename(const char *path);
/*
- * Count occurences of 'c' in 'str' of length 'size'.
- *
- * Returns:
- * Number of occurrences of 'c'
+ * Returns number of occurrences of 'c' in 'str' of length 'size'.
*/
unsigned dm_count_chars(const char *str, size_t len, const int c);
const void *sortvalue);
-/*********************************
- * config file parse/prettyprint
- *********************************/
+/*************************
+ * config file parse/print
+ *************************/
+// FIXME AGK Review this interface before inclusion in a release.
enum {
DM_CFG_STRING,
DM_CFG_FLOAT,
int type;
union {
int64_t i;
- float r;
+ float f;
+ double d; /* For completeness. (Unused.) */
const char *str;
} v;
- struct dm_config_value *next; /* for arrays */
+ struct dm_config_value *next; /* For arrays */
};
struct dm_config_node {
int dm_config_find_int(const struct dm_config_node *cn, const char *path, int fail);
float dm_config_find_float(const struct dm_config_node *cn, const char *path, float fail);
-const struct dm_config_node *dm_config_tree_find_node(
- const struct dm_config_tree *cft, const char *path);
+const struct dm_config_node *dm_config_tree_find_node(const struct dm_config_tree *cft, const char *path);
const char *dm_config_tree_find_str(const struct dm_config_tree *cft,
const char *path, const char *fail);
int dm_config_tree_find_int(const struct dm_config_tree *cft,
off_t st_size;
char *filename;
int exists;
- int keep_open;
+ int keep_open; // FIXME AGK Remove this before release
void *custom; /* LVM uses this for a device pointer */
};
void dm_config_set_custom(struct dm_config_tree *cft, void *custom)
{
struct cs *c = (struct cs *) cft;
+
c->custom = custom;
}
void *dm_config_get_custom(struct dm_config_tree *cft)
{
struct cs *c = (struct cs *) cft;
+
return c->custom;
}
int dm_config_keep_open(struct dm_config_tree *cft)
{
struct cs *c = (struct cs *) cft;
+
return c->keep_open;
}
time_t dm_config_timestamp(struct dm_config_tree *cft)
{
struct cs *c = (struct cs *) cft;
+
return c->timestamp;
}
break;
case DM_CFG_FLOAT:
- line_append("%f", v->v.r);
+ line_append("%f", v->v.f);
break;
case DM_CFG_INT:
outline.fp = NULL;
outline.putline = NULL;
+// FIXME AGK remove the fopen from libdm before release
if (!file)
file = "stdout";
else if (!(outline.fp = fopen(file, "w"))) {
case TOK_FLOAT:
v->type = DM_CFG_FLOAT;
- v->v.r = strtod(p->tb, NULL); /* FIXME: check error */
+ v->v.f = strtod(p->tb, NULL); /* FIXME: check error */
match(TOK_FLOAT);
break;
}
/*
- * utility functions
+ * Utility functions
+ */
+
+/*
+ * node_lookup_fn is either:
+ * _find_config_node to perform a lookup starting from a given config_node
+ * in a config_tree;
+ * or
+ * _find_first_config_node to find the first config_node in a set of
+ * cascaded trees.
*/
+typedef const struct dm_config_node *node_lookup_fn(const void *start, const char *path);
+
static const struct dm_config_node *_find_config_node(const void *start,
const char *path)
{
return cn_found;
}
-typedef const struct dm_config_node *_node_lookup_fn(const void *start, const char *path);
-
static const struct dm_config_node *_find_first_config_node(const void *start, const char *path)
{
const struct dm_config_tree *cft = start;
return NULL;
}
-static const char *_find_config_str(const void *start, _node_lookup_fn find,
+static const char *_find_config_str(const void *start, node_lookup_fn find_fn,
const char *path, const char *fail)
{
- const struct dm_config_node *n = find(start, path);
+ const struct dm_config_node *n = find_fn(start, path);
/* Empty strings are ignored */
if ((n && n->v && n->v->type == DM_CFG_STRING) && (*n->v->v.str)) {
return _find_config_str(cn, _find_config_node, path, fail);
}
-static int64_t _find_config_int64(const void *start, _node_lookup_fn find,
+static int64_t _find_config_int64(const void *start, node_lookup_fn find,
const char *path, int64_t fail)
{
const struct dm_config_node *n = find(start, path);
return fail;
}
-static float _find_config_float(const void *start, _node_lookup_fn find,
+static float _find_config_float(const void *start, node_lookup_fn find,
const char *path, float fail)
{
const struct dm_config_node *n = find(start, path);
if (n && n->v && n->v->type == DM_CFG_FLOAT) {
- log_very_verbose("Setting %s to %f", path, n->v->v.r);
- return n->v->v.r;
+ log_very_verbose("Setting %s to %f", path, n->v->v.f);
+ return n->v->v.f;
}
log_very_verbose("%s not found in config: defaulting to %f",
return fail;
}
-static int _find_config_bool(const void *start, _node_lookup_fn find,
+static int _find_config_bool(const void *start, node_lookup_fn find,
const char *path, int fail)
{
const struct dm_config_node *n = find(start, path);