|
PatchworkOS
966e257
A non-POSIX operating system.
|
System configuration files. More...
System configuration files.
Patchwork uses a /cfg folder for all system configuration files. These files are simple INI style text files that store key-value pairs in sections.
Data Structures | |
| struct | config_array_t |
| Configuration array structure. More... | |
| struct | config_t |
| Opaque configuration structure. More... | |
Typedefs | |
| typedef struct config | config_t |
Functions | |
| config_t * | config_open (const char *prefix, const char *name) |
| Open a configuration file. | |
| void | config_close (config_t *config) |
| Close a configuration file. | |
| void | config_get (config_t *config, const char *section, uint64_t index, const char *fallback, const char **outValue, const char **outKey) |
| Get a value as a string by index from a configuration file. | |
| const char * | config_get_string (config_t *config, const char *section, const char *key, const char *fallback) |
| Get a string value from a configuration file. | |
| int64_t | config_get_int (config_t *config, const char *section, const char *key, int64_t fallback) |
| Get an integer value from a configuration file. | |
| bool | config_get_bool (config_t *config, const char *section, const char *key, bool fallback) |
| Get a boolean value from a configuration file. | |
| config_array_t * | config_get_array (config_t *config, const char *section, const char *key) |
| Get an array of strings from a configuration file. | |
| void | config_array_free (config_array_t *array) |
| Free a configuration array. | |
| config_t * config_open | ( | const char * | prefix, |
| const char * | name | ||
| ) |
Open a configuration file.
All configuration files have this full path: /cfg/<prefix>-<name>.cfg.
The goal is that each system or application uses its own prefix to avoid name collisions.
| prefix | The prefix of the configuration file, for example theme for theme related settings. |
| name | The name of the configuration file, for example colors for color related settings. |
NULL. Definition at line 93 of file config.c.
| void config_close | ( | config_t * | config | ) |
| void config_get | ( | config_t * | config, |
| const char * | section, | ||
| uint64_t | index, | ||
| const char * | fallback, | ||
| const char ** | outValue, | ||
| const char ** | outKey | ||
| ) |
Get a value as a string by index from a configuration file.
| config | The configuration file. |
| section | The section to get the value from, case insensitive. |
| index | The index of the value to get. |
| fallback | A default value to return if the index is out of bounds. |
| outValue | The output value, will be set to fallback if the index is out of bounds. |
| outKey | The output key, will be set to fallback if the index is out of bounds. |
Definition at line 228 of file config.c.
| const char * config_get_string | ( | config_t * | config, |
| const char * | section, | ||
| const char * | key, | ||
| const char * | fallback | ||
| ) |
Get a string value from a configuration file.
The value returned is owned by the configuration system and should not be freed or modified.
| config | The configuration file. |
| section | The section to get the value from, case insensitive. |
| key | The key to get the value for, case insensitive. |
| fallback | A default value to return if the key is not found. |
fallback otherwise. Definition at line 263 of file config.c.
| int64_t config_get_int | ( | config_t * | config, |
| const char * | section, | ||
| const char * | key, | ||
| int64_t | fallback | ||
| ) |
Get an integer value from a configuration file.
| config | The configuration file. |
| section | The section to get the value from, case insensitive. |
| key | The key to get the value for, case insensitive. |
| fallback | A default value to return if the key is not found or cannot be parsed as an integer. |
fallback otherwise. Definition at line 285 of file config.c.
Get a boolean value from a configuration file.
Recognized "true" values (case-insensitive): "true", "yes", "on", "1". Recognized "false" values (case-insensitive): "false", "no", "off", "0".
| config | The configuration file. |
| section | The section to get the value from, case insensitive. |
| key | The key to get the value for, case insensitive. |
| fallback | A default value to return if not found or unrecognized. |
fallback otherwise. Definition at line 308 of file config.c.
| config_array_t * config_get_array | ( | config_t * | config, |
| const char * | section, | ||
| const char * | key | ||
| ) |
Get an array of strings from a configuration file.
Parses the string value into an array of strings, split by commas and with the whitespace trimmed.
| config | The configuration file. |
| section | The section to get the value from, case insensitive. |
| key | The key to get the value for, case insensitive. |
NULL on memory allocation failure. Definition at line 335 of file config.c.
| void config_array_free | ( | config_array_t * | array | ) |