mirror of
https://github.com/swaywm/sway.git
synced 2024-12-01 10:56:36 +00:00
Function to find and execute a command handler
This commit is contained in:
parent
1f0bb9a803
commit
2c6e9d7d5f
|
@ -3463,6 +3463,18 @@ static struct cmd_handler *__find_handler(char *line, const struct cmd_handler *
|
||||||
|
|
||||||
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
|
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
|
||||||
|
|
||||||
|
static struct cmd_results *find_and_execute_handler(int argc, char **argv,
|
||||||
|
const struct cmd_handler *handlers,
|
||||||
|
size_t handlers_size,
|
||||||
|
const char *expected_syntax) {
|
||||||
|
char *command = argv[0];
|
||||||
|
struct cmd_handler *handler = __find_handler(command, handlers, handlers_size);
|
||||||
|
if (!handler) {
|
||||||
|
return cmd_results_new(CMD_INVALID, command, expected_syntax);
|
||||||
|
}
|
||||||
|
return handler->handle(argc - 1, argv + 1);
|
||||||
|
}
|
||||||
|
|
||||||
static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
|
static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
|
||||||
struct cmd_handler *res = NULL;
|
struct cmd_handler *res = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue