=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-set-option.c,v retrieving revision 1.114 retrieving revision 1.115 diff -u -r1.114 -r1.115 --- src/usr.bin/tmux/cmd-set-option.c 2017/04/22 10:22:39 1.114 +++ src/usr.bin/tmux/cmd-set-option.c 2017/05/10 13:05:41 1.115 @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-option.c,v 1.114 2017/04/22 10:22:39 nicm Exp $ */ +/* $OpenBSD: cmd-set-option.c,v 1.115 2017/05/10 13:05:41 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -42,8 +42,8 @@ .name = "set-option", .alias = "set", - .args = { "agoqst:uw", 1, 2 }, - .usage = "[-agosquw] [-t target-window] option [value]", + .args = { "aFgoqst:uw", 1, 2 }, + .usage = "[-aFgosquw] [-t target-window] option [value]", .target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL }, @@ -55,8 +55,8 @@ .name = "set-window-option", .alias = "setw", - .args = { "agoqt:u", 1, 2 }, - .usage = "[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]", + .args = { "aFgoqt:u", 1, 2 }, + .usage = "[-aFgoqu] " CMD_TARGET_WINDOW_USAGE " option [value]", .target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL }, @@ -70,33 +70,38 @@ struct args *args = self->args; int append = args_has(args, 'a'); struct cmd_find_state *fs = &item->target; + struct client *c, *loop; struct session *s = fs->s; struct winlink *wl = fs->wl; struct window *w; - struct client *c; enum options_table_scope scope; struct options *oo; struct options_entry *parent, *o; - char *name; - const char *value, *target; + char *name, *argument, *value = NULL, *cause; + const char *target; int window, idx, already, error, ambiguous; - char *cause; + /* Expand argument. */ + c = cmd_find_client(item, NULL, 1); + argument = format_single(item, args->argv[0], c, s, wl, NULL); + /* Parse option name and index. */ - name = options_match(args->argv[0], &idx, &ambiguous); + name = options_match(argument, &idx, &ambiguous); if (name == NULL) { if (args_has(args, 'q')) - return (CMD_RETURN_NORMAL); + goto out; if (ambiguous) - cmdq_error(item, "ambiguous option: %s", args->argv[0]); + cmdq_error(item, "ambiguous option: %s", argument); else - cmdq_error(item, "invalid option: %s", args->argv[0]); - return (CMD_RETURN_ERROR); + cmdq_error(item, "invalid option: %s", argument); + goto fail; } if (args->argc < 2) value = NULL; + else if (args_has(args, 'F')) + value = format_single(item, args->argv[1], c, s, wl, NULL); else - value = args->argv[1]; + value = xstrdup(args->argv[1]); /* * Figure out the scope: for user options it comes from the arguments, @@ -114,12 +119,12 @@ scope = OPTIONS_TABLE_WINDOW; else { scope = OPTIONS_TABLE_NONE; - xasprintf(&cause, "unknown option: %s", args->argv[0]); + xasprintf(&cause, "unknown option: %s", argument); } } if (scope == OPTIONS_TABLE_NONE) { if (args_has(args, 'q')) - return (CMD_RETURN_NORMAL); + goto out; cmdq_error(item, "%s", cause); free(cause); goto fail; @@ -159,7 +164,7 @@ /* Check that array options and indexes match up. */ if (idx != -1) { if (*name == '@' || options_array_size(parent, NULL) == -1) { - cmdq_error(item, "not an array: %s", args->argv[0]); + cmdq_error(item, "not an array: %s", argument); goto fail; } } @@ -176,8 +181,8 @@ } if (already) { if (args_has(args, 'q')) - return (CMD_RETURN_NORMAL); - cmdq_error(item, "already set: %s", args->argv[0]); + goto out; + cmdq_error(item, "already set: %s", argument); goto fail; } } @@ -217,7 +222,7 @@ options_array_clear(o); options_array_assign(o, value); } else if (options_array_set(o, idx, value, append) != 0) { - cmdq_error(item, "invalid index: %s", args->argv[0]); + cmdq_error(item, "invalid index: %s", argument); goto fail; } } @@ -232,8 +237,8 @@ } } if (strcmp(name, "key-table") == 0) { - TAILQ_FOREACH(c, &clients, entry) - server_client_set_key_table(c, NULL); + TAILQ_FOREACH(loop, &clients, entry) + server_client_set_key_table(loop, NULL); } if (strcmp(name, "status") == 0 || strcmp(name, "status-interval") == 0) @@ -257,15 +262,20 @@ * anyway. */ recalculate_sizes(); - TAILQ_FOREACH(c, &clients, entry) { - if (c->session != NULL) - server_redraw_client(c); + TAILQ_FOREACH(loop, &clients, entry) { + if (loop->session != NULL) + server_redraw_client(loop); } +out: + free(argument); + free(value); free(name); return (CMD_RETURN_NORMAL); fail: + free(argument); + free(value); free(name); return (CMD_RETURN_ERROR); }