Code

Use enum_map for handling obsolete color names
authorJonas Fonseca <fonseca@diku.dk>
Wed, 4 Feb 2009 13:25:29 +0000 (14:25 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Thu, 5 Feb 2009 20:56:50 +0000 (21:56 +0100)
tig.c

diff --git a/tig.c b/tig.c
index 6f13a2f2b9e1c76fd5cf45b9e5b007edc56cfe9b..d99307e5fdd4cfcba86cf181f47e5fc2206d0273 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -1404,19 +1404,18 @@ option_color_command(int argc, const char *argv[])
 
        info = get_line_info(argv[0]);
        if (!info) {
-               if (!string_enum_compare(argv[0], "main-delim", strlen("main-delim"))) {
-                       info = get_line_info("delimiter");
-
-               } else if (!string_enum_compare(argv[0], "main-date", strlen("main-date"))) {
-                       info = get_line_info("date");
-
-               } else if (!string_enum_compare(argv[0], "main-author", strlen("main-author"))) {
-                       info = get_line_info("author");
+               static struct enum_map obsolete[] = {
+                       ENUM_MAP("main-delim",  LINE_DELIMITER),
+                       ENUM_MAP("main-date",   LINE_DATE),
+                       ENUM_MAP("main-author", LINE_AUTHOR),
+               };
+               int index;
 
-               } else {
+               if (!map_enum(&index, obsolete, argv[0])) {
                        config_msg = "Unknown color name";
                        return ERR;
                }
+               info = &line_info[index];
        }
 
        if (!set_color(&info->fg, argv[1]) ||