summaryrefslogtreecommitdiffstats
path: root/cmd-set-option.c
diff options
context:
space:
mode:
authornicm <nicm>2017-05-10 13:05:41 +0000
committernicm <nicm>2017-05-10 13:05:41 +0000
commitb519551153f5451615a9d64966350400e141e540 (patch)
tree1f9c618e1107bed04b6f87f2825bc39995bd1bc4 /cmd-set-option.c
parent0e3c5ebe1a229fbb8d829c9413ae013fb2eeb1ed (diff)
Expand formats in option names and add -F flag to do so in option values as well.
Diffstat (limited to 'cmd-set-option.c')
-rw-r--r--cmd-set-option.c60
1 files changed, 35 insertions, 25 deletions
diff --git a/cmd-set-option.c b/cmd-set-option.c
index b35d60d8..ad058b8e 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -42,8 +42,8 @@ const struct cmd_entry cmd_set_option_entry = {
.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 @@ const struct cmd_entry cmd_set_window_option_entry = {
.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 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
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 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
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 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
/* 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 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
}
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 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
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 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
}
}
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 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
* 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);
}