Mercurial > hg > th-libs
annotate 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 |
rev | line source |
---|---|
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
10 | 2 * Very simple configuration file handling |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Programmed and designed by Matti 'ccr' Hamalainen |
726 | 4 * (C) Copyright 2004-2022 Tecnic Software productions (TNSP) |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * Please read file 'COPYING' for information on license and distribution. |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 */ |
622
6d99150a8f89
Some more slight Doxygenisation.
Matti Hamalainen <ccr@tnsp.org>
parents:
604
diff
changeset
|
8 /// @file |
6d99150a8f89
Some more slight Doxygenisation.
Matti Hamalainen <ccr@tnsp.org>
parents:
604
diff
changeset
|
9 /// @brief Configuration file handling functionality. |
49
598609fb49b0
Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
10 #ifndef TH_CONFIG_H |
598609fb49b0
Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
11 #define TH_CONFIG_H |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
270
6cfa9bc91ee6
Remember to include th_datastruct.h where needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
13 #include "th_datastruct.h" |
153
4cd94649475d
Move header includes before C++ guard.
Matti Hamalainen <ccr@tnsp.org>
parents:
152
diff
changeset
|
14 #include "th_ioctx.h" |
4cd94649475d
Move header includes before C++ guard.
Matti Hamalainen <ccr@tnsp.org>
parents:
152
diff
changeset
|
15 |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 #ifdef __cplusplus |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 extern "C" { |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 #endif |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 |
604 | 20 // |
21 // Definitions | |
22 // | |
774 | 23 enum CFG_ITEM_TYPE |
69 | 24 { |
774 | 25 CFG_ITEM_SECTION = 1, |
26 CFG_ITEM_COMMENT, | |
496
8c837a33cfb6
Add argument names to some function prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents:
457
diff
changeset
|
27 |
774 | 28 CFG_ITEM_STRING, |
29 CFG_ITEM_INT, | |
30 CFG_ITEM_UINT, | |
31 CFG_ITEM_BOOL, | |
32 CFG_ITEM_FLOAT, | |
33 CFG_ITEM_HEX_TRIPLET, | |
16 | 34 |
774 | 35 CFG_ITEM_STRING_LIST, |
36 CFG_ITEM_HEX_TRIPLET_LIST | |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 }; |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 |
654 | 40 typedef struct th_cfgitem_t |
70
a0e1b29be35d
Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
41 { |
500
25fc4ab342d3
Add a comment about struct aliasing.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
42 // th_llist_t must be the first item, as this |
25fc4ab342d3
Add a comment about struct aliasing.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
43 // is used to alias th_cfgitem_t to llist nodes |
155
23a79bd6c9d6
Use th_llist for th_config module as well instead of duped linked list
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
44 th_llist_t node; |
23a79bd6c9d6
Use th_llist for th_config module as well instead of duped linked list
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
45 |
15 | 46 int type; |
11 | 47 char *name; |
15 | 48 union { |
49 int *val_int; | |
50 unsigned int *val_uint; | |
16 | 51 char **val_str; |
735
31bc1ed07cf5
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
52 bool *val_bool; |
172
eb2c073d93b3
Adding floating point configuration item support.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
53 float *val_float; |
16 | 54 |
55 void *data; | |
152
b4e1b15a64e1
Rename qlist_t doubly linked list structure to th_llist_t.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
56 th_llist_t **list; |
654 | 57 struct th_cfgitem_t *section; |
22
1ac2449c4df7
ISO C99 compatibility fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
58 } v; |
70
a0e1b29be35d
Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
59 } th_cfgitem_t; |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 |
604 | 62 // |
63 // Functions | |
64 // | |
780 | 65 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 */); |
66 void th_cfg_free(th_cfgitem_t *cfg, void (*freefunc)(th_cfgitem_t *)); | |
67 int th_cfg_write(th_ioctx_t *fh, const th_cfgitem_t *cfg); | |
70
a0e1b29be35d
Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
68 |
a0e1b29be35d
Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
69 int th_cfg_add_comment(th_cfgitem_t **cfg, const char *comment); |
499 | 70 int th_cfg_add_section(th_cfgitem_t **cfg, const char *name, th_cfgitem_t *sect); |
781
4cc514343376
Rename th_cfg_find() to th_cfg_item_find().
Matti Hamalainen <ccr@tnsp.org>
parents:
780
diff
changeset
|
71 th_cfgitem_t * th_cfg_item_find(th_cfgitem_t *cfg, const char *section, const char *name, const int type); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 |
170 | 73 int th_cfg_add_int(th_cfgitem_t **cfg, const char *name, int *data, int defValue); |
74 int th_cfg_add_uint(th_cfgitem_t **cfg, const char *name, unsigned int *data, unsigned int defValue); | |
75 int th_cfg_add_float(th_cfgitem_t **cfg, const char *name, float *data, float defValue); | |
76 int th_cfg_add_string(th_cfgitem_t **cfg, const char *name, char **data, char *defValue); | |
735
31bc1ed07cf5
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents:
726
diff
changeset
|
77 int th_cfg_add_bool(th_cfgitem_t **cfg, const char *name, bool *data, bool defValue); |
170 | 78 int th_cfg_add_float(th_cfgitem_t **cfg, const char *name, float *data, float defValue); |
777
484853471eaf
Rename th_cfg_add_hexvalue() to th_cfg_add_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
774
diff
changeset
|
79 int th_cfg_add_hex_triplet(th_cfgitem_t **cfg, const char *name, unsigned int *data, unsigned int defValue); |
152
b4e1b15a64e1
Rename qlist_t doubly linked list structure to th_llist_t.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
80 int th_cfg_add_string_list(th_cfgitem_t **cfg, const char *name, th_llist_t **list); |
15 | 81 |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 #ifdef __cplusplus |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 #endif |
129 | 86 #endif // TH_CONFIG_H |