diff options
author | Kevin McCarthy <kevin@8t8.us> | 2021-11-11 15:05:33 -0800 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2021-11-12 14:53:13 -0800 |
commit | 543e115132b32571ff98d2e89a82cc0a5e3110d4 (patch) | |
tree | 437940bccc671138c334e3af05547a58d0342383 /init.c | |
parent | f210e9a0ed906574cbc367d3e9d80a823e5581e5 (diff) |
Convert COLOR_DEFAULT constant to -1.
Previously, "mono" assigned -1 to fg/bg to indicate "unset" values.
NCurses uses -1 to indicate "default" color (when supported), but
COLOR_DEFAULT was assigned the value -2 and swapped at the last
moment. While it worked, I personally found this confusing.
To make the logic clearer, create a COLOR_UNSET constant with value
-2, and switch COLOR_DEFAULT to -1. Then remove the last-minute
translation when allocating the color.
Change the "not set" initialization and testing to use COLOR_UNSET for
clarity.
Because map_getvaluebyname() returns -1 for a missing value,
create a new lookup function that returns the matching mapping_t or
NULL if not found.
Diffstat (limited to 'init.c')
-rw-r--r-- | init.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -3557,14 +3557,23 @@ const char *mutt_getnamebyvalue (int val, const struct mapping_t *map) return NULL; } -int mutt_getvaluebyname (const char *name, const struct mapping_t *map) +const struct mapping_t *mutt_get_mapentry_by_name (const char *name, + const struct mapping_t *map) { int i; for (i = 0; map[i].name; i++) if (ascii_strcasecmp (map[i].name, name) == 0) - return (map[i].value); - return (-1); + return &map[i]; + return NULL; +} + +int mutt_getvaluebyname (const char *name, const struct mapping_t *map) +{ + const struct mapping_t *entry = mutt_get_mapentry_by_name (name, map); + if (entry) + return entry->value; + return -1; } #ifdef DEBUG |