aboutsummaryrefslogtreecommitdiff
path: root/src/commands.c
diff options
context:
space:
mode:
authorJeinzi <Jeinzi@gmx.de>2018-09-01 00:34:50 +0200
committerJeinzi <Jeinzi@gmx.de>2018-09-01 00:34:50 +0200
commit88d6dc2ef7ebee4b04b079455727034a0f594aae (patch)
tree41d30d23311f780440fbc4b1bdc02443c52f6dfb /src/commands.c
parent7221ef8319ad88c9ab81e7734e89b8debfe861b4 (diff)
downloadimv-88d6dc2ef7ebee4b04b079455727034a0f594aae.tar.gz
Added support for multiple commands per bind.
Diffstat (limited to 'src/commands.c')
-rw-r--r--src/commands.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/commands.c b/src/commands.c
index 7dfbc2c..2bc33fe 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -46,29 +46,35 @@ void imv_command_alias(struct imv_commands *cmds, const char *command, const cha
list_append(cmds->command_list, cmd);
}
-int imv_command_exec(struct imv_commands *cmds, const char *command, void *data)
+int imv_command_exec(struct imv_commands *cmds, struct list *commands, void *data)
{
- struct list *args = list_from_string(command, ' ');
int ret = 1;
+ for(size_t i = 0; i < commands->len; ++i) {
+ const char *command = commands->items[i];
+ struct list *args = list_from_string(command, ' ');
- if(args->len > 0) {
- for(size_t i = 0; i < cmds->command_list->len; ++i) {
- struct command *cmd = cmds->command_list->items[i];
- if(!strcmp(cmd->command, args->items[0])) {
- if(cmd->handler) {
- /* argstr = all args as a single string */
- const char *argstr = command + strlen(cmd->command) + 1;
- cmd->handler(args, argstr, data);
- ret = 0;
- } else if(cmd->alias) {
- ret = imv_command_exec(cmds, cmd->alias, data);
+ if(args->len > 0) {
+ for(size_t i = 0; i < cmds->command_list->len; ++i) {
+ struct command *cmd = cmds->command_list->items[i];
+ if(!strcmp(cmd->command, args->items[0])) {
+ if(cmd->handler) {
+ /* argstr = all args as a single string */
+ const char *argstr = command + strlen(cmd->command) + 1;
+ cmd->handler(args, argstr, data);
+ ret = 0;
+ } else if(cmd->alias) {
+ struct list *commands = list_create();
+ list_append(commands, cmd->alias);
+ ret = imv_command_exec(cmds, commands, data);
+ list_free(commands);
+ }
+ break;
}
- break;
}
}
+ list_deep_free(args);
}
- list_deep_free(args);
return ret;
}