comparison th_config.h @ 0:bd61a80a6c54

Initial import into Mercurial repository. Discarding old cvs/svn history here, because it's cluttered and commit messages are mostly crap.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 26 Mar 2008 04:41:58 +0200
parents
children 5a327a2988fa
comparison
equal deleted inserted replaced
-1:000000000000 0:bd61a80a6c54
1 /*
2 * Very simple configuration file parsing functions
3 * Programmed and designed by Matti 'ccr' Hamalainen
4 * (C) Copyright 2004-2007 Tecnic Software productions (TNSP)
5 *
6 * Please read file 'COPYING' for information on license and distribution.
7 */
8 #ifndef _TH_CONFIG_H
9 #define _TH_CONFIG_H
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 #include "th_util.h"
16 #include <stdio.h>
17
18 /*
19 * Type definations
20 */
21 enum ITEM_TYPE {
22 ITEM_BLOCK = 1,
23 ITEM_STRING,
24 ITEM_INT,
25 ITEM_UINT,
26 ITEM_BOOL
27 };
28
29
30 typedef struct tconfignode {
31 char *itemName; /* Config item name */
32 int itemType; /* Type of the item */
33 void *itemData; /* Data / value */
34
35 BOOL (*itemValidate)(struct tconfignode *);
36
37 struct tconfignode *pNext, *pPrev;
38 } t_config_item;
39
40
41 typedef struct {
42 t_config_item *pItems;
43 } t_config;
44
45
46 /*
47 * Functions
48 */
49 t_config * th_config_new(void);
50 int th_config_read(char *, t_config *);
51 void th_config_free(t_config *);
52 int th_config_write(FILE *, t_config *);
53
54 int th_config_add_int(t_config *cfg, char *itemName, BOOL (*itemValidate)(t_config_item *), int *itemData, int itemDef);
55 int th_config_add_uint(t_config *cfg, char *itemName, BOOL (*itemValidate)(t_config_item *), unsigned int *itemData, unsigned int itemDef);
56 int th_config_add_str(t_config *cfg, char *itemName, BOOL (*itemValidate)(t_config_item *), char **itemData, char *itemDef);
57 int th_config_add_bool(t_config *cfg, char *itemName, BOOL (*itemValidate)(t_config_item *), BOOL *itemData, BOOL itemDef);
58
59 #ifdef __cplusplus
60 }
61 #endif
62 #endif /* _TH_CONFIG_H */