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.
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) }
27 get_request(const char *name
)
29 int namelen
= strlen(name
);
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
;
40 get_request_name(enum request request
)
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
);
51 foreach_request(bool (*visitor
)(void *data
, const struct request_info
*req_info
, const char *group
), void *data
)
53 const char *group
= NULL
;
56 for (i
= 0; i
< ARRAY_SIZE(req_info
); i
++) {
57 if (!req_info
[i
].request
) {
58 group
= req_info
[i
].help
;
62 if (!visitor(data
, &req_info
[i
], group
))
69 /* vim: set ts=8 sw=8 noexpandtab: */