view th_config.h @ 789:d61d3eb29053 default tip

Bump copyright.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 08 Mar 2024 15:26:24 +0200
parents 4cc514343376
children
line wrap: on
line source

/*
 * Very simple configuration file handling
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2004-2022 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 CFG_ITEM_TYPE
{
    CFG_ITEM_SECTION = 1,
    CFG_ITEM_COMMENT,

    CFG_ITEM_STRING,
    CFG_ITEM_INT,
    CFG_ITEM_UINT,
    CFG_ITEM_BOOL,
    CFG_ITEM_FLOAT,
    CFG_ITEM_HEX_TRIPLET,

    CFG_ITEM_STRING_LIST,
    CFG_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_t *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, void (*freefunc)(th_cfgitem_t *));
int        th_cfg_write(th_ioctx_t *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);
th_cfgitem_t * th_cfg_item_find(th_cfgitem_t *cfg, const char *section, const char *name, const int type);

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_hex_triplet(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);


#ifdef __cplusplus
}
#endif
#endif // TH_CONFIG_H