Move keybinding and run requests to new keys module
[tig.git] / src / request.c
blob3d9eede030a143d088b2dac2960e762511142079
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"
16 #include "request.h"
18 static const struct request_info req_info[] = {
19 #define REQ_GROUP(help) { 0, NULL, 0, (help) },
20 #define REQ_(req, help) { REQ_##req, (#req), STRING_SIZE(#req), (help) }
21 REQ_INFO
22 #undef REQ_GROUP
23 #undef REQ_
26 enum request
27 get_request(const char *name)
29 int namelen = strlen(name);
30 int i;
32 for (i = 0; i < ARRAY_SIZE(req_info); i++)
33 if (enum_equals(req_info[i], name, namelen))
34 return req_info[i].request;
36 return REQ_UNKNOWN;
39 bool
40 foreach_request(bool (*visitor)(void *data, const struct request_info *req_info, const char *group), void *data)
42 const char *group = NULL;
43 int i;
45 for (i = 0; i < ARRAY_SIZE(req_info); i++) {
46 if (!req_info[i].request) {
47 group = req_info[i].help;
48 continue;
51 if (!visitor(data, &req_info[i], group))
52 return FALSE;
55 return TRUE;
58 /* vim: set ts=8 sw=8 noexpandtab: */