Mercurial > hg > th-libs
view th_config.h @ 638:c4bca120bfb0
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 21 Jan 2020 12:23:59 +0200 |
parents | 893b2deeb5be |
children | 1092eb33bd59 |
line wrap: on
line source
/* * Very simple configuration file handling * Programmed and designed by Matti 'ccr' Hamalainen * (C) Copyright 2004-2020 Tecnic Software productions (TNSP) * * Please read file 'COPYING' for information on license and distribution. */ /// @file /// @brief Configuration file handling functionality. #ifndef TH_CONFIG_H #define TH_CONFIG_H #include "th_datastruct.h" #include "th_ioctx.h" #ifdef __cplusplus extern "C" { #endif // // Definitions // enum ITEM_TYPE { ITEM_SECTION = 1, ITEM_COMMENT, ITEM_STRING, ITEM_INT, ITEM_UINT, ITEM_BOOL, ITEM_FLOAT, ITEM_HEX_TRIPLET, ITEM_STRING_LIST, ITEM_HEX_TRIPLET_LIST }; typedef struct _th_cfgitem_t { // th_llist_t must be the first item, as this // is used to alias th_cfgitem_t to llist nodes th_llist_t node; int type; char *name; union { int *val_int; unsigned int *val_uint; char **val_str; BOOL *val_bool; float *val_float; void *data; th_llist_t **list; struct _th_cfgitem_t *section; } v; } th_cfgitem_t; // // Functions // int th_cfg_read(th_ioctx *fh, th_cfgitem_t *cfg /*, TODO XXX const int flags (for controlling things like "error out on unknown items or ignore" etc */); void th_cfg_free(th_cfgitem_t *cfg); int th_cfg_write(th_ioctx *fh, const th_cfgitem_t *cfg); int th_cfg_add_comment(th_cfgitem_t **cfg, const char *comment); int th_cfg_add_section(th_cfgitem_t **cfg, const char *name, th_cfgitem_t *sect); int th_cfg_add_int(th_cfgitem_t **cfg, const char *name, int *data, int defValue); int th_cfg_add_uint(th_cfgitem_t **cfg, const char *name, unsigned int *data, unsigned int defValue); int th_cfg_add_float(th_cfgitem_t **cfg, const char *name, float *data, float defValue); int th_cfg_add_string(th_cfgitem_t **cfg, const char *name, char **data, char *defValue); int th_cfg_add_bool(th_cfgitem_t **cfg, const char *name, BOOL *data, BOOL defValue); int th_cfg_add_float(th_cfgitem_t **cfg, const char *name, float *data, float defValue); int th_cfg_add_hexvalue(th_cfgitem_t **cfg, const char *name, unsigned int *data, unsigned int defValue); int th_cfg_add_string_list(th_cfgitem_t **cfg, const char *name, th_llist_t **list); th_cfgitem_t *th_cfg_find(th_cfgitem_t *cfg, const char *section, const char *name, const int type); #ifdef __cplusplus } #endif #endif // TH_CONFIG_H