Debian Codegraph @

src/config_file.c

raw symbols SCIP
1 /*
2 * OpenTyrian: A modern cross-platform port of Tyrian
3 * Copyright (C) 2015 The OpenTyrian Development Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 /*!
20 * \file config_file.c
21 * \author Carl Reinke
22 * \date 2015
23 * \copyright GNU General Public License v2+ or Mozilla Public License 2.0
24 */
25 #include "config_file.h"cxx . . $ `<file>/src/config_file.h`/
26
27 #include <assert.h>
28 #include <limits.h>
29 #include <stdbool.h>
30 #include <stddef.h>
31 #include <string.h>
32
33 /* potential size of decimal representation of type */
34 #define udecsizeofcxx . . $ `src/config_file.c:34:9`!(t) ((CHAR_BITcxx . . $ `<external>/67164224788392828/limits.h:64:9`! * sizeof(t) / 3) + 1)
35 #define sdecsizeofcxx . . $ `src/config_file.c:35:9`!(t) (udecsizeofcxx . . $ `src/config_file.c:34:9`!(t) + 1)
36
37 extern void config_oomcxx . . $ config_oom(49f6e7a06ebc5aa8).(void);
38
39 void config_oomcxx . . $ config_oom(49f6e7a06ebc5aa8).(void)
40 {
41 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "out of memory\n");
42 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
43 }
44
45 /* string manipulators */
46
47 static ConfigStringcxx . . $ ConfigString# string_init_lencxx . . $ string_init_len(86ba0ae5cc355dba).(const char *s, size_t n)
48 {
49 ConfigStringcxx . . $ ConfigString# string;
50
51 if (s == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
52 {
53 CONFIG_STRING_LONG_TAGcxx . . $ `src/config_file.h:86:9`!(string) = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
54
55 string.long_bufcxx . . $ $anonymous_type_88ace789ff2dc3d9_0#long_buf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
56 }
57 else
58 {
59 char is_long = n >= COUNTOFcxx . . $ `src/config_file.h:51:9`!(string.short_buf);
60
61 CONFIG_STRING_LONG_TAGcxx . . $ `src/config_file.h:86:9`!(string) = is_long;
62
63 char *buffer = is_long ?
64 string.long_bufcxx . . $ $anonymous_type_88ace789ff2dc3d9_0#long_buf. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((n + 1) * sizeof(char)) :
65 string.short_bufcxx . . $ $anonymous_type_88ace789ff2dc3d9_0#short_buf.;
66 if (buffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
67 config_oomcxx . . $ config_oom(49f6e7a06ebc5aa8).();
68
69 memcpycxx . . $ memcpy(cc817cb175f282d).(buffer, s, n * sizeof(char));
70 buffer[n] = '\0';
71 }
72
73 return string;
74 }
75
76 static void string_deinitcxx . . $ string_deinit(2cb55483ce1f54cf).(ConfigStringcxx . . $ ConfigString# *string)
77 {
78 char is_long = CONFIG_STRING_LONG_TAGcxx . . $ `src/config_file.h:86:9`!(*string);
79
80 if (is_long)
81 {
82 freecxx . . $ free(5d22bdacc48458e8).(string->long_bufcxx . . $ $anonymous_type_88ace789ff2dc3d9_0#long_buf.);
83 string->long_bufcxx . . $ $anonymous_type_88ace789ff2dc3d9_0#long_buf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
84 }
85 }
86
87 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! string_equal_lencxx . . $ string_equal_len(cfcbb7169d78c0d).(ConfigStringcxx . . $ ConfigString# *string, const char *s, size_t n)
88 {
89 const char *cstr = config_string_to_cstrcxx . . $ config_string_to_cstr(f431c5a37e14148e).(string);
90 return strncmpcxx . . $ strncmp(fd278af2f295fa2e).(cstr, s, n) == 0 && cstr[n] == '\0';
91 }
92
93 /* config manipulators */
94
95 static void deinit_sectioncxx . . $ deinit_section(236ce553d602fba1).(ConfigSectioncxx . . $ ConfigSection# *section);
96 static void deinit_optioncxx . . $ deinit_option(6d64c9bf03f2972a).(ConfigOptioncxx . . $ ConfigOption# *option);
97
98 void config_initcxx . . $ config_init(b7cb4517c44ac027).(Configcxx . . $ Config# *config)
99 {
100 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(config != NULL);
101
102 config->sections_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections_count. = 0;
103 config->sectionscxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
104 }
105
106 void config_deinitcxx . . $ config_deinit(b7cb4517c44ac027).(Configcxx . . $ Config# *config)
107 {
108 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(config != NULL);
109
110 for (unsigned int s = 0; s < config->sections_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections_count.; ++s)
111 {
112 ConfigSectioncxx . . $ ConfigSection# *section = &config->sectionscxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections.[s];
113
114 deinit_sectioncxx . . $ deinit_section(236ce553d602fba1).(section);
115 }
116
117 freecxx . . $ free(5d22bdacc48458e8).(config->sectionscxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections.);
118 config->sectionscxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
119 }
120
121 /* config section manipulators -- internal */
122
123 static void init_sectioncxx . . $ init_section(b5b26d77152c566b).(ConfigSectioncxx . . $ ConfigSection# *section, const char *type, size_t type_len, const char *name, size_t name_len)
124 {
125 section->typecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#type. = string_init_lencxx . . $ string_init_len(86ba0ae5cc355dba).(type, type_len);
126 section->namecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#name. = string_init_lencxx . . $ string_init_len(86ba0ae5cc355dba).(name, name_len);
127 section->options_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options_count. = 0;
128 section->optionscxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
129 }
130
131 static void deinit_sectioncxx . . $ deinit_section(236ce553d602fba1).(ConfigSectioncxx . . $ ConfigSection# *section)
132 {
133 for (unsigned int o = 0; o < section->options_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options_count.; ++o)
134 {
135 ConfigOptioncxx . . $ ConfigOption# *option = &section->optionscxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options.[o];
136
137 deinit_optioncxx . . $ deinit_option(6d64c9bf03f2972a).(option);
138 }
139
140 string_deinitcxx . . $ string_deinit(2cb55483ce1f54cf).(&section->typecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#type.);
141 string_deinitcxx . . $ string_deinit(2cb55483ce1f54cf).(&section->namecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#name.);
142
143 freecxx . . $ free(5d22bdacc48458e8).(section->optionscxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options.);
144 section->optionscxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
145 }
146
147 /* config section accessors/manipulators -- by type, name */
148
149 ConfigSectioncxx . . $ ConfigSection# *config_add_section_lencxx . . $ config_add_section_len(ee1a9159675f0d4e).(Configcxx . . $ Config# *config, const char *type, size_t type_len, const char *name, size_t name_len)
150 {
151 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(config != NULL);
152 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(type != NULL);
153
154 ConfigSectioncxx . . $ ConfigSection# *sections = realloccxx . . $ realloc(417ab160f6baadc6).(config->sectionscxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections., (config->sections_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections_count. + 1) * sizeof(ConfigSectioncxx . . $ ConfigSection#));
155 if (sections == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
156 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
157
158 ConfigSectioncxx . . $ ConfigSection# *section = &sections[config->sections_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections_count.];
159
160 config->sections_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections_count. += 1;
161 config->sectionscxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections. = sections;
162
163 init_sectioncxx . . $ init_section(b5b26d77152c566b).(section, type, type_len, name, name_len);
164
165 return section;
166 }
167
168 ConfigSectioncxx . . $ ConfigSection# *config_find_sectionscxx . . $ config_find_sections(5403134a7215bba0).(Configcxx . . $ Config# *config, const char *type, ConfigSectioncxx . . $ ConfigSection# **save)
169 {
170 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(config != NULL);
171 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(type != NULL);
172
173 ConfigSectioncxx . . $ ConfigSection# *sections_end = &config->sectionscxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections.[config->sections_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections_count.];
174
175 ConfigSectioncxx . . $ ConfigSection# *section = save != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && *save != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ?
176 *save :
177 &config->sectionscxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections.[0];
178
179 for (; section < sections_end; ++section)
180 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(config_string_to_cstrcxx . . $ config_string_to_cstr(f431c5a37e14148e).(&section->typecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#type.), type) == 0)
181 break;
182
183 if (save != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
184 *save = section;
185
186 return section < sections_end ? section : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
187 }
188
189 ConfigSectioncxx . . $ ConfigSection# *config_find_sectioncxx . . $ config_find_section(9d60c5d7489db765).(Configcxx . . $ Config# *config, const char *type, const char *name)
190 {
191 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(config != NULL);
192 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(type != NULL);
193
194 ConfigSectioncxx . . $ ConfigSection# *sections_end = &config->sectionscxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections.[config->sections_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections_count.];
195
196 for (ConfigSectioncxx . . $ ConfigSection# *section = &config->sectionscxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections.[0]; section < sections_end; ++section)
197 {
198 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(config_string_to_cstrcxx . . $ config_string_to_cstr(f431c5a37e14148e).(&section->typecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#type.), type) == 0)
199 {
200 const char *section_name = config_string_to_cstrcxx . . $ config_string_to_cstr(f431c5a37e14148e).(&section->namecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#name.);
201 if ((section_name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) ? section_name == name : strcmpcxx . . $ strcmp(5ae29d726ae57f88).(config_string_to_cstrcxx . . $ config_string_to_cstr(f431c5a37e14148e).(&section->namecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#name.), name) == 0)
202 return section;
203 }
204 }
205
206 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
207 }
208
209 ConfigSectioncxx . . $ ConfigSection# *config_find_or_add_sectioncxx . . $ config_find_or_add_section(9d60c5d7489db765).(Configcxx . . $ Config# *config, const char *type, const char *name)
210 {
211 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(config != NULL);
212 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(type != NULL);
213
214 ConfigSectioncxx . . $ ConfigSection# *section = config_find_sectioncxx . . $ config_find_section(9d60c5d7489db765).(config, type, name);
215
216 if (section != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
217 return section;
218
219 return config_add_sectioncxx . . $ config_add_section(9d60c5d7489db765).(config, type, name);
220 }
221
222 /* config option manipulators -- internal */
223
224 static void init_option_valuecxx . . $ init_option_value(3d468763d7044909).(ConfigOptioncxx . . $ ConfigOption# *option, const char *value, size_t value_len)
225 {
226 option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. = 0;
227 option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuecxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#value. = string_init_lencxx . . $ string_init_len(86ba0ae5cc355dba).(value, value_len);
228 }
229
230 static void deinit_option_valuecxx . . $ deinit_option_value(6d64c9bf03f2972a).(ConfigOptioncxx . . $ ConfigOption# *option)
231 {
232 if (option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. != 0)
233 {
234 ConfigStringcxx . . $ ConfigString# *values_end = &option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values.[option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count.];
235 for (ConfigStringcxx . . $ ConfigString# *value = &option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values.[0]; value < values_end; ++value)
236 string_deinitcxx . . $ string_deinit(2cb55483ce1f54cf).(value);
237
238 freecxx . . $ free(5d22bdacc48458e8).(option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values.);
239 option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
240 }
241 else
242 {
243 string_deinitcxx . . $ string_deinit(2cb55483ce1f54cf).(&option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuecxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#value.);
244 }
245 }
246
247 static void init_optioncxx . . $ init_option(686e3c879a2fd292).(ConfigOptioncxx . . $ ConfigOption# *option, const char *key, size_t key_len, const char *value, size_t value_len)
248 {
249 option->keycxx . . $ $anonymous_type_88ace789ff2dc3d9_1#key. = string_init_lencxx . . $ string_init_len(86ba0ae5cc355dba).(key, key_len);
250 init_option_valuecxx . . $ init_option_value(3d468763d7044909).(option, value, value_len);
251 }
252
253 static void deinit_optioncxx . . $ deinit_option(6d64c9bf03f2972a).(ConfigOptioncxx . . $ ConfigOption# *option)
254 {
255 string_deinitcxx . . $ string_deinit(2cb55483ce1f54cf).(&option->keycxx . . $ $anonymous_type_88ace789ff2dc3d9_1#key.);
256 deinit_option_valuecxx . . $ deinit_option_value(6d64c9bf03f2972a).(option);
257 }
258
259 static ConfigOptioncxx . . $ ConfigOption# *append_optioncxx . . $ append_option(36a359f33b0d911c).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, size_t key_len, const char *value, size_t value_len)
260 {
261 ConfigOptioncxx . . $ ConfigOption# *options = realloccxx . . $ realloc(417ab160f6baadc6).(section->optionscxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options., (section->options_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options_count. + 1) * sizeof(ConfigSectioncxx . . $ ConfigSection#));
262 if (options == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
263 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
264
265 ConfigOptioncxx . . $ ConfigOption# *option = &options[section->options_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options_count.];
266
267 section->options_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options_count. += 1;
268 section->optionscxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options. = options;
269
270 init_optioncxx . . $ init_option(686e3c879a2fd292).(option, key, key_len, value, value_len);
271
272 return option;
273 }
274
275 static ConfigOptioncxx . . $ ConfigOption# *get_option_lencxx . . $ get_option_len(dff1fda3c5fd4052).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, size_t key_len)
276 {
277 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(section != NULL);
278 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
279
280 ConfigOptioncxx . . $ ConfigOption# *options_end = &section->optionscxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options.[section->options_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options_count.];
281 for (ConfigOptioncxx . . $ ConfigOption# *option = &section->optionscxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options.[0]; option < options_end; ++option)
282 if (string_equal_lencxx . . $ string_equal_len(cfcbb7169d78c0d).(&option->keycxx . . $ $anonymous_type_88ace789ff2dc3d9_1#key., key, key_len))
283 return option;
284
285 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
286 }
287
288 /* config option accessors/manipulators -- by key */
289
290 ConfigOptioncxx . . $ ConfigOption# *config_set_option_lencxx . . $ config_set_option_len(36a359f33b0d911c).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, size_t key_len, const char *value, size_t value_len)
291 {
292 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(section != NULL);
293 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
294
295 ConfigOptioncxx . . $ ConfigOption# *option = get_option_lencxx . . $ get_option_len(dff1fda3c5fd4052).(section, key, key_len);
296
297 if (option != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
298 return config_set_value_lencxx . . $ config_set_value_len(a7b414abafe16dd0).(option, value, value_len);
299
300 return append_optioncxx . . $ append_option(36a359f33b0d911c).(section, key, key_len, value, value_len);
301 }
302
303 ConfigOptioncxx . . $ ConfigOption# *config_get_optioncxx . . $ config_get_option(5d3990c1f9186589).(const ConfigSectioncxx . . $ ConfigSection# *section, const char *key)
304 {
305 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(section != NULL);
306 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
307
308 ConfigOptioncxx . . $ ConfigOption# *options_end = &section->optionscxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options.[section->options_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options_count.];
309 for (ConfigOptioncxx . . $ ConfigOption# *option = &section->optionscxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options.[0]; option < options_end; ++option)
310 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(config_string_to_cstrcxx . . $ config_string_to_cstr(f431c5a37e14148e).(&option->keycxx . . $ $anonymous_type_88ace789ff2dc3d9_1#key.), key) == 0)
311 return option;
312
313 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
314 }
315
316 ConfigOptioncxx . . $ ConfigOption# *config_get_or_set_option_lencxx . . $ config_get_or_set_option_len(36a359f33b0d911c).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, size_t key_len, const char *value, size_t value_len)
317 {
318 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(section != NULL);
319 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
320
321 ConfigOptioncxx . . $ ConfigOption# *option = get_option_lencxx . . $ get_option_len(dff1fda3c5fd4052).(section, key, key_len);
322
323 if (option != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
324 return option;
325
326 return append_optioncxx . . $ append_option(36a359f33b0d911c).(section, key, key_len, value, value_len);
327 }
328
329 void config_set_string_option_lencxx . . $ config_set_string_option_len(b5b26d77152c566b).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, size_t key_len, const char *value, size_t value_len)
330 {
331 if (config_set_option_lencxx . . $ config_set_option_len(36a359f33b0d911c).(section, key, key_len, value, value_len) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
332 config_oomcxx . . $ config_oom(49f6e7a06ebc5aa8).();
333 }
334
335 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! config_get_string_optioncxx . . $ config_get_string_option(667c6ff1f014f85c).(const ConfigSectioncxx . . $ ConfigSection# *section, const char *key, const char **out_value)
336 {
337 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(section != NULL);
338 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
339
340 ConfigOptioncxx . . $ ConfigOption# *option = config_get_optioncxx . . $ config_get_option(5d3990c1f9186589).(section, key);
341 if (option != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
342 {
343 const char *value = config_get_valuecxx . . $ config_get_value(7c319b7c0e111005).(option);
344 if (value != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
345 {
346 *out_value = value;
347 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
348 }
349 }
350
351 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
352 }
353
354 const char *config_get_or_set_string_optioncxx . . $ config_get_or_set_string_option(b808a65f0fa43528).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, const char *value)
355 {
356 if (!config_get_string_optioncxx . . $ config_get_string_option(667c6ff1f014f85c).(section, key, &value))
357 config_set_string_option_lencxx . . $ config_set_string_option_len(b5b26d77152c566b).(section, key, strlencxx . . $ strlen(751346f8406fd082).(key), value, value == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ? 0 : strlencxx . . $ strlen(751346f8406fd082).(value));
358 return value;
359 }
360
361 static const char *const bool_valuescxx . . $ bool_values.[][2] =
362 {
363 { "0", "1" },
364 { "no", "yes" },
365 { "off", "on" },
366 { "false", "true" },
367 };
368
369 void config_set_bool_optioncxx . . $ config_set_bool_option(f5dd347f13677d31).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! value, ConfigBoolStylecxx . . $ ConfigBoolStyle# style)
370 {
371 if (config_set_optioncxx . . $ config_set_option(a828e1840e46298e).(section, key, bool_valuescxx . . $ bool_values.[style][value ? 1 : 0]) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
372 config_oomcxx . . $ config_oom(49f6e7a06ebc5aa8).();
373 }
374
375 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! config_get_bool_optioncxx . . $ config_get_bool_option(fe7db5902bd636d8).(const ConfigSectioncxx . . $ ConfigSection# *section, const char *key, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! *out_value)
376 {
377 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(section != NULL);
378 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
379 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(out_value != NULL);
380
381 const char *value;
382 if (config_get_string_optioncxx . . $ config_get_string_option(667c6ff1f014f85c).(section, key, &value))
383 {
384 for (size_t i = 0; i < COUNTOFcxx . . $ `src/config_file.h:51:9`!(bool_values); ++i)
385 {
386 for (size_t j = 0; j < COUNTOFcxx . . $ `src/config_file.h:51:9`!(bool_values[i]); ++j)
387 {
388 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(value, bool_valuescxx . . $ bool_values.[i][j]) == 0)
389 {
390 *out_value = j == 0 ? falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`! : truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
391 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
392 }
393 }
394 }
395 }
396
397 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
398 }
399
400 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! config_get_or_set_bool_optioncxx . . $ config_get_or_set_bool_option(d7712a9617cb47df).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! value, ConfigBoolStylecxx . . $ ConfigBoolStyle# style)
401 {
402 if (!config_get_bool_optioncxx . . $ config_get_bool_option(fe7db5902bd636d8).(section, key, &value))
403 config_set_bool_optioncxx . . $ config_set_bool_option(f5dd347f13677d31).(section, key, value, style);
404 return value;
405 }
406
407 void config_set_int_optioncxx . . $ config_set_int_option(3efcdbae08d7b398).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, int value)
408 {
409 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
410
411 char buffer[sdecsizeofcxx . . $ `src/config_file.c:35:9`!(int) + 1];
412 int buffer_len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buffer, sizeof(buffer), "%i", value);
413
414 if (config_set_option_lencxx . . $ config_set_option_len(36a359f33b0d911c).(section, key, strlencxx . . $ strlen(751346f8406fd082).(key), buffer, buffer_len) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
415 config_oomcxx . . $ config_oom(49f6e7a06ebc5aa8).();
416 }
417
418 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! config_get_int_optioncxx . . $ config_get_int_option(e9b2851f0de0b00d).(const ConfigSectioncxx . . $ ConfigSection# *section, const char *key, int *out_value)
419 {
420 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(section != NULL);
421 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
422 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(out_value != NULL);
423
424 const char *value;
425 if (config_get_string_optioncxx . . $ config_get_string_option(667c6ff1f014f85c).(section, key, &value))
426 {
427 int i;
428 int n;
429 if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(value, "%i%n", &i, &n) > 0 && value[n] == '\0') /* must be entire string */
430 {
431 *out_value = i;
432 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
433 }
434 }
435
436 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
437 }
438
439 int config_get_or_set_int_optioncxx . . $ config_get_or_set_int_option(bd9cb9e767e253ec).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, int value)
440 {
441 if (!config_get_int_optioncxx . . $ config_get_int_option(e9b2851f0de0b00d).(section, key, &value))
442 config_set_int_optioncxx . . $ config_set_int_option(3efcdbae08d7b398).(section, key, value);
443 return value;
444 }
445
446 void config_set_uint_optioncxx . . $ config_set_uint_option(63eb13e196eff8e6).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, unsigned int value)
447 {
448 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
449
450 char buffer[udecsizeofcxx . . $ `src/config_file.c:34:9`!(unsigned int) + 1];
451 int buffer_len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buffer, sizeof(buffer), "%u", value);
452
453 if (config_set_option_lencxx . . $ config_set_option_len(36a359f33b0d911c).(section, key, strlencxx . . $ strlen(751346f8406fd082).(key), buffer, buffer_len) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
454 config_oomcxx . . $ config_oom(49f6e7a06ebc5aa8).();
455 }
456
457 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! config_get_uint_optioncxx . . $ config_get_uint_option(f78eb4a7a72b688a).(const ConfigSectioncxx . . $ ConfigSection# *section, const char *key, unsigned int *out_value)
458 {
459 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(section != NULL);
460 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
461 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(out_value != NULL);
462
463 const char *value;
464 if (config_get_string_optioncxx . . $ config_get_string_option(667c6ff1f014f85c).(section, key, &value))
465 {
466 unsigned int u;
467 int n;
468 if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(value, "%u%n", &u, &n) > 0 && value[n] == '\0') /* must be entire string */
469 {
470 *out_value = u;
471 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
472 }
473 }
474
475 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
476 }
477
478 unsigned int config_get_or_set_uint_optioncxx . . $ config_get_or_set_uint_option(bb41ab88d5ddc12a).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, unsigned int value)
479 {
480 if (!config_get_uint_optioncxx . . $ config_get_uint_option(f78eb4a7a72b688a).(section, key, &value))
481 config_set_uint_optioncxx . . $ config_set_uint_option(63eb13e196eff8e6).(section, key, value);
482 return value;
483 }
484
485 /* config option accessors/manipulators -- by reference */
486
487 ConfigOptioncxx . . $ ConfigOption# *config_set_value_lencxx . . $ config_set_value_len(a7b414abafe16dd0).(ConfigOptioncxx . . $ ConfigOption# *option, const char *value, size_t value_len)
488 {
489 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(option != NULL);
490
491 deinit_option_valuecxx . . $ deinit_option_value(6d64c9bf03f2972a).(option);
492
493 init_option_valuecxx . . $ init_option_value(3d468763d7044909).(option, value, value_len);
494
495 return option;
496 }
497
498 ConfigOptioncxx . . $ ConfigOption# *config_add_value_lencxx . . $ config_add_value_len(a7b414abafe16dd0).(ConfigOptioncxx . . $ ConfigOption# *option, const char *value, size_t value_len)
499 {
500 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(option != NULL);
501 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(value != NULL);
502
503 /* convert 'item' to 'list' */
504 if (option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. == 0 && config_string_to_cstrcxx . . $ config_string_to_cstr(f431c5a37e14148e).(&option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuecxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#value.) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
505 {
506 ConfigStringcxx . . $ ConfigString# option_value = option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuecxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#value.;
507
508 ConfigStringcxx . . $ ConfigString# *values = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(2 * sizeof(ConfigStringcxx . . $ ConfigString#));
509 if (values == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
510 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
511
512 option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values. = values;
513 option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values.[0] = option_value;
514 option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values.[1] = string_init_lencxx . . $ string_init_len(86ba0ae5cc355dba).(value, value_len);
515 option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. = 2;
516 }
517 else
518 {
519 ConfigStringcxx . . $ ConfigString# *values = realloccxx . . $ realloc(417ab160f6baadc6).(option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values., (option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. + 1) * sizeof(ConfigStringcxx . . $ ConfigString#));
520 if (values == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
521 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
522
523 option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values. = values;
524 option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values.[option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count.] = string_init_lencxx . . $ string_init_len(86ba0ae5cc355dba).(value, value_len);
525 option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. += 1;
526 }
527
528 return option;
529 }
530
531 ConfigOptioncxx . . $ ConfigOption# *config_remove_valuecxx . . $ config_remove_value(c3bd1c7e617a3a76).(ConfigOptioncxx . . $ ConfigOption# *option, unsigned int i)
532 {
533 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(option != NULL);
534
535 if (!config_is_value_listcxx . . $ config_is_value_list(5baeb70b3f01321d).(option))
536 {
537 if (i > 0)
538 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
539
540 config_set_value_lencxx . . $ config_set_value_len(a7b414abafe16dd0).(option, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
541 }
542 else
543 {
544 if (i >= option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count.)
545 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
546
547 string_deinitcxx . . $ string_deinit(2cb55483ce1f54cf).(&option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values.[i]);
548 memmovecxx . . $ memmove(cc817cb175f282d).(&option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values.[i], &option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values.[i + 1], (option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. - i - 1) * sizeof(ConfigStringcxx . . $ ConfigString#));
549
550 if (option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. - 1 == 0)
551 {
552 option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuecxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#value. = string_init_lencxx . . $ string_init_len(86ba0ae5cc355dba).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
553 option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. = 0;
554 }
555 else
556 {
557 ConfigStringcxx . . $ ConfigString# *values = realloccxx . . $ realloc(417ab160f6baadc6).(option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values., (option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. - 1) * sizeof(ConfigStringcxx . . $ ConfigString#));
558 if (values == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
559 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
560
561 option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values. = values;
562 option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. -= 1;
563 }
564 }
565
566 return option;
567 }
568
569 const char *config_get_valuecxx . . $ config_get_value(7c319b7c0e111005).(const ConfigOptioncxx . . $ ConfigOption# *option)
570 {
571 if (option == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. != 0)
572 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
573
574 return config_string_to_cstrcxx . . $ config_string_to_cstr(f431c5a37e14148e).(&option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuecxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#value.);
575 }
576
577 /* config parser */
578
579 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! is_whitespacecxx . . $ is_whitespace(b5fd09639b7a0261).(char c)
580 {
581 return c == '\t' || c == ' ';
582 }
583
584 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! is_endcxx . . $ is_end(b5fd09639b7a0261).(char c)
585 {
586 return c == '\0' || c == '\n' || c == '\r';
587 }
588
589 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! is_whitespace_or_endcxx . . $ is_whitespace_or_end(b5fd09639b7a0261).(char c)
590 {
591 return is_whitespacecxx . . $ is_whitespace(b5fd09639b7a0261).(c) || is_endcxx . . $ is_end(b5fd09639b7a0261).(c);
592 }
593
594 typedef enumcxx . . $ $anonymous_type_e4ab1a6ee34b8c2a_0#
595 {
596 INVALID_DIRECTIVEcxx . . $ INVALID_DIRECTIVE. = 0,
597 SECTION_DIRECTIVEcxx . . $ SECTION_DIRECTIVE.,
598 ITEM_DIRECTIVEcxx . . $ ITEM_DIRECTIVE.,
599 LIST_DIRECTIVEcxx . . $ LIST_DIRECTIVE.,
600 } Directivecxx . . $ Directive#;
601
602 static Directivecxx . . $ Directive# match_directivecxx . . $ match_directive(f9e06350e2fbe85e).(const char *buffer, size_t *index)
603 {
604 size_t i = *index;
605
606 while (is_whitespacecxx . . $ is_whitespace(b5fd09639b7a0261).(buffer[i]))
607 ++i;
608
609 Directivecxx . . $ Directive# directive;
610
611 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).("section", &buffer[i], 7) == 0)
612 {
613 directive = SECTION_DIRECTIVEcxx . . $ SECTION_DIRECTIVE.;
614 i += 7;
615 }
616 else if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).("item", &buffer[i], 4) == 0)
617 {
618 directive = ITEM_DIRECTIVEcxx . . $ ITEM_DIRECTIVE.;
619 i += 4;
620 }
621 else if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).("list", &buffer[i], 4) == 0)
622 {
623 directive = LIST_DIRECTIVEcxx . . $ LIST_DIRECTIVE.;
624 i += 4;
625 }
626 else
627 {
628 return INVALID_DIRECTIVEcxx . . $ INVALID_DIRECTIVE.;
629 }
630
631 if (!is_whitespace_or_endcxx . . $ is_whitespace_or_end(b5fd09639b7a0261).(buffer[i]))
632 return INVALID_DIRECTIVEcxx . . $ INVALID_DIRECTIVE.;
633
634 *index = i;
635
636 return directive;
637 }
638
639 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! match_nonquote_fieldcxx . . $ match_nonquote_field(ddc2e61b0e945862).(const char *buffer, size_t *index, size_t *length)
640 {
641 size_t i = *index;
642
643 for (; ; ++i)
644 {
645 char c = buffer[i];
646
647 if (is_whitespace_or_endcxx . . $ is_whitespace_or_end(b5fd09639b7a0261).(c))
648 {
649 break;
650 }
651 else if (c <= ' ' || c > '~' || c == '#' || c == '\'' || c == '"')
652 {
653 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
654 }
655 }
656
657 *length = i - *index;
658 *index = i;
659
660 return *length > 0;
661 }
662
663 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! parse_quote_fieldcxx . . $ parse_quote_field(573e52b18977fc3).(char *buffer, size_t *index, size_t *length)
664 {
665 size_t i = *index;
666 size_t o = *index;
667
668 char quote = buffer[i];
669
670 for (; ; )
671 {
672 char c = buffer[++i];
673
674 if (c == quote)
675 {
676 ++i;
677 break;
678 }
679 else if (c == '\\')
680 {
681 c = buffer[++i];
682 if (c == quote)
683 {
684 buffer[o++] = quote;
685 }
686 else
687 {
688 switch (c)
689 {
690 case 't':
691 buffer[o++] = '\t';
692 break;
693 case 'n':
694 buffer[o++] = '\n';
695 break;
696 case 'r':
697 buffer[o++] = '\r';
698 break;
699 case '\\':
700 buffer[o++] = '\\';
701 break;
702 case 'x':
703 /* parse two hex digits */
704 c = buffer[++i];
705 char m = (c >= '0' && c <= '9') ? '0' :
706 (c >= 'a' && c <= 'f') ? 'a' - 10 :
707 (c >= 'A' && c <= 'F') ? 'A' - 10 : 0;
708 if (m == 0)
709 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
710 char h = c - m;
711 c = buffer[++i];
712 m = (c >= '0' && c <= '9') ? '0' :
713 (c >= 'a' && c <= 'f') ? 'a' - 10 :
714 (c >= 'A' && c <= 'F') ? 'A' - 10 : 0;
715 if (m == 0)
716 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
717 buffer[o++] = (h << 4) | (c - m);
718 break;
719 default:
720 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
721 }
722 }
723 }
724 else if (c >= ' ' && c <= '~')
725 {
726 buffer[o++] = c;
727 }
728 else
729 {
730 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
731 }
732 }
733
734 *length = o - *index;
735 *index = i;
736
737 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
738 }
739
740 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! parse_fieldcxx . . $ parse_field(8fac874ce383ae9a).(char *buffer, size_t *index, size_t *start, size_t *length)
741 {
742 size_t i = *index;
743
744 while (is_whitespacecxx . . $ is_whitespace(b5fd09639b7a0261).(buffer[i]))
745 ++i;
746
747 *start = i;
748
749 if (buffer[i] == '"' || buffer[i] == '\'')
750 {
751 if (!parse_quote_fieldcxx . . $ parse_quote_field(573e52b18977fc3).(buffer, &i, length))
752 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
753 }
754 else
755 {
756 if (!match_nonquote_fieldcxx . . $ match_nonquote_field(ddc2e61b0e945862).(buffer, &i, length))
757 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
758 }
759
760 if (!is_whitespace_or_endcxx . . $ is_whitespace_or_end(b5fd09639b7a0261).(buffer[i]))
761 return INVALID_DIRECTIVEcxx . . $ INVALID_DIRECTIVE.;
762
763 *index = i;
764
765 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
766 }
767
768 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! config_parsecxx . . $ config_parse(7d28d4b21896e09c).(Configcxx . . $ Config# *config, FILEcxx . . $ FILE# *file)
769 {
770 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(config != NULL);
771 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(file != NULL);
772
773 config_initcxx . . $ config_init(b7cb4517c44ac027).(config);
774
775 ConfigSectioncxx . . $ ConfigSection# *section = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
776 ConfigOptioncxx . . $ ConfigOption# *option = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
777
778 size_t buffer_cap = 128;
779 char *buffer = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(buffer_cap * sizeof(char));
780 if (buffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
781 config_oomcxx . . $ config_oom(49f6e7a06ebc5aa8).();
782 size_t buffer_end = 1;
783 buffer[buffer_end - 1] = '\0';
784
785 for (size_t line = 0, next_line = 0; ; line = next_line)
786 {
787 /* find beginning of next line */
788 while (next_line < buffer_end)
789 {
790 char c = buffer[next_line];
791
792 if (c == '\0' && next_line == buffer_end - 1)
793 {
794 if (line > 0)
795 {
796 /* shift to front */
797 memmovecxx . . $ memmove(cc817cb175f282d).(&buffer[0], &buffer[line], buffer_end - line);
798 buffer_end -= line;
799 next_line -= line;
800 line = 0;
801 }
802 else if (buffer_end > 1)
803 {
804 /* need larger capacity */
805 buffer_cap *= 2;
806 char *new_buffer = realloccxx . . $ realloc(417ab160f6baadc6).(buffer, buffer_cap * sizeof(char));
807 if (new_buffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
808 config_oomcxx . . $ config_oom(49f6e7a06ebc5aa8).();
809 buffer = new_buffer;
810 }
811
812 size_t read = freadcxx . . $ fread(738fc8ac1d711e58).(&buffer[buffer_end - 1], sizeof(char), buffer_cap - buffer_end, file);
813 if (read == 0)
814 break;
815
816 buffer_end += read;
817 buffer[buffer_end - 1] = '\0';
818 }
819 else
820 {
821 ++next_line;
822
823 if (c == '\n' || c == '\r')
824 break;
825 }
826 }
827
828 /* if at end of file */
829 if (next_line == line)
830 break;
831
832 size_t i = line;
833
834 Directivecxx . . $ Directive# directive = match_directivecxx . . $ match_directive(f9e06350e2fbe85e).(buffer, &i);
835
836 switch (directive)
837 {
838 case INVALID_DIRECTIVEcxx . . $ INVALID_DIRECTIVE.:
839 continue;
840 case SECTION_DIRECTIVEcxx . . $ SECTION_DIRECTIVE.:
841 {
842 size_t type_start;
843 size_t type_length;
844
845 if (!parse_fieldcxx . . $ parse_field(8fac874ce383ae9a).(buffer, &i, &type_start, &type_length))
846 continue;
847
848 size_t name_start;
849 size_t name_length;
850
851 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! has_name = parse_fieldcxx . . $ parse_field(8fac874ce383ae9a).(buffer, &i, &name_start, &name_length);
852
853 section = config_add_section_lencxx . . $ config_add_section_len(ee1a9159675f0d4e).(config,
854 &buffer[type_start], type_length,
855 has_name ? &buffer[name_start] : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, has_name ? name_length : 0);
856 if (section == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
857 config_oomcxx . . $ config_oom(49f6e7a06ebc5aa8).();
858 option = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
859 }
860 break;
861 case ITEM_DIRECTIVEcxx . . $ ITEM_DIRECTIVE.:
862 case LIST_DIRECTIVEcxx . . $ LIST_DIRECTIVE.:
863 {
864 if (section == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
865 continue;
866
867 size_t key_start;
868 size_t key_length;
869
870 if (!parse_fieldcxx . . $ parse_field(8fac874ce383ae9a).(buffer, &i, &key_start, &key_length))
871 continue;
872
873 size_t value_start;
874 size_t value_length;
875
876 if (!parse_fieldcxx . . $ parse_field(8fac874ce383ae9a).(buffer, &i, &value_start, &value_length))
877 continue;
878
879 if (directive == ITEM_DIRECTIVEcxx . . $ ITEM_DIRECTIVE.)
880 {
881 option = config_set_option_lencxx . . $ config_set_option_len(36a359f33b0d911c).(section,
882 &buffer[key_start], key_length,
883 &buffer[value_start], value_length);
884 }
885 else
886 {
887 if (option == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || !string_equal_lencxx . . $ string_equal_len(cfcbb7169d78c0d).(&option->keycxx . . $ $anonymous_type_88ace789ff2dc3d9_1#key., &buffer[key_start], key_length))
888 option = config_get_or_set_option_lencxx . . $ config_get_or_set_option_len(36a359f33b0d911c).(section,
889 &buffer[key_start], key_length,
890 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
891 if (option != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
892 option = config_add_value_lencxx . . $ config_add_value_len(a7b414abafe16dd0).(option,
893 &buffer[value_start], value_length);
894 }
895 if (option == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
896 config_oomcxx . . $ config_oom(49f6e7a06ebc5aa8).();
897 }
898 break;
899 }
900
901 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(i <= next_line);
902 }
903
904 freecxx . . $ free(5d22bdacc48458e8).(buffer);
905
906 return config;
907 }
908
909 /* config writer */
910
911 static void write_fieldcxx . . $ write_field(56d14b100ea5681b).(const ConfigStringcxx . . $ ConfigString# *field, FILEcxx . . $ FILE# *file)
912 {
913 fputccxx . . $ fputc(b1cd03d6c470d1bd).('\'', file);
914
915 char buffer[128];
916 size_t o = 0;
917
918 for (const char *ci = config_string_to_cstrcxx . . $ config_string_to_cstr(f431c5a37e14148e).(field); *ci != '\0'; ++ci)
919 {
920 char c = *ci;
921
922 size_t l;
923 switch (c)
924 {
925 case '\t':
926 case '\n':
927 case '\r':
928 case '\'':
929 case '\\':
930 l = 2;
931 break;
932 default:
933 l = (c >= ' ' && c <= '~') ? 1 : 4;
934 break;
935 }
936
937 if (o + l > COUNTOFcxx . . $ `src/config_file.h:51:9`!(buffer))
938 {
939 fwritecxx . . $ fwrite(ab0609fa07c47d6e).(buffer, sizeof(*buffer), o, file);
940 o = 0;
941 }
942
943 switch (l)
944 {
945 case 1:
946 buffer[o++] = c;
947 break;
948 case 2:
949 switch (c)
950 {
951 case '\t':
952 buffer[o++] = '\\';
953 buffer[o++] = 't';
954 break;
955 case '\n':
956 buffer[o++] = '\\';
957 buffer[o++] = 'n';
958 break;
959 case '\r':
960 buffer[o++] = '\\';
961 buffer[o++] = 'r';
962 break;
963 case '\'':
964 case '\\':
965 buffer[o++] = '\\';
966 buffer[o++] = c;
967 break;
968 }
969 break;
970 case 4:
971 buffer[o++] = '\\';
972 buffer[o++] = 'x';
973 char n = (c >> 4) & 0x0f;
974 buffer[o++] = (n < 10 ? '0' : ('a' - 10)) + n;
975 n = c & 0x0f;
976 buffer[o++] = (n < 10 ? '0' : ('a' - 10)) + n;
977 break;
978 }
979 }
980
981 if (o > 0)
982 fwritecxx . . $ fwrite(ab0609fa07c47d6e).(buffer, sizeof(*buffer), o, file);
983
984 fputccxx . . $ fputc(b1cd03d6c470d1bd).('\'', file);
985 }
986
987 void config_writecxx . . $ config_write(743dd42310ca6b83).(const Configcxx . . $ Config# *config, FILEcxx . . $ FILE# *file)
988 {
989 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(config != NULL);
990 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(file != NULL);
991
992 for (unsigned int s = 0; s < config->sections_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections_count.; ++s)
993 {
994 ConfigSectioncxx . . $ ConfigSection# *section = &config->sectionscxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections.[s];
995
996 fputscxx . . $ fputs(874fa6a5e59ab9bd).("section ", file);
997 write_fieldcxx . . $ write_field(56d14b100ea5681b).(&section->typecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#type., file);
998 if (config_string_to_cstrcxx . . $ config_string_to_cstr(f431c5a37e14148e).(&section->namecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#name.) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
999 {
1000 fputccxx . . $ fputc(b1cd03d6c470d1bd).(' ', file);
1001 write_fieldcxx . . $ write_field(56d14b100ea5681b).(&section->namecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#name., file);
1002 }
1003 fputccxx . . $ fputc(b1cd03d6c470d1bd).('\n', file);
1004
1005 for (unsigned int o = 0; o < section->options_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options_count.; ++o)
1006 {
1007 ConfigOptioncxx . . $ ConfigOption# *option = &section->optionscxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options.[o];
1008
1009 if (option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. == 0 && config_string_to_cstrcxx . . $ config_string_to_cstr(f431c5a37e14148e).(&option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuecxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#value.) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1010 {
1011 fputscxx . . $ fputs(874fa6a5e59ab9bd).("\titem ", file);
1012 write_fieldcxx . . $ write_field(56d14b100ea5681b).(&option->keycxx . . $ $anonymous_type_88ace789ff2dc3d9_1#key., file);
1013 fputccxx . . $ fputc(b1cd03d6c470d1bd).(' ', file);
1014 write_fieldcxx . . $ write_field(56d14b100ea5681b).(&option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuecxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#value., file);
1015 fputccxx . . $ fputc(b1cd03d6c470d1bd).('\n', file);
1016 }
1017 else
1018 {
1019 ConfigStringcxx . . $ ConfigString# *values_end = &option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values.[option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count.];
1020 for (ConfigStringcxx . . $ ConfigString# *value = &option->vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v..valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values.[0]; value < values_end; ++value)
1021 {
1022 fputscxx . . $ fputs(874fa6a5e59ab9bd).("\tlist ", file);
1023 write_fieldcxx . . $ write_field(56d14b100ea5681b).(&option->keycxx . . $ $anonymous_type_88ace789ff2dc3d9_1#key., file);
1024 fputccxx . . $ fputc(b1cd03d6c470d1bd).(' ', file);
1025 write_fieldcxx . . $ write_field(56d14b100ea5681b).(value, file);
1026 fputccxx . . $ fputc(b1cd03d6c470d1bd).('\n', file);
1027 }
1028 }
1029 }
1030
1031 fputccxx . . $ fputc(b1cd03d6c470d1bd).('\n', file);
1032 }
1033 }