mirror of
https://github.com/tmux/tmux.git
synced 2026-07-03 10:12:31 +00:00
Options and hooks updates.
This commit is contained in:
@@ -100,8 +100,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cdata->confirm_key = confirm_key[0];
|
cdata->confirm_key = confirm_key[0];
|
||||||
else {
|
else {
|
||||||
cmdq_error(item, "invalid confirm key");
|
cmdq_error(item, "invalid confirm key");
|
||||||
cmd_parse_free(cdata->tree);
|
cmd_confirm_before_free(cdata);
|
||||||
free(cdata);
|
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
cmd-parse.y
10
cmd-parse.y
@@ -791,12 +791,10 @@ cmd_parse_add_ref(struct cmd_parse_tree *tree)
|
|||||||
void
|
void
|
||||||
cmd_parse_free(struct cmd_parse_tree *tree)
|
cmd_parse_free(struct cmd_parse_tree *tree)
|
||||||
{
|
{
|
||||||
if (tree == NULL)
|
if (tree != NULL && --tree->references == 0) {
|
||||||
return;
|
cmd_parse_free_node(tree->root);
|
||||||
if (--tree->references != 0)
|
free(tree);
|
||||||
return;
|
}
|
||||||
cmd_parse_free_node(tree->root);
|
|
||||||
free(tree);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_parse_node *
|
struct cmd_parse_node *
|
||||||
|
|||||||
@@ -369,7 +369,7 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
|
|||||||
struct cmdq_state *new_state;
|
struct cmdq_state *new_state;
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
struct options_array_item *a;
|
struct options_array_item *a;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_parse_tree *tree;
|
||||||
|
|
||||||
if (item->state->flags & CMDQ_STATE_NOHOOKS)
|
if (item->state->flags & CMDQ_STATE_NOHOOKS)
|
||||||
return;
|
return;
|
||||||
@@ -429,9 +429,9 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
|
|||||||
|
|
||||||
a = options_array_first(o);
|
a = options_array_first(o);
|
||||||
while (a != NULL) {
|
while (a != NULL) {
|
||||||
cmdlist = options_array_item_value(a)->cmdlist;
|
tree = options_array_item_value(a)->cmd;
|
||||||
if (cmdlist != NULL) {
|
if (tree != NULL) {
|
||||||
new_item = cmdq_get_command(cmdlist, new_state);
|
new_item = cmd_invoke_get(tree, new_state, NULL);
|
||||||
if (item != NULL)
|
if (item != NULL)
|
||||||
item = cmdq_insert_after(item, new_item);
|
item = cmdq_insert_after(item, new_item);
|
||||||
else
|
else
|
||||||
|
|||||||
14
notify.c
14
notify.c
@@ -37,19 +37,19 @@ struct notify_entry {
|
|||||||
|
|
||||||
static struct cmdq_item *
|
static struct cmdq_item *
|
||||||
notify_insert_one_hook(struct cmdq_item *item, struct notify_entry *ne,
|
notify_insert_one_hook(struct cmdq_item *item, struct notify_entry *ne,
|
||||||
struct cmd_list *cmdlist, struct cmdq_state *state)
|
struct cmd_parse_tree *tree, struct cmdq_state *state)
|
||||||
{
|
{
|
||||||
struct cmdq_item *new_item;
|
struct cmdq_item *new_item;
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
if (cmdlist == NULL)
|
if (tree == NULL)
|
||||||
return (item);
|
return (item);
|
||||||
if (log_get_level() != 0) {
|
if (log_get_level() != 0) {
|
||||||
s = cmd_list_print(cmdlist, 0);
|
s = cmd_parse_print(tree);
|
||||||
log_debug("%s: hook %s is: %s", __func__, ne->name, s);
|
log_debug("%s: hook %s is: %s", __func__, ne->name, s);
|
||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
new_item = cmdq_get_command(cmdlist, state);
|
new_item = cmd_invoke_get(tree, state, NULL);
|
||||||
return (cmdq_insert_after(item, new_item));
|
return (cmdq_insert_after(item, new_item));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ notify_insert_hook(struct cmdq_item *item, struct notify_entry *ne)
|
|||||||
struct cmdq_state *state;
|
struct cmdq_state *state;
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
struct options_array_item *a;
|
struct options_array_item *a;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_parse_tree *tree;
|
||||||
|
|
||||||
log_debug("%s: inserting hook %s", __func__, ne->name);
|
log_debug("%s: inserting hook %s", __func__, ne->name);
|
||||||
|
|
||||||
@@ -116,8 +116,8 @@ notify_insert_hook(struct cmdq_item *item, struct notify_entry *ne)
|
|||||||
} else {
|
} else {
|
||||||
a = options_array_first(o);
|
a = options_array_first(o);
|
||||||
while (a != NULL) {
|
while (a != NULL) {
|
||||||
cmdlist = options_array_item_value(a)->cmdlist;
|
tree = options_array_item_value(a)->cmd;
|
||||||
item = notify_insert_one_hook(item, ne, cmdlist, state);
|
item = notify_insert_one_hook(item, ne, tree, state);
|
||||||
a = options_array_next(a);
|
a = options_array_next(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
89
options.c
89
options.c
@@ -125,8 +125,8 @@ options_value_free(struct options_entry *o, union options_value *ov)
|
|||||||
{
|
{
|
||||||
if (OPTIONS_IS_STRING(o))
|
if (OPTIONS_IS_STRING(o))
|
||||||
free(ov->string);
|
free(ov->string);
|
||||||
if (OPTIONS_IS_COMMAND(o) && ov->cmdlist != NULL)
|
if (OPTIONS_IS_COMMAND(o))
|
||||||
cmd_list_free(ov->cmdlist);
|
cmd_parse_free(ov->cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
@@ -136,7 +136,7 @@ options_value_to_string(struct options_entry *o, union options_value *ov,
|
|||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
if (OPTIONS_IS_COMMAND(o))
|
if (OPTIONS_IS_COMMAND(o))
|
||||||
return (cmd_list_print(ov->cmdlist, 0));
|
return (cmd_parse_print(ov->cmd));
|
||||||
if (OPTIONS_IS_NUMBER(o)) {
|
if (OPTIONS_IS_NUMBER(o)) {
|
||||||
switch (o->tableentry->type) {
|
switch (o->tableentry->type) {
|
||||||
case OPTIONS_TABLE_NUMBER:
|
case OPTIONS_TABLE_NUMBER:
|
||||||
@@ -259,6 +259,7 @@ options_default(struct options *oo, const struct options_table_entry *oe)
|
|||||||
{
|
{
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
union options_value *ov;
|
union options_value *ov;
|
||||||
|
char *error = NULL;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
o = options_empty(oo, oe);
|
o = options_empty(oo, oe);
|
||||||
@@ -279,22 +280,9 @@ options_default(struct options *oo, const struct options_table_entry *oe)
|
|||||||
ov->string = xstrdup(oe->default_str);
|
ov->string = xstrdup(oe->default_str);
|
||||||
break;
|
break;
|
||||||
case OPTIONS_TABLE_COMMAND:
|
case OPTIONS_TABLE_COMMAND:
|
||||||
#if 0 /* XXX: command parser conversion */
|
ov->cmd = cmd_parse_from_string(oe->default_str, NULL, &error);
|
||||||
struct cmd_parse_result *pr;
|
if (ov->cmd == NULL)
|
||||||
|
fatalx("bad default option %s", oe->name);
|
||||||
pr = cmd_parse_from_string(oe->default_str, NULL);
|
|
||||||
switch (pr->status) {
|
|
||||||
case CMD_PARSE_ERROR:
|
|
||||||
free(pr->error);
|
|
||||||
break;
|
|
||||||
case CMD_PARSE_SUCCESS:
|
|
||||||
ov->cmdlist = pr->cmdlist;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
log_debug("XXX: command parser conversion not done for command option default %s",
|
|
||||||
oe->name);
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ov->number = oe->default_num;
|
ov->number = oe->default_num;
|
||||||
@@ -443,6 +431,8 @@ options_array_set(struct options_entry *o, u_int idx, const char *value,
|
|||||||
struct options_array_item *a;
|
struct options_array_item *a;
|
||||||
char *new;
|
char *new;
|
||||||
long long number;
|
long long number;
|
||||||
|
struct cmd_parse_tree *tree;
|
||||||
|
char *error = NULL;
|
||||||
|
|
||||||
if (!OPTIONS_IS_ARRAY(o)) {
|
if (!OPTIONS_IS_ARRAY(o)) {
|
||||||
if (cause != NULL)
|
if (cause != NULL)
|
||||||
@@ -458,19 +448,13 @@ options_array_set(struct options_entry *o, u_int idx, const char *value,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (OPTIONS_IS_COMMAND(o)) {
|
if (OPTIONS_IS_COMMAND(o)) {
|
||||||
#if 0 /* XXX: command parser conversion */
|
tree = cmd_parse_from_string(value, NULL, &error);
|
||||||
struct cmd_parse_result *pr;
|
if (tree == NULL) {
|
||||||
|
|
||||||
pr = cmd_parse_from_string(value, NULL);
|
|
||||||
switch (pr->status) {
|
|
||||||
case CMD_PARSE_ERROR:
|
|
||||||
if (cause != NULL)
|
if (cause != NULL)
|
||||||
*cause = pr->error;
|
*cause = error;
|
||||||
else
|
else
|
||||||
free(pr->error);
|
free(error);
|
||||||
return (-1);
|
return (-1);
|
||||||
case CMD_PARSE_SUCCESS:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a = options_array_item(o, idx);
|
a = options_array_item(o, idx);
|
||||||
@@ -478,15 +462,8 @@ options_array_set(struct options_entry *o, u_int idx, const char *value,
|
|||||||
a = options_array_new(o, idx);
|
a = options_array_new(o, idx);
|
||||||
else
|
else
|
||||||
options_value_free(o, &a->value);
|
options_value_free(o, &a->value);
|
||||||
a->value.cmdlist = pr->cmdlist;
|
a->value.cmd = tree;
|
||||||
return (0);
|
return (0);
|
||||||
#else
|
|
||||||
if (cause != NULL) {
|
|
||||||
xasprintf(cause,
|
|
||||||
"XXX: command parser conversion not done for command option array");
|
|
||||||
}
|
|
||||||
return (-1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OPTIONS_IS_STRING(o)) {
|
if (OPTIONS_IS_STRING(o)) {
|
||||||
@@ -776,7 +753,7 @@ options_get_number(struct options *oo, const char *name)
|
|||||||
return (o->value.number);
|
return (o->value.number);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_list *
|
struct cmd_parse_tree *
|
||||||
options_get_command(struct options *oo, const char *name)
|
options_get_command(struct options *oo, const char *name)
|
||||||
{
|
{
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
@@ -786,7 +763,7 @@ options_get_command(struct options *oo, const char *name)
|
|||||||
fatalx("missing option %s", name);
|
fatalx("missing option %s", name);
|
||||||
if (!OPTIONS_IS_COMMAND(o))
|
if (!OPTIONS_IS_COMMAND(o))
|
||||||
fatalx("option %s is not a command", name);
|
fatalx("option %s is not a command", name);
|
||||||
return (o->value.cmdlist);
|
return (o->value.cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct options_entry *
|
struct options_entry *
|
||||||
@@ -852,7 +829,7 @@ options_set_number(struct options *oo, const char *name, long long value)
|
|||||||
|
|
||||||
struct options_entry *
|
struct options_entry *
|
||||||
options_set_command(struct options *oo, const char *name,
|
options_set_command(struct options *oo, const char *name,
|
||||||
struct cmd_list *value)
|
struct cmd_parse_tree *value)
|
||||||
{
|
{
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
|
|
||||||
@@ -868,9 +845,8 @@ options_set_command(struct options *oo, const char *name,
|
|||||||
|
|
||||||
if (!OPTIONS_IS_COMMAND(o))
|
if (!OPTIONS_IS_COMMAND(o))
|
||||||
fatalx("option %s is not a command", name);
|
fatalx("option %s is not a command", name);
|
||||||
if (o->value.cmdlist != NULL)
|
cmd_parse_free(o->value.cmd);
|
||||||
cmd_list_free(o->value.cmdlist);
|
o->value.cmd = cmd_parse_add_ref(value);
|
||||||
o->value.cmdlist = value;
|
|
||||||
return (o);
|
return (o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1146,6 +1122,8 @@ options_from_string(struct options *oo, const struct options_table_entry *oe,
|
|||||||
const char *errstr, *new;
|
const char *errstr, *new;
|
||||||
char *old;
|
char *old;
|
||||||
key_code key;
|
key_code key;
|
||||||
|
struct cmd_parse_tree *tree;
|
||||||
|
struct cmd_parse_input pi = { 0 };
|
||||||
|
|
||||||
if (oe != NULL) {
|
if (oe != NULL) {
|
||||||
if (value == NULL &&
|
if (value == NULL &&
|
||||||
@@ -1203,25 +1181,14 @@ options_from_string(struct options *oo, const struct options_table_entry *oe,
|
|||||||
return (options_from_string_flag(oo, name, value, cause));
|
return (options_from_string_flag(oo, name, value, cause));
|
||||||
case OPTIONS_TABLE_CHOICE:
|
case OPTIONS_TABLE_CHOICE:
|
||||||
return (options_from_string_choice(oe, oo, name, value, cause));
|
return (options_from_string_choice(oe, oo, name, value, cause));
|
||||||
case OPTIONS_TABLE_COMMAND:
|
case OPTIONS_TABLE_COMMAND: {
|
||||||
#if 0 /* XXX: command parser conversion */
|
tree = cmd_parse_from_string(value, &pi, cause);
|
||||||
struct cmd_parse_result *pr;
|
if (tree == NULL)
|
||||||
|
|
||||||
pr = cmd_parse_from_string(value, NULL);
|
|
||||||
switch (pr->status) {
|
|
||||||
case CMD_PARSE_ERROR:
|
|
||||||
*cause = pr->error;
|
|
||||||
return (-1);
|
return (-1);
|
||||||
case CMD_PARSE_SUCCESS:
|
options_set_command(oo, name, tree);
|
||||||
options_set_command(oo, name, pr->cmdlist);
|
cmd_parse_free(tree);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
#else
|
|
||||||
xasprintf(cause,
|
|
||||||
"XXX: command parser conversion not done for command option");
|
|
||||||
return (-1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2527,28 +2527,15 @@ bad:
|
|||||||
proc_kill_peer(c->peer);
|
proc_kill_peer(c->peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback when command is not allowed. */
|
|
||||||
static enum cmd_retval
|
|
||||||
server_client_read_only(struct cmdq_item *item, __unused void *data)
|
|
||||||
{
|
|
||||||
cmdq_error(item, "client is read-only");
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Callback for default command. */
|
/* Callback for default command. */
|
||||||
static enum cmd_retval
|
static enum cmd_retval
|
||||||
server_client_default_command(struct cmdq_item *item, __unused void *data)
|
server_client_default_command(struct cmdq_item *item, __unused void *data)
|
||||||
{
|
{
|
||||||
struct client *c = cmdq_get_client(item);
|
struct cmd_parse_tree *tree;
|
||||||
struct cmd_list *cmdlist;
|
|
||||||
struct cmdq_item *new_item;
|
struct cmdq_item *new_item;
|
||||||
|
|
||||||
cmdlist = options_get_command(global_options, "default-client-command");
|
tree = options_get_command(global_options, "default-client-command");
|
||||||
if ((c->flags & CLIENT_READONLY) &&
|
new_item = cmd_invoke_get(tree, NULL, NULL);
|
||||||
!cmd_list_all_have(cmdlist, CMD_READONLY))
|
|
||||||
new_item = cmdq_get_callback(server_client_read_only, NULL);
|
|
||||||
else
|
|
||||||
new_item = cmdq_get_command(cmdlist, NULL);
|
|
||||||
cmdq_insert_after(item, new_item);
|
cmdq_insert_after(item, new_item);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ struct args_value;
|
|||||||
struct cmd_parse_input {
|
struct cmd_parse_input {
|
||||||
int flags;
|
int flags;
|
||||||
#define CMD_PARSE_QUIET 0x1
|
#define CMD_PARSE_QUIET 0x1
|
||||||
#define CMD_PARSE_PARSEONLY 0x2 /* XXX */
|
#define CMD_PARSE_PARSEONLY 0x2
|
||||||
#define CMD_PARSE_NOALIAS 0x4 /* XXX */
|
#define CMD_PARSE_NOALIAS 0x4
|
||||||
#define CMD_PARSE_VERBOSE 0x8 /* XXX */
|
#define CMD_PARSE_VERBOSE 0x8
|
||||||
#define CMD_PARSE_ONEGROUP 0x10
|
#define CMD_PARSE_ONEGROUP 0x10
|
||||||
|
|
||||||
const char *file;
|
const char *file;
|
||||||
|
|||||||
6
tmux.h
6
tmux.h
@@ -2340,7 +2340,7 @@ union options_value {
|
|||||||
long long number;
|
long long number;
|
||||||
struct style style;
|
struct style style;
|
||||||
struct options_array array;
|
struct options_array array;
|
||||||
struct cmd_list *cmdlist;
|
struct cmd_parse_tree *cmd;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Option table entries. */
|
/* Option table entries. */
|
||||||
@@ -2673,13 +2673,13 @@ struct options_entry *options_match_get(struct options *, const char *, int *,
|
|||||||
int, int *);
|
int, int *);
|
||||||
const char *options_get_string(struct options *, const char *);
|
const char *options_get_string(struct options *, const char *);
|
||||||
long long options_get_number(struct options *, const char *);
|
long long options_get_number(struct options *, const char *);
|
||||||
struct cmd_list *options_get_command(struct options *, const char *);
|
struct cmd_parse_tree *options_get_command(struct options *, const char *);
|
||||||
struct options_entry * printflike(4, 5) options_set_string(struct options *,
|
struct options_entry * printflike(4, 5) options_set_string(struct options *,
|
||||||
const char *, int, const char *, ...);
|
const char *, int, const char *, ...);
|
||||||
struct options_entry *options_set_number(struct options *, const char *,
|
struct options_entry *options_set_number(struct options *, const char *,
|
||||||
long long);
|
long long);
|
||||||
struct options_entry *options_set_command(struct options *, const char *,
|
struct options_entry *options_set_command(struct options *, const char *,
|
||||||
struct cmd_list *);
|
struct cmd_parse_tree *);
|
||||||
int options_scope_from_name(struct args *, int,
|
int options_scope_from_name(struct args *, int,
|
||||||
const char *, struct cmd_find_state *, struct options **,
|
const char *, struct cmd_find_state *, struct options **,
|
||||||
char **);
|
char **);
|
||||||
|
|||||||
Reference in New Issue
Block a user