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