|
My Project
|
#include "config_file.h"#include <assert.h>#include <limits.h>#include <stdbool.h>#include <stddef.h>#include <string.h>Macros | |
| #define | udecsizeof(t) ((CHAR_BIT * sizeof(t) / 3) + 1) |
| #define | sdecsizeof(t) (udecsizeof(t) + 1) |
Enumerations | |
| enum | Directive { INVALID_DIRECTIVE = 0 , SECTION_DIRECTIVE , ITEM_DIRECTIVE , LIST_DIRECTIVE } |
Functions | |
| void | config_oom (void) |
| void | config_init (Config *config) |
| Initialize a configuration. | |
| void | config_deinit (Config *config) |
| Release any memory allocated inside a configuration. | |
| 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. | |
| 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 ) |
| ConfigOption * config_add_value_len | ( | ConfigOption * | option, |
| const char * | value, | ||
| size_t | value_len ) |
| void config_deinit | ( | Config * | config | ) |
Release any memory allocated inside a configuration.
| [in] | config | the configuration |
| 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.
| [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 | ConfigSection * config_find_section | ( | Config * | config, |
| const char * | type, | ||
| const char * | name ) |
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 | ConfigSection * config_find_sections | ( | Config * | config, |
| const char * | type, | ||
| ConfigSection ** | save ) |
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 | bool config_get_bool_option | ( | const ConfigSection * | section, |
| const char * | key, | ||
| bool * | out_value ) |
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 | bool config_get_int_option | ( | const ConfigSection * | section, |
| const char * | key, | ||
| int * | out_value ) |
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 | ConfigOption * config_get_option | ( | const ConfigSection * | section, |
| const char * | key ) |
Get an option by key.
| [in] | section | the section containing the option |
| [in] | key | the option key |
NULL if it does not exist | 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.
| [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 |
| 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.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the default item value |
| ConfigOption * config_get_or_set_option_len | ( | ConfigSection * | section, |
| const char * | key, | ||
| size_t | key_len, | ||
| const char * | value, | ||
| size_t | value_len ) |
| 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.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the default item value |
| 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.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the default item value |
| 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.
| [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 | 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.
| [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 | const char * config_get_value | ( | const ConfigOption * | option | ) |
Get the value of an 'item' option.
| [in] | option | the option |
NULL if option was NULL or was a 'list' option | void config_init | ( | Config * | config | ) |
Initialize a configuration.
| [in] | config | the configuration |
| bool config_parse | ( | Config * | config, |
| FILE * | file ) |
Parse a configuration from a file.
| [in] | config | the uninitialized configuration |
| [in] | file | the file handle |
| ConfigOption * config_remove_value | ( | ConfigOption * | option, |
| unsigned int | i ) |
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 | 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.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the item value |
| [in] | style | the style of boolean value |
| 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.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the item value |
| ConfigOption * config_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 ) |
| 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.
| [in] | section | the section containing the option |
| [in] | key | the option key |
| [in] | value | the item value |
| ConfigOption * config_set_value_len | ( | ConfigOption * | option, |
| const char * | value, | ||
| size_t | value_len ) |
| void config_write | ( | const Config * | config, |
| FILE * | file ) |
Write a configuration to a file.
| [in] | config | the configuration |
| [in] | file | the file handle |