diff options
Diffstat (limited to 'src/commands.c')
-rw-r--r-- | src/commands.c | 36 |
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; } |