Add date column option controlling whether to show local date
[tig.git] / include / tig / types.h
blobb733f23b8d0e473887beb83b021a42b9e583abfd
1 /* Copyright (c) 2006-2015 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.
14 #ifndef TIG_TYPES_H
15 #define TIG_TYPES_H
17 #include "tig/tig.h"
20 * Enumerations
23 struct enum_map_entry {
24 const char *name;
25 int namelen;
26 int value;
29 struct enum_map {
30 const struct enum_map_entry *entries;
31 const int size;
34 #define string_enum_sep(x) ((x) == '-' || (x) == '_')
35 int string_enum_compare(const char *str1, const char *str2, int len);
37 #define enum_equals(entry, str, len) \
38 ((entry).namelen == (len) && !string_enum_compare((entry).name, str, len))
40 #define enum_equals_static(str, name, namelen) \
41 (namelen == STRING_SIZE(str) && !string_enum_compare(str, name, namelen))
43 #define enum_equals_prefix(entry, name_, namelen_) \
44 ((namelen_) > (entry).namelen && \
45 string_enum_sep((name_)[(entry).namelen]) && \
46 enum_equals(entry, name_, (entry).namelen))
48 const char *enum_name(const char *name);
49 bool enum_name_copy(char buf[], size_t bufsize, const char *name);
50 bool enum_name_prefixed(char buf[], size_t bufsize, const char *prefix, const char *name);
52 const struct enum_map *find_enum_map(const char *type);
54 bool map_enum_do(const struct enum_map_entry *map, size_t map_size, int *value, const char *name);
56 #define map_enum(attr, map, name) \
57 map_enum_do(map, ARRAY_SIZE(map), attr, name)
59 #define ENUM_MAP_ENTRY(name, value) { name, STRING_SIZE(name), value }
61 #define ENUM_SYM_MACRO(prefix, name) prefix##_##name
62 #define ENUM_MAP_MACRO(prefix, name) ENUM_MAP_ENTRY(#name, ENUM_SYM_MACRO(prefix, name))
64 #define DEFINE_ENUM(name, info) \
65 enum name { info(ENUM_SYM_MACRO) }; \
66 extern const struct enum_map name##_map[];
68 #define DEFINE_ENUM_MAP(name, info) \
69 const struct enum_map_entry name##_map_entries[] = { info(ENUM_MAP_MACRO) }; \
70 const struct enum_map name##_map[] = { { name##_map_entries, ARRAY_SIZE(name##_map_entries) } }
72 #define VERTICAL_SPLIT_ENUM(_) \
73 _(VERTICAL_SPLIT, HORIZONTAL), \
74 _(VERTICAL_SPLIT, VERTICAL), \
75 _(VERTICAL_SPLIT, AUTO)
77 #define GRAPHIC_ENUM(_) \
78 _(GRAPHIC, ASCII), \
79 _(GRAPHIC, DEFAULT), \
80 _(GRAPHIC, UTF_8)
82 #define GRAPH_DISPLAY_ENUM(_) \
83 _(GRAPH_DISPLAY, NO), \
84 _(GRAPH_DISPLAY, V2), \
85 _(GRAPH_DISPLAY, V1)
87 #define DATE_ENUM(_) \
88 _(DATE, NO), \
89 _(DATE, DEFAULT), \
90 _(DATE, RELATIVE), \
91 _(DATE, RELATIVE_COMPACT), \
92 _(DATE, SHORT)
94 #define FILE_SIZE_ENUM(_) \
95 _(FILE_SIZE, NO), \
96 _(FILE_SIZE, DEFAULT), \
97 _(FILE_SIZE, UNITS)
99 #define AUTHOR_ENUM(_) \
100 _(AUTHOR, NO), \
101 _(AUTHOR, FULL), \
102 _(AUTHOR, ABBREVIATED), \
103 _(AUTHOR, EMAIL), \
104 _(AUTHOR, EMAIL_USER)
106 #define FILENAME_ENUM(_) \
107 _(FILENAME, NO), \
108 _(FILENAME, AUTO), \
109 _(FILENAME, ALWAYS)
111 #define IGNORE_SPACE_ENUM(_) \
112 _(IGNORE_SPACE, NO), \
113 _(IGNORE_SPACE, ALL), \
114 _(IGNORE_SPACE, SOME), \
115 _(IGNORE_SPACE, AT_EOL)
117 #define COMMIT_ORDER_ENUM(_) \
118 _(COMMIT_ORDER, AUTO), \
119 _(COMMIT_ORDER, DEFAULT), \
120 _(COMMIT_ORDER, TOPO), \
121 _(COMMIT_ORDER, DATE), \
122 _(COMMIT_ORDER, AUTHOR_DATE), \
123 _(COMMIT_ORDER, REVERSE)
125 #define VIEW_COLUMN_ENUM(_) \
126 _(VIEW_COLUMN, AUTHOR), \
127 _(VIEW_COLUMN, COMMIT_TITLE), \
128 _(VIEW_COLUMN, DATE), \
129 _(VIEW_COLUMN, FILE_NAME), \
130 _(VIEW_COLUMN, FILE_SIZE), \
131 _(VIEW_COLUMN, ID), \
132 _(VIEW_COLUMN, LINE_NUMBER), \
133 _(VIEW_COLUMN, MODE), \
134 _(VIEW_COLUMN, REF), \
135 _(VIEW_COLUMN, SECTION), \
136 _(VIEW_COLUMN, STATUS), \
137 _(VIEW_COLUMN, TEXT)
139 #define REFERENCE_ENUM(_) \
140 _(REFERENCE, HEAD), \
141 _(REFERENCE, BRANCH), \
142 _(REFERENCE, TRACKED_REMOTE), \
143 _(REFERENCE, REMOTE), \
144 _(REFERENCE, TAG), \
145 _(REFERENCE, LOCAL_TAG), \
146 _(REFERENCE, REPLACE), \
148 #define STATUS_LABEL_ENUM(_) \
149 _(STATUS_LABEL, NO), \
150 _(STATUS_LABEL, SHORT), \
151 _(STATUS_LABEL, LONG), \
153 #define REFRESH_MODE_ENUM(_) \
154 _(REFRESH_MODE, MANUAL), \
155 _(REFRESH_MODE, AUTO), \
156 _(REFRESH_MODE, AFTER_COMMAND), \
157 _(REFRESH_MODE, PERIODIC), \
159 #define ENUM_INFO(_) \
160 _(author, AUTHOR_ENUM) \
161 _(commit_order, COMMIT_ORDER_ENUM) \
162 _(date, DATE_ENUM) \
163 _(file_size, FILE_SIZE_ENUM) \
164 _(filename, FILENAME_ENUM) \
165 _(graphic, GRAPHIC_ENUM) \
166 _(graph_display, GRAPH_DISPLAY_ENUM) \
167 _(ignore_space, IGNORE_SPACE_ENUM) \
168 _(vertical_split, VERTICAL_SPLIT_ENUM) \
169 _(view_column_type, VIEW_COLUMN_ENUM) \
170 _(reference_type, REFERENCE_ENUM) \
171 _(refresh_mode, REFRESH_MODE_ENUM) \
172 _(status_label, STATUS_LABEL_ENUM) \
174 #define DEFINE_ENUMS(name, macro) DEFINE_ENUM(name, macro)
175 ENUM_INFO(DEFINE_ENUMS)
177 #endif
178 /* vim: set ts=8 sw=8 noexpandtab: */