Move refs helpers to refs module
[tig.git] / src / types.c
blobc862b8cac15dbf1ee232f4f34a1552aaa114585e
1 /* Copyright (c) 2006-2014 Jonas Fonseca <fonseca@diku.dk>
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 #include "tig.h"
15 #include "types.h"
18 * Enumerations
21 int
22 string_enum_compare(const char *str1, const char *str2, int len)
24 size_t i;
26 #define string_enum_sep(x) ((x) == '-' || (x) == '_' || (x) == '.')
28 /* Diff-Header == DIFF_HEADER */
29 for (i = 0; i < len; i++) {
30 if (ascii_toupper(str1[i]) == ascii_toupper(str2[i]))
31 continue;
33 if (string_enum_sep(str1[i]) &&
34 string_enum_sep(str2[i]))
35 continue;
37 return str1[i] - str2[i];
40 return 0;
43 char *
44 enum_map_name(const char *name, size_t namelen)
46 static char buf[SIZEOF_STR];
47 int bufpos;
49 for (bufpos = 0; bufpos <= namelen; bufpos++) {
50 buf[bufpos] = ascii_tolower(name[bufpos]);
51 if (buf[bufpos] == '_')
52 buf[bufpos] = '-';
55 buf[bufpos] = 0;
56 return buf;
59 bool
60 map_enum_do(const struct enum_map_entry *map, size_t map_size, int *value, const char *name)
62 size_t namelen = strlen(name);
63 int i;
65 for (i = 0; i < map_size; i++)
66 if (enum_equals(map[i], name, namelen)) {
67 *value = map[i].value;
68 return TRUE;
71 return FALSE;
74 DEFINE_ENUM_MAP(author, AUTHOR_ENUM);
75 DEFINE_ENUM_MAP(commit_order, COMMIT_ORDER_ENUM);
76 DEFINE_ENUM_MAP(date, DATE_ENUM);
77 DEFINE_ENUM_MAP(file_size, FILE_SIZE_ENUM);
78 DEFINE_ENUM_MAP(filename, FILENAME_ENUM);
79 DEFINE_ENUM_MAP(graphic, GRAPHIC_ENUM);
80 DEFINE_ENUM_MAP(ignore_space, IGNORE_SPACE_ENUM);
81 DEFINE_ENUM_MAP(vertical_split, VERTICAL_SPLIT_ENUM);
83 /* vim: set ts=8 sw=8 noexpandtab: */