annotate th_config.c @ 160:a69764b4305f

Simplify.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Feb 2015 04:18:18 +0200
parents fc914ff7a9b8
children a2cd862315c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Very simple configuration handling functions
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
144
51eec969b07a Update copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
4 * (C) Copyright 2004-2015 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 */
49
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
8 #include "th_util.h"
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
9 #include "th_config.h"
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
10 #include "th_string.h"
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include <stdio.h>
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include <stdarg.h>
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
14 #define SET_MAX_BUF (8192)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 /* Free a given configuration (the values are not free'd)
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 */
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
19 void th_cfg_free(th_cfgitem_t *cfg)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
21 th_cfgitem_t *node = cfg;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
23 while (node != NULL)
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
24 {
155
23a79bd6c9d6 Use th_llist for th_config module as well instead of duped linked list
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
25 th_cfgitem_t *next = (th_cfgitem_t *) node->node.next;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
26
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
27 if (node->type == ITEM_SECTION)
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
28 th_cfg_free((th_cfgitem_t *) node->v.data);
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
29
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
30 th_free(node->name);
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
31 th_free(node);
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
32 node = next;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
33 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 /* Allocate and add new item to configuration
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 */
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
39 static th_cfgitem_t *th_cfg_add(th_cfgitem_t **cfg, const char *name,
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
40 const int type, void *data)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
42 th_cfgitem_t *node;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
44 if (cfg == NULL)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
45 return NULL;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
47 // Allocate new item
125
0ac59c798773 Use th_malloc0() where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
48 node = (th_cfgitem_t *) th_malloc0(sizeof(th_cfgitem_t));
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
49 if (node == NULL)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
50 return NULL;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
52 // Set values
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
53 node->type = type;
22
1ac2449c4df7 ISO C99 compatibility fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
54 node->v.data = data;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
55 node->name = th_strdup(name);
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
56
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
57 // Insert into linked list
155
23a79bd6c9d6 Use th_llist for th_config module as well instead of duped linked list
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
58 th_llist_append_node((th_llist_t **) cfg, (th_llist_t *) node);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
60 return node;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 /* Add integer type setting into give configuration
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 */
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
66 int th_cfg_add_int(th_cfgitem_t **cfg, const char *name, int *itemData, int itemDef)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
68 th_cfgitem_t *node;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
70 node = th_cfg_add(cfg, name, ITEM_INT, (void *) itemData);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
71 if (node == NULL)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
72 return -1;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
74 *itemData = itemDef;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
76 return 0;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
80 int th_cfg_add_hexvalue(th_cfgitem_t **cfg, const char *name,
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
81 int *itemData, int itemDef)
15
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
82 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
83 th_cfgitem_t *node;
15
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
84
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
85 node = th_cfg_add(cfg, name, ITEM_HEX_TRIPLET, (void *) itemData);
15
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
86 if (node == NULL)
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
87 return -1;
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
88
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
89 *itemData = itemDef;
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
90
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
91 return 0;
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
92 }
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
93
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
94
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 /* Add unsigned integer type setting into give configuration
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 */
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
97 int th_cfg_add_uint(th_cfgitem_t **cfg, const char *name,
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
98 unsigned int *itemData, unsigned int itemDef)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
100 th_cfgitem_t *node;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
102 node = th_cfg_add(cfg, name, ITEM_UINT, (void *) itemData);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
103 if (node == NULL)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
104 return -1;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
106 *itemData = itemDef;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
108 return 0;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 /* Add strint type setting into given configuration
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 */
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
114 int th_cfg_add_string(th_cfgitem_t **cfg, const char *name,
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
115 char **itemData, char *itemDef)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
117 th_cfgitem_t *node;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
119 node = th_cfg_add(cfg, name, ITEM_STRING, (void *) itemData);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
120 if (node == NULL)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
121 return -1;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
123 *itemData = th_strdup(itemDef);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
125 return 0;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 /* Add boolean type setting into given configuration
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 */
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
131 int th_cfg_add_bool(th_cfgitem_t **cfg, const char *name,
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
132 BOOL *itemData, BOOL itemDef)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
134 th_cfgitem_t *node;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
135
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
136 node = th_cfg_add(cfg, name, ITEM_BOOL, (void *) itemData);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
137 if (node == NULL)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
138 return -1;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
139
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
140 *itemData = itemDef;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
141
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
142 return 0;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
143 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
144
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
146 /* Add implicit comment
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
147 */
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
148 int th_cfg_add_comment(th_cfgitem_t **cfg, const char *comment)
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
149 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
150 th_cfgitem_t *node;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
151
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
152 node = th_cfg_add(cfg, comment, ITEM_COMMENT, NULL);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
153 if (node == NULL)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
154 return -1;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
155
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
156 return 0;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
157 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
160 /* Add new section
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
161 */
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
162 int th_cfg_add_section(th_cfgitem_t **cfg, const char *name, th_cfgitem_t *data)
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
163 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
164 th_cfgitem_t *node;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
165
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
166 node = th_cfg_add(cfg, name, ITEM_SECTION, (void *) data);
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
167 if (node == NULL)
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
168 return -1;
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
169
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
170 return 0;
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
171 }
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
172
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
173
152
b4e1b15a64e1 Rename qlist_t doubly linked list structure to th_llist_t.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
174 int th_cfg_add_string_list(th_cfgitem_t **cfg, const char *name, th_llist_t **data)
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
175 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
176 th_cfgitem_t *node;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
177
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
178 if (data == NULL)
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
179 return -5;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
180
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
181 node = th_cfg_add(cfg, name, ITEM_STRING_LIST, (void *) data);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
182 if (node == NULL)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
183 return -1;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
184
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
185 return 0;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 /* Read a given file into configuration structure and variables
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 */
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
191 enum
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
192 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
193 PM_EOF,
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
194 PM_ERROR,
159
fc914ff7a9b8 Rename a constant.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
195 PM_IDLE,
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
196 PM_COMMENT,
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
197 PM_NEXT,
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
198 PM_KEYNAME,
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
199 PM_KEYSET,
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
200 PM_STRING,
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
201 PM_INT,
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
202 PM_BOOL,
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
203 PM_SECTION,
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
204 PM_ARRAY
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 };
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 #define VADDCH(ch) if (strPos < SET_MAX_BUF) { tmpStr[strPos++] = ch; }
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
208 #define VISEND(ch) (ch == '\r' || ch == '\n' || ch == ';' || th_isspace(c) || ch == '#')
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
210 static int th_cfg_read_sect(th_ioctx_t *ctx, th_cfgitem_t *cfg, int nesting)
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
211 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
212 th_cfgitem_t *item = NULL;
110
d739df7efba7 Use dynamic allocation for one buffer.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
213 char *tmpStr = NULL;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
214 size_t strPos;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
215 int c, parseMode, prevMode, nextMode, tmpCh;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
216 BOOL isFound, isStart, isError, validError;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
217
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
218 // Initialize values
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
219 tmpCh = 0;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
220 strPos = 0;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
221 c = -1;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
222 isFound = isStart = isError = validError = FALSE;
159
fc914ff7a9b8 Rename a constant.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
223 nextMode = prevMode = parseMode = PM_IDLE;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
224
110
d739df7efba7 Use dynamic allocation for one buffer.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
225 if ((tmpStr = th_malloc(SET_MAX_BUF + 1)) == NULL)
d739df7efba7 Use dynamic allocation for one buffer.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
226 goto out;
d739df7efba7 Use dynamic allocation for one buffer.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
227
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
228 // Parse the configuration
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
229 while (parseMode != PM_EOF && parseMode != PM_ERROR)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
230 {
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
231 if (c == -1)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
232 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
233 // Get next character
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
234 switch (c = fgetc(ctx->fp))
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
235 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
236 case EOF:
159
fc914ff7a9b8 Rename a constant.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
237 if (parseMode != PM_IDLE)
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
238 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
239 th_ioctx_error(ctx, -1, "Unexpected end of file.\n");
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
240 parseMode = PM_ERROR;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
241 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
242 else
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
243 parseMode = PM_EOF;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
244 break;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
245
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
246 case '\n':
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
247 ctx->line++;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
248 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
249 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
250
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
251 switch (parseMode)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
252 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
253 case PM_COMMENT:
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
254 // Comment parsing mode
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
255 if (c == '\n')
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
256 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
257 // End of line, end of comment
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
258 parseMode = prevMode;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
259 prevMode = PM_COMMENT;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
260 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
261 c = -1;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
262 break;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
263
159
fc914ff7a9b8 Rename a constant.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
264 case PM_IDLE:
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
265 // Normal parsing mode
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
266 if (c == '#')
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
267 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
268 prevMode = parseMode;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
269 parseMode = PM_COMMENT;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
270 c = -1;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
271 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
272 else if (VISEND(c))
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
273 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
274 c = -1;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
275 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
276 else if (c == '}')
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
277 {
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
278 if (nesting > 0)
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
279 // Check for validation errors
110
d739df7efba7 Use dynamic allocation for one buffer.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
280 goto out;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
281 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
282 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
283 th_ioctx_error(ctx, -1,
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
284 "Invalid nesting sequence encountered.\n");
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
285 parseMode = PM_ERROR;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
286 }
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
287 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
288 else if (th_isalpha(c))
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
289 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
290 // Start of key name found
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
291 prevMode = parseMode;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
292 parseMode = PM_KEYNAME;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
293 strPos = 0;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
294 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
295 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
296 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
297 // Error! Invalid character found
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
298 th_ioctx_error(ctx, -1, "Unexpected character '%c'.\n", c);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
299 parseMode = PM_ERROR;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
300 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
301 break;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
302
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
303 case PM_KEYNAME:
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
304 // Configuration KEY name parsing mode
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
305 if (c == '#')
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
306 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
307 // Start of comment
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
308 prevMode = parseMode;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
309 parseMode = PM_COMMENT;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
310 c = -1;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
311 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
312 else if (th_iscrlf(c) || th_isspace(c) || c == '=')
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
313 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
314 // End of key name
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
315 prevMode = parseMode;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
316 parseMode = PM_NEXT;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
317 nextMode = PM_KEYSET;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
318 }
151
434c0eae87c9 Add '-' to allowed configuration key names.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
319 else if (th_isalnum(c) || c == '_' || c == '-')
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
320 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
321 // Add to key name string
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
322 VADDCH(c)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
323 else
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
324 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
325 // Error! Key name string too long!
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
326 th_ioctx_error(ctx, -1, "Config key name too long!");
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
327 parseMode = PM_ERROR;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
328 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
329 c = -1;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
330 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
331 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
332 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
333 // Error! Invalid character found
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
334 tmpStr[strPos] = 0;
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
335 th_ioctx_error(ctx, -1,
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
336 "Unexpected character '%c' in key name '%s'.\n",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
337 c, tmpStr);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
338 parseMode = PM_ERROR;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
339 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
340 break;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
341
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
342 case PM_KEYSET:
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
343 if (c == '=')
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
344 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
345 // Find key from configuration
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
346 tmpStr[strPos] = 0;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
347 isFound = FALSE;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
348 item = cfg;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
349 while (item != NULL && !isFound)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
350 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
351 if (item->name != NULL && strcmp(item->name, tmpStr) == 0)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
352 isFound = TRUE;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
353 else
155
23a79bd6c9d6 Use th_llist for th_config module as well instead of duped linked list
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
354 item = (th_cfgitem_t *) item->node.next;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
355 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
356
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
357 // Check if key was found
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
358 if (isFound)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
359 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
360 // Okay, set next mode
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
361 switch (item->type)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
362 {
15
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
363 case ITEM_HEX_TRIPLET:
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
364 case ITEM_STRING:
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
365 nextMode = PM_STRING;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
366 break;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
367
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
368 case ITEM_STRING_LIST:
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
369 nextMode = PM_ARRAY;
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
370 break;
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
371
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
372 case ITEM_INT:
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
373 case ITEM_UINT:
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
374 nextMode = PM_INT;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
375 break;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
376
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
377 case ITEM_BOOL:
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
378 nextMode = PM_BOOL;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
379 break;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
380
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
381 case ITEM_SECTION:
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
382 nextMode = PM_SECTION;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
383 break;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
384 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
385
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
386 prevMode = parseMode;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
387 parseMode = PM_NEXT;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
388 isStart = TRUE;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
389 strPos = 0;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
390 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
391 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
392 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
393 // Error! No configuration key by this name found
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
394 th_ioctx_error(ctx, -1,
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
395 "No such configuration setting ('%s')\n",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
396 tmpStr);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
397 parseMode = PM_ERROR;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
398 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
399
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
400 c = -1;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
401 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
402 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
403 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
404 // Error! '=' expected!
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
405 th_ioctx_error(ctx, -1,
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
406 "Unexpected character '%c', assignation '=' was expected.\n",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
407 c);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
408 parseMode = PM_ERROR;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
409 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
410 break;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
412 case PM_NEXT:
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
413 // Search next item parsing mode
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
414 if (c == '#')
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
415 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
416 // Start of comment
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
417 prevMode = parseMode;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
418 parseMode = PM_COMMENT;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
419 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
420 else if (th_isspace(c) || th_iscrlf(c))
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
421 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
422 // Ignore whitespaces and linechanges
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
423 c = -1;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
424 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
425 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
426 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
427 // Next item found
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
428 prevMode = parseMode;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
429 parseMode = nextMode;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
430 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
431 break;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
432
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
433 case PM_ARRAY:
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
434 if (isStart)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
435 {
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
436 switch (item->type)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
437 {
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
438 case ITEM_STRING_LIST:
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
439 prevMode = parseMode;
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
440 parseMode = PM_STRING;
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
441 break;
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
442 }
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
443 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
444 else if (c == ',')
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
445 {
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
446 switch (item->type)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
447 {
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
448 case ITEM_STRING_LIST:
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
449 c = -1;
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
450 isStart = TRUE;
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
451 prevMode = parseMode;
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
452 parseMode = PM_NEXT;
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
453 nextMode = PM_STRING;
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
454 break;
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
455 }
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
456 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
457 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
458 {
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
459 prevMode = parseMode;
159
fc914ff7a9b8 Rename a constant.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
460 parseMode = PM_IDLE;
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
461 }
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
462 break;
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
463
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
464 case PM_SECTION:
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
465 // Section parsing mode
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
466 if (c != '{')
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
467 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
468 // Error! Section start '{' expected!
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
469 th_ioctx_error(ctx, -1,
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
470 "Unexpected character '%c', section start '{' was expected.\n",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
471 c);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
472 parseMode = PM_ERROR;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
473 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
474 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
475 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
476 int res = th_cfg_read_sect(ctx, item->v.section, nesting + 1);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
477 c = -1;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
478 if (res > 0)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
479 validError = TRUE;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
480 else if (res < 0)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
481 parseMode = PM_ERROR;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
482 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
483 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
484 prevMode = parseMode;
159
fc914ff7a9b8 Rename a constant.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
485 parseMode = PM_IDLE;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
486 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
487 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
488 break;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
489
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
490 case PM_STRING:
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
491 // String parsing mode
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
492 if (isStart)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
493 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
494 // Start of string, get delimiter
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
495 tmpCh = c;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
496 isStart = FALSE;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
497 strPos = 0;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
498 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
499 else if (c == tmpCh)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
500 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
501 // End of string, set the value
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
502 tmpStr[strPos] = 0;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
503
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
504 switch (item->type)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
505 {
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
506 case ITEM_HEX_TRIPLET:
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
507 *(item->v.val_int) = th_get_hex_triplet(tmpStr);
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
508 prevMode = parseMode;
159
fc914ff7a9b8 Rename a constant.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
509 parseMode = PM_IDLE;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
510 break;
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
511 case ITEM_STRING:
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
512 th_pstrcpy(item->v.val_str, tmpStr);
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
513 prevMode = parseMode;
159
fc914ff7a9b8 Rename a constant.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
514 parseMode = PM_IDLE;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
515 break;
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
516 case ITEM_STRING_LIST:
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
517 th_llist_append(item->v.list, th_strdup(tmpStr));
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
518 prevMode = parseMode;
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
519 parseMode = PM_NEXT;
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
520 nextMode = PM_ARRAY;
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
521 break;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
522 }
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
523
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
524 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
525 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
526 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
527 // Add character to string
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
528 VADDCH(c)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
529 else
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
530 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
531 // Error! String too long!
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
532 th_ioctx_error(ctx, -1,
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
533 "String too long! Maximum is %d characters.",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
534 SET_MAX_BUF);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
535 parseMode = PM_ERROR;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
536 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
537 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
538
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
539 c = -1;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
540 break;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
541
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
542 case PM_INT:
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
543 // Integer parsing mode
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
544 if (isStart && item->type == ITEM_UINT && c == '-')
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
545 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
546 // Error! Negative values not allowed for unsigned ints
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
547 th_ioctx_error(ctx, -1,
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
548 "Negative value specified for %s, unsigned value expected.",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
549 item->name);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
550 parseMode = PM_ERROR;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
551 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
552 else if (isStart && (c == '-' || c == '+'))
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
553 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
554 VADDCH(c)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
555 else
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
556 isError = TRUE;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
557 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
558 else if (th_isdigit(c))
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
559 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
560 VADDCH(c)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
561 else
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
562 isError = TRUE;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
563 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
564 else if (VISEND(c))
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
565 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
566 // End of integer parsing mode
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
567 tmpStr[strPos] = 0;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
568 switch (item->type)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
569 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
570 case ITEM_INT:
22
1ac2449c4df7 ISO C99 compatibility fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
571 *(item->v.val_int) = atoi(tmpStr);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
572 break;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
574 case ITEM_UINT:
22
1ac2449c4df7 ISO C99 compatibility fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
575 *(item->v.val_uint) = atol(tmpStr);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
576 break;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
577 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
578
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
579 prevMode = parseMode;
159
fc914ff7a9b8 Rename a constant.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
580 parseMode = PM_IDLE;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
581 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
582 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
583 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
584 // Error! Unexpected character.
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
585 th_ioctx_error(ctx, -1,
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
586 "Unexpected character '%c' for integer setting '%s'.",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
587 c, item->name);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
588 parseMode = PM_ERROR;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
589 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
590
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
591 if (isError)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
592 {
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
593 // Error! String too long!
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
594 th_ioctx_error(ctx, -1,
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
595 "String too long! Maximum is %d characters.",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
596 SET_MAX_BUF);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
597 parseMode = PM_ERROR;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
598 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
599
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
600 isStart = FALSE;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
601 c = -1;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
602 break;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
603
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
604 case PM_BOOL:
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
605 // Boolean parsing mode
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
606 if (isStart)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
607 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
608 tmpCh = c;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
609 isStart = FALSE;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
610 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
611 else if (VISEND(c))
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
612 {
20
05a44cbd1150 Minor warning fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
613 BOOL tmpBool = FALSE;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
614
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
615 // End of boolean parsing
160
a69764b4305f Simplify.
Matti Hamalainen <ccr@tnsp.org>
parents: 159
diff changeset
616 switch (th_toupper(tmpCh))
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
617 {
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
618 case 'Y':
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
619 case 'T':
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
620 case '1':
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
621 tmpBool = TRUE;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
622 break;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
623
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
624 case 'N':
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
625 case 'F':
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
626 case '0':
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
627 tmpBool = FALSE;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
628 break;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
629
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
630 default:
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
631 isError = TRUE;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
632 }
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
633
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
634 if (isError)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
635 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
636 th_ioctx_error(ctx, -1,
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
637 "Invalid boolean value for '%s'.\n",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
638 item->name);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
639 parseMode = PM_ERROR;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
640 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
641 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
642 {
22
1ac2449c4df7 ISO C99 compatibility fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
643 *(item->v.val_bool) = tmpBool;
15
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
644
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
645 prevMode = parseMode;
159
fc914ff7a9b8 Rename a constant.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
646 parseMode = PM_IDLE;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
647 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
648 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
649 c = -1;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
650 break;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
651 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
652 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
653
110
d739df7efba7 Use dynamic allocation for one buffer.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
654 out:
d739df7efba7 Use dynamic allocation for one buffer.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
655 th_free(tmpStr);
d739df7efba7 Use dynamic allocation for one buffer.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
656
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
657 // Check for validation errors
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
658 if (validError)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
659 return 1;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
660
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
661 // Return result
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
662 if (parseMode == PM_ERROR)
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
663 return -2;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
664 else
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
665 return 0;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
666 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
667
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
668
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
669 int th_cfg_read(th_ioctx_t *ctx, th_cfgitem_t *cfg)
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
670 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
671 if (ctx == NULL || cfg == NULL)
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
672 return -1;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
673
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
674 return th_cfg_read_sect(ctx, cfg, 0);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
676
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
677
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 /* Write a configuration into file
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
679 */
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
680 static void th_print_indent(th_ioctx_t *ctx, int nesting)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
681 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
682 int i;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
683 for (i = 0; i < nesting * 2; i++)
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
684 fputc(' ', ctx->fp);
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
685 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
686
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
687
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
688 static int th_cfg_write_sect(th_ioctx_t *ctx, const th_cfgitem_t *item, int nesting)
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
689 {
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
690 while (item != NULL)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
691 {
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
692 if (item->type == ITEM_COMMENT)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
693 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
694 th_print_indent(ctx, nesting);
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
695 if (fprintf(ctx->fp, "# %s\n",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
696 (item->name != NULL) ? item->name : "") < 0)
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
697 return -1;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
698 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
699 else if (item->name != NULL)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
700 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
701 th_print_indent(ctx, nesting);
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
702
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
703 switch (item->type)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
704 {
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
705 case ITEM_STRING:
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
706 if (*(item->v.val_str) == NULL)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
707 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
708 if (fprintf(ctx->fp, "#%s = \"\"\n",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
709 item->name) < 0)
15
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
710 return -3;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
711 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
712 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
713 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
714 if (fprintf(ctx->fp, "%s = \"%s\"\n",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
715 item->name, *(item->v.val_str)) < 0)
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
716 return -3;
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
717 }
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
718 break;
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
719
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
720 case ITEM_STRING_LIST:
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
721 if (*(item->v.list) == NULL)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
722 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
723 if (fprintf(ctx->fp,
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
724 "#%s = \"\", \"\"\n", item->name) < 0)
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
725 return -3;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
726 }
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
727 else
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
728 {
152
b4e1b15a64e1 Rename qlist_t doubly linked list structure to th_llist_t.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
729 th_llist_t *node = *(item->v.list);
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
730 size_t n = th_llist_length(node);
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
731 if (fprintf(ctx->fp, "%s = ", item->name) < 0)
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
732 return -3;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
733
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
734 while (node != NULL)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
735 {
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
736 if (node->data != NULL)
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
737 fprintf(ctx->fp, "\"%s\"", (char *) node->data);
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
738
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
739 if (--n > 0)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
740 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
741 fprintf(ctx->fp, ",\n");
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
742 th_print_indent(ctx, nesting);
34
8dac45860fc7 Prettify writing of string lists in config files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
743 }
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
744 node = node->next;
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
745 }
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
746
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
747 if (fprintf(ctx->fp, "\n") < 0)
15
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
748 return -3;
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
749 }
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
750 break;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
751
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
752 case ITEM_INT:
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
753 if (fprintf(ctx->fp, "%s = %i\n",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
754 item->name, *(item->v.val_int)) < 0)
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
755 return -4;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
756 break;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
758 case ITEM_UINT:
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
759 if (fprintf(ctx->fp, "%s = %d\n",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
760 item->name, *(item->v.val_uint)) < 0)
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
761 return -5;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
762 break;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
763
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
764 case ITEM_BOOL:
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
765 if (fprintf(ctx->fp, "%s = %s\n", item->name,
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
766 *(item->v.val_bool) ? "yes" : "no") < 0)
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
767 return -6;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
768 break;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
769
16
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
770 case ITEM_SECTION:
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
771 {
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
772 int res;
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
773 if (fprintf(ctx->fp, "%s = {\n", item->name) < 0)
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
774 return -7;
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
775 res = th_cfg_write_sect(ctx, item->v.section, nesting + 1);
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
776 if (res != 0)
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
777 return res;
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
778 if (fprintf(ctx->fp, "}\n\n") < 0)
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
779 return -8;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
780 }
15
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
781 break;
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
782
15
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
783 case ITEM_HEX_TRIPLET:
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
784 if (fprintf(ctx->fp, "%s = \"%06x\"\n",
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
785 item->name, *(item->v.val_int)) < 0)
15
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
786 return -6;
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
787 break;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
788 }
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
789 }
155
23a79bd6c9d6 Use th_llist for th_config module as well instead of duped linked list
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
790 item = (th_cfgitem_t *) item->node.next;
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
791 }
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
792
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
793 return 0;
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
794 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
796
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
797 int th_cfg_write(th_ioctx_t *ctx, const th_cfgitem_t *cfg)
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
798 {
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
799 if (ctx == NULL || cfg == NULL)
13
adcbcac66125 Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
800 return -1;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
801
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
802 fprintf(ctx->fp, "# Configuration written by %s %s\n\n",
62
36286f2561e1 Oops, 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
803 th_prog_desc, th_prog_version);
42
7851f704d499 Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
804
70
a0e1b29be35d Refactor configuration file handling module rather thoroughly. The API is
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
805 return th_cfg_write_sect(ctx, cfg, 0);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
806 }
83
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
807
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
808
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
809 /* Find a configuration item based on section, name, type.
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
810 * Name MUST be defined. Section can be NULL and type -1,
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
811 * first matching item will be returned.
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
812 */
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
813 static th_cfgitem_t *th_cfg_find_do(th_cfgitem_t *item, BOOL *sect, const char *section, const char *name, const int type)
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
814 {
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
815 while (item != NULL)
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
816 {
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
817 BOOL match = TRUE;
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
818
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
819 if (item->type == ITEM_SECTION)
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
820 {
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
821 // Check section name if set
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
822 if (section != NULL && strcmp(section, item->name) == 0)
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
823 *sect = TRUE;
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
824
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
825 // Recurse to sub-section
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
826 th_cfgitem_t *tmp = th_cfg_find_do(item->v.section, sect, section, name, type);
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
827 if (tmp != NULL)
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
828 return tmp;
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
829 }
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
830 else
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
831 // Has type check been set, and does it match?
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
832 if (type != -1 && item->type != type)
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
833 match = FALSE;
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
834 else
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
835 // Check name (not section name, tho)
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
836 if (strcmp(name, item->name) != 0)
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
837 match = FALSE;
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
838
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
839 // Do we have a match?
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
840 if (*sect && match)
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
841 return item;
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
842 }
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
843
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
844 return NULL;
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
845 }
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
846
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
847
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
848 th_cfgitem_t *th_cfg_find(th_cfgitem_t *cfg, const char *section, const char *name, const int type)
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
849 {
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
850 BOOL sect = FALSE;
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
851
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
852 if (section == NULL)
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
853 sect = TRUE;
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
854
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
855 return th_cfg_find_do(cfg, &sect, section, name, type);
50006067bcd1 Add new function, th_cfg_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
856 }