tig-2.1.1
[tig.git] / src / request.c
blob1ce8d3d1768515c875bfd169883ef9f7437ae1b8
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 #include "tig/tig.h"
15 #include "tig/types.h"
16 #include "tig/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 const char *
40 get_request_name(enum request request)
42 int i;
44 for (i = 0; i < ARRAY_SIZE(req_info); i++)
45 if (req_info[i].request == request)
46 return enum_name(req_info[i].name);
47 return "run request";
50 bool
51 foreach_request(bool (*visitor)(void *data, const struct request_info *req_info, const char *group), void *data)
53 const char *group = NULL;
54 int i;
56 for (i = 0; i < ARRAY_SIZE(req_info); i++) {
57 if (!req_info[i].request) {
58 group = req_info[i].help;
59 continue;
62 if (!visitor(data, &req_info[i], group))
63 return FALSE;
66 return TRUE;
69 /* vim: set ts=8 sw=8 noexpandtab: */