summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 87e4431)
raw | patch | inline | side by side (parent: 87e4431)
author | Jonas Fonseca <fonseca@diku.dk> | |
Wed, 4 Feb 2009 13:23:10 +0000 (14:23 +0100) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Thu, 5 Feb 2009 20:56:49 +0000 (21:56 +0100) |
Renames int_map to enum_map and set_from_int_map to map_enum, which
now uses string_enum_compare instead of strncasecmp.
now uses string_enum_compare instead of strncasecmp.
tig.c | patch | blob | history |
index b0132fbdadff6e08ec8437252d99d021f8472775..c5e3380bbd5a267f38639a02647b66e76f14d29e 100644 (file)
--- a/tig.c
+++ b/tig.c
static bool format_argv(const char *dst[], const char *src[], enum format_flags flags);
-struct int_map {
- const char *name;
- int namelen;
- int value;
-};
-
-static int
-set_from_int_map(struct int_map *map, size_t map_size,
- int *value, const char *name, int namelen)
-{
-
- int i;
-
- for (i = 0; i < map_size; i++)
- if (namelen == map[i].namelen &&
- !strncasecmp(name, map[i].name, namelen)) {
- *value = map[i].value;
- return OK;
- }
-
- return ERR;
-}
-
enum input_status {
INPUT_OK,
INPUT_SKIP,
return 0;
}
+struct enum_map {
+ const char *name;
+ int namelen;
+ int value;
+};
+
+#define ENUM_MAP(name, value) { name, STRING_SIZE(name), value }
+
+static bool
+map_enum_do(struct enum_map *map, size_t map_size, int *value, const char *name)
+{
+ size_t namelen = strlen(name);
+ int i;
+
+ for (i = 0; i < map_size; i++)
+ if (namelen == map[i].namelen &&
+ !string_enum_compare(name, map[i].name, namelen)) {
+ *value = map[i].value;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+#define map_enum(attr, map, name) \
+ map_enum_do(map, ARRAY_SIZE(map), attr, name)
+
#define prefixcmp(str1, str2) \
strncmp(str1, str2, STRING_SIZE(str2))
#undef KEYMAP_
};
-static struct int_map keymap_table[] = {
-#define KEYMAP_(name) { #name, STRING_SIZE(#name), KEYMAP_##name }
+static struct enum_map keymap_table[] = {
+#define KEYMAP_(name) ENUM_MAP(#name, KEYMAP_##name)
KEYMAP_INFO
#undef KEYMAP_
};
-#define set_keymap(map, name) \
- set_from_int_map(keymap_table, ARRAY_SIZE(keymap_table), map, name, strlen(name))
+#define set_keymap(map, name) map_enum(map, keymap_table, name)
struct keybinding_table {
struct keybinding *data;
* User config file handling.
*/
-static struct int_map color_map[] = {
-#define COLOR_MAP(name) { #name, STRING_SIZE(#name), COLOR_##name }
+static struct enum_map color_map[] = {
+#define COLOR_MAP(name) ENUM_MAP(#name, COLOR_##name)
COLOR_MAP(DEFAULT),
COLOR_MAP(BLACK),
COLOR_MAP(BLUE),
COLOR_MAP(YELLOW),
};
-#define set_color(color, name) \
- set_from_int_map(color_map, ARRAY_SIZE(color_map), color, name, strlen(name))
-
-static struct int_map attr_map[] = {
-#define ATTR_MAP(name) { #name, STRING_SIZE(#name), A_##name }
+static struct enum_map attr_map[] = {
+#define ATTR_MAP(name) ENUM_MAP(#name, A_##name)
ATTR_MAP(NORMAL),
ATTR_MAP(BLINK),
ATTR_MAP(BOLD),
ATTR_MAP(UNDERLINE),
};
-#define set_attribute(attr, name) \
- set_from_int_map(attr_map, ARRAY_SIZE(attr_map), attr, name, strlen(name))
+#define set_color(color, name) map_enum(color, color_map, name)
+#define set_attribute(attr, name) map_enum(attr, attr_map, name)
static int config_lineno;
static bool config_errors;
}
}
- if (set_color(&info->fg, argv[1]) == ERR ||
- set_color(&info->bg, argv[2]) == ERR) {
+ if (!set_color(&info->fg, argv[1]) ||
+ !set_color(&info->bg, argv[2])) {
config_msg = "Unknown color";
return ERR;
}
- if (argc == 4 && set_attribute(&info->attr, argv[3]) == ERR) {
+ if (argc == 4 && !set_attribute(&info->attr, argv[3])) {
config_msg = "Unknown attribute";
return ERR;
}