-/* $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>
* Manipulate command arguments.
*/
-struct args_value {
- char *value;
- TAILQ_ENTRY(args_value) entry;
-};
TAILQ_HEAD(args_values, args_value);
struct args_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. */
-/* $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>
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;
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) {
/*
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);
-/* $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>
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
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;
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) {
-/* $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>
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;
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) {
}
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);
-/* $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>
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);
}
-/* $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>
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;
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;
if (spawn_pane(&sc, &cause) == NULL) {
cmdq_error(item, "respawn pane failed: %s", cause);
free(cause);
+ environ_free(sc.environ);
return (CMD_RETURN_ERROR);
}
-/* $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>
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;
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;
if (spawn_window(&sc, &cause) == NULL) {
cmdq_error(item, "respawn window failed: %s", cause);
free(cause);
+ environ_free(sc.environ);
return (CMD_RETURN_ERROR);
}
-/* $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>
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;
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;
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) {
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'))
-/* $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>
extern char **environ;
struct args;
-struct args_value;
struct client;
struct cmd;
struct cmd_find_state;
};
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 {
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,