diff --git a/src/cw/cfg.c b/src/cw/cfg.c index 2eac81a7..4dc70d57 100644 --- a/src/cw/cfg.c +++ b/src/cw/cfg.c @@ -80,7 +80,13 @@ static void del(void *ptr) free((void *) e->val); } - +/** + * Create an empty cfg + * @return A pointer to the cfg or NULL if an error has accoured. + * + * In case of an error consult errno to find out the reason. + * The created config must be freed by #cw_cfg_destroy. + */ cw_Cfg_t *cw_cfg_create() { cw_Cfg_t * cfg; @@ -88,6 +94,7 @@ cw_Cfg_t *cw_cfg_create() if (cfg == NULL) return NULL; memset(cfg,0,sizeof(cw_Cfg_t)); + cfg->name = CW_CFG_DEFAULT_NAME; cfg->cfg = mavl_create(cmp, del, sizeof(struct cw_Cfg_entry)); if (cfg->cfg==NULL){ cw_cfg_destroy(cfg); @@ -682,7 +689,6 @@ void cw_cfg_set_int(cw_Cfg_t * cfg, const char * key, int val) } - int cw_cfg_get_next_index(cw_Cfg_t * cfg, const char *key) { char ikey[CW_CFG_MAX_KEY_LEN]; diff --git a/src/cw/cfg.h b/src/cw/cfg.h index 7d4e7688..b9f9a609 100644 --- a/src/cw/cfg.h +++ b/src/cw/cfg.h @@ -5,28 +5,53 @@ #include "val.h" #include "bstr.h" -#define CW_CFG_MAX_KEY_LEN 1024 +/** + *@file + *@brief + *@defgroup CFG SOCK + *@{ + */ + + +/** Maximum size of a key used in cfg objects */ +#define CW_CFG_MAX_KEY_LEN 1024 + +/** Default name for fresh cfg's created by #cw_cfg_create */ +#define CW_CFG_DEFAULT_NAME "[anonymous]" + + +/** + * A Cfg object + */ struct cw_Cfg { - struct mavl * cfg; - const char *name; + struct mavl * cfg; /**< The AVL-tree containig the keys + and vals */ + const char *name; /**< A name for this config object */ int dbg_level; const char *dbg_prefix; }; typedef struct cw_Cfg cw_Cfg_t; + +/** + * An antry for a Cfg object + */ +struct cw_Cfg_entry{ + const char *key; /**< A string representing the key + of this entry */ + const char *val; /**< The value, represented by a string */ +}; + + + cw_Cfg_t * cw_cfg_create(); int cw_cfg_set(cw_Cfg_t *cfg,const char *key, const char *val); void cw_cfg_dump(cw_Cfg_t *cfg); int cw_cfg_read_from_file(FILE * file, cw_Cfg_t * cfg); int cw_cfg_load(const char *filename,cw_Cfg_t * cfg); -struct cw_Cfg_entry{ - const char *key; - const char *val; -}; - struct cw_Cfg_iter{ struct mavliter it; @@ -74,3 +99,6 @@ int cw_cfg_set_val(cw_Cfg_t * cfg, const char *key, const struct cw_Type *t, con #endif + +/**@}*/ +