From ff90170738dad3ab6d302790672c57a3e10e9075 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Wed, 15 Jul 2009 17:44:47 +0000 Subject: [PATCH] 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. --- cmd-set-option.c | 14 +++++++------- cmd-set-window-option.c | 14 +++++++------- cmd-show-options.c | 7 ++----- cmd-show-window-options.c | 7 ++----- status.c | 10 ++++------ tmux.h | 4 +--- 6 files changed, 23 insertions(+), 33 deletions(-) diff --git a/cmd-set-option.c b/cmd-set-option.c index 094bf525..0457a2cc 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.66 2009-07-14 06:43:32 nicm Exp $ */ +/* $Id: cmd-set-option.c,v 1.67 2009-07-15 17:44:47 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -48,7 +48,7 @@ const char *set_option_status_keys_list[] = { const char *set_option_bell_action_list[] = { "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 }, { "buffer-limit", SET_OPTION_NUMBER, 1, INT_MAX, 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-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL }, { "status-utf8", SET_OPTION_FLAG, 0, 0, NULL }, + { NULL, 0, 0, 0, NULL } }; int @@ -84,7 +85,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) struct session *s; struct client *c; struct options *oo; - const struct set_option_entry *entry; + const struct set_option_entry *entry, *opt; u_int i; if (data->chflags & CMD_CHFLAG('g')) @@ -101,15 +102,14 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) } entry = NULL; - for (i = 0; i < NSETOPTION; i++) { - if (strncmp(set_option_table[i].name, - data->option, strlen(data->option)) != 0) + for (opt = set_option_table; opt->name != NULL; opt++) { + if (strncmp(opt->name, data->option, strlen(data->option)) != 0) continue; if (entry != NULL) { ctx->error(ctx, "ambiguous option: %s", data->option); return (-1); } - entry = &set_option_table[i]; + entry = opt; /* Bail now if an exact match. */ if (strcmp(entry->name, data->option) == 0) diff --git a/cmd-set-window-option.c b/cmd-set-window-option.c index 75c4d27f..1ea8f971 100644 --- a/cmd-set-window-option.c +++ b/cmd-set-window-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-window-option.c,v 1.32 2009-07-15 17:44:25 nicm Exp $ */ +/* $Id: cmd-set-window-option.c,v 1.33 2009-07-15 17:44:47 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -48,7 +48,7 @@ const char *set_option_mode_keys_list[] = { const char *set_option_clock_mode_style_list[] = { "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 }, { "automatic-rename", SET_OPTION_FLAG, 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-fg", SET_OPTION_COLOUR, 0, 0, NULL }, { "xterm-keys", SET_OPTION_FLAG, 0, 0, NULL }, + { NULL, 0, 0, 0, NULL } }; int @@ -79,7 +80,7 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx) struct winlink *wl; struct client *c; struct options *oo; - const struct set_option_entry *entry; + const struct set_option_entry *entry, *opt; u_int i; if (data->chflags & CMD_CHFLAG('g')) @@ -96,15 +97,14 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx) } entry = NULL; - for (i = 0; i < NSETWINDOWOPTION; i++) { - if (strncmp(set_window_option_table[i].name, - data->option, strlen(data->option)) != 0) + for (opt = set_window_option_table; opt->name != NULL; opt++) { + if (strncmp(opt->name, data->option, strlen(data->option)) != 0) continue; if (entry != NULL) { ctx->error(ctx, "ambiguous option: %s", data->option); return (-1); } - entry = &set_window_option_table[i]; + entry = opt; /* Bail now if an exact match. */ if (strcmp(entry->name, data->option) == 0) diff --git a/cmd-show-options.c b/cmd-show-options.c index 8406cc16..4b4a809e 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -1,4 +1,4 @@ -/* $Id: cmd-show-options.c,v 1.14 2009-07-14 06:43:33 nicm Exp $ */ +/* $Id: cmd-show-options.c,v 1.15 2009-07-15 17:44:47 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -49,7 +49,6 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) struct session *s; struct options *oo; const struct set_option_entry *entry; - u_int i; char *vs; long long vn; @@ -61,9 +60,7 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) oo = &s->options; } - for (i = 0; i < NSETOPTION; i++) { - entry = &set_option_table[i]; - + for (entry = set_option_table; entry->name != NULL; entry++) { if (options_find1(oo, entry->name) == NULL) continue; diff --git a/cmd-show-window-options.c b/cmd-show-window-options.c index 5acec208..181f482e 100644 --- a/cmd-show-window-options.c +++ b/cmd-show-window-options.c @@ -1,4 +1,4 @@ -/* $Id: cmd-show-window-options.c,v 1.10 2009-07-14 06:43:33 nicm Exp $ */ +/* $Id: cmd-show-window-options.c,v 1.11 2009-07-15 17:44:47 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -49,7 +49,6 @@ cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx) struct winlink *wl; struct options *oo; const struct set_option_entry *entry; - u_int i; char *vs; long long vn; @@ -61,9 +60,7 @@ cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx) oo = &wl->window->options; } - for (i = 0; i < NSETWINDOWOPTION; i++) { - entry = &set_window_option_table[i]; - + for (entry = set_window_option_table; entry->name != NULL; entry++) { if (options_find1(oo, entry->name) == NULL) continue; diff --git a/status.c b/status.c index 4e3eaf0a..7442f162 100644 --- a/status.c +++ b/status.c @@ -1,4 +1,4 @@ -/* $Id: status.c,v 1.93 2009-07-15 17:44:06 nicm Exp $ */ +/* $Id: status.c,v 1.94 2009-07-15 17:44:47 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -898,7 +898,7 @@ status_prompt_complete(const char *s) const struct set_option_entry *optent; ARRAY_DECL(, const char *) list; char *prefix, *s2; - u_int i; + u_int i; size_t j; if (*s == '\0') @@ -910,13 +910,11 @@ status_prompt_complete(const char *s) if (strncmp((*cmdent)->name, s, strlen(s)) == 0) ARRAY_ADD(&list, (*cmdent)->name); } - for (i = 0; i < NSETOPTION; i++) { - optent = &set_option_table[i]; + for (optent = set_option_table; optent->name != NULL; optent++) { if (strncmp(optent->name, s, strlen(s)) == 0) ARRAY_ADD(&list, optent->name); } - for (i = 0; i < NSETWINDOWOPTION; i++) { - optent = &set_window_option_table[i]; + for (optent = set_window_option_table; optent->name != NULL; optent++) { if (strncmp(optent->name, s, strlen(s)) == 0) ARRAY_ADD(&list, optent->name); } diff --git a/tmux.h b/tmux.h index eeb47fbb..d2fa3e16 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.364 2009-07-15 17:44:25 nicm Exp $ */ +/* $Id: tmux.h,v 1.365 2009-07-15 17:44:47 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -940,8 +940,6 @@ struct set_option_entry { }; extern const struct set_option_entry set_option_table[]; extern const struct set_option_entry set_window_option_table[]; -#define NSETOPTION 26 -#define NSETWINDOWOPTION 20 /* tmux.c */ extern volatile sig_atomic_t sigwinch;