aboutsummaryrefslogtreecommitdiff
path: root/src/commands.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2017-04-14 16:23:50 +0100
committerHarry Jeffery <harry@exec64.co.uk>2017-04-14 16:23:50 +0100
commitb46385618eb6c2e6ee468c672c6824259d97add2 (patch)
tree08c64828f5ae44c07fdf81a903af2628a153e883 /src/commands.c
parent83959687adbd90303ee2ff630f659b8994000808 (diff)
downloadimv-b46385618eb6c2e6ee468c672c6824259d97add2.tar.gz
Add basic alias support
Diffstat (limited to 'src/commands.c')
-rw-r--r--src/commands.c23
1 files changed, 21 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;
}
}