Code

Refactor help_name into enum_name
authorJonas Fonseca <jonas.fonseca@savoirfairelinux.com>
Fri, 11 Dec 2009 22:42:41 +0000 (17:42 -0500)
committerJonas Fonseca <jonas.fonseca@savoirfairelinux.com>
Fri, 11 Dec 2009 22:49:28 +0000 (17:49 -0500)
tig.c

diff --git a/tig.c b/tig.c
index cf4e61a131a5b8c8286e4d97bba2f0faaa88e180..41d8123379eec382c30f9e7d9e9bb9c1f09892d2 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -305,6 +305,24 @@ struct enum_map {
 
 #define ENUM_MAP(name, value) { name, STRING_SIZE(name), value }
 
+static char *
+enum_map_name(const char *name, size_t namelen)
+{
+       static char buf[SIZEOF_STR];
+       int bufpos;
+
+       for (bufpos = 0; bufpos <= namelen; bufpos++) {
+               buf[bufpos] = tolower(name[bufpos]);
+               if (buf[bufpos] == '_')
+                       buf[bufpos] = '-';
+       }
+
+       buf[bufpos] = 0;
+       return buf;
+}
+
+#define enum_name(entry) enum_map_name((entry).name, (entry).namelen)
+
 static bool
 map_enum_do(const struct enum_map *map, size_t map_size, int *value, const char *name)
 {
@@ -3962,33 +3980,14 @@ static struct view_ops diff_ops = {
 
 static bool help_keymap_hidden[ARRAY_SIZE(keymap_table)];
 
-static char *
-help_name(char buf[SIZEOF_STR], const char *name, size_t namelen)
-{
-       int bufpos;
-
-       for (bufpos = 0; bufpos <= namelen; bufpos++) {
-               buf[bufpos] = tolower(name[bufpos]);
-               if (buf[bufpos] == '_')
-                       buf[bufpos] = '-';
-       }
-
-       buf[bufpos] = 0;
-       return buf;
-}
-
-#define help_keymap_name(buf, keymap) \
-       help_name(buf, keymap_table[keymap].name, keymap_table[keymap].namelen)
-
 static bool
 help_open_keymap_title(struct view *view, enum keymap keymap)
 {
-       char buf[SIZEOF_STR];
        struct line *line;
 
        line = add_line_format(view, LINE_HELP_KEYMAP, "[%c] %s bindings",
                               help_keymap_hidden[keymap] ? '+' : '-',
-                              help_keymap_name(buf, keymap));
+                              enum_name(keymap_table[keymap]));
        if (line)
                line->other = keymap;
 
@@ -4029,8 +4028,7 @@ help_open_keymap(struct view *view, enum keymap keymap)
                }
 
                add_line_format(view, LINE_DEFAULT, "    %-25s %-20s %s", key,
-                               help_name(buf, req_info[i].name, req_info[i].namelen),
-                               req_info[i].help);
+                               enum_name(req_info[i]), req_info[i].help);
        }
 
        group = "External commands:";