summaryrefslogtreecommitdiffstats
path: root/init.c
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2021-11-11 15:05:33 -0800
committerKevin McCarthy <kevin@8t8.us>2021-11-12 14:53:13 -0800
commit543e115132b32571ff98d2e89a82cc0a5e3110d4 (patch)
tree437940bccc671138c334e3af05547a58d0342383 /init.c
parentf210e9a0ed906574cbc367d3e9d80a823e5581e5 (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.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/init.c b/init.c
index 7a0f1353..64571ce4 100644
--- a/init.c
+++ b/init.c
@@ -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