Mercurial > hg > th-libs
diff th_config.h @ 10:a25f5d22483e
Updates.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 20 Apr 2009 00:01:43 +0300 |
parents | 5a327a2988fa |
children | e467b3586e4d |
line wrap: on
line diff
--- a/th_config.h Tue Feb 10 06:53:46 2009 +0200 +++ b/th_config.h Mon Apr 20 00:01:43 2009 +0300 @@ -1,5 +1,5 @@ /* - * Very simple configuration file parsing functions + * Very simple configuration file handling * Programmed and designed by Matti 'ccr' Hamalainen * (C) Copyright 2004-2008 Tecnic Software productions (TNSP) * @@ -15,46 +15,43 @@ #include "th_util.h" #include <stdio.h> -/* - * Type definations + +/* Definitions */ enum ITEM_TYPE { - ITEM_BLOCK = 1, - ITEM_STRING, - ITEM_INT, - ITEM_UINT, - ITEM_BOOL + ITEM_BLOCK = 1, + ITEM_STRING, + ITEM_INT, + ITEM_UINT, + ITEM_BOOL, + ITEM_FLOAT }; -typedef struct _th_cfgitem_t { - char *itemName; /* Config item name */ - int itemType; /* Type of the item */ - void *itemData; /* Data / value */ +typedef struct _cfgitem_t { + char *name; /* Config item name */ + int type; /* Type of the item */ + void *data; /* Data / value */ - BOOL (*itemValidate)(struct _th_cfgitem_t *); + BOOL (*validate)(struct _cfgitem_t *); - struct _th_cfgitem_t *next, *prev; -} th_cfgitem_t; + struct _cfgitem_t *next, *prev; +} cfgitem_t; -typedef struct { - th_cfgitem_t *items; -} th_config_t; - - -/* - * Functions +/* Functions */ -th_config_t * th_config_new(void); -int th_config_read(char *, th_config_t *); -void th_config_free(th_config_t *); -int th_config_write(FILE *, th_config_t *); +cfgitem_t * th_config_new(void); +int th_config_read(char *, cfgitem_t **); +void th_config_free(cfgitem_t *); +int th_config_write(FILE *, cfgitem_t *); -int th_config_add_int(th_config_t *cfg, char *itemName, BOOL (*itemValidate)(th_cfgitem_t *), int *itemData, int itemDef); -int th_config_add_uint(th_config_t *cfg, char *itemName, BOOL (*itemValidate)(th_cfgitem_t *), unsigned int *itemData, unsigned int itemDef); -int th_config_add_str(th_config_t *cfg, char *itemName, BOOL (*itemValidate)(th_cfgitem_t *), char **itemData, char *itemDef); -int th_config_add_bool(th_config_t *cfg, char *itemName, BOOL (*itemValidate)(th_cfgitem_t *), BOOL *itemData, BOOL itemDef); +int th_config_add_block(cfgitem_t *cfg, char *name, BOOL (*validate)(cfgitem_t *)); +int th_config_add_int(cfgitem_t *cfg, char *name, BOOL (*validate)(cfgitem_t *), int *data, int itemDef); +int th_config_add_uint(cfgitem_t *cfg, char *name, BOOL (*validate)(cfgitem_t *), unsigned int *data, unsigned int itemDef); +int th_config_add_str(cfgitem_t *cfg, char *name, BOOL (*validate)(cfgitem_t *), char **data, char *itemDef); +int th_config_add_bool(cfgitem_t *cfg, char *name, BOOL (*validate)(cfgitem_t *), BOOL *data, BOOL itemDef); +int th_config_add_float(cfgitem_t *cfg, char *name, BOOL (*validate)(cfgitem_t *), float *data, float itemDef); #ifdef __cplusplus }