view th_config.h @ 349:8662c07455be

Added tag dev-0_9_6 for changeset f3572f4f73d1
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 23 Jun 2011 01:37:43 +0300
parents 0db02b8d2d11
children
line wrap: on
line source

/*
 * Very simple configuration file handling
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2004-2008 Tecnic Software productions (TNSP)
 *
 * Please read file 'COPYING' for information on license and distribution.
 */
#ifndef _TH_CONFIG_H
#define _TH_CONFIG_H

#ifdef __cplusplus
extern "C" {
#endif

#include "th_util.h"
#include <stdio.h>


/* 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 _cfgitem_t {
    int  type;
    char *name;
    union {
        int *val_int;
        unsigned int *val_uint;
        char **val_str;
        BOOL *val_bool;

        void *data;
        qlist_t **list;
        struct _cfgitem_t *section;
    } v;
    
    struct _cfgitem_t *next, *prev;
} cfgitem_t;


/* Functions
 */
int     th_cfg_read(FILE *, char *, cfgitem_t *);
void    th_cfg_free(cfgitem_t *);
int     th_cfg_write(FILE *, char *, cfgitem_t *);

int     th_cfg_add_section(cfgitem_t **cfg, char *name, cfgitem_t *data);
int     th_cfg_add_comment(cfgitem_t **cfg, char *comment);
int     th_cfg_add_int(cfgitem_t **cfg, char *name, int *data, int itemDef);
int     th_cfg_add_uint(cfgitem_t **cfg, char *name, unsigned int *data, unsigned int itemDef);
int     th_cfg_add_string(cfgitem_t **cfg, char *name, char **data, char *itemDef);
int     th_cfg_add_bool(cfgitem_t **cfg, char *name, BOOL *data, BOOL itemDef);
int     th_cfg_add_float(cfgitem_t **cfg, char *name, float *data, float itemDef);
int     th_cfg_add_hexvalue(cfgitem_t **cfg, char *name, int *data, int itemDef);

int     th_cfg_add_string_list(cfgitem_t **cfg, char *name, qlist_t **list);

#ifdef __cplusplus
}
#endif
#endif /* _TH_CONFIG_H */