mirror of https://github.com/tmux/tmux.git
Merge branch 'obsd-master'
This commit is contained in:
commit
c869366133
|
@ -366,8 +366,6 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
case OPTIONS_TABLE_ARRAY:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
19
cmd.c
19
cmd.c
|
@ -320,10 +320,11 @@ cmd_try_alias(int *argc, char ***argv)
|
||||||
{
|
{
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
struct options_array_item *a;
|
struct options_array_item *a;
|
||||||
|
union options_value *ov;
|
||||||
int old_argc = *argc, new_argc, i;
|
int old_argc = *argc, new_argc, i;
|
||||||
char **old_argv = *argv, **new_argv;
|
char **old_argv = *argv, **new_argv;
|
||||||
size_t wanted;
|
size_t wanted;
|
||||||
const char *s, *cp = NULL;
|
const char *cp = NULL;
|
||||||
|
|
||||||
o = options_get_only(global_options, "command-alias");
|
o = options_get_only(global_options, "command-alias");
|
||||||
if (o == NULL)
|
if (o == NULL)
|
||||||
|
@ -332,14 +333,16 @@ cmd_try_alias(int *argc, char ***argv)
|
||||||
|
|
||||||
a = options_array_first(o);
|
a = options_array_first(o);
|
||||||
while (a != NULL) {
|
while (a != NULL) {
|
||||||
s = options_array_item_value(a);
|
ov = options_array_item_value(a);
|
||||||
if (s != NULL) {
|
if (ov == NULL) {
|
||||||
cp = strchr(s, '=');
|
a = options_array_next(a);
|
||||||
if (cp != NULL &&
|
continue;
|
||||||
(size_t)(cp - s) == wanted &&
|
|
||||||
strncmp(old_argv[0], s, wanted) == 0)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
cp = strchr(ov->string, '=');
|
||||||
|
if (cp != NULL &&
|
||||||
|
(size_t)(cp - ov->string) == wanted &&
|
||||||
|
strncmp(old_argv[0], ov->string, wanted) == 0)
|
||||||
|
break;
|
||||||
a = options_array_next(a);
|
a = options_array_next(a);
|
||||||
}
|
}
|
||||||
if (a == NULL)
|
if (a == NULL)
|
||||||
|
|
10
environ.c
10
environ.c
|
@ -177,20 +177,20 @@ environ_update(struct options *oo, struct environ *src, struct environ *dst)
|
||||||
struct environ_entry *envent;
|
struct environ_entry *envent;
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
struct options_array_item *a;
|
struct options_array_item *a;
|
||||||
const char *value;
|
union options_value *ov;
|
||||||
|
|
||||||
o = options_get(oo, "update-environment");
|
o = options_get(oo, "update-environment");
|
||||||
if (o == NULL)
|
if (o == NULL)
|
||||||
return;
|
return;
|
||||||
a = options_array_first(o);
|
a = options_array_first(o);
|
||||||
while (a != NULL) {
|
while (a != NULL) {
|
||||||
value = options_array_item_value(a);
|
ov = options_array_item_value(a);
|
||||||
if (value == NULL) {
|
if (ov == NULL) {
|
||||||
a = options_array_next(a);
|
a = options_array_next(a);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((envent = environ_find(src, value)) == NULL)
|
if ((envent = environ_find(src, ov->string)) == NULL)
|
||||||
environ_clear(dst, value);
|
environ_clear(dst, ov->string);
|
||||||
else
|
else
|
||||||
environ_set(dst, envent->name, "%s", envent->value);
|
environ_set(dst, envent->name, "%s", envent->value);
|
||||||
a = options_array_next(a);
|
a = options_array_next(a);
|
||||||
|
|
|
@ -140,8 +140,9 @@ const struct options_table_entry options_table[] = {
|
||||||
},
|
},
|
||||||
|
|
||||||
{ .name = "command-alias",
|
{ .name = "command-alias",
|
||||||
.type = OPTIONS_TABLE_ARRAY,
|
.type = OPTIONS_TABLE_STRING,
|
||||||
.scope = OPTIONS_TABLE_SERVER,
|
.scope = OPTIONS_TABLE_SERVER,
|
||||||
|
.flags = OPTIONS_TABLE_IS_ARRAY,
|
||||||
.default_str = "split-pane=split-window,"
|
.default_str = "split-pane=split-window,"
|
||||||
"splitp=split-window,"
|
"splitp=split-window,"
|
||||||
"server-info=show-messages -JT,"
|
"server-info=show-messages -JT,"
|
||||||
|
@ -205,8 +206,9 @@ const struct options_table_entry options_table[] = {
|
||||||
},
|
},
|
||||||
|
|
||||||
{ .name = "terminal-overrides",
|
{ .name = "terminal-overrides",
|
||||||
.type = OPTIONS_TABLE_ARRAY,
|
.type = OPTIONS_TABLE_STRING,
|
||||||
.scope = OPTIONS_TABLE_SERVER,
|
.scope = OPTIONS_TABLE_SERVER,
|
||||||
|
.flags = OPTIONS_TABLE_IS_ARRAY,
|
||||||
.default_str = "xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007"
|
.default_str = "xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007"
|
||||||
":Cs=\\E]12;%p1%s\\007:Cr=\\E]112\\007"
|
":Cs=\\E]12;%p1%s\\007:Cr=\\E]112\\007"
|
||||||
":Ss=\\E[%p1%d q:Se=\\E[2 q,screen*:XT",
|
":Ss=\\E[%p1%d q:Se=\\E[2 q,screen*:XT",
|
||||||
|
@ -214,8 +216,9 @@ const struct options_table_entry options_table[] = {
|
||||||
},
|
},
|
||||||
|
|
||||||
{ .name = "user-keys",
|
{ .name = "user-keys",
|
||||||
.type = OPTIONS_TABLE_ARRAY,
|
.type = OPTIONS_TABLE_STRING,
|
||||||
.scope = OPTIONS_TABLE_SERVER,
|
.scope = OPTIONS_TABLE_SERVER,
|
||||||
|
.flags = OPTIONS_TABLE_IS_ARRAY,
|
||||||
.default_str = "",
|
.default_str = "",
|
||||||
.separator = ","
|
.separator = ","
|
||||||
},
|
},
|
||||||
|
@ -420,8 +423,9 @@ const struct options_table_entry options_table[] = {
|
||||||
},
|
},
|
||||||
|
|
||||||
{ .name = "status-format",
|
{ .name = "status-format",
|
||||||
.type = OPTIONS_TABLE_ARRAY,
|
.type = OPTIONS_TABLE_STRING,
|
||||||
.scope = OPTIONS_TABLE_SESSION,
|
.scope = OPTIONS_TABLE_SESSION,
|
||||||
|
.flags = OPTIONS_TABLE_IS_ARRAY,
|
||||||
.default_arr = options_table_status_format_default,
|
.default_arr = options_table_status_format_default,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -503,8 +507,9 @@ const struct options_table_entry options_table[] = {
|
||||||
},
|
},
|
||||||
|
|
||||||
{ .name = "update-environment",
|
{ .name = "update-environment",
|
||||||
.type = OPTIONS_TABLE_ARRAY,
|
.type = OPTIONS_TABLE_STRING,
|
||||||
.scope = OPTIONS_TABLE_SESSION,
|
.scope = OPTIONS_TABLE_SESSION,
|
||||||
|
.flags = OPTIONS_TABLE_IS_ARRAY,
|
||||||
.default_str = "DISPLAY KRB5CCNAME SSH_ASKPASS SSH_AUTH_SOCK "
|
.default_str = "DISPLAY KRB5CCNAME SSH_ASKPASS SSH_AUTH_SOCK "
|
||||||
"SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
|
"SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
|
||||||
},
|
},
|
||||||
|
|
209
options.c
209
options.c
|
@ -32,10 +32,9 @@
|
||||||
|
|
||||||
struct options_array_item {
|
struct options_array_item {
|
||||||
u_int index;
|
u_int index;
|
||||||
char *value;
|
union options_value value;
|
||||||
RB_ENTRY(options_array_item) entry;
|
RB_ENTRY(options_array_item) entry;
|
||||||
};
|
};
|
||||||
RB_HEAD(options_array, options_array_item);
|
|
||||||
static int
|
static int
|
||||||
options_array_cmp(struct options_array_item *a1, struct options_array_item *a2)
|
options_array_cmp(struct options_array_item *a1, struct options_array_item *a2)
|
||||||
{
|
{
|
||||||
|
@ -48,19 +47,13 @@ options_array_cmp(struct options_array_item *a1, struct options_array_item *a2)
|
||||||
RB_GENERATE_STATIC(options_array, options_array_item, entry, options_array_cmp);
|
RB_GENERATE_STATIC(options_array, options_array_item, entry, options_array_cmp);
|
||||||
|
|
||||||
struct options_entry {
|
struct options_entry {
|
||||||
struct options *owner;
|
struct options *owner;
|
||||||
|
|
||||||
const char *name;
|
const char *name;
|
||||||
const struct options_table_entry *tableentry;
|
const struct options_table_entry *tableentry;
|
||||||
|
union options_value value;
|
||||||
|
|
||||||
union {
|
RB_ENTRY(options_entry) entry;
|
||||||
char *string;
|
|
||||||
long long number;
|
|
||||||
struct style style;
|
|
||||||
struct options_array array;
|
|
||||||
};
|
|
||||||
|
|
||||||
RB_ENTRY(options_entry) entry;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct options {
|
struct options {
|
||||||
|
@ -83,9 +76,10 @@ static struct options_entry *options_add(struct options *, const char *);
|
||||||
#define OPTIONS_IS_STYLE(o) \
|
#define OPTIONS_IS_STYLE(o) \
|
||||||
((o)->tableentry != NULL && \
|
((o)->tableentry != NULL && \
|
||||||
(o)->tableentry->type == OPTIONS_TABLE_STYLE)
|
(o)->tableentry->type == OPTIONS_TABLE_STYLE)
|
||||||
#define OPTIONS_IS_ARRAY(o) \
|
|
||||||
|
#define OPTIONS_IS_ARRAY(o) \
|
||||||
((o)->tableentry != NULL && \
|
((o)->tableentry != NULL && \
|
||||||
(o)->tableentry->type == OPTIONS_TABLE_ARRAY)
|
((o)->tableentry->flags & OPTIONS_TABLE_IS_ARRAY))
|
||||||
|
|
||||||
static int options_cmp(struct options_entry *, struct options_entry *);
|
static int options_cmp(struct options_entry *, struct options_entry *);
|
||||||
RB_GENERATE_STATIC(options_tree, options_entry, entry, options_cmp);
|
RB_GENERATE_STATIC(options_tree, options_entry, entry, options_cmp);
|
||||||
|
@ -109,6 +103,56 @@ options_parent_table_entry(struct options *oo, const char *s)
|
||||||
return (o->tableentry);
|
return (o->tableentry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
options_value_free(struct options_entry *o, union options_value *ov)
|
||||||
|
{
|
||||||
|
if (OPTIONS_IS_STRING(o))
|
||||||
|
free(ov->string);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
options_value_tostring(struct options_entry *o, union options_value *ov,
|
||||||
|
int numeric)
|
||||||
|
{
|
||||||
|
static char s[1024];
|
||||||
|
const char *tmp;
|
||||||
|
|
||||||
|
if (OPTIONS_IS_STYLE(o))
|
||||||
|
return (style_tostring(&ov->style));
|
||||||
|
if (OPTIONS_IS_NUMBER(o)) {
|
||||||
|
tmp = NULL;
|
||||||
|
switch (o->tableentry->type) {
|
||||||
|
case OPTIONS_TABLE_NUMBER:
|
||||||
|
xsnprintf(s, sizeof s, "%lld", ov->number);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_KEY:
|
||||||
|
tmp = key_string_lookup_key(ov->number);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_COLOUR:
|
||||||
|
tmp = colour_tostring(ov->number);
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_FLAG:
|
||||||
|
if (numeric)
|
||||||
|
xsnprintf(s, sizeof s, "%lld", ov->number);
|
||||||
|
else
|
||||||
|
tmp = (ov->number ? "on" : "off");
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_CHOICE:
|
||||||
|
tmp = o->tableentry->choices[ov->number];
|
||||||
|
break;
|
||||||
|
case OPTIONS_TABLE_STRING:
|
||||||
|
case OPTIONS_TABLE_STYLE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (tmp != NULL)
|
||||||
|
xsnprintf(s, sizeof s, "%s", tmp);
|
||||||
|
return (s);
|
||||||
|
}
|
||||||
|
if (OPTIONS_IS_STRING(o))
|
||||||
|
return (ov->string);
|
||||||
|
return ("");
|
||||||
|
}
|
||||||
|
|
||||||
struct options *
|
struct options *
|
||||||
options_create(struct options *parent)
|
options_create(struct options *parent)
|
||||||
{
|
{
|
||||||
|
@ -174,8 +218,11 @@ options_empty(struct options *oo, const struct options_table_entry *oe)
|
||||||
o = options_add(oo, oe->name);
|
o = options_add(oo, oe->name);
|
||||||
o->tableentry = oe;
|
o->tableentry = oe;
|
||||||
|
|
||||||
if (oe->type == OPTIONS_TABLE_ARRAY)
|
if (oe->flags & OPTIONS_TABLE_IS_ARRAY) {
|
||||||
RB_INIT(&o->array);
|
if (oe->type != OPTIONS_TABLE_STRING)
|
||||||
|
fatalx("arrays can only be strings");
|
||||||
|
RB_INIT(&o->value.array);
|
||||||
|
}
|
||||||
|
|
||||||
return (o);
|
return (o);
|
||||||
}
|
}
|
||||||
|
@ -183,23 +230,34 @@ options_empty(struct options *oo, const struct options_table_entry *oe)
|
||||||
struct options_entry *
|
struct options_entry *
|
||||||
options_default(struct options *oo, const struct options_table_entry *oe)
|
options_default(struct options *oo, const struct options_table_entry *oe)
|
||||||
{
|
{
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
u_int i;
|
union options_value *ov;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
o = options_empty(oo, oe);
|
o = options_empty(oo, oe);
|
||||||
if (oe->type == OPTIONS_TABLE_ARRAY) {
|
ov = &o->value;
|
||||||
|
|
||||||
|
if (oe->flags & OPTIONS_TABLE_IS_ARRAY) {
|
||||||
if (oe->default_arr != NULL) {
|
if (oe->default_arr != NULL) {
|
||||||
for (i = 0; oe->default_arr[i] != NULL; i++)
|
for (i = 0; oe->default_arr[i] != NULL; i++)
|
||||||
options_array_set(o, i, oe->default_arr[i], 0);
|
options_array_set(o, i, oe->default_arr[i], 0);
|
||||||
} else
|
} else
|
||||||
options_array_assign(o, oe->default_str);
|
options_array_assign(o, oe->default_str);
|
||||||
} else if (oe->type == OPTIONS_TABLE_STRING)
|
return (o);
|
||||||
o->string = xstrdup(oe->default_str);
|
}
|
||||||
else if (oe->type == OPTIONS_TABLE_STYLE) {
|
|
||||||
style_set(&o->style, &grid_default_cell);
|
switch (oe->type) {
|
||||||
style_parse(&o->style, &grid_default_cell, oe->default_str);
|
case OPTIONS_TABLE_STRING:
|
||||||
} else
|
ov->string = xstrdup(oe->default_str);
|
||||||
o->number = oe->default_num;
|
break;
|
||||||
|
case OPTIONS_TABLE_STYLE:
|
||||||
|
style_set(&ov->style, &grid_default_cell);
|
||||||
|
style_parse(&ov->style, &grid_default_cell, oe->default_str);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ov->number = oe->default_num;
|
||||||
|
break;
|
||||||
|
}
|
||||||
return (o);
|
return (o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,11 +283,10 @@ options_remove(struct options_entry *o)
|
||||||
{
|
{
|
||||||
struct options *oo = o->owner;
|
struct options *oo = o->owner;
|
||||||
|
|
||||||
if (OPTIONS_IS_STRING(o))
|
if (OPTIONS_IS_ARRAY(o))
|
||||||
free(o->string);
|
|
||||||
else if (OPTIONS_IS_ARRAY(o))
|
|
||||||
options_array_clear(o);
|
options_array_clear(o);
|
||||||
|
else
|
||||||
|
options_value_free(o, &o->value);
|
||||||
RB_REMOVE(options_tree, &oo->tree, o);
|
RB_REMOVE(options_tree, &oo->tree, o);
|
||||||
free(o);
|
free(o);
|
||||||
}
|
}
|
||||||
|
@ -252,14 +309,14 @@ options_array_item(struct options_entry *o, u_int idx)
|
||||||
struct options_array_item a;
|
struct options_array_item a;
|
||||||
|
|
||||||
a.index = idx;
|
a.index = idx;
|
||||||
return (RB_FIND(options_array, &o->array, &a));
|
return (RB_FIND(options_array, &o->value.array, &a));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
options_array_free(struct options_entry *o, struct options_array_item *a)
|
options_array_free(struct options_entry *o, struct options_array_item *a)
|
||||||
{
|
{
|
||||||
free(a->value);
|
options_value_free(o, &a->value);
|
||||||
RB_REMOVE(options_array, &o->array, a);
|
RB_REMOVE(options_array, &o->value.array, a);
|
||||||
free(a);
|
free(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,11 +328,11 @@ options_array_clear(struct options_entry *o)
|
||||||
if (!OPTIONS_IS_ARRAY(o))
|
if (!OPTIONS_IS_ARRAY(o))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RB_FOREACH_SAFE(a, options_array, &o->array, a1)
|
RB_FOREACH_SAFE(a, options_array, &o->value.array, a1)
|
||||||
options_array_free(o, a);
|
options_array_free(o, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
union options_value *
|
||||||
options_array_get(struct options_entry *o, u_int idx)
|
options_array_get(struct options_entry *o, u_int idx)
|
||||||
{
|
{
|
||||||
struct options_array_item *a;
|
struct options_array_item *a;
|
||||||
|
@ -285,7 +342,7 @@ options_array_get(struct options_entry *o, u_int idx)
|
||||||
a = options_array_item(o, idx);
|
a = options_array_item(o, idx);
|
||||||
if (a == NULL)
|
if (a == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
return (a->value);
|
return (&a->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -308,15 +365,15 @@ options_array_set(struct options_entry *o, u_int idx, const char *value,
|
||||||
if (a == NULL) {
|
if (a == NULL) {
|
||||||
a = xcalloc(1, sizeof *a);
|
a = xcalloc(1, sizeof *a);
|
||||||
a->index = idx;
|
a->index = idx;
|
||||||
a->value = xstrdup(value);
|
a->value.string = xstrdup(value);
|
||||||
RB_INSERT(options_array, &o->array, a);
|
RB_INSERT(options_array, &o->value.array, a);
|
||||||
} else {
|
} else {
|
||||||
free(a->value);
|
options_value_free(o, &a->value);
|
||||||
if (a != NULL && append)
|
if (a != NULL && append)
|
||||||
xasprintf(&new, "%s%s", a->value, value);
|
xasprintf(&new, "%s%s", a->value.string, value);
|
||||||
else
|
else
|
||||||
new = xstrdup(value);
|
new = xstrdup(value);
|
||||||
a->value = new;
|
a->value.string = new;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -353,13 +410,13 @@ options_array_first(struct options_entry *o)
|
||||||
{
|
{
|
||||||
if (!OPTIONS_IS_ARRAY(o))
|
if (!OPTIONS_IS_ARRAY(o))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
return (RB_MIN(options_array, &o->array));
|
return (RB_MIN(options_array, &o->value.array));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct options_array_item *
|
struct options_array_item *
|
||||||
options_array_next(struct options_array_item *a)
|
options_array_next(struct options_array_item *a)
|
||||||
{
|
{
|
||||||
return (RB_NEXT(options_array, &o->array, a));
|
return (RB_NEXT(options_array, &o->value.array, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
u_int
|
u_int
|
||||||
|
@ -368,10 +425,10 @@ options_array_item_index(struct options_array_item *a)
|
||||||
return (a->index);
|
return (a->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
union options_value *
|
||||||
options_array_item_value(struct options_array_item *a)
|
options_array_item_value(struct options_array_item *a)
|
||||||
{
|
{
|
||||||
return (a->value);
|
return (&a->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -383,14 +440,12 @@ options_isarray(struct options_entry *o)
|
||||||
int
|
int
|
||||||
options_isstring(struct options_entry *o)
|
options_isstring(struct options_entry *o)
|
||||||
{
|
{
|
||||||
return (OPTIONS_IS_STRING(o) || OPTIONS_IS_ARRAY(o));
|
return (OPTIONS_IS_STRING(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
options_tostring(struct options_entry *o, int idx, int numeric)
|
options_tostring(struct options_entry *o, int idx, int numeric)
|
||||||
{
|
{
|
||||||
static char s[1024];
|
|
||||||
const char *tmp;
|
|
||||||
struct options_array_item *a;
|
struct options_array_item *a;
|
||||||
|
|
||||||
if (OPTIONS_IS_ARRAY(o)) {
|
if (OPTIONS_IS_ARRAY(o)) {
|
||||||
|
@ -399,43 +454,9 @@ options_tostring(struct options_entry *o, int idx, int numeric)
|
||||||
a = options_array_item(o, idx);
|
a = options_array_item(o, idx);
|
||||||
if (a == NULL)
|
if (a == NULL)
|
||||||
return ("");
|
return ("");
|
||||||
return (a->value);
|
return (options_value_tostring(o, &a->value, numeric));
|
||||||
}
|
}
|
||||||
if (OPTIONS_IS_STYLE(o))
|
return (options_value_tostring(o, &o->value, numeric));
|
||||||
return (style_tostring(&o->style));
|
|
||||||
if (OPTIONS_IS_NUMBER(o)) {
|
|
||||||
tmp = NULL;
|
|
||||||
switch (o->tableentry->type) {
|
|
||||||
case OPTIONS_TABLE_NUMBER:
|
|
||||||
xsnprintf(s, sizeof s, "%lld", o->number);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_KEY:
|
|
||||||
tmp = key_string_lookup_key(o->number);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_COLOUR:
|
|
||||||
tmp = colour_tostring(o->number);
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_FLAG:
|
|
||||||
if (numeric)
|
|
||||||
xsnprintf(s, sizeof s, "%lld", o->number);
|
|
||||||
else
|
|
||||||
tmp = (o->number ? "on" : "off");
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_CHOICE:
|
|
||||||
tmp = o->tableentry->choices[o->number];
|
|
||||||
break;
|
|
||||||
case OPTIONS_TABLE_STRING:
|
|
||||||
case OPTIONS_TABLE_STYLE:
|
|
||||||
case OPTIONS_TABLE_ARRAY:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (tmp != NULL)
|
|
||||||
xsnprintf(s, sizeof s, "%s", tmp);
|
|
||||||
return (s);
|
|
||||||
}
|
|
||||||
if (OPTIONS_IS_STRING(o))
|
|
||||||
return (o->string);
|
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
@ -549,7 +570,7 @@ options_get_string(struct options *oo, const char *name)
|
||||||
fatalx("missing option %s", name);
|
fatalx("missing option %s", name);
|
||||||
if (!OPTIONS_IS_STRING(o))
|
if (!OPTIONS_IS_STRING(o))
|
||||||
fatalx("option %s is not a string", name);
|
fatalx("option %s is not a string", name);
|
||||||
return (o->string);
|
return (o->value.string);
|
||||||
}
|
}
|
||||||
|
|
||||||
long long
|
long long
|
||||||
|
@ -562,7 +583,7 @@ options_get_number(struct options *oo, const char *name)
|
||||||
fatalx("missing option %s", name);
|
fatalx("missing option %s", name);
|
||||||
if (!OPTIONS_IS_NUMBER(o))
|
if (!OPTIONS_IS_NUMBER(o))
|
||||||
fatalx("option %s is not a number", name);
|
fatalx("option %s is not a number", name);
|
||||||
return (o->number);
|
return (o->value.number);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct style *
|
struct style *
|
||||||
|
@ -575,7 +596,7 @@ options_get_style(struct options *oo, const char *name)
|
||||||
fatalx("missing option %s", name);
|
fatalx("missing option %s", name);
|
||||||
if (!OPTIONS_IS_STYLE(o))
|
if (!OPTIONS_IS_STYLE(o))
|
||||||
fatalx("option %s is not a style", name);
|
fatalx("option %s is not a style", name);
|
||||||
return (&o->style);
|
return (&o->value.style);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct options_entry *
|
struct options_entry *
|
||||||
|
@ -592,7 +613,7 @@ options_set_string(struct options *oo, const char *name, int append,
|
||||||
|
|
||||||
o = options_get_only(oo, name);
|
o = options_get_only(oo, name);
|
||||||
if (o != NULL && append && OPTIONS_IS_STRING(o)) {
|
if (o != NULL && append && OPTIONS_IS_STRING(o)) {
|
||||||
xasprintf(&value, "%s%s", o->string, s);
|
xasprintf(&value, "%s%s", o->value.string, s);
|
||||||
free(s);
|
free(s);
|
||||||
} else
|
} else
|
||||||
value = s;
|
value = s;
|
||||||
|
@ -606,8 +627,8 @@ options_set_string(struct options *oo, const char *name, int append,
|
||||||
|
|
||||||
if (!OPTIONS_IS_STRING(o))
|
if (!OPTIONS_IS_STRING(o))
|
||||||
fatalx("option %s is not a string", name);
|
fatalx("option %s is not a string", name);
|
||||||
free(o->string);
|
free(o->value.string);
|
||||||
o->string = value;
|
o->value.string = value;
|
||||||
return (o);
|
return (o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,7 +649,7 @@ options_set_number(struct options *oo, const char *name, long long value)
|
||||||
|
|
||||||
if (!OPTIONS_IS_NUMBER(o))
|
if (!OPTIONS_IS_NUMBER(o))
|
||||||
fatalx("option %s is not a number", name);
|
fatalx("option %s is not a number", name);
|
||||||
o->number = value;
|
o->value.number = value;
|
||||||
return (o);
|
return (o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,7 +665,7 @@ options_set_style(struct options *oo, const char *name, int append,
|
||||||
|
|
||||||
o = options_get_only(oo, name);
|
o = options_get_only(oo, name);
|
||||||
if (o != NULL && append && OPTIONS_IS_STYLE(o))
|
if (o != NULL && append && OPTIONS_IS_STYLE(o))
|
||||||
style_copy(&sy, &o->style);
|
style_copy(&sy, &o->value.style);
|
||||||
else
|
else
|
||||||
style_set(&sy, &grid_default_cell);
|
style_set(&sy, &grid_default_cell);
|
||||||
if (style_parse(&sy, &grid_default_cell, value) == -1)
|
if (style_parse(&sy, &grid_default_cell, value) == -1)
|
||||||
|
@ -657,7 +678,7 @@ options_set_style(struct options *oo, const char *name, int append,
|
||||||
|
|
||||||
if (!OPTIONS_IS_STYLE(o))
|
if (!OPTIONS_IS_STYLE(o))
|
||||||
fatalx("option %s is not a style", name);
|
fatalx("option %s is not a style", name);
|
||||||
style_copy(&o->style, &sy);
|
style_copy(&o->value.style, &sy);
|
||||||
return (o);
|
return (o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
status.c
16
status.c
|
@ -323,8 +323,8 @@ status_redraw(struct client *c)
|
||||||
u_int lines, i, width = c->tty.sx;
|
u_int lines, i, width = c->tty.sx;
|
||||||
int flags, force = 0, changed = 0;
|
int flags, force = 0, changed = 0;
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
|
union options_value *ov;
|
||||||
struct format_tree *ft;
|
struct format_tree *ft;
|
||||||
const char *fmt;
|
|
||||||
char *expanded;
|
char *expanded;
|
||||||
|
|
||||||
log_debug("%s enter", __func__);
|
log_debug("%s enter", __func__);
|
||||||
|
@ -370,14 +370,14 @@ status_redraw(struct client *c)
|
||||||
for (i = 0; i < lines; i++) {
|
for (i = 0; i < lines; i++) {
|
||||||
screen_write_cursormove(&ctx, 0, i, 0);
|
screen_write_cursormove(&ctx, 0, i, 0);
|
||||||
|
|
||||||
fmt = options_array_get(o, i);
|
ov = options_array_get(o, i);
|
||||||
if (fmt == NULL) {
|
if (ov == NULL) {
|
||||||
screen_write_clearline(&ctx, gc.bg);
|
screen_write_clearline(&ctx, gc.bg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sle = &sl->entries[i];
|
sle = &sl->entries[i];
|
||||||
|
|
||||||
expanded = format_expand_time(ft, fmt);
|
expanded = format_expand_time(ft, ov->string);
|
||||||
if (!force &&
|
if (!force &&
|
||||||
sle->expanded != NULL &&
|
sle->expanded != NULL &&
|
||||||
strcmp(expanded, sle->expanded) == 0) {
|
strcmp(expanded, sle->expanded) == 0) {
|
||||||
|
@ -1293,6 +1293,7 @@ status_prompt_complete_list(u_int *size, const char *s)
|
||||||
size_t slen = strlen(s), valuelen;
|
size_t slen = strlen(s), valuelen;
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
struct options_array_item *a;
|
struct options_array_item *a;
|
||||||
|
union options_value *ov;
|
||||||
const char *layouts[] = {
|
const char *layouts[] = {
|
||||||
"even-horizontal", "even-vertical", "main-horizontal",
|
"even-horizontal", "even-vertical", "main-horizontal",
|
||||||
"main-vertical", "tiled", NULL
|
"main-vertical", "tiled", NULL
|
||||||
|
@ -1321,10 +1322,13 @@ status_prompt_complete_list(u_int *size, const char *s)
|
||||||
if (o != NULL) {
|
if (o != NULL) {
|
||||||
a = options_array_first(o);
|
a = options_array_first(o);
|
||||||
while (a != NULL) {
|
while (a != NULL) {
|
||||||
value = options_array_item_value(a);;
|
ov = options_array_item_value(a);
|
||||||
if (value == NULL || (cp = strchr(value, '=')) == NULL)
|
if (ov == NULL)
|
||||||
goto next;
|
goto next;
|
||||||
|
|
||||||
|
value = ov->string;
|
||||||
|
if ((cp = strchr(value, '=')) == NULL)
|
||||||
|
goto next;
|
||||||
valuelen = cp - value;
|
valuelen = cp - value;
|
||||||
if (slen > valuelen || strncmp(value, s, slen) != 0)
|
if (slen > valuelen || strncmp(value, s, slen) != 0)
|
||||||
goto next;
|
goto next;
|
||||||
|
|
19
tmux.h
19
tmux.h
|
@ -1516,6 +1516,15 @@ struct key_table {
|
||||||
};
|
};
|
||||||
RB_HEAD(key_tables, key_table);
|
RB_HEAD(key_tables, key_table);
|
||||||
|
|
||||||
|
/* Option data. */
|
||||||
|
RB_HEAD(options_array, options_array_item);
|
||||||
|
union options_value {
|
||||||
|
char *string;
|
||||||
|
long long number;
|
||||||
|
struct style style;
|
||||||
|
struct options_array array;
|
||||||
|
};
|
||||||
|
|
||||||
/* Option table entries. */
|
/* Option table entries. */
|
||||||
enum options_table_type {
|
enum options_table_type {
|
||||||
OPTIONS_TABLE_STRING,
|
OPTIONS_TABLE_STRING,
|
||||||
|
@ -1524,8 +1533,7 @@ enum options_table_type {
|
||||||
OPTIONS_TABLE_COLOUR,
|
OPTIONS_TABLE_COLOUR,
|
||||||
OPTIONS_TABLE_FLAG,
|
OPTIONS_TABLE_FLAG,
|
||||||
OPTIONS_TABLE_CHOICE,
|
OPTIONS_TABLE_CHOICE,
|
||||||
OPTIONS_TABLE_STYLE,
|
OPTIONS_TABLE_STYLE
|
||||||
OPTIONS_TABLE_ARRAY,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum options_table_scope {
|
enum options_table_scope {
|
||||||
|
@ -1535,10 +1543,13 @@ enum options_table_scope {
|
||||||
OPTIONS_TABLE_WINDOW,
|
OPTIONS_TABLE_WINDOW,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define OPTIONS_TABLE_IS_ARRAY 0x1
|
||||||
|
|
||||||
struct options_table_entry {
|
struct options_table_entry {
|
||||||
const char *name;
|
const char *name;
|
||||||
enum options_table_type type;
|
enum options_table_type type;
|
||||||
enum options_table_scope scope;
|
enum options_table_scope scope;
|
||||||
|
int flags;
|
||||||
|
|
||||||
u_int minimum;
|
u_int minimum;
|
||||||
u_int maximum;
|
u_int maximum;
|
||||||
|
@ -1723,14 +1734,14 @@ struct options_entry *options_get_only(struct options *, const char *);
|
||||||
struct options_entry *options_get(struct options *, const char *);
|
struct options_entry *options_get(struct options *, const char *);
|
||||||
void options_remove(struct options_entry *);
|
void options_remove(struct options_entry *);
|
||||||
void options_array_clear(struct options_entry *);
|
void options_array_clear(struct options_entry *);
|
||||||
const char *options_array_get(struct options_entry *, u_int);
|
union options_value *options_array_get(struct options_entry *, u_int);
|
||||||
int options_array_set(struct options_entry *, u_int, const char *,
|
int options_array_set(struct options_entry *, u_int, const char *,
|
||||||
int);
|
int);
|
||||||
void options_array_assign(struct options_entry *, const char *);
|
void options_array_assign(struct options_entry *, const char *);
|
||||||
struct options_array_item *options_array_first(struct options_entry *);
|
struct options_array_item *options_array_first(struct options_entry *);
|
||||||
struct options_array_item *options_array_next(struct options_array_item *);
|
struct options_array_item *options_array_next(struct options_array_item *);
|
||||||
u_int options_array_item_index(struct options_array_item *);
|
u_int options_array_item_index(struct options_array_item *);
|
||||||
const char *options_array_item_value(struct options_array_item *);
|
union options_value *options_array_item_value(struct options_array_item *);
|
||||||
int options_isarray(struct options_entry *);
|
int options_isarray(struct options_entry *);
|
||||||
int options_isstring(struct options_entry *);
|
int options_isstring(struct options_entry *);
|
||||||
const char *options_tostring(struct options_entry *, int, int);
|
const char *options_tostring(struct options_entry *, int, int);
|
||||||
|
|
|
@ -399,9 +399,10 @@ tty_keys_build(struct tty *tty)
|
||||||
const struct tty_default_key_raw *tdkr;
|
const struct tty_default_key_raw *tdkr;
|
||||||
const struct tty_default_key_code *tdkc;
|
const struct tty_default_key_code *tdkc;
|
||||||
u_int i;
|
u_int i;
|
||||||
const char *s, *value;
|
const char *s;
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
struct options_array_item *a;
|
struct options_array_item *a;
|
||||||
|
union options_value *ov;
|
||||||
|
|
||||||
if (tty->key_tree != NULL)
|
if (tty->key_tree != NULL)
|
||||||
tty_keys_free(tty);
|
tty_keys_free(tty);
|
||||||
|
@ -427,9 +428,9 @@ tty_keys_build(struct tty *tty)
|
||||||
if (o != NULL) {
|
if (o != NULL) {
|
||||||
a = options_array_first(o);
|
a = options_array_first(o);
|
||||||
while (a != NULL) {
|
while (a != NULL) {
|
||||||
value = options_array_item_value(a);
|
ov = options_array_item_value(a);
|
||||||
if (value != NULL)
|
if (ov != NULL)
|
||||||
tty_keys_add(tty, value, KEYC_USER + i);
|
tty_keys_add(tty, ov->string, KEYC_USER + i);
|
||||||
a = options_array_next(a);
|
a = options_array_next(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -420,6 +420,7 @@ tty_term_find(char *name, int fd, char **cause)
|
||||||
struct tty_code *code;
|
struct tty_code *code;
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
struct options_array_item *a;
|
struct options_array_item *a;
|
||||||
|
union options_value *ov;
|
||||||
u_int i;
|
u_int i;
|
||||||
int n, error;
|
int n, error;
|
||||||
const char *s, *acs;
|
const char *s, *acs;
|
||||||
|
@ -497,9 +498,9 @@ tty_term_find(char *name, int fd, char **cause)
|
||||||
o = options_get_only(global_options, "terminal-overrides");
|
o = options_get_only(global_options, "terminal-overrides");
|
||||||
a = options_array_first(o);
|
a = options_array_first(o);
|
||||||
while (a != NULL) {
|
while (a != NULL) {
|
||||||
s = options_array_item_value(a);
|
ov = options_array_item_value(a);
|
||||||
if (s != NULL)
|
if (ov != NULL)
|
||||||
tty_term_override(term, s);
|
tty_term_override(term, ov->string);
|
||||||
a = options_array_next(a);
|
a = options_array_next(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue