From 90dd474c3ea8bf10bde6ee15eaaf9f3af3fb46f6 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 20 Aug 2021 18:59:53 +0000 Subject: Expose args_value struct (will be needed soon) and add some missing frees. --- cmd-new-window.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'cmd-new-window.c') diff --git a/cmd-new-window.c b/cmd-new-window.c index 712e2a79..9393f6e4 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -62,9 +62,9 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) int idx = target->idx, before; struct winlink *new_wl = NULL; char *cause = NULL, *cp; - const char *template, *add, *name; + const char *template, *name; struct cmd_find_state fs; - struct args_value *value; + struct args_value *av; /* * If -S and -n are given and -t is not and a single window with this @@ -112,10 +112,10 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) sc.argv = args->argv; sc.environ = environ_create(); - add = args_first_value(args, 'e', &value); - while (add != NULL) { - environ_put(sc.environ, add, 0); - add = args_next_value(&value); + av = args_first_value(args, 'e'); + while (av != NULL) { + environ_put(sc.environ, av->value, 0); + av = args_next_value(av); } sc.idx = idx; @@ -130,6 +130,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) if ((new_wl = spawn_window(&sc, &cause)) == NULL) { cmdq_error(item, "create window failed: %s", cause); free(cause); + environ_free(sc.environ); return (CMD_RETURN_ERROR); } if (!args_has(args, 'd') || new_wl == s->curw) { -- cgit From c76b28de242696a78a256dda3b42ba49d607a751 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 20 Aug 2021 19:08:36 +0000 Subject: Remove some unnecessary blank lines. --- cmd-new-window.c | 1 - 1 file changed, 1 deletion(-) (limited to 'cmd-new-window.c') diff --git a/cmd-new-window.c b/cmd-new-window.c index 9393f6e4..a9156a6f 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -94,7 +94,6 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) } } - before = args_has(args, 'b'); if (args_has(args, 'a') || before) { idx = winlink_shuffle_up(s, wl, before); -- cgit From 5f32b7d9613e9ef3f8198302379a42630323da6a Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 20 Aug 2021 19:50:16 +0000 Subject: Hide struct args behind a couple of accessor functions. --- cmd-new-window.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'cmd-new-window.c') diff --git a/cmd-new-window.c b/cmd-new-window.c index a9156a6f..f24de8e9 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -55,12 +55,11 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) struct client *c = cmdq_get_client(item); struct cmd_find_state *current = cmdq_get_current(item); struct cmd_find_state *target = cmdq_get_target(item); - struct spawn_context sc; + struct spawn_context sc = { 0 }; struct client *tc = cmdq_get_target_client(item); struct session *s = target->s; - struct winlink *wl = target->wl; + struct winlink *wl = target->wl, *new_wl = NULL; int idx = target->idx, before; - struct winlink *new_wl = NULL; char *cause = NULL, *cp; const char *template, *name; struct cmd_find_state fs; @@ -101,14 +100,12 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) idx = target->idx; } - memset(&sc, 0, sizeof sc); sc.item = item; sc.s = s; sc.tc = tc; sc.name = args_get(args, 'n'); - sc.argc = args->argc; - sc.argv = args->argv; + args_vector(args, &sc.argc, &sc.argv); sc.environ = environ_create(); av = args_first_value(args, 'e'); @@ -129,6 +126,8 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) if ((new_wl = spawn_window(&sc, &cause)) == NULL) { cmdq_error(item, "create window failed: %s", cause); free(cause); + if (sc.argv != NULL) + cmd_free_argv(sc.argc, sc.argv); environ_free(sc.environ); return (CMD_RETURN_ERROR); } @@ -150,6 +149,8 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) cmd_find_from_winlink(&fs, new_wl, 0); cmdq_insert_hook(s, item, &fs, "after-new-window"); + if (sc.argv != NULL) + cmd_free_argv(sc.argc, sc.argv); environ_free(sc.environ); return (CMD_RETURN_NORMAL); } -- cgit