summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2016-03-03 14:15:23 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2016-03-03 14:15:23 +0000
commit1e24b1a85d274af46535cec96788be2e00cb8649 (patch)
treee9c6db7e2a9f22736158445397761adc8f837349
parent818d7160c4141e9369173352b52d8babfd7d95a1 (diff)
show-* and set-* need to handle a missing target.
-rw-r--r--usr.bin/tmux/cmd-set-environment.c17
-rw-r--r--usr.bin/tmux/cmd-set-option.c40
-rw-r--r--usr.bin/tmux/cmd-show-environment.c23
-rw-r--r--usr.bin/tmux/cmd-show-options.c33
4 files changed, 77 insertions, 36 deletions
diff --git a/usr.bin/tmux/cmd-set-environment.c b/usr.bin/tmux/cmd-set-environment.c
index a9f14b21cae..f8591b5246f 100644
--- a/usr.bin/tmux/cmd-set-environment.c
+++ b/usr.bin/tmux/cmd-set-environment.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-environment.c,v 1.17 2016/01/19 15:59:12 nicm Exp $ */
+/* $OpenBSD: cmd-set-environment.c,v 1.18 2016/03/03 14:15:22 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -47,7 +47,7 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct environ *env;
- const char *name, *value;
+ const char *name, *value, *target;
name = args->argv[0];
if (*name == '\0') {
@@ -64,10 +64,19 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq)
else
value = args->argv[1];
- if (args_has(self->args, 'g') || cmdq->state.tflag.s == NULL)
+ if (args_has(self->args, 'g'))
env = global_environ;
- else
+ else {
+ if (cmdq->state.tflag.s == NULL) {
+ target = args_get(args, 't');
+ if (target != NULL)
+ cmdq_error(cmdq, "no such session: %s", target);
+ else
+ cmdq_error(cmdq, "no current session");
+ return (CMD_RETURN_ERROR);
+ }
env = cmdq->state.tflag.s->environ;
+ }
if (args_has(self->args, 'u')) {
if (value != NULL) {
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c
index 67f1187a173..e855f44cb9b 100644
--- a/usr.bin/tmux/cmd-set-option.c
+++ b/usr.bin/tmux/cmd-set-option.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-option.c,v 1.93 2016/01/19 15:59:12 nicm Exp $ */
+/* $OpenBSD: cmd-set-option.c,v 1.94 2016/03/03 14:15:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -100,7 +100,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
struct client *c;
const struct options_table_entry *oe;
struct options *oo;
- const char *optstr, *valstr;
+ const char *optstr, *valstr, *target;
/* Get the option name and value. */
optstr = args->argv[0];
@@ -140,29 +140,29 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
else if (oe->scope == OPTIONS_TABLE_WINDOW) {
if (args_has(self->args, 'g'))
oo = global_w_options;
- else {
- if (wl == NULL) {
- cmdq_error(cmdq,
- "couldn't set '%s'%s", optstr,
- (!args_has(args, 't') && !args_has(args,
- 'g')) ? " need target window or -g" : "");
- return (CMD_RETURN_ERROR);
- }
+ else if (wl == NULL) {
+ target = args_get(args, 't');
+ if (target != NULL) {
+ cmdq_error(cmdq, "no such window: %s",
+ target);
+ } else
+ cmdq_error(cmdq, "no current window");
+ return (CMD_RETURN_ERROR);
+ } else
oo = wl->window->options;
- }
} else if (oe->scope == OPTIONS_TABLE_SESSION) {
if (args_has(self->args, 'g'))
oo = global_s_options;
- else {
- if (s == NULL) {
- cmdq_error(cmdq,
- "couldn't set '%s'%s", optstr,
- (!args_has(args, 't') && !args_has(args,
- 'g')) ? " need target session or -g" : "");
- return (CMD_RETURN_ERROR);
- }
+ else if (s == NULL) {
+ target = args_get(args, 't');
+ if (target != NULL) {
+ cmdq_error(cmdq, "no such session: %s",
+ target);
+ } else
+ cmdq_error(cmdq, "no current session");
+ return (CMD_RETURN_ERROR);
+ } else
oo = s->options;
- }
} else {
cmdq_error(cmdq, "unknown table");
return (CMD_RETURN_ERROR);
diff --git a/usr.bin/tmux/cmd-show-environment.c b/usr.bin/tmux/cmd-show-environment.c
index 3d8a7247647..0986ead535e 100644
--- a/usr.bin/tmux/cmd-show-environment.c
+++ b/usr.bin/tmux/cmd-show-environment.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-show-environment.c,v 1.18 2016/01/19 15:59:12 nicm Exp $ */
+/* $OpenBSD: cmd-show-environment.c,v 1.19 2016/03/03 14:15:22 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -93,11 +93,28 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq)
struct args *args = self->args;
struct environ *env;
struct environ_entry *envent;
+ const char *target;
- if (args_has(self->args, 'g') || cmdq->state.tflag.s == NULL)
+ if ((target = args_get(args, 't')) != NULL) {
+ if (cmdq->state.tflag.s == NULL) {
+ cmdq_error(cmdq, "no such session: %s", target);
+ return (CMD_RETURN_ERROR);
+ }
+ }
+
+ if (args_has(self->args, 'g'))
env = global_environ;
- else
+ else {
+ if (cmdq->state.tflag.s == NULL) {
+ target = args_get(args, 't');
+ if (target != NULL)
+ cmdq_error(cmdq, "no such session: %s", target);
+ else
+ cmdq_error(cmdq, "no current session");
+ return (CMD_RETURN_ERROR);
+ }
env = cmdq->state.tflag.s->environ;
+ }
if (args->argc != 0) {
envent = environ_find(env, args->argv[0]);
diff --git a/usr.bin/tmux/cmd-show-options.c b/usr.bin/tmux/cmd-show-options.c
index 2e654139821..9e0f518f330 100644
--- a/usr.bin/tmux/cmd-show-options.c
+++ b/usr.bin/tmux/cmd-show-options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-show-options.c,v 1.30 2016/01/19 15:59:12 nicm Exp $ */
+/* $OpenBSD: cmd-show-options.c,v 1.31 2016/03/03 14:15:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -63,12 +63,13 @@ const struct cmd_entry cmd_show_window_options_entry = {
enum cmd_retval
cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
{
- struct args *args = self->args;
- struct session *s = cmdq->state.tflag.s;
- struct winlink *wl = cmdq->state.tflag.wl;
- struct options *oo;
- enum options_table_scope scope;
- int quiet;
+ struct args *args = self->args;
+ struct session *s = cmdq->state.tflag.s;
+ struct winlink *wl = cmdq->state.tflag.wl;
+ struct options *oo;
+ enum options_table_scope scope;
+ int quiet;
+ const char *target;
if (args_has(self->args, 's')) {
oo = global_options;
@@ -78,13 +79,27 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
scope = OPTIONS_TABLE_WINDOW;
if (args_has(self->args, 'g'))
oo = global_w_options;
- else
+ else if (wl == NULL) {
+ target = args_get(args, 't');
+ if (target != NULL) {
+ cmdq_error(cmdq, "no such window: %s", target);
+ } else
+ cmdq_error(cmdq, "no current window");
+ return (CMD_RETURN_ERROR);
+ } else
oo = wl->window->options;
} else {
scope = OPTIONS_TABLE_SESSION;
if (args_has(self->args, 'g'))
oo = global_s_options;
- else
+ else if (s == NULL) {
+ target = args_get(args, 't');
+ if (target != NULL) {
+ cmdq_error(cmdq, "no such session: %s", target);
+ } else
+ cmdq_error(cmdq, "no current session");
+ return (CMD_RETURN_ERROR);
+ } else
oo = s->options;
}