1 /* Copyright (c) 2006-2014 Jonas Fonseca <jonas.fonseca@gmail.com>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
23 struct enum_map_entry
{
30 const struct enum_map_entry
*entries
;
34 int string_enum_compare(const char *str1
, const char *str2
, int len
);
36 #define enum_equals(entry, str, len) \
37 ((entry).namelen == (len) && !string_enum_compare((entry).name, str, len))
39 #define enum_equals_static(str, name, namelen) \
40 (namelen == STRING_SIZE(str) && !string_enum_compare(str, name, namelen))
42 bool enum_name_ncopy(char *buf
, size_t bufsize
, const char *name
, size_t namelen
);
43 const char *enum_name_static(const char *name
, size_t namelen
);
45 #define enum_name(entry) enum_name_static((entry).name, (entry).namelen)
46 #define enum_name_copy(buf, name, namelen) enum_name_ncopy(buf, sizeof(buf), name, namelen)
48 const struct enum_map
*find_enum_map(const char *type
);
50 bool map_enum_do(const struct enum_map_entry
*map
, size_t map_size
, int *value
, const char *name
);
52 #define map_enum(attr, map, name) \
53 map_enum_do(map, ARRAY_SIZE(map), attr, name)
55 #define ENUM_MAP_ENTRY(name, value) { name, STRING_SIZE(name), value }
57 #define ENUM_SYM_MACRO(prefix, name) prefix##_##name
58 #define ENUM_MAP_MACRO(prefix, name) ENUM_MAP_ENTRY(#name, ENUM_SYM_MACRO(prefix, name))
60 #define DEFINE_ENUM(name, info) \
61 enum name { info(ENUM_SYM_MACRO) }; \
62 extern const struct enum_map name##_map[];
64 #define DEFINE_ENUM_MAP(name, info) \
65 const struct enum_map_entry name##_map_entries[] = { info(ENUM_MAP_MACRO) }; \
66 const struct enum_map name##_map[] = { { name##_map_entries, ARRAY_SIZE(name##_map_entries) } }
68 #define VERTICAL_SPLIT_ENUM(_) \
69 _(VERTICAL_SPLIT, HORIZONTAL), \
70 _(VERTICAL_SPLIT, VERTICAL), \
71 _(VERTICAL_SPLIT, AUTO)
73 #define GRAPHIC_ENUM(_) \
75 _(GRAPHIC, DEFAULT), \
78 #define DATE_ENUM(_) \
85 #define FILE_SIZE_ENUM(_) \
87 _(FILE_SIZE, DEFAULT), \
90 #define AUTHOR_ENUM(_) \
93 _(AUTHOR, ABBREVIATED), \
97 #define FILENAME_ENUM(_) \
102 #define IGNORE_SPACE_ENUM(_) \
103 _(IGNORE_SPACE, NO), \
104 _(IGNORE_SPACE, ALL), \
105 _(IGNORE_SPACE, SOME), \
106 _(IGNORE_SPACE, AT_EOL)
108 #define COMMIT_ORDER_ENUM(_) \
109 _(COMMIT_ORDER, DEFAULT), \
110 _(COMMIT_ORDER, TOPO), \
111 _(COMMIT_ORDER, DATE), \
112 _(COMMIT_ORDER, REVERSE)
114 #define VIEW_COLUMN_ENUM(_) \
115 _(VIEW_COLUMN, AUTHOR), \
116 _(VIEW_COLUMN, COMMIT_TITLE), \
117 _(VIEW_COLUMN, DATE), \
118 _(VIEW_COLUMN, FILE_NAME), \
119 _(VIEW_COLUMN, FILE_SIZE), \
120 _(VIEW_COLUMN, ID), \
121 _(VIEW_COLUMN, LINE_NUMBER), \
122 _(VIEW_COLUMN, MODE), \
123 _(VIEW_COLUMN, REF), \
126 #define REFERENCE_ENUM(_) \
127 _(REFERENCE, HEAD), \
128 _(REFERENCE, BRANCH), \
129 _(REFERENCE, TRACKED_REMOTE), \
130 _(REFERENCE, REMOTE), \
132 _(REFERENCE, LOCAL_TAG), \
133 _(REFERENCE, REPLACE), \
135 #define ENUM_INFO(_) \
136 _(author, AUTHOR_ENUM) \
137 _(commit_order, COMMIT_ORDER_ENUM) \
139 _(file_size, FILE_SIZE_ENUM) \
140 _(filename, FILENAME_ENUM) \
141 _(graphic, GRAPHIC_ENUM) \
142 _(ignore_space, IGNORE_SPACE_ENUM) \
143 _(vertical_split, VERTICAL_SPLIT_ENUM) \
144 _(view_column_type, VIEW_COLUMN_ENUM) \
145 _(reference_type, REFERENCE_ENUM) \
147 #define DEFINE_ENUMS(name, macro) DEFINE_ENUM(name, macro);
148 ENUM_INFO(DEFINE_ENUMS
);
151 /* vim: set ts=8 sw=8 noexpandtab: */