annotate th_config.c @ 378:afbc3bfd3e03

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