diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2017-04-14 16:23:50 +0100 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2017-04-14 16:23:50 +0100 |
commit | b46385618eb6c2e6ee468c672c6824259d97add2 (patch) | |
tree | 08c64828f5ae44c07fdf81a903af2628a153e883 /src | |
parent | 83959687adbd90303ee2ff630f659b8994000808 (diff) | |
download | imv-b46385618eb6c2e6ee468c672c6824259d97add2.tar.gz |
Add basic alias support
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.c | 23 | ||||
-rw-r--r-- | src/commands.h | 1 |
2 files changed, 22 insertions, 2 deletions
diff --git a/src/commands.c b/src/commands.c index 9b93933..f9a4ff3 100644 --- a/src/commands.c +++ b/src/commands.c @@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. struct imv_command { const char* command; void (*handler)(struct imv_list *args); + const char* alias; }; struct imv_list *g_commands = NULL; @@ -34,6 +35,20 @@ void imv_command_register(const char *command, void (*handler)()) struct imv_command *cmd = malloc(sizeof(struct imv_command)); cmd->command = strdup(command); cmd->handler = handler; + cmd->alias = NULL; + imv_list_append(g_commands, cmd); +} + +void imv_command_alias(const char *command, const char *alias) +{ + if(!g_commands) { + g_commands = imv_list_create(); + } + + struct imv_command *cmd = malloc(sizeof(struct imv_command)); + cmd->command = strdup(command); + cmd->handler = NULL; + cmd->alias = strdup(alias); imv_list_append(g_commands, cmd); } @@ -50,8 +65,12 @@ int imv_command_exec(const char *command) for(size_t i = 0; i < g_commands->len; ++i) { struct imv_command *cmd = g_commands->items[i]; if(!strcmp(cmd->command, args->items[0])) { - cmd->handler(args); - ret = 0; + if(cmd->handler) { + cmd->handler(args); + ret = 0; + } else if(cmd->alias) { + ret = imv_command_exec(cmd->alias); + } break; } } diff --git a/src/commands.h b/src/commands.h index 1dfa3bf..b3a78e6 100644 --- a/src/commands.h +++ b/src/commands.h @@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define COMMANDS_H void imv_command_register(const char *command, void (*handler)()); +void imv_command_alias(const char *command, const char *alias); int imv_command_exec(const char *command); #endif |