diff options
| author | David Bremner <david@tethera.net> | 2020-08-26 08:41:48 -0300 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2021-02-06 19:14:11 -0400 |
| commit | a4af7a2a1b56efb11f2ed0c365202a8f234b4438 (patch) | |
| tree | 65e46e09c86689c17e0185fdfe94e9fea8a5f797 /lib/config.cc | |
| parent | 53f27aaf73192babf831e907ade71dc16f6880be (diff) | |
lib: add notmuch_config_get_bool
Booleans have no out of band values, so return a status for errors.
Diffstat (limited to 'lib/config.cc')
| -rw-r--r-- | lib/config.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/config.cc b/lib/config.cc index b2957f0c..d14f5422 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -359,6 +359,32 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch, return status; } +notmuch_status_t +notmuch_config_get_bool (notmuch_database_t *notmuch, notmuch_config_key_t key, notmuch_bool_t *val) +{ + const char *key_string, *val_string; + + key_string = _notmuch_config_key_to_string (key); + if (! key_string) { + return NOTMUCH_STATUS_ILLEGAL_ARGUMENT; + } + + val_string = _notmuch_string_map_get (notmuch->config, key_string); + if (! val_string) { + *val = FALSE; + return NOTMUCH_STATUS_SUCCESS; + } + + if (strcase_equal (val_string, "false") || strcase_equal (val_string, "no")) + *val = FALSE; + else if (strcase_equal (val_string, "true") || strcase_equal (val_string, "yes")) + *val = TRUE; + else + return NOTMUCH_STATUS_ILLEGAL_ARGUMENT; + + return NOTMUCH_STATUS_SUCCESS; +} + static const char * _notmuch_config_key_to_string (notmuch_config_key_t key) { switch (key) { |
