aboutsummaryrefslogtreecommitdiff
path: root/cmd-set-option.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmd-set-option.c')
-rw-r--r--cmd-set-option.c52
1 files changed, 30 insertions, 22 deletions
diff --git a/cmd-set-option.c b/cmd-set-option.c
index 01d691d5..83d31b93 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -91,7 +91,6 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
struct options *oo;
struct window *w;
const char *optstr, *valstr;
- u_int i;
/* Get the option name and value. */
optstr = args->argv[0];
@@ -176,9 +175,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
/* Start or stop timers when automatic-rename changed. */
if (strcmp(oe->name, "automatic-rename") == 0) {
- for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
- if ((w = ARRAY_ITEM(&windows, i)) == NULL)
- continue;
+ RB_FOREACH(w, windows, &windows) {
if (options_get_number(&w->options, "automatic-rename"))
queue_window_name(w);
else if (event_initialized(&w->name_timer))
@@ -188,9 +185,8 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
/* Update sizes and redraw. May not need it but meh. */
recalculate_sizes();
- for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
- c = ARRAY_ITEM(&clients, i);
- if (c != NULL && c->session != NULL)
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session != NULL)
server_redraw_client(c);
}
@@ -291,9 +287,15 @@ cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq,
{
struct options_entry *o;
- if (oe->type != OPTIONS_TABLE_FLAG && value == NULL) {
- cmdq_error(cmdq, "empty value");
- return (-1);
+ switch (oe->type) {
+ case OPTIONS_TABLE_FLAG:
+ case OPTIONS_TABLE_CHOICE:
+ break;
+ default:
+ if (value == NULL) {
+ cmdq_error(cmdq, "empty value");
+ return (-1);
+ }
}
o = NULL;
@@ -457,21 +459,27 @@ cmd_set_option_choice(unused struct cmd *self, struct cmd_q *cmdq,
const char **choicep;
int n, choice = -1;
- n = 0;
- for (choicep = oe->choices; *choicep != NULL; choicep++) {
- n++;
- if (strncmp(*choicep, value, strlen(value)) != 0)
- continue;
+ if (value == NULL) {
+ choice = options_get_number(oo, oe->name);
+ if (choice < 2)
+ choice = !choice;
+ } else {
+ n = 0;
+ for (choicep = oe->choices; *choicep != NULL; choicep++) {
+ n++;
+ if (strncmp(*choicep, value, strlen(value)) != 0)
+ continue;
- if (choice != -1) {
- cmdq_error(cmdq, "ambiguous value: %s", value);
+ if (choice != -1) {
+ cmdq_error(cmdq, "ambiguous value: %s", value);
+ return (NULL);
+ }
+ choice = n - 1;
+ }
+ if (choice == -1) {
+ cmdq_error(cmdq, "unknown value: %s", value);
return (NULL);
}
- choice = n - 1;
- }
- if (choice == -1) {
- cmdq_error(cmdq, "unknown value: %s", value);
- return (NULL);
}
return (options_set_number(oo, oe->name, choice));