|
My Project
|
#include <assert.h>#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <string.h>Go to the source code of this file.
Classes | |
| union | ConfigString |
| A short-string-optimizing string type. More... | |
| struct | ConfigOption |
| An option consisting of one (an item) or many (a list) values. More... | |
| struct | ConfigSection |
| A section consisting of options. More... | |
| struct | Config |
| A configuration consisting of sections. More... | |
Macros | |
| #define | COMPILE_TIME_ASSERT(name, cond) typedef int assert_ ## name[(cond) * 2 - 1] |
| Cause compile error if compile-time computable condition fails. | |
| #define | COUNTOF(a) (sizeof(a) / sizeof(*(a))) |
| Calculate the number of elements in a fixed-length array. | |
| #define | foreach_option_value(string_value, option) |
| Iterate over the values assigned to the option. | |
| #define | foreach_option_i_value(i, string_value, option) |
| Iterate over the values assigned to the option. | |
| #define | foreach_remove_option_value() |
Remove a value from an option during iteration. Should be followed by continue. | |
Enumerations | |
| enum | ConfigBoolStyle { ZERO_ONE = 0 , NO_YES = 1 , OFF_ON = 2 , FALSE_TRUE = 3 } |
| The styles of boolean values. | |
Functions | |
| void | config_init (Config *config) |
| Initialize a configuration. | |
| void | config_deinit (Config *config) |
| Release any memory allocated inside a configuration. | |
| bool | config_parse (Config *config, FILE *file) |
| Parse a configuration from a file. | |
| void | config_write (const Config *config, FILE *file) |
| Write a configuration to a file. | |
| ConfigSection * | config_add_section_len (Config *config, const char *type, size_t type_len, const char *name, size_t name_len) |
| ConfigSection * | config_find_sections (Config *config, const char *type, ConfigSection **save) |
| Iterate sections by type. | |
| ConfigSection * | config_find_section (Config *config, const char *type, const char *name) |
| Find a section by type and name. | |
| ConfigSection * | config_find_or_add_section (Config *config, const char *type, const char *name) |
| Find a section by type and name, creating the section if it did not exist. | |
| ConfigOption * | config_set_option_len (ConfigSection *section, const char *key, size_t key_len, const char *value, size_t value_len) |
| ConfigOption * | config_get_option (const ConfigSection *section, const char *key) |
| Get an option by key. | |
| ConfigOption * | config_get_or_set_option_len (ConfigSection *section, const char *key, size_t key_len, const char *value, size_t value_len) |
| void | config_set_string_option_len (ConfigSection *section, const char *key, size_t key_len, const char *value, size_t value_len) |
| bool | config_get_string_option (const ConfigSection *section, const char *key, const char **out_value) |
| Get a string value of an 'item' option by key. | |
| const char * | config_get_or_set_string_option (ConfigSection *section, const char *key, const char *value) |
| Get a string value of an 'item' option by key, setting the option if it was invalid or creating the option if it did not exist. | |
| void | config_set_bool_option (ConfigSection *section, const char *key, bool value, ConfigBoolStyle style) |
| Set a boolean value of an 'item' option by key, creating the option if necessary. | |
| bool | config_get_bool_option (const ConfigSection *section, const char *key, bool *out_value) |
| Get a boolean value of an 'item' option by key. | |
| bool | config_get_or_set_bool_option (ConfigSection *section, const char *key, bool value, ConfigBoolStyle style) |
| Get a boolean value of an 'item' option by key, setting the option if it was invalid or creating the option if it did not exist. | |
| void | config_set_int_option (ConfigSection *section, const char *key, int value) |
| Set an integer value of an 'item' option by key, creating the option if necessary. | |
| bool | config_get_int_option (const ConfigSection *section, const char *key, int *out_value) |
| Get an integer value of an 'item' option by key. | |
| int | config_get_or_set_int_option (ConfigSection *section, const char *key, int value) |
| Get an integer value of an 'item' option by key, setting the option if it was invalid or creating the option if it did not exist. | |
| void | config_set_uint_option (ConfigSection *section, const char *key, unsigned int value) |
| Set an unsigned integer value of an 'item' option by key, creating the option if necessary. | |
| bool | config_get_uint_option (const ConfigSection *section, const char *key, unsigned int *out_value) |
| Get an unsigned integer value of an 'item' option by key. | |
| unsigned int | config_get_or_set_uint_option (ConfigSection *section, const char *key, unsigned int value) |
| Get an unsigned integer value of an 'item' option by key, setting the option if it was invalid or creating the option if it did not exist. | |
| ConfigOption * | config_set_value_len (ConfigOption *option, const char *value, size_t value_len) |
| ConfigOption * | config_add_value_len (ConfigOption *option, const char *value, size_t value_len) |
| ConfigOption * | config_remove_value (ConfigOption *option, unsigned int i) |
| Remove a value from a 'list' option. | |
| const char * | config_get_value (const ConfigOption *option) |
| Get the value of an 'item' option. | |
| #define COMPILE_TIME_ASSERT | ( | name, | |
| cond ) typedef int assert_ ## name[(cond) * 2 - 1] |
Cause compile error if compile-time computable condition fails.
| [in] | name | the unique identifier of the assertion |
| [in] | cond | the condition |
| #define COUNTOF | ( | a | ) | (sizeof(a) / sizeof(*(a))) |
Calculate the number of elements in a fixed-length array.
| [in] | a | the fixed-length array |
| #define foreach_option_i_value | ( | i, | |
| string_value, | |||
| option ) |
Iterate over the values assigned to the option.
| [out] | i | the index variable to declare |
| [out] | string_value | the value variable to declare |
| [in] | option | the option |
| #define foreach_option_value | ( | string_value, | |
| option ) |
Iterate over the values assigned to the option.
| [out] | string_value | the value variable to declare |
| [in] | option | the option |
| #define foreach_remove_option_value | ( | ) |
Remove a value from an option during iteration. Should be followed by continue.
|
extern |
|
extern |
|
extern |
Release any memory allocated inside a configuration.
| [in] | config | the configuration |
|
extern |
Find a section by type and name, creating the section if it did not exist.
| [in] | config | the configuration containing the section |
| [in] | type | the type of the section |
| [in] | name | the name of the section; may be NULL |
NULL if out of memory
|
extern |
Find a section by type and name.
| [in] | config | the configuration containing the section |
| [in] | type | the type of the section |
| [in] | name | the name of the section |
NULL if it does not exist
|
extern |
Iterate sections by type.
| [in] | config | the configuration containing the sections |
| [in] | type | the type of the section |
| [in,out] | save | the saved state of the iterator; initialize *save to NULL before iteration |
NULL if iteration finished
|
extern |
Get a boolean value of an 'item' option by key.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [out] | out_value | the item value if a valid option exists; otherwise unset |
out_value was set
|
extern |
Get an integer value of an 'item' option by key.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [out] | out_value | the item value if a valid option exists; otherwise unset |
out_value was set
|
extern |
Get an option by key.
| [in] | section | the section containing the option |
| [in] | key | the option key |
NULL if it does not exist
|
extern |
Get a boolean value of an 'item' option by key, setting the option if it was invalid or creating the option if it did not exist.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the default item value |
| [in] | style | the style of boolean value |
|
extern |
Get an integer value of an 'item' option by key, setting the option if it was invalid or creating the option if it did not exist.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the default item value |
|
extern |
|
extern |
Get a string value of an 'item' option by key, setting the option if it was invalid or creating the option if it did not exist.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the default item value |
|
extern |
Get an unsigned integer value of an 'item' option by key, setting the option if it was invalid or creating the option if it did not exist.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the default item value |
|
extern |
Get a string value of an 'item' option by key.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [out] | out_value | the item value if a valid option exists; otherwise unset |
out_value was set
|
extern |
Get an unsigned integer value of an 'item' option by key.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [out] | out_value | the item value if a valid option exists; otherwise unset |
out_value was set
|
extern |
Get the value of an 'item' option.
| [in] | option | the option |
NULL if option was NULL or was a 'list' option
|
extern |
Initialize a configuration.
| [in] | config | the configuration |
|
extern |
Parse a configuration from a file.
| [in] | config | the uninitialized configuration |
| [in] | file | the file handle |
|
extern |
Remove a value from a 'list' option.
| [in] | option | the option |
| [in] | i | the index of the value |
NULL if out of memory or invalid index
|
extern |
Set a boolean value of an 'item' option by key, creating the option if necessary.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the item value |
| [in] | style | the style of boolean value |
|
extern |
Set an integer value of an 'item' option by key, creating the option if necessary.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the item value |
|
extern |
|
extern |
|
extern |
Set an unsigned integer value of an 'item' option by key, creating the option if necessary.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the item value |
|
extern |
|
extern |
Write a configuration to a file.
| [in] | config | the configuration |
| [in] | file | the file handle |