|
ginnOS
The reference: libc, the libraries and the kernel
|
settings files: sections of "key = value" lines. More...
Go to the source code of this file.
Macros | |
| #define | CONF_SYSTEM_DIR "/etc/ginnos" |
| #define | CONF_USER_DIR ".config/ginnos" |
Typedefs | |
| typedef struct conf | conf_t |
Functions | |
| conf_t * | conf_open (const char *name) |
| open the settings called name: /etc/ginnos/<name>.conf and ~/.config/ginnos/<name>.conf. | |
| conf_t * | conf_load (const char *system_path, const char *user_path) |
| open two files. | |
| conf_t * | conf_from_text (const char *system_text, const char *user_text) |
| settings from text in memory (for tests). | |
| void | conf_free (conf_t *conf) |
| const char * | conf_get (const conf_t *conf, const char *section, const char *key, const char *fallback) |
| a value. | |
| const char * | conf_section (const conf_t *conf, int index) |
| the name of a section, to go through all of them: index 0, 1, ... until NULL. | |
| long | conf_get_int (const conf_t *conf, const char *section, const char *key, long fallback) |
| a whole number: decimal, or hexadecimal with 0x. | |
| bool | conf_get_bool (const conf_t *conf, const char *section, const char *key, bool fallback) |
| true, yes, on, 1 / false, no, off, 0 (any letter case). | |
| uint32_t | conf_get_color (const conf_t *conf, const char *section, const char *key, uint32_t fallback) |
| a colour: #rrggbb or #rrggbbaa. | |
| int | conf_set (conf_t *conf, const char *section, const char *key, const char *value) |
| set a user value. | |
| int | conf_set_int (conf_t *conf, const char *section, const char *key, long value) |
| int | conf_set_bool (conf_t *conf, const char *section, const char *key, bool value) |
| int | conf_set_color (conf_t *conf, const char *section, const char *key, uint32_t argb) |
| int | conf_unset (conf_t *conf, const char *section, const char *key) |
| remove the user's value, so the system value is used again. | |
| int | conf_save (const conf_t *conf) |
| write the user's file: to a new file, fsync, then rename over the old one, so a crash leaves the old file or the new one. | |
| char * | conf_user_text (const conf_t *conf) |
| the user's file as text, as conf_save writes it (for tests). | |
| int | conf_bad_lines (const conf_t *conf) |
| how many bad lines the two files had. | |
settings files: sections of "key = value" lines.
a settings file looks like this:
# the look of the desktop [theme] mode = dark accent = #3b82f6 font_size = 13
a conf_t has two layers: the system defaults (/etc/ginnos/<name>.conf, read only) and the user's values (~/.config/ginnos/<name>.conf). a get looks at the user's values first. a set changes only the user's values, and conf_save writes only the user's file. comments, blank lines and the order of the lines stay as they were.
| #define CONF_SYSTEM_DIR "/etc/ginnos" |
| #define CONF_USER_DIR ".config/ginnos" |
| typedef struct conf conf_t |
| conf_t * conf_open | ( | const char * | name | ) |
open the settings called name: /etc/ginnos/<name>.conf and ~/.config/ginnos/<name>.conf.
a file that is not there is empty.
| name | letters, digits, '-' and '_' only. |
| conf_t * conf_load | ( | const char * | system_path, |
| const char * | user_path ) |
open two files.
user_path is the file conf_save writes.
| system_path | may be NULL (no defaults). |
| user_path | may be NULL (conf_save then fails). |
| conf_t * conf_from_text | ( | const char * | system_text, |
| const char * | user_text ) |
settings from text in memory (for tests).
conf_save fails on them.
| system_text | the defaults, may be NULL. |
| user_text | the user's values, may be NULL. |
| void conf_free | ( | conf_t * | conf | ) |
| const char * conf_get | ( | const conf_t * | conf, |
| const char * | section, | ||
| const char * | key, | ||
| const char * | fallback ) |
a value.
| const char * conf_section | ( | const conf_t * | conf, |
| int | index ) |
the name of a section, to go through all of them: index 0, 1, ... until NULL.
the sections of the system file come first, then the sections that only the user's file has, each in file order and each name one time. only a [name] line makes a section; keys before the first [section] are not one.
| long conf_get_int | ( | const conf_t * | conf, |
| const char * | section, | ||
| const char * | key, | ||
| long | fallback ) |
a whole number: decimal, or hexadecimal with 0x.
true, yes, on, 1 / false, no, off, 0 (any letter case).
| uint32_t conf_get_color | ( | const conf_t * | conf, |
| const char * | section, | ||
| const char * | key, | ||
| uint32_t | fallback ) |
a colour: #rrggbb or #rrggbbaa.
| int conf_set | ( | conf_t * | conf, |
| const char * | section, | ||
| const char * | key, | ||
| const char * | value ) |
set a user value.
the line is changed where it is; a new key goes after the last line of its section, and a new section goes at the end.
| section | a name without '[', ']' or a line break. |
| key | a name without '=', a line break, or a '#' or ';' or '[' at its start. |
| value | text without a line break. |
| int conf_set_int | ( | conf_t * | conf, |
| const char * | section, | ||
| const char * | key, | ||
| long | value ) |
| int conf_unset | ( | conf_t * | conf, |
| const char * | section, | ||
| const char * | key ) |
remove the user's value, so the system value is used again.
| int conf_save | ( | const conf_t * | conf | ) |
write the user's file: to a new file, fsync, then rename over the old one, so a crash leaves the old file or the new one.
the directory is made if it is not there.
| char * conf_user_text | ( | const conf_t * | conf | ) |
the user's file as text, as conf_save writes it (for tests).
| int conf_bad_lines | ( | const conf_t * | conf | ) |
how many bad lines the two files had.