annotate th_config.c @ 42:7851f704d499

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