mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00:00
Expose args_value struct (will be needed soon) and add some missing frees.
This commit is contained in:
parent
6cbc83c6a6
commit
90dd474c3e
25
arguments.c
25
arguments.c
@ -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. */
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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) {
|
||||
|
16
cmd-queue.c
16
cmd-queue.c
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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'))
|
||||
|
13
tmux.h
13
tmux.h
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user