Mercurial > hg > th-libs
annotate th_config.c @ 62:36286f2561e1
Oops, 10L.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 20 Sep 2012 00:00:16 +0300 |
parents | 598609fb49b0 |
children | 34d58b0f2d52 |
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 |
16 | 4 * (C) Copyright 2004-2010 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 */ |
16 | 19 void th_cfg_free(cfgitem_t *cfg) |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
21 cfgitem_t *curr = cfg; |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
23 while (curr != NULL) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
24 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
25 cfgitem_t *next = curr->next; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
26 |
16 | 27 if (curr->type == ITEM_SECTION) |
22
1ac2449c4df7
ISO C99 compatibility fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
28 th_cfg_free((cfgitem_t *) curr->v.data); |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
29 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
30 th_free(curr->name); |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
31 th_free(curr); |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
32 curr = next; |
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 */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
39 static cfgitem_t *th_cfg_add(cfgitem_t **cfg, const char *name, |
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 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
42 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 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
47 /* Allocate new item */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
48 node = (cfgitem_t *) th_calloc(1, sizeof(cfgitem_t)); |
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 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
52 /* Set values */ |
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 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
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 */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
77 int th_cfg_add_int(cfgitem_t **cfg, 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 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
79 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 |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
91 int th_cfg_add_hexvalue(cfgitem_t **cfg, char *name, |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
92 int *itemData, int itemDef) |
15 | 93 { |
94 cfgitem_t *node; | |
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 */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
108 int th_cfg_add_uint(cfgitem_t **cfg, char *name, |
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 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
111 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 */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
125 int th_cfg_add_string(cfgitem_t **cfg, char *name, |
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 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
128 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 */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
142 int th_cfg_add_bool(cfgitem_t **cfg, char *name, |
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 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
145 cfgitem_t *node; |
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 */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
159 int th_cfg_add_comment(cfgitem_t **cfg, 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 { |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
161 cfgitem_t *node; |
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 */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
173 int th_cfg_add_section(cfgitem_t **cfg, char *name, 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 { |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
175 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 | |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
185 int th_cfg_add_string_list(cfgitem_t **cfg, char *name, qlist_t **data) |
16 | 186 { |
187 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 |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
221 typedef struct |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
222 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
223 FILE *file; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
224 char *filename; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
225 size_t line; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
226 } conffile_t; |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 |
16 | 229 static void th_cfg_error(conffile_t *f, const char *fmt, ...) |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
230 { |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
231 va_list ap; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
232 va_start(ap, fmt); |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
233 fprintf(stderr, "%s: '%s', line #%d: ", th_prog_name, f->filename, |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
234 (unsigned int) f->line); |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
235 vfprintf(stderr, fmt, ap); |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
236 va_end(ap); |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
237 } |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
240 static int th_cfg_read_sect(conffile_t *f, 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
|
241 { |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
242 cfgitem_t *item = NULL; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
243 char tmpStr[SET_MAX_BUF + 1]; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
244 size_t strPos; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
245 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
|
246 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
|
247 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
248 /* Initialize values */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
249 tmpCh = 0; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
250 strPos = 0; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
251 c = -1; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
252 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
|
253 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
|
254 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
255 /* Parse the configuration */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
256 while (parseMode != PM_EOF && parseMode != PM_ERROR) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
257 { |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
258 if (c == -1) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
259 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
260 /* Get next character */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
261 switch (c = fgetc(f->file)) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
262 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
263 case EOF: |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
264 if (parseMode != PM_NORMAL) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
265 { |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
266 th_cfg_error(f, "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
|
267 parseMode = PM_ERROR; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
268 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
269 else |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
270 parseMode = PM_EOF; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
271 break; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
272 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
273 case '\n': |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
274 f->line++; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
275 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
276 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
277 |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
278 switch (parseMode) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
279 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
280 case PM_COMMENT: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
281 /* Comment parsing mode */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
282 if (c == '\n') |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
283 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
284 /* End of line, end of comment */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
285 parseMode = prevMode; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
286 prevMode = PM_COMMENT; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
287 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
288 c = -1; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
289 break; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
290 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
291 case PM_NORMAL: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
292 /* Normal parsing mode */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
293 if (c == '#') |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
294 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
295 prevMode = parseMode; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
296 parseMode = PM_COMMENT; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
297 c = -1; |
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 (VISEND(c)) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
300 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
301 c = -1; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
302 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
303 else if (c == '}') |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
304 { |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
305 if (nesting > 0) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
306 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
307 /* Check for validation errors */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
308 return (validError) ? 1 : 0; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
309 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
310 else |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
311 { |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
312 th_cfg_error(f, |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
313 "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
|
314 parseMode = PM_ERROR; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
315 } |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
316 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
317 else if (th_isalpha(c)) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
318 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
319 /* Start of key name found */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
320 prevMode = parseMode; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
321 parseMode = PM_KEYNAME; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
322 strPos = 0; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
323 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
324 else |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
325 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
326 /* Error! Invalid character found */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
327 th_cfg_error(f, "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
|
328 parseMode = PM_ERROR; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
329 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
330 break; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
331 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
332 case PM_KEYNAME: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
333 /* Configuration KEY name parsing mode */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
334 if (c == '#') |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
335 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
336 /* Start of comment */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
337 prevMode = parseMode; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
338 parseMode = PM_COMMENT; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
339 c = -1; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
340 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
341 else if (th_iscrlf(c) || th_isspace(c) || c == '=') |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
342 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
343 /* End of key name */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
344 prevMode = parseMode; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
345 parseMode = PM_NEXT; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
346 nextMode = PM_KEYSET; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
347 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
348 else if (th_isalnum(c) || c == '_') |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
349 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
350 /* Add to key name string */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
351 VADDCH(c) |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
352 else |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
353 { |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
354 /* Error! Key name string too long! */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
355 th_cfg_error(f, "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
|
356 parseMode = PM_ERROR; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
357 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
358 c = -1; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
359 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
360 else |
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 /* Error! Invalid character found */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
363 tmpStr[strPos] = 0; |
16 | 364 th_cfg_error(f, |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
365 "Unexpected character '%c' in key name '%s'.\n", |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
366 c, tmpStr); |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
367 parseMode = PM_ERROR; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
368 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
369 break; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
370 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
371 case PM_KEYSET: |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
372 if (c == '=') |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
373 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
374 /* Find key from configuration */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
375 tmpStr[strPos] = 0; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
376 isFound = FALSE; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
377 item = cfg; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
378 while (item != NULL && !isFound) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
379 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
380 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
|
381 isFound = TRUE; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
382 else |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
383 item = item->next; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
384 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
385 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
386 /* Check if key was found */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
387 if (isFound) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
388 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
389 /* Okay, set next mode */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
390 switch (item->type) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
391 { |
15 | 392 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
|
393 case ITEM_STRING: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
394 nextMode = PM_STRING; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
395 break; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
396 |
16 | 397 case ITEM_STRING_LIST: |
398 nextMode = PM_ARRAY; | |
399 break; | |
400 | |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
401 case ITEM_INT: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
402 case ITEM_UINT: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
403 nextMode = PM_INT; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
404 break; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
405 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
406 case ITEM_BOOL: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
407 nextMode = PM_BOOL; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
408 break; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
409 |
16 | 410 case ITEM_SECTION: |
411 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
|
412 break; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
413 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
414 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
415 prevMode = parseMode; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
416 parseMode = PM_NEXT; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
417 isStart = TRUE; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
418 strPos = 0; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
419 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
420 else |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
421 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
422 /* Error! No configuration key by this name found */ |
16 | 423 th_cfg_error(f, |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
424 "No such configuration setting ('%s')\n", |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
425 tmpStr); |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
426 parseMode = PM_ERROR; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
427 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
428 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
429 c = -1; |
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 |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
432 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
433 /* Error! '=' expected! */ |
16 | 434 th_cfg_error(f, |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
435 "Unexpected character '%c', assignation '=' was expected.\n", |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
436 c); |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
437 parseMode = PM_ERROR; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
438 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
439 break; |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
440 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
441 case PM_NEXT: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
442 /* Search next item parsing mode */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
443 if (c == '#') |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
444 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
445 /* Start of comment */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
446 prevMode = parseMode; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
447 parseMode = PM_COMMENT; |
42
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 else if (th_isspace(c) || th_iscrlf(c)) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
450 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
451 /* Ignore whitespaces and linechanges */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
452 c = -1; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
453 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
454 else |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
455 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
456 /* Next item found */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
457 prevMode = parseMode; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
458 parseMode = nextMode; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
459 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
460 break; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
461 |
16 | 462 case PM_ARRAY: |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
463 if (isStart) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
464 { |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
465 switch (item->type) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
466 { |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
467 case ITEM_STRING_LIST: |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
468 prevMode = parseMode; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
469 parseMode = PM_STRING; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
470 break; |
16 | 471 } |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
472 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
473 else if (c == ',') |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
474 { |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
475 switch (item->type) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
476 { |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
477 case ITEM_STRING_LIST: |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
478 c = -1; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
479 isStart = TRUE; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
480 prevMode = parseMode; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
481 parseMode = PM_NEXT; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
482 nextMode = PM_STRING; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
483 break; |
16 | 484 } |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
485 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
486 else |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
487 { |
16 | 488 prevMode = parseMode; |
489 parseMode = PM_NORMAL; | |
490 } | |
491 break; | |
492 | |
493 case PM_SECTION: | |
494 /* Section parsing mode */ | |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
495 if (c != '{') |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
496 { |
16 | 497 /* Error! Section start '{' expected! */ |
498 th_cfg_error(f, | |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
499 "Unexpected character '%c', section start '{' was expected.\n", |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
500 c); |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
501 parseMode = PM_ERROR; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
502 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
503 else |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
504 { |
22
1ac2449c4df7
ISO C99 compatibility fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
505 int res = th_cfg_read_sect(f, 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
|
506 c = -1; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
507 if (res > 0) |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
508 validError = TRUE; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
509 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
|
510 parseMode = PM_ERROR; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
511 else |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
512 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
513 prevMode = parseMode; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
514 parseMode = PM_NORMAL; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
515 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
516 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
517 break; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
518 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
519 case PM_STRING: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
520 /* String parsing mode */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
521 if (isStart) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
522 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
523 /* Start of string, get delimiter */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
524 tmpCh = c; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
525 isStart = FALSE; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
526 strPos = 0; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
527 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
528 else if (c == tmpCh) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
529 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
530 /* End of string, set the value */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
531 tmpStr[strPos] = 0; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
532 |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
533 switch (item->type) |
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 case ITEM_HEX_TRIPLET: |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
536 *(item->v.val_int) = th_get_hex_triplet(tmpStr); |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
537 prevMode = parseMode; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
538 parseMode = PM_NORMAL; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
539 break; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
540 case ITEM_STRING: |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
541 th_pstrcpy(item->v.val_str, tmpStr); |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
542 prevMode = parseMode; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
543 parseMode = PM_NORMAL; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
544 break; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
545 case ITEM_STRING_LIST: |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
546 th_llist_append(item->v.list, th_strdup(tmpStr)); |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
547 prevMode = parseMode; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
548 parseMode = PM_NEXT; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
549 nextMode = PM_ARRAY; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
550 break; |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
551 } |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
552 |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
553 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
554 else |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
555 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
556 /* Add character to string */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
557 VADDCH(c) |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
558 else |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
559 { |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
560 /* Error! String too long! */ |
16 | 561 th_cfg_error(f, |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
562 "String too long! Maximum is %d characters.", |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
563 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
|
564 parseMode = PM_ERROR; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
565 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
566 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
567 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
568 c = -1; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
569 break; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
570 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
571 case PM_INT: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
572 /* Integer parsing mode */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
573 if (isStart && item->type == ITEM_UINT && c == '-') |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
574 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
575 /* Error! Negative values not allowed for unsigned ints */ |
16 | 576 th_cfg_error(f, |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
577 "Negative value specified for %s, unsigned value expected.", |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
578 item->name); |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
579 parseMode = PM_ERROR; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
580 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
581 else if (isStart && (c == '-' || c == '+')) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
582 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
583 VADDCH(c) |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
584 else |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
585 isError = TRUE; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
586 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
587 else if (th_isdigit(c)) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
588 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
589 VADDCH(c) |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
590 else |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
591 isError = TRUE; |
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 if (VISEND(c)) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
594 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
595 /* End of integer parsing mode */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
596 tmpStr[strPos] = 0; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
597 switch (item->type) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
598 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
599 case ITEM_INT: |
22
1ac2449c4df7
ISO C99 compatibility fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
600 *(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
|
601 break; |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
602 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
603 case ITEM_UINT: |
22
1ac2449c4df7
ISO C99 compatibility fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
604 *(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
|
605 break; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
606 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
607 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
608 prevMode = parseMode; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
609 parseMode = PM_NORMAL; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
610 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
611 else |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
612 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
613 /* Error! Unexpected character. */ |
16 | 614 th_cfg_error(f, |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
615 "Unexpected character '%c' for integer setting '%s'.", |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
616 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
|
617 parseMode = PM_ERROR; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
618 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
619 |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
620 if (isError) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
621 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
622 /* Error! String too long! */ |
16 | 623 th_cfg_error(f, "String too long! Maximum is %d characters.", |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
624 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
|
625 parseMode = PM_ERROR; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
626 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
627 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
628 isStart = FALSE; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
629 c = -1; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
630 break; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
631 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
632 case PM_BOOL: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
633 /* Boolean parsing mode */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
634 if (isStart) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
635 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
636 tmpCh = c; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
637 isStart = FALSE; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
638 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
639 else if (VISEND(c)) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
640 { |
20 | 641 BOOL tmpBool = FALSE; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
642 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
643 /* End of boolean parsing */ |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
644 switch (tmpCh) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
645 { |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
646 case 'Y': |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
647 case 'y': |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
648 case 'T': |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
649 case 't': |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
650 case '1': |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
651 tmpBool = TRUE; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
652 break; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
653 |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
654 case 'N': |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
655 case 'n': |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
656 case 'F': |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
657 case 'f': |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
658 case '0': |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
659 tmpBool = FALSE; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
660 break; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
661 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
662 default: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
663 isError = TRUE; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
664 } |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
665 |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
666 if (isError) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
667 { |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
668 th_cfg_error(f, "Invalid boolean value for '%s'.\n", |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
669 item->name); |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
670 parseMode = PM_ERROR; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
671 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
672 else |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
673 { |
22
1ac2449c4df7
ISO C99 compatibility fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
674 *(item->v.val_bool) = tmpBool; |
15 | 675 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
676 prevMode = parseMode; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
677 parseMode = PM_NORMAL; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
678 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
679 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
680 c = -1; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
681 break; |
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 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
684 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
685 /* Check for validation errors */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
686 if (validError) |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
687 return 1; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
688 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
689 /* Return result */ |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
690 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
|
691 return -2; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
692 else |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
693 return 0; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
694 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
695 |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
696 |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
697 int th_cfg_read(FILE *inFile, char *filename, 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
|
698 { |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
699 conffile_t f; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
700 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
701 f.file = inFile; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
702 f.filename = filename; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
703 f.line = 1; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
704 |
16 | 705 return th_cfg_read_sect(&f, cfg, 0); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
706 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
707 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
708 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
709 /* Write a configuration into file |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
710 */ |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
711 static void th_print_indent(conffile_t *f, int nesting) |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
712 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
713 int i; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
714 for (i = 0; i < nesting * 2; i++) |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
715 fputc(' ', f->file); |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
716 } |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
717 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
718 |
16 | 719 static int th_cfg_write_sect(conffile_t *f, 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
|
720 { |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
721 while (item != NULL) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
722 { |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
723 if (item->type == ITEM_COMMENT) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
724 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
725 th_print_indent(f, nesting); |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
726 if (fprintf |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
727 (f->file, "# %s\n", |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
728 (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
|
729 return -1; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
730 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
731 else if (item->name != NULL) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
732 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
733 th_print_indent(f, nesting); |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
734 |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
735 switch (item->type) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
736 { |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
737 case ITEM_STRING: |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
738 if (*(item->v.val_str) == NULL) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
739 { |
15 | 740 if (fprintf(f->file, "#%s = \"\"\n", item->name) < 0) |
741 return -3; | |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
742 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
743 else |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
744 { |
15 | 745 if (fprintf(f->file, "%s = \"%s\"\n", |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
746 item->name, *(item->v.val_str)) < 0) |
16 | 747 return -3; |
748 } | |
749 break; | |
750 | |
751 case ITEM_STRING_LIST: | |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
752 if (*(item->v.list) == NULL) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
753 { |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
754 if (fprintf(f->file, "#%s = \"\", \"\"\n", item->name) < |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
755 0) |
16 | 756 return -3; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
757 } |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
758 else |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
759 { |
22
1ac2449c4df7
ISO C99 compatibility fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
760 qlist_t *node = *(item->v.list); |
16 | 761 size_t n = th_llist_length(node); |
762 if (fprintf(f->file, "%s = ", item->name) < 0) | |
763 return -3; | |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
764 |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
765 while (node != NULL) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
766 { |
16 | 767 if (node->data != NULL) |
768 fprintf(f->file, "\"%s\"", (char *) node->data); | |
769 | |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
770 if (--n > 0) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
771 { |
34
8dac45860fc7
Prettify writing of string lists in config files.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
772 fprintf(f->file, ",\n"); |
8dac45860fc7
Prettify writing of string lists in config files.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
773 th_print_indent(f, nesting); |
8dac45860fc7
Prettify writing of string lists in config files.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
774 } |
16 | 775 node = node->next; |
776 } | |
777 | |
778 if (fprintf(f->file, "\n") < 0) | |
15 | 779 return -3; |
780 } | |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
781 break; |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
782 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
783 case ITEM_INT: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
784 if (fprintf(f->file, "%s = %i\n", |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
785 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
|
786 return -4; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
787 break; |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
788 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
789 case ITEM_UINT: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
790 if (fprintf(f->file, "%s = %d\n", |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
791 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
|
792 return -5; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
793 break; |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
794 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
795 case ITEM_BOOL: |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
796 if (fprintf(f->file, "%s = %s\n", |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
797 item->name, |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
798 *(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
|
799 return -6; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
800 break; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
801 |
16 | 802 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
|
803 { |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
804 int res; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
805 if (fprintf(f->file, "%s = {\n", item->name) < 0) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
806 return -7; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
807 res = th_cfg_write_sect(f, item->v.section, nesting + 1); |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
808 if (res != 0) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
809 return res; |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
810 if (fprintf(f->file, "}\n\n") < 0) |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
811 return -8; |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
812 } |
15 | 813 break; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
814 |
15 | 815 case ITEM_HEX_TRIPLET: |
816 if (fprintf(f->file, "%s = \"%06x\"\n", | |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
817 item->name, *(item->v.val_int)) < 0) |
15 | 818 return -6; |
819 break; | |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
820 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
821 } |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
822 item = item->next; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
823 } |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
824 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
825 return 0; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
826 } |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
827 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
828 |
16 | 829 int th_cfg_write(FILE *outFile, char *filename, 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
|
830 { |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
831 conffile_t f; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
832 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
833 if (cfg == NULL) |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
834 return -1; |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
835 |
13
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
836 f.file = outFile; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
837 f.filename = filename; |
adcbcac66125
Import improved config code from chat client fork of th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
838 f.line = 1; |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
839 |
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
840 fprintf(outFile, "# Configuration written by %s %s\n\n", |
62 | 841 th_prog_desc, th_prog_version); |
42
7851f704d499
Reindent and cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
842 |
16 | 843 return th_cfg_write_sect(&f, cfg, 0); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
844 } |