mirror of
https://github.com/tmux/tmux.git
synced 2024-12-13 01:48:47 +00:00
Having to update NSETOPTION/NSETWINDOWOPTION when adding new options is a bit
annoying and it is only use for iterating, so use a sentinel to mark the end of each array instead. Different fix for a problem pointed out by Kalle Olavi Niemitalo.
This commit is contained in:
parent
615d85fb23
commit
ca617d679f
@ -48,7 +48,7 @@ const char *set_option_status_keys_list[] = {
|
|||||||
const char *set_option_bell_action_list[] = {
|
const char *set_option_bell_action_list[] = {
|
||||||
"none", "any", "current", NULL
|
"none", "any", "current", NULL
|
||||||
};
|
};
|
||||||
const struct set_option_entry set_option_table[NSETOPTION] = {
|
const struct set_option_entry set_option_table[] = {
|
||||||
{ "bell-action", SET_OPTION_CHOICE, 0, 0, set_option_bell_action_list },
|
{ "bell-action", SET_OPTION_CHOICE, 0, 0, set_option_bell_action_list },
|
||||||
{ "buffer-limit", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
{ "buffer-limit", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
|
||||||
{ "default-command", SET_OPTION_STRING, 0, 0, NULL },
|
{ "default-command", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
@ -75,6 +75,7 @@ const struct set_option_entry set_option_table[NSETOPTION] = {
|
|||||||
{ "status-right", SET_OPTION_STRING, 0, 0, NULL },
|
{ "status-right", SET_OPTION_STRING, 0, 0, NULL },
|
||||||
{ "status-right-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
|
{ "status-right-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
|
||||||
{ "status-utf8", SET_OPTION_FLAG, 0, 0, NULL },
|
{ "status-utf8", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ NULL, 0, 0, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -84,7 +85,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct session *s;
|
struct session *s;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
const struct set_option_entry *entry;
|
const struct set_option_entry *entry, *opt;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
if (data->chflags & CMD_CHFLAG('g'))
|
if (data->chflags & CMD_CHFLAG('g'))
|
||||||
@ -101,15 +102,14 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
entry = NULL;
|
entry = NULL;
|
||||||
for (i = 0; i < NSETOPTION; i++) {
|
for (opt = set_option_table; opt->name != NULL; opt++) {
|
||||||
if (strncmp(set_option_table[i].name,
|
if (strncmp(opt->name, data->option, strlen(data->option)) != 0)
|
||||||
data->option, strlen(data->option)) != 0)
|
|
||||||
continue;
|
continue;
|
||||||
if (entry != NULL) {
|
if (entry != NULL) {
|
||||||
ctx->error(ctx, "ambiguous option: %s", data->option);
|
ctx->error(ctx, "ambiguous option: %s", data->option);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
entry = &set_option_table[i];
|
entry = opt;
|
||||||
|
|
||||||
/* Bail now if an exact match. */
|
/* Bail now if an exact match. */
|
||||||
if (strcmp(entry->name, data->option) == 0)
|
if (strcmp(entry->name, data->option) == 0)
|
||||||
|
@ -48,7 +48,7 @@ const char *set_option_mode_keys_list[] = {
|
|||||||
const char *set_option_clock_mode_style_list[] = {
|
const char *set_option_clock_mode_style_list[] = {
|
||||||
"12", "24", NULL
|
"12", "24", NULL
|
||||||
};
|
};
|
||||||
const struct set_option_entry set_window_option_table[NSETWINDOWOPTION] = {
|
const struct set_option_entry set_window_option_table[] = {
|
||||||
{ "aggressive-resize", SET_OPTION_FLAG, 0, 0, NULL },
|
{ "aggressive-resize", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
{ "automatic-rename", SET_OPTION_FLAG, 0, 0, NULL },
|
{ "automatic-rename", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
{ "clock-mode-colour", SET_OPTION_COLOUR, 0, 0, NULL },
|
{ "clock-mode-colour", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
@ -70,6 +70,7 @@ const struct set_option_entry set_window_option_table[NSETWINDOWOPTION] = {
|
|||||||
{ "window-status-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
{ "window-status-bg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
{ "window-status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
{ "window-status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
|
||||||
{ "xterm-keys", SET_OPTION_FLAG, 0, 0, NULL },
|
{ "xterm-keys", SET_OPTION_FLAG, 0, 0, NULL },
|
||||||
|
{ NULL, 0, 0, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -79,7 +80,7 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
const struct set_option_entry *entry;
|
const struct set_option_entry *entry, *opt;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
if (data->chflags & CMD_CHFLAG('g'))
|
if (data->chflags & CMD_CHFLAG('g'))
|
||||||
@ -96,15 +97,14 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
entry = NULL;
|
entry = NULL;
|
||||||
for (i = 0; i < NSETWINDOWOPTION; i++) {
|
for (opt = set_window_option_table; opt->name != NULL; opt++) {
|
||||||
if (strncmp(set_window_option_table[i].name,
|
if (strncmp(opt->name, data->option, strlen(data->option)) != 0)
|
||||||
data->option, strlen(data->option)) != 0)
|
|
||||||
continue;
|
continue;
|
||||||
if (entry != NULL) {
|
if (entry != NULL) {
|
||||||
ctx->error(ctx, "ambiguous option: %s", data->option);
|
ctx->error(ctx, "ambiguous option: %s", data->option);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
entry = &set_window_option_table[i];
|
entry = opt;
|
||||||
|
|
||||||
/* Bail now if an exact match. */
|
/* Bail now if an exact match. */
|
||||||
if (strcmp(entry->name, data->option) == 0)
|
if (strcmp(entry->name, data->option) == 0)
|
||||||
|
@ -49,7 +49,6 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct session *s;
|
struct session *s;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
const struct set_option_entry *entry;
|
const struct set_option_entry *entry;
|
||||||
u_int i;
|
|
||||||
char *vs;
|
char *vs;
|
||||||
long long vn;
|
long long vn;
|
||||||
|
|
||||||
@ -61,9 +60,7 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
oo = &s->options;
|
oo = &s->options;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < NSETOPTION; i++) {
|
for (entry = set_option_table; entry->name != NULL; entry++) {
|
||||||
entry = &set_option_table[i];
|
|
||||||
|
|
||||||
if (options_find1(oo, entry->name) == NULL)
|
if (options_find1(oo, entry->name) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -49,7 +49,6 @@ cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
const struct set_option_entry *entry;
|
const struct set_option_entry *entry;
|
||||||
u_int i;
|
|
||||||
char *vs;
|
char *vs;
|
||||||
long long vn;
|
long long vn;
|
||||||
|
|
||||||
@ -61,9 +60,7 @@ cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
oo = &wl->window->options;
|
oo = &wl->window->options;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < NSETWINDOWOPTION; i++) {
|
for (entry = set_window_option_table; entry->name != NULL; entry++) {
|
||||||
entry = &set_window_option_table[i];
|
|
||||||
|
|
||||||
if (options_find1(oo, entry->name) == NULL)
|
if (options_find1(oo, entry->name) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
8
status.c
8
status.c
@ -898,7 +898,7 @@ status_prompt_complete(const char *s)
|
|||||||
const struct set_option_entry *optent;
|
const struct set_option_entry *optent;
|
||||||
ARRAY_DECL(, const char *) list;
|
ARRAY_DECL(, const char *) list;
|
||||||
char *prefix, *s2;
|
char *prefix, *s2;
|
||||||
u_int i;
|
u_int i;
|
||||||
size_t j;
|
size_t j;
|
||||||
|
|
||||||
if (*s == '\0')
|
if (*s == '\0')
|
||||||
@ -910,13 +910,11 @@ status_prompt_complete(const char *s)
|
|||||||
if (strncmp((*cmdent)->name, s, strlen(s)) == 0)
|
if (strncmp((*cmdent)->name, s, strlen(s)) == 0)
|
||||||
ARRAY_ADD(&list, (*cmdent)->name);
|
ARRAY_ADD(&list, (*cmdent)->name);
|
||||||
}
|
}
|
||||||
for (i = 0; i < NSETOPTION; i++) {
|
for (optent = set_option_table; optent->name != NULL; optent++) {
|
||||||
optent = &set_option_table[i];
|
|
||||||
if (strncmp(optent->name, s, strlen(s)) == 0)
|
if (strncmp(optent->name, s, strlen(s)) == 0)
|
||||||
ARRAY_ADD(&list, optent->name);
|
ARRAY_ADD(&list, optent->name);
|
||||||
}
|
}
|
||||||
for (i = 0; i < NSETWINDOWOPTION; i++) {
|
for (optent = set_window_option_table; optent->name != NULL; optent++) {
|
||||||
optent = &set_window_option_table[i];
|
|
||||||
if (strncmp(optent->name, s, strlen(s)) == 0)
|
if (strncmp(optent->name, s, strlen(s)) == 0)
|
||||||
ARRAY_ADD(&list, optent->name);
|
ARRAY_ADD(&list, optent->name);
|
||||||
}
|
}
|
||||||
|
2
tmux.h
2
tmux.h
@ -941,8 +941,6 @@ struct set_option_entry {
|
|||||||
};
|
};
|
||||||
extern const struct set_option_entry set_option_table[];
|
extern const struct set_option_entry set_option_table[];
|
||||||
extern const struct set_option_entry set_window_option_table[];
|
extern const struct set_option_entry set_window_option_table[];
|
||||||
#define NSETOPTION 26
|
|
||||||
#define NSETWINDOWOPTION 20
|
|
||||||
|
|
||||||
/* tmux.c */
|
/* tmux.c */
|
||||||
extern volatile sig_atomic_t sigwinch;
|
extern volatile sig_atomic_t sigwinch;
|
||||||
|
Loading…
Reference in New Issue
Block a user