summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/tmux/arguments.c27
-rw-r--r--usr.bin/tmux/cmd-new-session.c14
-rw-r--r--usr.bin/tmux/cmd-new-window.c15
-rw-r--r--usr.bin/tmux/cmd-queue.c18
-rw-r--r--usr.bin/tmux/cmd-refresh-client.c18
-rw-r--r--usr.bin/tmux/cmd-respawn-pane.c14
-rw-r--r--usr.bin/tmux/cmd-respawn-window.c14
-rw-r--r--usr.bin/tmux/cmd-split-window.c16
-rw-r--r--usr.bin/tmux/tmux.h15
9 files changed, 73 insertions, 78 deletions
diff --git a/usr.bin/tmux/arguments.c b/usr.bin/tmux/arguments.c
index 53649afe1ac..aac6acb9ce4 100644
--- a/usr.bin/tmux/arguments.c
+++ b/usr.bin/tmux/arguments.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arguments.c,v 1.36 2021/08/20 17:53:54 nicm Exp $ */
+/* $OpenBSD: arguments.c,v 1.37 2021/08/20 18:59:53 nicm Exp $ */
/*
* Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -29,10 +29,6 @@
* Manipulate command arguments.
*/
-struct args_value {
- char *value;
- TAILQ_ENTRY(args_value) entry;
-};
TAILQ_HEAD(args_values, args_value);
struct args_entry {
@@ -335,30 +331,21 @@ args_next(struct args_entry **entry)
}
/* Get first value in argument. */
-const char *
-args_first_value(struct args *args, u_char flag, struct args_value **value)
+struct args_value *
+args_first_value(struct args *args, u_char flag)
{
struct args_entry *entry;
if ((entry = args_find(args, flag)) == NULL)
return (NULL);
-
- *value = TAILQ_FIRST(&entry->values);
- if (*value == NULL)
- return (NULL);
- return ((*value)->value);
+ return (TAILQ_FIRST(&entry->values));
}
/* Get next value in argument. */
-const char *
-args_next_value(struct args_value **value)
+struct args_value *
+args_next_value(struct args_value *value)
{
- if (*value == NULL)
- return (NULL);
- *value = TAILQ_NEXT(*value, entry);
- if (*value == NULL)
- return (NULL);
- return ((*value)->value);
+ return (TAILQ_NEXT(value, entry));
}
/* Convert an argument value to a number. */
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c
index fbcd907dff0..c35c00b0c09 100644
--- a/usr.bin/tmux/cmd-new-session.c
+++ b/usr.bin/tmux/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-session.c,v 1.139 2021/08/13 06:52:51 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.140 2021/08/20 18:59:53 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -75,7 +75,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
struct options *oo;
struct termios tio, *tiop;
struct session_group *sg = NULL;
- const char *errstr, *template, *group, *tmp, *add;
+ const char *errstr, *template, *group, *tmp;
char *cause, *cwd = NULL, *cp, *newname = NULL;
char *name, *prefix = NULL;
int detached, already_attached, is_control = 0;
@@ -83,7 +83,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
struct spawn_context sc;
enum cmd_retval retval;
struct cmd_find_state fs;
- struct args_value *value;
+ struct args_value *av;
if (cmd_get_entry(self) == &cmd_has_session_entry) {
/*
@@ -269,10 +269,10 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
env = environ_create();
if (c != NULL && !args_has(args, 'E'))
environ_update(global_s_options, c->environ, env);
- add = args_first_value(args, 'e', &value);
- while (add != NULL) {
- environ_put(env, add, 0);
- add = args_next_value(&value);
+ av = args_first_value(args, 'e');
+ while (av != NULL) {
+ environ_put(env, av->value, 0);
+ av = args_next_value(av);
}
s = session_create(prefix, newname, cwd, env, oo, tiop);
diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c
index d74ce0fef5c..de34fbbefdd 100644
--- a/usr.bin/tmux/cmd-new-window.c
+++ b/usr.bin/tmux/cmd-new-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-window.c,v 1.90 2021/02/05 12:23:49 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.91 2021/08/20 18:59:53 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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) {
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index be36a9be8f1..1e6fe15db8f 100644
--- a/usr.bin/tmux/cmd-queue.c
+++ b/usr.bin/tmux/cmd-queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-queue.c,v 1.103 2021/08/12 08:05:11 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.104 2021/08/20 18:59:53 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -352,8 +352,8 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
struct cmdq_state *state = item->state;
struct cmd *cmd = item->cmd;
struct args *args = cmd_get_args(cmd);
- struct args_entry *entryp;
- struct args_value *valuep;
+ struct args_entry *ae;
+ struct args_value *av;
struct options *oo;
va_list ap;
char *name, tmp[32], flag, *arguments;
@@ -398,7 +398,7 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
xsnprintf(tmp, sizeof tmp, "hook_argument_%d", i);
cmdq_add_format(new_state, tmp, "%s", args->argv[i]);
}
- flag = args_first(args, &entryp);
+ flag = args_first(args, &ae);
while (flag != 0) {
value = args_get(args, flag);
if (value == NULL) {
@@ -410,15 +410,15 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
}
i = 0;
- value = args_first_value(args, flag, &valuep);
- while (value != NULL) {
+ av = args_first_value(args, flag);
+ while (av != NULL) {
xsnprintf(tmp, sizeof tmp, "hook_flag_%c_%d", flag, i);
- cmdq_add_format(new_state, tmp, "%s", value);
+ cmdq_add_format(new_state, tmp, "%s", av->value);
i++;
- value = args_next_value(&valuep);
+ av = args_next_value(av);
}
- flag = args_next(&entryp);
+ flag = args_next(&ae);
}
a = options_array_first(o);
diff --git a/usr.bin/tmux/cmd-refresh-client.c b/usr.bin/tmux/cmd-refresh-client.c
index d939d5e35bb..c95daca0c97 100644
--- a/usr.bin/tmux/cmd-refresh-client.c
+++ b/usr.bin/tmux/cmd-refresh-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-refresh-client.c,v 1.39 2020/07/06 09:14:20 nicm Exp $ */
+/* $OpenBSD: cmd-refresh-client.c,v 1.40 2021/08/20 18:59:53 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -184,20 +184,20 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'A')) {
if (~tc->flags & CLIENT_CONTROL)
goto not_control_client;
- value = args_first_value(args, 'A', &av);
- while (value != NULL) {
- cmd_refresh_client_update_offset(tc, value);
- value = args_next_value(&av);
+ av = args_first_value(args, 'A');
+ while (av != NULL) {
+ cmd_refresh_client_update_offset(tc, av->value);
+ av = args_next_value(&av);
}
return (CMD_RETURN_NORMAL);
}
if (args_has(args, 'B')) {
if (~tc->flags & CLIENT_CONTROL)
goto not_control_client;
- value = args_first_value(args, 'B', &av);
- while (value != NULL) {
- cmd_refresh_client_update_subscription(tc, value);
- value = args_next_value(&av);
+ av = args_first_value(args, 'B');
+ while (av != NULL) {
+ cmd_refresh_client_update_subscription(tc, av);
+ av = args_next_value(av);
}
return (CMD_RETURN_NORMAL);
}
diff --git a/usr.bin/tmux/cmd-respawn-pane.c b/usr.bin/tmux/cmd-respawn-pane.c
index 73616b953aa..e13b2c5700b 100644
--- a/usr.bin/tmux/cmd-respawn-pane.c
+++ b/usr.bin/tmux/cmd-respawn-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-respawn-pane.c,v 1.33 2020/05/16 15:01:30 nicm Exp $ */
+/* $OpenBSD: cmd-respawn-pane.c,v 1.34 2021/08/20 18:59:53 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -54,8 +54,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
struct winlink *wl = target->wl;
struct window_pane *wp = target->wp;
char *cause = NULL;
- const char *add;
- struct args_value *value;
+ struct args_value *av;
memset(&sc, 0, sizeof sc);
sc.item = item;
@@ -70,10 +69,10 @@ cmd_respawn_pane_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 = -1;
@@ -86,6 +85,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
if (spawn_pane(&sc, &cause) == NULL) {
cmdq_error(item, "respawn pane failed: %s", cause);
free(cause);
+ environ_free(sc.environ);
return (CMD_RETURN_ERROR);
}
diff --git a/usr.bin/tmux/cmd-respawn-window.c b/usr.bin/tmux/cmd-respawn-window.c
index 39033bf26ba..e4887c32c88 100644
--- a/usr.bin/tmux/cmd-respawn-window.c
+++ b/usr.bin/tmux/cmd-respawn-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-respawn-window.c,v 1.44 2020/04/13 20:51:57 nicm Exp $ */
+/* $OpenBSD: cmd-respawn-window.c,v 1.45 2021/08/20 18:59:53 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -54,8 +54,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = target->s;
struct winlink *wl = target->wl;
char *cause = NULL;
- const char *add;
- struct args_value *value;
+ struct args_value *av;
memset(&sc, 0, sizeof sc);
sc.item = item;
@@ -68,10 +67,10 @@ cmd_respawn_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 = -1;
@@ -84,6 +83,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
if (spawn_window(&sc, &cause) == NULL) {
cmdq_error(item, "respawn window failed: %s", cause);
free(cause);
+ environ_free(sc.environ);
return (CMD_RETURN_ERROR);
}
diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c
index 671fdfb1276..7bee92277e6 100644
--- a/usr.bin/tmux/cmd-split-window.c
+++ b/usr.bin/tmux/cmd-split-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-split-window.c,v 1.105 2021/03/11 06:31:05 nicm Exp $ */
+/* $OpenBSD: cmd-split-window.c,v 1.106 2021/08/20 18:59:53 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -65,10 +65,10 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
struct layout_cell *lc;
struct cmd_find_state fs;
int size, percentage, flags, input;
- const char *template, *add, *errstr, *p;
+ const char *template, *errstr, *p;
char *cause, *cp, *copy;
size_t plen;
- struct args_value *value;
+ struct args_value *av;
if (args_has(args, 'h'))
type = LAYOUT_LEFTRIGHT;
@@ -141,10 +141,10 @@ cmd_split_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 = -1;
@@ -159,6 +159,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
if ((new_wp = spawn_pane(&sc, &cause)) == NULL) {
cmdq_error(item, "create pane failed: %s", cause);
free(cause);
+ environ_free(sc.environ);
return (CMD_RETURN_ERROR);
}
if (input && window_pane_start_input(new_wp, item, &cause) != 0) {
@@ -167,6 +168,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
window_remove_pane(wp->window, new_wp);
cmdq_error(item, "%s", cause);
free(cause);
+ environ_free(sc.environ);
return (CMD_RETURN_ERROR);
}
if (!args_has(args, 'd'))
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 6fdc52ef6fc..ace9f84ca64 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.1124 2021/08/20 17:53:54 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1125 2021/08/20 18:59:53 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -37,7 +37,6 @@
extern char **environ;
struct args;
-struct args_value;
struct client;
struct cmd;
struct cmd_find_state;
@@ -1356,7 +1355,13 @@ struct message_entry {
};
TAILQ_HEAD(message_list, message_entry);
-/* Parsed arguments structures. */
+/* Argument value. */
+struct args_value {
+ char *value;
+ TAILQ_ENTRY(args_value) entry;
+};
+
+/* Arguments set. */
struct args_entry;
RB_HEAD(args_tree, args_entry);
struct args {
@@ -2191,8 +2196,8 @@ int args_has(struct args *, u_char);
const char *args_get(struct args *, u_char);
u_char args_first(struct args *, struct args_entry **);
u_char args_next(struct args_entry **);
-const char *args_first_value(struct args *, u_char, struct args_value **);
-const char *args_next_value(struct args_value **);
+struct args_value *args_first_value(struct args *, u_char);
+struct args_value *args_next_value(struct args_value *);
long long args_strtonum(struct args *, u_char, long long, long long,
char **);
long long args_percentage(struct args *, u_char, long long,