Debian Codegraph @

src/config_file.h

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.h
21 * \author Carl Reinke
22 * \date 2015
23 * \copyright GNU General Public License v2+ or Mozilla Public License 2.0
24 */
25 #ifndef CONFIG_FILE_H
26 #define CONFIG_FILE_Hcxx . . $ `src/config_file.h:26:9`!
27
28 #include <assert.h>
29 #include <stdbool.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #ifndef COMPILE_TIME_ASSERT
35 /*!
36 * \brief Cause compile error if compile-time computable condition fails.
37 *
38 * \param[in] name the unique identifier of the assertion
39 * \param[in] cond the condition
40 */
41 #define COMPILE_TIME_ASSERTcxx . . $ `src/config_file.h:41:9`!(name, cond) typedef int assert_ ## name[(cond) * 2 - 1]
42 #endif
43
44 #ifndef COUNTOFcxx . . $ `src/opentyr.h:27:9`!
45 /*!
46 * \brief Calculate the number of elements in a fixed-length array.
47 *
48 * \param[in] a the fixed-length array
49 * \return the number of elements in the array
50 */
51 #define COUNTOFcxx . . $ `src/config_file.h:51:9`!(a) (sizeof(a) / sizeof(*(a)))
52 #endif
53
54 /* string type */
55
56 /*!
57 * \brief A short-string-optimizing string type.
58 *
59 * This struct allows for storing up to 15 characters (plus a terminating \c '\0') inline. For
60 * longer strings memory will be allocated.
61 *
62 * The tag for this union is the last character of \p short_buf:
63 * \li if \c '\0' then \p short_buf is valid,
64 * \li otherwise \p long_buf is valid.
65 */
66 typedef unioncxx . . $ $anonymous_type_88ace789ff2dc3d9_0#
67 {
68 /*!
69 * \brief The inline buffer for short strings.
70 */
71 char short_bufcxx . . $ $anonymous_type_88ace789ff2dc3d9_0#short_buf.[16];
72
73 /*!
74 * \brief The buffer for long strings.
75 *
76 * May be \c NULL.
77 */
78 char *long_bufcxx . . $ $anonymous_type_88ace789ff2dc3d9_0#long_buf.;
79 } ConfigStringcxx . . $ ConfigString#;
80
81 /*! \cond suppress_doxygen */
82 COMPILE_TIME_ASSERTcxx . . $ ConfigString#(string_short_buf_sufficient, sizeof(char *) + 1 <= COUNTOFcxx . . $ `src/config_file.h:51:9`!(((ConfigString *)NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)->short_buf));
83 /*! \endcond */
84
85 /*! \cond suppress_doxygen */
86 #define CONFIG_STRING_LONG_TAGcxx . . $ `src/config_file.h:86:9`!(s) ((s).short_buf[COUNTOFcxx . . $ `src/config_file.h:51:9`!((s).short_buf) - 1])
87 /*! \endcond */
88
89 /*!
90 * \brief Return a C-string backed by a string.
91 *
92 * \param[in] string the string
93 * \return the C-string
94 */
95 static inline const char *config_string_to_cstrcxx . . $ config_string_to_cstr(f431c5a37e14148e).(const ConfigStringcxx . . $ ConfigString# *string)
96 {
97 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(string != NULL);
98 char is_long = CONFIG_STRING_LONG_TAGcxx . . $ `src/config_file.h:86:9`!(*string);
99 return is_long ?
100 string->long_bufcxx . . $ $anonymous_type_88ace789ff2dc3d9_0#long_buf. :
101 string->short_bufcxx . . $ $anonymous_type_88ace789ff2dc3d9_0#short_buf.;
102 }
103
104 /* config types */
105
106 /*!
107 * \brief An option consisting of one (an item) or many (a list) values.
108 */
109 typedef structcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#
110 {
111 /*!
112 * \brief The key of the option.
113 */
114 ConfigStringcxx . . $ ConfigString# keycxx . . $ $anonymous_type_88ace789ff2dc3d9_1#key.;
115
116 /*!
117 * \brief The number of values in the option if it is a 'list' option.
118 *
119 * If \c 0 then the option \e may be an 'item' option.
120 *
121 * \see ::ConfigOption::value
122 */
123 unsigned int values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count.;
124
125 /*!
126 * \brief The value or values.
127 *
128 * The tag for this union is \p value_count:
129 * \li if \c 0 then \p value is valid,
130 * \li otherwise \p values is valid.
131 */
132 unioncxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#
133 {
134 /*!
135 * \brief The value of an 'item' option or an empty 'list' option.
136 *
137 * If this field is \c NULL then the option is an empty 'list' option.
138 */
139 ConfigStringcxx . . $ ConfigString# valuecxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#value.;
140
141 /*!
142 * \brief The values of a non-empty 'list' option.
143 */
144 ConfigStringcxx . . $ ConfigString# *valuescxx . . $ $anonymous_type_88ace789ff2dc3d9_1#$anonymous_type_2#values.;
145 } vcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#v.;
146 } ConfigOptioncxx . . $ ConfigOption#;
147
148 /*!
149 * \brief A section consisting of options.
150 */
151 typedef structcxx . . $ $anonymous_type_88ace789ff2dc3d9_3#
152 {
153 /*!
154 * \brief The type of the section.
155 */
156 ConfigStringcxx . . $ ConfigString# typecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#type.;
157
158 /*!
159 * \brief The optional name of the section.
160 *
161 * May be \c NULL.
162 */
163 ConfigStringcxx . . $ ConfigString# namecxx . . $ $anonymous_type_88ace789ff2dc3d9_3#name.;
164
165 /*!
166 * \brief The number of options in the section.
167 */
168 unsigned int options_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options_count.;
169
170 /*!
171 * \brief The options in the section.
172 *
173 * \c NULL if \p options_count is \c 0.
174 */
175 ConfigOptioncxx . . $ ConfigOption# *optionscxx . . $ $anonymous_type_88ace789ff2dc3d9_3#options.;
176 } ConfigSectioncxx . . $ ConfigSection#;
177
178 /*!
179 * \brief A configuration consisting of sections.
180 */
181 typedef structcxx . . $ $anonymous_type_88ace789ff2dc3d9_4#
182 {
183 /*!
184 * \brief The number of sections in the configuration.
185 */
186 unsigned int sections_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections_count.;
187
188 /*!
189 * \brief The sections in the configuration.
190 *
191 * \c NULL if \p sections_count is \c 0.
192 */
193 ConfigSectioncxx . . $ ConfigSection# *sectionscxx . . $ $anonymous_type_88ace789ff2dc3d9_4#sections.;
194 } Configcxx . . $ Config#;
195
196 /* config manipulators */
197
198 /*!
199 * \brief Initialize a configuration.
200 *
201 * \param[in] config the configuration
202 * \return void
203 */
204 extern void config_initcxx . . $ config_init(b7cb4517c44ac027).(Configcxx . . $ Config# *config);
205
206 /*!
207 * \brief Release any memory allocated inside a configuration.
208 *
209 * \param[in] config the configuration
210 * \return void
211 */
212 extern void config_deinitcxx . . $ config_deinit(b7cb4517c44ac027).(Configcxx . . $ Config# *config);
213
214 /*!
215 * \brief Parse a configuration from a file.
216 *
217 * \param[in] config the uninitialized configuration
218 * \param[in] file the file handle
219 * \return whether parsing succeeded
220 */
221 extern boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! config_parsecxx . . $ config_parse(7d28d4b21896e09c).(Configcxx . . $ Config# *config, FILEcxx . . $ FILE# *file);
222
223 /*!
224 * \brief Write a configuration to a file.
225 *
226 * \param[in] config the configuration
227 * \param[in] file the file handle
228 * \return void
229 */
230 extern void config_writecxx . . $ config_write(743dd42310ca6b83).(const Configcxx . . $ Config# *config, FILEcxx . . $ FILE# *file);
231
232 /* config section accessors/manipulators -- by type, name */
233
234 /*! \see ::config_add_section() */
235 extern 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);
236
237 /*!
238 * \brief Add a section to a configuration.
239 *
240 * \param[in] config the configuration to contain the section
241 * \param[in] type the type of the section
242 * \param[in] name the name of the section; may be \c NULL
243 * \return the added section; \c NULL if out of memory
244 */
245 static inline ConfigSectioncxx . . $ ConfigSection# *config_add_sectioncxx . . $ config_add_section(9d60c5d7489db765).(Configcxx . . $ Config# *config, const char *type, const char *name)
246 {
247 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(type != NULL);
248 return config_add_section_lencxx . . $ config_add_section_len(ee1a9159675f0d4e).(config, type, strlencxx . . $ strlen(751346f8406fd082).(type), name, name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ? 0 : strlencxx . . $ strlen(751346f8406fd082).(name));
249 }
250
251 // TODO: extern Config *config_remove_section(Config *config, unsigned int i);
252
253 /*!
254 * \brief Iterate sections by type.
255 *
256 * \param[in] config the configuration containing the sections
257 * \param[in] type the type of the section
258 * \param[in,out] save the saved state of the iterator; initialize \c *save to \c NULL before
259 * iteration
260 * \return the section; \c NULL if iteration finished
261 */
262 extern ConfigSectioncxx . . $ ConfigSection# *config_find_sectionscxx . . $ config_find_sections(5403134a7215bba0).(Configcxx . . $ Config# *config, const char *type, ConfigSectioncxx . . $ ConfigSection# **save);
263
264 /*!
265 * \brief Find a section by type and name.
266 *
267 * \param[in] config the configuration containing the section
268 * \param[in] type the type of the section
269 * \param[in] name the name of the section
270 * \return the section; \c NULL if it does not exist
271 */
272 extern ConfigSectioncxx . . $ ConfigSection# *config_find_sectioncxx . . $ config_find_section(9d60c5d7489db765).(Configcxx . . $ Config# *config, const char *type, const char *name);
273
274 /*!
275 * \brief Find a section by type and name, creating the section if it did not exist.
276 *
277 * \param[in] config the configuration containing the section
278 * \param[in] type the type of the section
279 * \param[in] name the name of the section; may be \c NULL
280 * \return the section; \c NULL if out of memory
281 */
282 extern ConfigSectioncxx . . $ ConfigSection# *config_find_or_add_sectioncxx . . $ config_find_or_add_section(9d60c5d7489db765).(Configcxx . . $ Config# *config, const char *type, const char *name);
283
284 /* config option accessors/manipulators -- by key */
285
286 /*! \see ::config_set_option() */
287 extern 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);
288
289 /*!
290 * \brief Set a value of an 'item' option by key, creating the option if necessary.
291 *
292 * \param[in] section the section containing the option
293 * \param[in] key the option key
294 * \param[in] value the item value; \c NULL to set an emtpy 'list' option instead of an 'item'
295 * option (can be used to delete an 'item' option)
296 * \return the option; \c NULL if out of memory
297 */
298 static inline ConfigOptioncxx . . $ ConfigOption# *config_set_optioncxx . . $ config_set_option(a828e1840e46298e).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, const char *value)
299 {
300 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
301 return config_set_option_lencxx . . $ config_set_option_len(36a359f33b0d911c).(section, key, strlencxx . . $ strlen(751346f8406fd082).(key), value, value == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! ? 0 : strlencxx . . $ strlen(751346f8406fd082).(value));
302 }
303
304 /*!
305 * \brief Get an option by key.
306 *
307 * \param[in] section the section containing the option
308 * \param[in] key the option key
309 * \return the option; \c NULL if it does not exist
310 */
311 extern ConfigOptioncxx . . $ ConfigOption# *config_get_optioncxx . . $ config_get_option(5d3990c1f9186589).(const ConfigSectioncxx . . $ ConfigSection# *section, const char *key);
312
313 /*! \see ::config_get_or_set_option() */
314 extern 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);
315
316 /*!
317 * \brief Get an option by key, creating an 'item' option if the option did not exist.
318 *
319 * \param[in] section the section containing the option
320 * \param[in] key the option key
321 * \param[in] value the default item value; \c NULL to set an empty 'list' option instead of an
322 * 'item' option
323 * \return the option; \c NULL if out of memory
324 */
325 static inline ConfigOptioncxx . . $ ConfigOption# *config_get_or_set_optioncxx . . $ config_get_or_set_option(a828e1840e46298e).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, const char *value)
326 {
327 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
328 return config_get_or_set_option_lencxx . . $ config_get_or_set_option_len(36a359f33b0d911c).(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));
329 }
330
331 /*! \see ::config_set_string_option() */
332 extern 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);
333
334 /*!
335 * \brief Set a string value of an 'item' option by key, creating the option if necessary.
336 *
337 * \param[in] section the section containing the option
338 * \param[in] key the option key
339 * \param[in] value the item value
340 * \return void
341 */
342 static inline void config_set_string_optioncxx . . $ config_set_string_option(b1b38906554e988).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, const char *value)
343 {
344 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(key != NULL);
345 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));
346 }
347
348 /*!
349 * \brief Get a string value of an 'item' option by key.
350 *
351 * \param[in] section the section containing the option
352 * \param[in] key the option key
353 * \param[out] out_value the item value if a valid option exists; otherwise unset
354 * \return whether \p out_value was set
355 */
356 extern 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);
357
358 /*!
359 * \brief Get a string value of an 'item' option by key, setting the option if it was invalid or
360 * creating the option if it did not exist.
361 *
362 * \param[in] section the section containing the option
363 * \param[in] key the option key
364 * \param[in] value the default item value
365 * \return the value
366 */
367 extern const char *config_get_or_set_string_optioncxx . . $ config_get_or_set_string_option(b808a65f0fa43528).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, const char *value);
368
369 /*!
370 * \brief The styles of boolean values.
371 */
372 typedef enumcxx . . $ $anonymous_type_88ace789ff2dc3d9_5#
373 {
374 ZERO_ONEcxx . . $ ZERO_ONE. = 0,
375 NO_YEScxx . . $ NO_YES. = 1,
376 OFF_ONcxx . . $ OFF_ON. = 2,
377 FALSE_TRUEcxx . . $ FALSE_TRUE. = 3,
378 } ConfigBoolStylecxx . . $ ConfigBoolStyle#;
379
380 /*!
381 * \brief Set a boolean value of an 'item' option by key, creating the option if necessary.
382 *
383 * \param[in] section the section containing the option
384 * \param[in] key the option key
385 * \param[in] value the item value
386 * \param[in] style the style of boolean value
387 * \return void
388 */
389 extern 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);
390
391 /*!
392 * \brief Get a boolean value of an 'item' option by key.
393 *
394 * \param[in] section the section containing the option
395 * \param[in] key the option key
396 * \param[out] out_value the item value if a valid option exists; otherwise unset
397 * \return whether \p out_value was set
398 */
399 extern 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);
400
401 /*!
402 * \brief Get a boolean value of an 'item' option by key, setting the option if it was invalid or
403 * creating the option if it did not exist.
404 *
405 * \param[in] section the section containing the option
406 * \param[in] key the option key
407 * \param[in] value the default item value
408 * \param[in] style the style of boolean value
409 * \return the value
410 */
411 extern 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);
412
413 /*!
414 * \brief Set an integer value of an 'item' option by key, creating the option if necessary.
415 *
416 * \param[in] section the section containing the option
417 * \param[in] key the option key
418 * \param[in] value the item value
419 * \return void
420 */
421 extern void config_set_int_optioncxx . . $ config_set_int_option(3efcdbae08d7b398).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, int value);
422
423 /*!
424 * \brief Get an integer value of an 'item' option by key.
425 *
426 * \param[in] section the section containing the option
427 * \param[in] key the option key
428 * \param[out] out_value the item value if a valid option exists; otherwise unset
429 * \return whether \p out_value was set
430 */
431 extern 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);
432
433 /*!
434 * \brief Get an integer value of an 'item' option by key, setting the option if it was invalid or
435 * creating the option if it did not exist.
436 *
437 * \param[in] section the section containing the option
438 * \param[in] key the option key
439 * \param[in] value the default item value
440 * \return the value
441 */
442 extern int config_get_or_set_int_optioncxx . . $ config_get_or_set_int_option(bd9cb9e767e253ec).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, int value);
443
444 /*!
445 * \brief Set an unsigned integer value of an 'item' option by key, creating the option if
446 * necessary.
447 *
448 * \param[in] section the section containing the option
449 * \param[in] key the option key
450 * \param[in] value the item value
451 * \return void
452 */
453 extern void config_set_uint_optioncxx . . $ config_set_uint_option(63eb13e196eff8e6).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, unsigned int value);
454
455 /*!
456 * \brief Get an unsigned integer value of an 'item' option by key.
457 *
458 * \param[in] section the section containing the option
459 * \param[in] key the option key
460 * \param[out] out_value the item value if a valid option exists; otherwise unset
461 * \return whether \p out_value was set
462 */
463 extern 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);
464
465 /*!
466 * \brief Get an unsigned integer value of an 'item' option by key, setting the option if it was
467 * invalid or creating the option if it did not exist.
468 *
469 * \param[in] section the section containing the option
470 * \param[in] key the option key
471 * \param[in] value the default item value
472 * \return the value
473 */
474 extern unsigned int config_get_or_set_uint_optioncxx . . $ config_get_or_set_uint_option(bb41ab88d5ddc12a).(ConfigSectioncxx . . $ ConfigSection# *section, const char *key, unsigned int value);
475
476 /* config option accessors/manipulators -- by reference */
477
478 /*! \see ::config_set_value() */
479 extern ConfigOptioncxx . . $ ConfigOption# *config_set_value_lencxx . . $ config_set_value_len(a7b414abafe16dd0).(ConfigOptioncxx . . $ ConfigOption# *option, const char *value, size_t value_len);
480
481 /*!
482 * \brief Set the value of an 'item' option.
483 *
484 * \param[in] option the option
485 * \param[in] value the value
486 * \return the option; \c NULL if out of memory
487 */
488 static inline ConfigOptioncxx . . $ ConfigOption# *config_set_valuecxx . . $ config_set_value(933b7be54a5eb800).(ConfigOptioncxx . . $ ConfigOption# *option, const char *value)
489 {
490 return config_set_value_lencxx . . $ config_set_value_len(a7b414abafe16dd0).(option, value, value == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ? 0 : strlencxx . . $ strlen(751346f8406fd082).(value));
491 }
492
493 /*! \see ::config_add_value() */
494 extern ConfigOptioncxx . . $ ConfigOption# *config_add_value_lencxx . . $ config_add_value_len(a7b414abafe16dd0).(ConfigOptioncxx . . $ ConfigOption# *option, const char *value, size_t value_len);
495
496 /*!
497 * \brief Add a value to a 'list' option.
498 *
499 * \param[in] option the option
500 * \param[in] value the value
501 * \return the option; \c NULL if out of memory
502 */
503 static inline ConfigOptioncxx . . $ ConfigOption# *config_add_valuecxx . . $ config_add_value(933b7be54a5eb800).(ConfigOptioncxx . . $ ConfigOption# *option, const char *value)
504 {
505 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(value != NULL);
506 return config_add_value_lencxx . . $ config_add_value_len(a7b414abafe16dd0).(option, value, strlencxx . . $ strlen(751346f8406fd082).(value));
507 }
508
509 /*!
510 * \brief Remove a value from a 'list' option.
511 *
512 * \param[in] option the option
513 * \param[in] i the index of the value
514 * \return the option; \c NULL if out of memory or invalid \p index
515 */
516 extern ConfigOptioncxx . . $ ConfigOption# *config_remove_valuecxx . . $ config_remove_value(c3bd1c7e617a3a76).(ConfigOptioncxx . . $ ConfigOption# *option, unsigned int i);
517
518 /*!
519 * \brief Get the value of an 'item' option.
520 *
521 * \param[in] option the option
522 * \return the value; \c NULL if \p option was \c NULL or was a 'list' option
523 */
524 extern const char *config_get_valuecxx . . $ config_get_value(7c319b7c0e111005).(const ConfigOptioncxx . . $ ConfigOption# *option);
525
526 /*!
527 * \brief Get the value that indicates whether the option is a 'list' option.
528 *
529 * \param[in] option the option
530 * \return whether the option is a 'list' option
531 */
532 static inline boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! config_is_value_listcxx . . $ config_is_value_list(5baeb70b3f01321d).(const ConfigOptioncxx . . $ ConfigOption# *option)
533 {
534 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(option != NULL);
535 return option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. > 0 ||
536 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`!;
537 }
538
539 /*!
540 * \brief Get the number of values assigned to the option.
541 *
542 * \param[in] option the option
543 * \return \c 1 if the option is an 'item' option; the number of elements if the option is a 'list'
544 * option
545 */
546 static inline unsigned int config_get_value_countcxx . . $ config_get_value_count(6881ebc08440b4a5).(const ConfigOptioncxx . . $ ConfigOption# *option)
547 {
548 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(option != NULL);
549 return option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count. == 0 ?
550 (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 . . $ `<external>/15298297234472979974/stddef.h:419:9`! ? 0 : 1) :
551 option->values_countcxx . . $ $anonymous_type_88ace789ff2dc3d9_1#values_count.;
552 }
553
554 /*!
555 * \brief Iterate over the values assigned to the option.
556 *
557 * \param[out] string_value the value variable to declare
558 * \param[in] option the option
559 */
560 #define foreach_option_valuecxx . . $ `src/config_file.h:560:9`!(string_value, option) \
561 for (ConfigOption *_option = (option); _option != NULL; _option = NULL) \
562 for (ConfigString *_values_begin = _option->values_count == 0 ? &_option->v.value : &_option->v.values[0], \
563 *_values_end = _option->values_count == 0 ? _values_begin + 1 : &_option->v.values[_option->values_count], \
564 *_value = _values_begin; _value < _values_end; ++_value) \
565 for (const char *(string_value) = config_string_to_cstr(_value); (string_value) != NULL; (string_value) = NULL)
566
567 /*!
568 * \brief Iterate over the values assigned to the option.
569 *
570 * \param[out] i the index variable to declare
571 * \param[out] string_value the value variable to declare
572 * \param[in] option the option
573 */
574 #define foreach_option_i_valuecxx . . $ `src/config_file.h:574:9`!(i, string_value, option) \
575 for (unsigned int (i) = 0; (i) == 0; (i) = ~0) \
576 for (ConfigOption *_option = (option); _option != NULL; _option = NULL) \
577 for (ConfigString *_values_begin = _option->values_count == 0 ? &_option->v.value : &_option->v.values[0], \
578 *_values_end = _option->values_count == 0 ? _values_begin + 1 : &_option->v.values[_option->values_count], \
579 *_value = _values_begin; _value < _values_end; ++_value, (i) = _value - _values_begin) \
580 for (const char *(string_value) = config_string_to_cstr(_value); (string_value) != NULL; (string_value) = NULL)
581
582 /*!
583 * \brief Remove a value from an option during iteration. Should be followed by \c continue.
584 */
585 #define foreach_remove_option_valuecxx . . $ `src/config_file.h:585:9`!() \
586 { \
587 extern void config_oom(void); \
588 unsigned int _value_i = _value - _values_begin; \
589 if (config_remove_value(_option, _value_i) == NULL) \
590 config_oom(); \
591 _values_begin = _option->values_count == 0 ? &_option->v.value : &_option->v.values[0]; \
592 _values_end = _option->values_count == 0 ? _values_begin + 1 : &_option->v.values[_option->values_count]; \
593 _value = _values_begin + _value_i - 1; \
594 }
595
596 #endif