mirror of
https://github.com/tmux/tmux.git
synced 2024-11-08 04:08:49 +00:00
|PatchSet 879
|Date: 2011/03/29 22:09:13 |Author: nicm |Branch: HEAD |Tag: (none) |Log: |For convenience, work out what type of option is being set by name |regardless of the -s or -w flags (these remain documented however).
This commit is contained in:
parent
ec3be580ec
commit
d9cb059e34
109
cmd-set-option.c
109
cmd-set-option.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-set-option.c,v 1.110 2011-04-06 22:22:25 nicm Exp $ */
|
/* $Id: cmd-set-option.c,v 1.111 2011-04-06 22:22:49 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -29,6 +29,9 @@
|
|||||||
|
|
||||||
int cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
|
int cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
|
||||||
|
|
||||||
|
int cmd_set_option_find(const char *, const struct options_table_entry **,
|
||||||
|
const struct options_table_entry **);
|
||||||
|
|
||||||
int cmd_set_option_unset(struct cmd *, struct cmd_ctx *,
|
int cmd_set_option_unset(struct cmd *, struct cmd_ctx *,
|
||||||
const struct options_table_entry *, struct options *,
|
const struct options_table_entry *, struct options *,
|
||||||
const char *);
|
const char *);
|
||||||
@ -78,11 +81,44 @@ const struct cmd_entry cmd_set_window_option_entry = {
|
|||||||
cmd_set_option_exec
|
cmd_set_option_exec
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Look for an option in all three tables. */
|
||||||
|
int
|
||||||
|
cmd_set_option_find(
|
||||||
|
const char *optstr, const struct options_table_entry **table,
|
||||||
|
const struct options_table_entry **oe)
|
||||||
|
{
|
||||||
|
static const struct options_table_entry *tables[] = {
|
||||||
|
server_options_table,
|
||||||
|
window_options_table,
|
||||||
|
session_options_table
|
||||||
|
};
|
||||||
|
const struct options_table_entry *oe_loop;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
for (i = 0; i < nitems(tables); i++) {
|
||||||
|
for (oe_loop = tables[i]; oe_loop->name != NULL; oe_loop++) {
|
||||||
|
if (strncmp(oe_loop->name, optstr, strlen(optstr)) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* If already found, ambiguous. */
|
||||||
|
if (*oe != NULL)
|
||||||
|
return (-1);
|
||||||
|
*oe = oe_loop;
|
||||||
|
*table = tables[i];
|
||||||
|
|
||||||
|
/* Bail now if an exact match. */
|
||||||
|
if (strcmp((*oe)->name, optstr) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
const struct options_table_entry *table, *oe, *oe_loop;
|
const struct options_table_entry *table, *oe;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
@ -90,33 +126,6 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
const char *optstr, *valstr;
|
const char *optstr, *valstr;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
/* Work out the options tree and table to use. */
|
|
||||||
if (args_has(self->args, 's')) {
|
|
||||||
oo = &global_options;
|
|
||||||
table = server_options_table;
|
|
||||||
} else if (args_has(self->args, 'w') ||
|
|
||||||
self->entry == &cmd_set_window_option_entry) {
|
|
||||||
table = window_options_table;
|
|
||||||
if (args_has(self->args, 'g'))
|
|
||||||
oo = &global_w_options;
|
|
||||||
else {
|
|
||||||
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
|
||||||
if (wl == NULL)
|
|
||||||
return (-1);
|
|
||||||
oo = &wl->window->options;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
table = session_options_table;
|
|
||||||
if (args_has(self->args, 'g'))
|
|
||||||
oo = &global_s_options;
|
|
||||||
else {
|
|
||||||
s = cmd_find_session(ctx, args_get(args, 't'));
|
|
||||||
if (s == NULL)
|
|
||||||
return (-1);
|
|
||||||
oo = &s->options;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the option name and value. */
|
/* Get the option name and value. */
|
||||||
optstr = args->argv[0];
|
optstr = args->argv[0];
|
||||||
if (*optstr == '\0') {
|
if (*optstr == '\0') {
|
||||||
@ -128,27 +137,43 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
else
|
else
|
||||||
valstr = args->argv[1];
|
valstr = args->argv[1];
|
||||||
|
|
||||||
/* Find the option table entry. */
|
/* Find the option entry, try each table. */
|
||||||
oe = NULL;
|
table = oe = NULL;
|
||||||
for (oe_loop = table; oe_loop->name != NULL; oe_loop++) {
|
if (cmd_set_option_find(optstr, &table, &oe) != 0) {
|
||||||
if (strncmp(oe_loop->name, optstr, strlen(optstr)) != 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (oe != NULL) {
|
|
||||||
ctx->error(ctx, "ambiguous option: %s", optstr);
|
ctx->error(ctx, "ambiguous option: %s", optstr);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
oe = oe_loop;
|
|
||||||
|
|
||||||
/* Bail now if an exact match. */
|
|
||||||
if (strcmp(oe->name, optstr) == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (oe == NULL) {
|
if (oe == NULL) {
|
||||||
ctx->error(ctx, "unknown option: %s", optstr);
|
ctx->error(ctx, "unknown option: %s", optstr);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Work out the tree from the table. */
|
||||||
|
if (table == server_options_table)
|
||||||
|
oo = &global_options;
|
||||||
|
else if (table == window_options_table) {
|
||||||
|
if (args_has(self->args, 'g'))
|
||||||
|
oo = &global_w_options;
|
||||||
|
else {
|
||||||
|
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
|
||||||
|
if (wl == NULL)
|
||||||
|
return (-1);
|
||||||
|
oo = &wl->window->options;
|
||||||
|
}
|
||||||
|
} else if (table == session_options_table) {
|
||||||
|
if (args_has(self->args, 'g'))
|
||||||
|
oo = &global_s_options;
|
||||||
|
else {
|
||||||
|
s = cmd_find_session(ctx, args_get(args, 't'));
|
||||||
|
if (s == NULL)
|
||||||
|
return (-1);
|
||||||
|
oo = &s->options;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx->error(ctx, "unknown table");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
/* Unset or set the option. */
|
/* Unset or set the option. */
|
||||||
if (args_has(args, 'u')) {
|
if (args_has(args, 'u')) {
|
||||||
if (cmd_set_option_unset(self, ctx, oe, oo, valstr) != 0)
|
if (cmd_set_option_unset(self, ctx, oe, oo, valstr) != 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user