aboutsummaryrefslogtreecommitdiff
path: root/src/commands.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2019-08-18 14:54:26 +0100
committerHarry Jeffery <harry@exec64.co.uk>2019-08-18 14:54:26 +0100
commit00ad6b1d8e946069963bc2ab09f4f01c8e81ab03 (patch)
treee3e0cef7a0c4ed26a1c7a4cb29630b0af3c92b48 /src/commands.c
parent901243b3f97368c05f7ed1c723d4ef5d18f634a1 (diff)
downloadimv-00ad6b1d8e946069963bc2ab09f4f01c8e81ab03.tar.gz
imv: Add bind command
Diffstat (limited to 'src/commands.c')
-rw-r--r--src/commands.c27
1 files changed, 1 insertions, 26 deletions
diff --git a/src/commands.c b/src/commands.c
index 25ec702..e72b9e0 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -11,31 +11,6 @@ struct command {
char* alias;
};
-static char *join_str_list(struct list *list, const char *sep, size_t start)
-{
- size_t len = 0;
- size_t cap = 512;
- char *buf = malloc(cap);
- buf[0] = 0;
-
- size_t sep_len = strlen(sep);
- for (size_t i = start; i < list->len; ++i) {
- size_t item_len = strlen(list->items[i]);
- if (len + item_len + sep_len >= cap) {
- cap *= 2;
- buf = realloc(buf, cap);
- assert(buf);
- }
-
- strncat(buf, list->items[i], cap - 1);
- len += item_len;
-
- strncat(buf, sep, cap - 1);
- len += sep_len;
- }
- return buf;
-}
-
struct imv_commands *imv_commands_create(void)
{
struct imv_commands *cmds = malloc(sizeof *cmds);
@@ -90,7 +65,7 @@ int imv_command_exec(struct imv_commands *cmds, const char *command, void *data)
cmd->handler(args, argstr, data);
ret = 0;
} else if(cmd->alias) {
- char *new_args = join_str_list(args, " ", 1);
+ char *new_args = list_to_string(args, " ", 1);
size_t cmd_len = strlen(cmd->alias) + 1 + strlen(new_args) + 1;
char *new_cmd = malloc(cmd_len);
snprintf(new_cmd, cmd_len, "%s %s", cmd->alias, new_args);