|
PatchworkOS
|
System configuration files. More...
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. | |
| 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. | |
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.
TODO: The current system is rather simplistic and in the future it might, if i can be bothered, be worth implementing a database like configuration system.
| void config_array_free | ( | config_array_t * | array | ) |
| void config_close | ( | config_t * | config | ) |
Close a configuration file.
| config | The configuration file to close. |
Definition at line 202 of file config.c.
References CONTAINER_OF, free(), config_pair_t::key, list_is_empty(), list_pop(), config_section_t::name, NULL, config_section_t::pairs, config_t::sections, and config_pair_t::value.
Referenced by config_open(), main(), start_menu_load_entries(), and theme_lazy_load().
| 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 300 of file config.c.
References config_get_string(), data, isspace(), config_array_t::items, config_array_t::length, malloc(), memcpy(), NULL, start(), and strlen().
Referenced by execute_commands(), start_menu_load_entries(), start_programs(), and start_services().
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 273 of file config.c.
References config_get_string(), NULL, strcasecmp(), and strcmp().
| 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 250 of file config.c.
References config_get_string(), NULL, and strtoll().
Referenced by start_programs(), start_services(), theme_colors_load(), and theme_lazy_load().
| 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 228 of file config.c.
References config_find_pair(), config_find_section(), NULL, and config_pair_t::value.
Referenced by config_get_array(), config_get_bool(), config_get_int(), and theme_lazy_load().
| 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.
References config_close(), config_trim_whitespace(), config_pair_t::entry, config_section_t::entry, fclose(), fgets(), file, fopen(), free(), config_pair_t::key, lineBuffer, list_entry_init(), list_init(), list_push(), malloc(), MAX_PATH, config_section_t::name, NULL, config_section_t::pairs, config_t::sections, snprintf(), strchr(), strdup(), and config_pair_t::value.
Referenced by main(), start_menu_load_entries(), and theme_lazy_load().