summaryrefslogtreecommitdiffstats
authornicm <nicm>2009-01-19 18:23:40 (GMT)
committer nicm <nicm>2009-01-19 18:23:40 (GMT)
commit2fd1100a3889ead3be34561fe55c3317a655940c (patch) (side-by-side diff)
tree3691d38b018b82aacfe685a5c890ea3d4efec4aa
parent5abf6bb85a525ce227997f14cb442d6d0d97cf0b (diff)
downloadtmux-old-2fd1100a3889ead3be34561fe55c3317a655940c.zip
tmux-old-2fd1100a3889ead3be34561fe55c3317a655940c.tar.gz
tmux-old-2fd1100a3889ead3be34561fe55c3317a655940c.tar.bz2
Pass return code from _exec; allow command sequences to work from the command line.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--CHANGES9
-rw-r--r--TODO1
-rw-r--r--cmd-attach-session.c16
-rw-r--r--cmd-bind-key.c11
-rw-r--r--cmd-choose-session.c14
-rw-r--r--cmd-choose-window.c14
-rw-r--r--cmd-clock-mode.c9
-rw-r--r--cmd-command-prompt.c11
-rw-r--r--cmd-copy-mode.c9
-rw-r--r--cmd-delete-buffer.c17
-rw-r--r--cmd-detach-client.c9
-rw-r--r--cmd-down-pane.c9
-rw-r--r--cmd-find-window.c13
-rw-r--r--cmd-has-session.c9
-rw-r--r--cmd-kill-pane.c13
-rw-r--r--cmd-kill-server.c9
-rw-r--r--cmd-kill-session.c9
-rw-r--r--cmd-kill-window.c9
-rw-r--r--cmd-last-window.c13
-rw-r--r--cmd-link-window.c18
-rw-r--r--cmd-list-buffers.c9
-rw-r--r--cmd-list-clients.c7
-rw-r--r--cmd-list-commands.c7
-rw-r--r--cmd-list-keys.c7
-rw-r--r--cmd-list-sessions.c7
-rw-r--r--cmd-list-windows.c9
-rw-r--r--cmd-list.c10
-rw-r--r--cmd-lock-server.c9
-rw-r--r--cmd-move-window.c18
-rw-r--r--cmd-new-session.c16
-rw-r--r--cmd-new-window.c15
-rw-r--r--cmd-next-window.c13
-rw-r--r--cmd-paste-buffer.c13
-rw-r--r--cmd-previous-window.c13
-rw-r--r--cmd-refresh-client.c9
-rw-r--r--cmd-rename-session.c9
-rw-r--r--cmd-rename-window.c9
-rw-r--r--cmd-resize-pane-down.c16
-rw-r--r--cmd-resize-pane-up.c16
-rw-r--r--cmd-respawn-window.c13
-rw-r--r--cmd-save-buffer.c23
-rw-r--r--cmd-scroll-mode.c9
-rw-r--r--cmd-select-pane.c13
-rw-r--r--cmd-select-prompt.c11
-rw-r--r--cmd-select-window.c9
-rw-r--r--cmd-send-keys.c11
-rw-r--r--cmd-send-prefix.c9
-rw-r--r--cmd-server-info.c7
-rw-r--r--cmd-set-buffer.c15
-rw-r--r--cmd-set-option.c21
-rw-r--r--cmd-set-password.c9
-rw-r--r--cmd-set-window-option.c21
-rw-r--r--cmd-show-buffer.c19
-rw-r--r--cmd-show-options.c9
-rw-r--r--cmd-show-window-options.c9
-rw-r--r--cmd-source-file.c9
-rw-r--r--cmd-split-window.c11
-rw-r--r--cmd-start-server.c9
-rw-r--r--cmd-suspend-client.c9
-rw-r--r--cmd-swap-window.c14
-rw-r--r--cmd-switch-client.c13
-rw-r--r--cmd-unbind-key.c9
-rw-r--r--cmd-unlink-window.c11
-rw-r--r--cmd-up-pane.c9
-rw-r--r--cmd.c6
-rw-r--r--server-msg.c25
-rw-r--r--tmux.c40
-rw-r--r--tmux.h11
68 files changed, 391 insertions, 427 deletions
diff --git a/CHANGES b/CHANGES
index 3ec8d43..58c8907 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
19 January 2009
+* An error in a command sequence now stops execution of that sequence.
+ Internally, each command code now passes a return code back rather than
+ talking to the calling client (if any) directly.
* attach-session now tries to start the server if it isn't already started - if
no sessions are created in .tmux.conf this will cause an error.
* Clean up starting server by making initial client get a special socketpair.
@@ -23,9 +26,9 @@
bind x lsk \; lsc
- Commands are executed from left to right and, importantly, an error does NOT
- stop execution. Also note that command sequences do not support repeat-time
- repetition unless all commands making up the sequence support it.
+ Commands are executed from left to right. Also note that command sequences do
+ not support repeat-time repetition unless all commands making up the sequence
+ support it.
* suspend-client command to suspend a client. Don't try to background it
though...
* Mark attached sessions in sessions lists. Suggested by Simon Kuhnle.
diff --git a/TODO b/TODO
index 5ce465b..c3490bb 100644
--- a/TODO
+++ b/TODO
@@ -83,4 +83,3 @@
- bring back -l/-p on splitw so i can do "splitw -p 75 elinks"
- UTF-8 combining characters don't work (probably should be width 1 but are
listed as 2)
-
diff --git a/cmd-attach-session.c b/cmd-attach-session.c
index d8abe65..97983e7 100644
--- a/cmd-attach-session.c
+++ b/cmd-attach-session.c
@@ -24,7 +24,7 @@
* Attach existing session to the current terminal.
*/
-void cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
+int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_attach_session_entry = {
"attach-session", "attach",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_attach_session_entry = {
cmd_target_print
};
-void
+int
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -47,24 +47,24 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
char *cause;
if (ctx->curclient != NULL)
- return;
+ return (0);
if (ARRAY_LENGTH(&sessions) == 0) {
ctx->error(ctx, "no sessions");
- return;
+ return (-1);
}
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
ctx->error(ctx, "not a terminal");
- return;
+ return (-1);
}
if (tty_open(&ctx->cmdclient->tty, &cause) != 0) {
ctx->error(ctx, "%s", cause);
xfree(cause);
- return;
+ return (-1);
}
if (data->flags & CMD_DFLAG)
@@ -74,5 +74,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
recalculate_sizes();
server_redraw_client(ctx->cmdclient);
+
+ return (1);
}
diff --git a/cmd-bind-key.c b/cmd-bind-key.c
index 7f00663..1a1d405 100644
--- a/cmd-bind-key.c
+++ b/cmd-bind-key.c
@@ -25,7 +25,7 @@
*/
int cmd_bind_key_parse(struct cmd *, int, char **, char **);
-void cmd_bind_key_exec(struct cmd *, struct cmd_ctx *);
+int cmd_bind_key_exec(struct cmd *, struct cmd_ctx *);
void cmd_bind_key_send(struct cmd *, struct buffer *);
void cmd_bind_key_recv(struct cmd *, struct buffer *);
void cmd_bind_key_free(struct cmd *);
@@ -89,19 +89,18 @@ error:
return (-1);
}
-void
-cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx)
+int
+cmd_bind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
{
struct cmd_bind_key_data *data = self->data;
if (data == NULL)
- return;
+ return (0);
key_bindings_add(data->key, data->cmdlist);
data->cmdlist = NULL; /* avoid free */
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
void
diff --git a/cmd-choose-session.c b/cmd-choose-session.c
index fed3775..04560a9 100644
--- a/cmd-choose-session.c
+++ b/cmd-choose-session.c
@@ -24,7 +24,7 @@
* Enter choice mode to choose a session.
*/
-void cmd_choose_session_exec(struct cmd *, struct cmd_ctx *);
+int cmd_choose_session_exec(struct cmd *, struct cmd_ctx *);
void cmd_choose_session_callback(void *, int);
@@ -45,7 +45,7 @@ struct cmd_choose_session_data {
u_int client;
};
-void
+int
cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -56,14 +56,14 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively");
- return;
+ return (-1);
}
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
- goto out;
+ return (0);
cur = idx = 0;
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
@@ -86,9 +86,7 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
window_choose_ready(
wl->window->active, cur, cmd_choose_session_callback, cdata);
-out:
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
void
diff --git a/cmd-choose-window.c b/cmd-choose-window.c
index 72fe955..28805fc 100644
--- a/cmd-choose-window.c
+++ b/cmd-choose-window.c
@@ -24,7 +24,7 @@
* Enter choice mode to choose a window.
*/
-void cmd_choose_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_choose_window_exec(struct cmd *, struct cmd_ctx *);
void cmd_choose_window_callback(void *, int);
@@ -45,7 +45,7 @@ struct cmd_choose_window_data {
u_int session;
};
-void
+int
cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -57,15 +57,15 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively");
- return;
+ return (-1);
}
s = ctx->curclient->session;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
- goto out;
+ return (0);
cur = idx = 0;
RB_FOREACH(wm, winlinks, &s->windows) {
@@ -87,9 +87,7 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
window_choose_ready(
wl->window->active, cur, cmd_choose_window_callback, cdata);
-out:
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
void
diff --git a/cmd-clock-mode.c b/cmd-clock-mode.c
index b23fa9a..e11f8a5 100644
--- a/cmd-clock-mode.c
+++ b/cmd-clock-mode.c
@@ -24,7 +24,7 @@
* Enter clock mode.
*/
-void cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
+int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_clock_mode_entry = {
"clock-mode", NULL,
@@ -39,17 +39,16 @@ const struct cmd_entry cmd_clock_mode_entry = {
cmd_target_print
};
-void
+int
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct winlink *wl;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
window_pane_set_mode(wl->window->active, &window_clock_mode);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c
index b94c40c..93461db 100644
--- a/cmd-command-prompt.c
+++ b/cmd-command-prompt.c
@@ -28,7 +28,7 @@
*/
void cmd_command_prompt_init(struct cmd *, int);
-void cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
+int cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
int cmd_command_prompt_callback(void *, const char *);
@@ -68,7 +68,7 @@ cmd_command_prompt_init(struct cmd *self, int key)
}
}
-void
+int
cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -77,10 +77,10 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
char *hdr, *ptr;
if ((c = cmd_find_client(ctx, data->target)) == NULL)
- return;
+ return (-1);
if (c->prompt_string != NULL)
- return;
+ return (0);
cdata = xmalloc(sizeof *cdata);
cdata->c = c;
@@ -96,8 +96,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
server_set_client_prompt(c, hdr, cmd_command_prompt_callback, cdata, 0);
xfree(hdr);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
int
diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c
index 8cb17e3..10a1bb5 100644
--- a/cmd-copy-mode.c
+++ b/cmd-copy-mode.c
@@ -24,7 +24,7 @@
* Enter copy mode.
*/
-void cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
+int cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_copy_mode_entry = {
"copy-mode", NULL,
@@ -39,17 +39,16 @@ const struct cmd_entry cmd_copy_mode_entry = {
NULL
};
-void
+int
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct winlink *wl;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
window_pane_set_mode(wl->window->active, &window_copy_mode);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-delete-buffer.c b/cmd-delete-buffer.c
index 6c7e8c8..6e080a3 100644
--- a/cmd-delete-buffer.c
+++ b/cmd-delete-buffer.c
@@ -26,7 +26,7 @@
* Delete a paste buffer.
*/
-void cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *);
+int cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_delete_buffer_entry = {
"delete-buffer", "deleteb",
@@ -41,22 +41,21 @@ const struct cmd_entry cmd_delete_buffer_entry = {
cmd_buffer_print
};
-void
+int
cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_buffer_data *data = self->data;
struct session *s;
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
if (data->buffer == -1)
paste_free_top(&s->buffers);
- else {
- if (paste_free_index(&s->buffers, data->buffer) != 0)
- ctx->error(ctx, "no buffer %d", data->buffer);
+ else if (paste_free_index(&s->buffers, data->buffer) != 0) {
+ ctx->error(ctx, "no buffer %d", data->buffer);
+ return (-1);
}
-
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+
+ return (0);
}
diff --git a/cmd-detach-client.c b/cmd-detach-client.c
index d99dff1..c299ca6 100644
--- a/cmd-detach-client.c
+++ b/cmd-detach-client.c
@@ -24,7 +24,7 @@
* Detach a client.
*/
-void cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
+int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_detach_client_entry = {
"detach-client", "detach",
@@ -39,17 +39,16 @@ const struct cmd_entry cmd_detach_client_entry = {
cmd_target_print
};
-void
+int
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct client *c;
if ((c = cmd_find_client(ctx, data->target)) == NULL)
- return;
+ return (-1);
server_write_client(c, MSG_DETACH, NULL, 0);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-down-pane.c b/cmd-down-pane.c
index 2991e90..b73d310 100644
--- a/cmd-down-pane.c
+++ b/cmd-down-pane.c
@@ -24,7 +24,7 @@
* Move down a pane.
*/
-void cmd_down_pane_exec(struct cmd *, struct cmd_ctx *);
+int cmd_down_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_down_pane_entry = {
"down-pane", "downp",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_down_pane_entry = {
cmd_target_print
};
-void
+int
cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -47,7 +47,7 @@ cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
struct window *w;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
w = wl->window;
do {
@@ -56,6 +56,5 @@ cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
w->active = TAILQ_FIRST(&w->panes);
} while (w->active->flags & PANE_HIDDEN);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-find-window.c b/cmd-find-window.c
index 90ad8bf..3e13c2c 100644
--- a/cmd-find-window.c
+++ b/cmd-find-window.c
@@ -26,7 +26,7 @@
* Find window containing text.
*/
-void cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
void cmd_find_window_callback(void *, int);
char *cmd_find_window_search(struct window_pane *, const char *);
@@ -48,7 +48,7 @@ struct cmd_find_window_data {
u_int session;
};
-void
+int
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -64,12 +64,12 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively");
- return;
+ return (-1);
}
s = ctx->curclient->session;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
ARRAY_INIT(&list_idx);
ARRAY_INIT(&list_ctx);
@@ -106,7 +106,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
ctx->error(ctx, "no windows matching: %s", data->arg);
ARRAY_FREE(&list_idx);
ARRAY_FREE(&list_ctx);
- return;
+ return (-1);
}
if (ARRAY_LENGTH(&list_idx) == 1) {
@@ -142,8 +142,7 @@ out:
ARRAY_FREE(&list_idx);
ARRAY_FREE(&list_ctx);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
void
diff --git a/cmd-has-session.c b/cmd-has-session.c
index 25ecea1..06f5911 100644
--- a/cmd-has-session.c
+++ b/cmd-has-session.c
@@ -24,7 +24,7 @@
* Cause client to report an error and exit with 1 if session doesn't exist.
*/
-void cmd_has_session_exec(struct cmd *, struct cmd_ctx *);
+int cmd_has_session_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_has_session_entry = {
"has-session", "has",
@@ -39,14 +39,13 @@ const struct cmd_entry cmd_has_session_entry = {
cmd_target_print
};
-void
+int
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
if (cmd_find_session(ctx, data->target) == NULL)
- return;
+ return (-1);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-kill-pane.c b/cmd-kill-pane.c
index 6140c2e..35a5f47 100644
--- a/cmd-kill-pane.c
+++ b/cmd-kill-pane.c
@@ -26,7 +26,7 @@
* Kill pane.
*/
-void cmd_kill_pane_exec(struct cmd *, struct cmd_ctx *);
+int cmd_kill_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_kill_pane_entry = {
"kill-pane", "killp",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_kill_pane_entry = {
cmd_pane_print
};
-void
+int
cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_pane_data *data = self->data;
@@ -49,24 +49,23 @@ cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
struct window_pane *wp;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
if (data->pane == -1)
wp = wl->window->active;
else {
wp = window_pane_at_index(wl->window, data->pane);
if (wp == NULL) {
ctx->error(ctx, "no pane: %d", data->pane);
- return;
+ return (-1);
}
}
if (window_count_panes(wl->window) == 1) {
ctx->error(ctx, "can't kill pane: %d", data->pane);
- return;
+ return (-1);
}
window_remove_pane(wl->window, wp);
server_redraw_window(wl->window);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-kill-server.c b/cmd-kill-server.c
index 82daa12..41eda26 100644
--- a/cmd-kill-server.c
+++ b/cmd-kill-server.c
@@ -27,7 +27,7 @@
* Kill the server and do nothing else.
*/
-void cmd_kill_server_exec(struct cmd *, struct cmd_ctx *);
+int cmd_kill_server_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_kill_server_entry = {
"kill-server", NULL,
@@ -42,11 +42,10 @@ const struct cmd_entry cmd_kill_server_entry = {
NULL
};
-void
-cmd_kill_server_exec(unused struct cmd *self, struct cmd_ctx *ctx)
+int
+cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
{
sigterm = 1;
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-kill-session.c b/cmd-kill-session.c
index a206443..18deaad 100644
--- a/cmd-kill-session.c
+++ b/cmd-kill-session.c
@@ -27,7 +27,7 @@
* Note this deliberately has no alias to make it hard to hit by accident.
*/
-void cmd_kill_session_exec(struct cmd *, struct cmd_ctx *);
+int cmd_kill_session_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_kill_session_entry = {
"kill-session", NULL,
@@ -42,7 +42,7 @@ const struct cmd_entry cmd_kill_session_entry = {
cmd_target_print
};
-void
+int
cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -51,7 +51,7 @@ cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx)
u_int i;
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
@@ -64,6 +64,5 @@ cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx)
session_destroy(s);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-kill-window.c b/cmd-kill-window.c
index be839eb..b580fd7 100644
--- a/cmd-kill-window.c
+++ b/cmd-kill-window.c
@@ -24,7 +24,7 @@
* Destroy window.
*/
-void cmd_kill_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_kill_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_kill_window_entry = {
"kill-window", "killw",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_kill_window_entry = {
cmd_target_print
};
-void
+int
cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -50,7 +50,7 @@ cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int destroyed;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
- return;
+ return (-1);
destroyed = session_detach(s, wl);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
@@ -65,6 +65,5 @@ cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
}
recalculate_sizes();
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-last-window.c b/cmd-last-window.c
index 75337f2..04bc716 100644
--- a/cmd-last-window.c
+++ b/cmd-last-window.c
@@ -24,7 +24,7 @@
* Move to last window.
*/
-void cmd_last_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_last_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_last_window_entry = {
"last-window", "last",
@@ -39,21 +39,22 @@ const struct cmd_entry cmd_last_window_entry = {
cmd_target_print
};
-void
+int
cmd_last_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct session *s;
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
if (session_last(s) == 0)
server_redraw_session(s);
- else
+ else {
ctx->error(ctx, "no last window");
+ return (-1);
+ }
recalculate_sizes();
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-link-window.c b/cmd-link-window.c
index 73f5708..0822ff4 100644
--- a/cmd-link-window.c
+++ b/cmd-link-window.c
@@ -26,7 +26,7 @@
* Link a window into another session.
*/
-void cmd_link_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_link_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_link_window_entry = {
"link-window", "linkw",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_link_window_entry = {
cmd_srcdst_print
};
-void
+int
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_srcdst_data *data = self->data;
@@ -50,11 +50,11 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int idx;
if ((wl_src = cmd_find_window(ctx, data->src, NULL)) == NULL)
- return;
+ return (-1);
if (arg_parse_window(data->dst, &dst, &idx) != 0) {
ctx->error(ctx, "bad window: %s", data->dst);
- return;
+ return (-1);
}
if (dst == NULL)
dst = ctx->cursession;
@@ -62,7 +62,7 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
dst = cmd_current_session(ctx);
if (dst == NULL) {
ctx->error(ctx, "session not found: %s", data->dst);
- return;
+ return (-1);
}
wl_dst = NULL;
@@ -70,7 +70,7 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
wl_dst = winlink_find_by_index(&dst->windows, idx);
if (wl_dst != NULL) {
if (wl_dst->window == wl_src->window)
- goto out;
+ return (0);
if (data->flags & CMD_KFLAG) {
/*
@@ -92,7 +92,7 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
wl_dst = session_attach(dst, wl_src->window, idx);
if (wl_dst == NULL) {
ctx->error(ctx, "index in use: %d", idx);
- return;
+ return (-1);
}
if (data->flags & CMD_DFLAG)
@@ -103,7 +103,5 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
}
recalculate_sizes();
-out:
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-list-buffers.c b/cmd-list-buffers.c
index e298bb3..ce60e23 100644
--- a/cmd-list-buffers.c
+++ b/cmd-list-buffers.c
@@ -26,7 +26,7 @@
* List paste buffers.
*/
-void cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *);
+int cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_list_buffers_entry = {
"list-buffers", "lsb",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_list_buffers_entry = {
cmd_target_print
};
-void
+int
cmd_list_buffers_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -52,7 +52,7 @@ cmd_list_buffers_exec(struct cmd *self, struct cmd_ctx *ctx)
size_t size, in, out;
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
if (s->sx > 35) { /* leave three for ... */
size = s->sx - 32;
@@ -87,6 +87,5 @@ cmd_list_buffers_exec(struct cmd *self, struct cmd_ctx *ctx)
if (tmp != NULL)
xfree(tmp);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-list-clients.c b/cmd-list-clients.c
index 5a85880..6cf1f38 100644
--- a/cmd-list-clients.c
+++ b/cmd-list-clients.c
@@ -27,7 +27,7 @@
* List all clients.
*/
-void cmd_list_clients_exec(struct cmd *, struct cmd_ctx *);
+int cmd_list_clients_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_list_clients_entry = {
"list-clients", "lsc",
@@ -42,7 +42,7 @@ const struct cmd_entry cmd_list_clients_entry = {
NULL
};
-void
+int
cmd_list_clients_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{
struct client *c;
@@ -57,6 +57,5 @@ cmd_list_clients_exec(unused struct cmd *self, struct cmd_ctx *ctx)
c->session->name, c->sx, c->sy, c->tty.termname);
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-list-commands.c b/cmd-list-commands.c
index 3846d6c..cafa203 100644
--- a/cmd-list-commands.c
+++ b/cmd-list-commands.c
@@ -24,7 +24,7 @@
* List all commands with usages.
*/
-void cmd_list_commands_exec(struct cmd *, struct cmd_ctx *);
+int cmd_list_commands_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_list_commands_entry = {
"list-commands", "lscm",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_list_commands_entry = {
NULL
};
-void
+int
cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{
const struct cmd_entry **entryp;
@@ -47,6 +47,5 @@ cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
for (entryp = cmd_table; *entryp != NULL; entryp++)
ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-list-keys.c b/cmd-list-keys.c
index c8aaac6..8fbcacd 100644
--- a/cmd-list-keys.c
+++ b/cmd-list-keys.c
@@ -24,7 +24,7 @@
* List key bindings.
*/
-void cmd_list_keys_exec(struct cmd *, struct cmd_ctx *);
+int cmd_list_keys_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_list_keys_entry = {
"list-keys", "lsk",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_list_keys_entry = {
NULL
};
-void
+int
cmd_list_keys_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{
struct key_binding *bd;
@@ -55,6 +55,5 @@ cmd_list_keys_exec(unused struct cmd *self, struct cmd_ctx *ctx)
ctx->print(ctx, "%11s: %s", key, tmp);
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c
index 499a685..7b2cda2 100644
--- a/cmd-list-sessions.c
+++ b/cmd-list-sessions.c
@@ -27,7 +27,7 @@
* List all sessions.
*/
-void cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
+int cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_list_sessions_entry = {
"list-sessions", "ls", "",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_list_sessions_entry = {
NULL
};
-void
+int
cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{
struct session *s;
@@ -63,6 +63,5 @@ cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
s->flags & SESSION_UNATTACHED ? "" : " (attached)");
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-list-windows.c b/cmd-list-windows.c
index 43c8d8f..a53411b 100644
--- a/cmd-list-windows.c
+++ b/cmd-list-windows.c
@@ -26,7 +26,7 @@
* List windows on given session.
*/
-void cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
+int cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_list_windows_entry = {
"list-windows", "lsw",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_list_windows_entry = {
cmd_target_print
};
-void
+int
cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -55,7 +55,7 @@ cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *name;
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
RB_FOREACH(wl, winlinks, &s->windows) {
w = wl->window;
@@ -81,6 +81,5 @@ cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
}
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-list.c b/cmd-list.c
index 7b92c84..5b4b619 100644
--- a/cmd-list.c
+++ b/cmd-list.c
@@ -60,13 +60,17 @@ bad:
return (NULL);
}
-void
+int
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
{
struct cmd *cmd;
+ int n;
- TAILQ_FOREACH(cmd, cmdlist, qentry)
- cmd_exec(cmd, ctx);
+ TAILQ_FOREACH(cmd, cmdlist, qentry) {
+ if ((n = cmd_exec(cmd, ctx)) != 0)
+ return (n);
+ }
+ return (0);
}
void
diff --git a/cmd-lock-server.c b/cmd-lock-server.c
index 6ca8a93..1e85a80 100644
--- a/cmd-lock-server.c
+++ b/cmd-lock-server.c
@@ -28,7 +28,7 @@
* Lock server.
*/
-void cmd_lock_server_exec(struct cmd *, struct cmd_ctx *);
+int cmd_lock_server_exec(struct cmd *, struct cmd_ctx *);
int cmd_lock_server_callback(void *, const char *);
@@ -45,11 +45,10 @@ const struct cmd_entry cmd_lock_server_entry = {
NULL,
};
-void
-cmd_lock_server_exec(unused struct cmd *self, struct cmd_ctx *ctx)
+int
+cmd_lock_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
{
server_lock();
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-move-window.c b/cmd-move-window.c
index a12143a..262fdab 100644
--- a/cmd-move-window.c
+++ b/cmd-move-window.c
@@ -26,7 +26,7 @@
* Move a window.
*/
-void cmd_move_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_move_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_move_window_entry = {
"move-window", "movew",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_move_window_entry = {
cmd_srcdst_print
};
-void
+int
cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_srcdst_data *data = self->data;
@@ -52,11 +52,11 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int destroyed, idx;
if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL)
- return;
+ return (-1);
if (arg_parse_window(data->dst, &dst, &idx) != 0) {
ctx->error(ctx, "bad window: %s", data->dst);
- return;
+ return (-1);
}
if (dst == NULL)
dst = ctx->cursession;
@@ -64,7 +64,7 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
dst = cmd_current_session(ctx);
if (dst == NULL) {
ctx->error(ctx, "session not found: %s", data->dst);
- return;
+ return (-1);
}
wl_dst = NULL;
@@ -72,7 +72,7 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
wl_dst = winlink_find_by_index(&dst->windows, idx);
if (wl_dst != NULL) {
if (wl_dst->window == wl_src->window)
- goto out;
+ return (0);
if (data->flags & CMD_KFLAG) {
/*
@@ -94,7 +94,7 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
wl_dst = session_attach(dst, wl_src->window, idx);
if (wl_dst == NULL) {
ctx->error(ctx, "index in use: %d", idx);
- return;
+ return (-1);
}
destroyed = session_detach(src, wl_src);
@@ -117,7 +117,5 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
}
recalculate_sizes();
-out:
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-new-session.c b/cmd-new-session.c
index e5efc0e..2bfd965 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -25,7 +25,7 @@
*/
int cmd_new_session_parse(struct cmd *, int, char **, char **);
-void cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
+int cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
void cmd_new_session_send(struct cmd *, struct buffer *);
void cmd_new_session_recv(struct cmd *, struct buffer *);
void cmd_new_session_free(struct cmd *);
@@ -107,7 +107,7 @@ usage:
return (-1);
}
-void
+int
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_new_session_data *data = self->data;
@@ -117,22 +117,22 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
u_int sx, sy;
if (ctx->curclient != NULL)
- return;
+ return (0);
if (!data->flag_detached) {
if (c == NULL) {
ctx->error(ctx, "no client to attach to");
- return;
+ return (-1);
}
if (!(c->flags & CLIENT_TERMINAL)) {
ctx->error(ctx, "not a terminal");
- return;
+ return (-1);
}
}
if (data->newname != NULL && session_find(data->newname) != NULL) {
ctx->error(ctx, "duplicate session: %s", data->newname);
- return;
+ return (-1);
}
cmd = data->cmd;
@@ -160,7 +160,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
if (!data->flag_detached && tty_open(&c->tty, &cause) != 0) {
ctx->error(ctx, "%s", cause);
xfree(cause);
- return;
+ return (-1);
}
@@ -179,6 +179,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
server_write_client(c, MSG_READY, NULL, 0);
server_redraw_client(c);
}
+
+ return (1);
}
void
diff --git a/cmd-new-window.c b/cmd-new-window.c
index 7d51898..ab7f4b0 100644
--- a/cmd-new-window.c
+++ b/cmd-new-window.c
@@ -27,7 +27,7 @@
*/
int cmd_new_window_parse(struct cmd *, int, char **, char **);
-void cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
void cmd_new_window_send(struct cmd *, struct buffer *);
void cmd_new_window_recv(struct cmd *, struct buffer *);
void cmd_new_window_free(struct cmd *);
@@ -109,7 +109,7 @@ usage:
return (-1);
}
-void
+int
cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_new_window_data *data = self->data;
@@ -119,11 +119,11 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int idx;
if (data == NULL)
- return;
+ return (0);
if (arg_parse_window(data->target, &s, &idx) != 0) {
ctx->error(ctx, "bad window: %s", data->target);
- return;
+ return (-1);
}
if (s == NULL)
s = ctx->cursession;
@@ -131,7 +131,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
s = cmd_current_session(ctx);
if (s == NULL) {
ctx->error(ctx, "session not found: %s", data->target);
- return;
+ return (-1);
}
cmd = data->cmd;
@@ -145,7 +145,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
wl = session_new(s, data->name, cmd, cwd, idx);
if (wl == NULL) {
ctx->error(ctx, "command failed: %s", cmd);
- return;
+ return (-1);
}
if (!data->flag_detached) {
session_select(s, wl->idx);
@@ -153,8 +153,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
} else
server_status_session(s);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
void
diff --git a/cmd-next-window.c b/cmd-next-window.c
index 75810bc..0120304 100644
--- a/cmd-next-window.c
+++ b/cmd-next-window.c
@@ -25,7 +25,7 @@
*/
void cmd_next_window_init(struct cmd *, int);
-void cmd_next_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_next_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_next_window_entry = {
"next-window", "next",
@@ -52,7 +52,7 @@ cmd_next_window_init(struct cmd *self, int key)
data->flags |= CMD_AFLAG;
}
-void
+int
cmd_next_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -60,7 +60,7 @@ cmd_next_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int activity;
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
activity = 0;
if (data->flags & CMD_AFLAG)
@@ -68,10 +68,11 @@ cmd_next_window_exec(struct cmd *self, struct cmd_ctx *ctx)
if (session_next(s, activity) == 0)
server_redraw_session(s);
- else
+ else {
ctx->error(ctx, "no next window");
+ return (-1);
+ }
recalculate_sizes();
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-paste-buffer.c b/cmd-paste-buffer.c
index 7380de6..5cd17a3 100644
--- a/cmd-paste-buffer.c
+++ b/cmd-paste-buffer.c
@@ -26,7 +26,7 @@
* Paste paste buffer if present.
*/
-void cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
+int cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_paste_buffer_entry = {
"paste-buffer", "pasteb",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_paste_buffer_entry = {
cmd_buffer_print
};
-void
+int
cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_buffer_data *data = self->data;
@@ -51,14 +51,16 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
struct paste_buffer *pb;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
- return;
+ return (-1);
w = wl->window;
if (data->buffer == -1)
pb = paste_get_top(&s->buffers);
else {
- if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL)
+ if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
ctx->error(ctx, "no buffer %d", data->buffer);
+ return (-1);
+ }
}
if (pb != NULL)
@@ -72,6 +74,5 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
paste_free_index(&s->buffers, data->buffer);
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-previous-window.c b/cmd-previous-window.c
index ecae5ee..2b6466d 100644
--- a/cmd-previous-window.c
+++ b/cmd-previous-window.c
@@ -25,7 +25,7 @@
*/
void cmd_previous_window_init(struct cmd *, int);
-void cmd_previous_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_previous_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_previous_window_entry = {
"previous-window", "prev",
@@ -52,7 +52,7 @@ cmd_previous_window_init(struct cmd *self, int key)
data->flags |= CMD_AFLAG;
}
-void
+int
cmd_previous_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -60,7 +60,7 @@ cmd_previous_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int activity;
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
activity = 0;
if (data->flags & CMD_AFLAG)
@@ -68,10 +68,11 @@ cmd_previous_window_exec(struct cmd *self, struct cmd_ctx *ctx)
if (session_previous(s, activity) == 0)
server_redraw_session(s);
- else
+ else {
ctx->error(ctx, "no previous window");
+ return (-1);
+ }
recalculate_sizes();
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-refresh-client.c b/cmd-refresh-client.c
index c6047d7..2ed1ed4 100644
--- a/cmd-refresh-client.c
+++ b/cmd-refresh-client.c
@@ -24,7 +24,7 @@
* Refresh client.
*/
-void cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *);
+int cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_refresh_client_entry = {
"refresh-client", "refresh",
@@ -39,17 +39,16 @@ const struct cmd_entry cmd_refresh_client_entry = {
cmd_target_print
};
-void
+int
cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct client *c;
if ((c = cmd_find_client(ctx, data->target)) == NULL)
- return;
+ return (-1);
server_redraw_client(c);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-rename-session.c b/cmd-rename-session.c
index 1aa04b6..0d0ee0b 100644
--- a/cmd-rename-session.c
+++ b/cmd-rename-session.c
@@ -26,7 +26,7 @@
* Change session name.
*/
-void cmd_rename_session_exec(struct cmd *, struct cmd_ctx *);
+int cmd_rename_session_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_rename_session_entry = {
"rename-session", "rename",
@@ -41,18 +41,17 @@ const struct cmd_entry cmd_rename_session_entry = {
cmd_target_print
};
-void
+int
cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct session *s;
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
xfree(s->name);
s->name = xstrdup(data->arg);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-rename-window.c b/cmd-rename-window.c
index 92939a6..5260c7a 100644
--- a/cmd-rename-window.c
+++ b/cmd-rename-window.c
@@ -26,7 +26,7 @@
* Rename a window.
*/
-void cmd_rename_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_rename_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_rename_window_entry = {
"rename-window", "renamew",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_rename_window_entry = {
cmd_target_print
};
-void
+int
cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -49,13 +49,12 @@ cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct winlink *wl;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
- return;
+ return (-1);
xfree(wl->window->name);
wl->window->name = xstrdup(data->arg);
server_status_session(s);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-resize-pane-down.c b/cmd-resize-pane-down.c
index 003c192..3ccc90d 100644
--- a/cmd-resize-pane-down.c
+++ b/cmd-resize-pane-down.c
@@ -27,7 +27,7 @@
*/
void cmd_resize_pane_down_init(struct cmd *, int);
-void cmd_resize_pane_down_exec(struct cmd *, struct cmd_ctx *);
+int cmd_resize_pane_down_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_resize_pane_down_entry = {
"resize-pane-down", "resizep-down",
@@ -54,7 +54,7 @@ cmd_resize_pane_down_init(struct cmd *self, int key)
data->arg = xstrdup("5");
}
-void
+int
cmd_resize_pane_down_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_pane_data *data = self->data;
@@ -64,14 +64,14 @@ cmd_resize_pane_down_exec(struct cmd *self, struct cmd_ctx *ctx)
u_int adjust;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
if (data->pane == -1)
wp = wl->window->active;
else {
wp = window_pane_at_index(wl->window, data->pane);
if (wp == NULL) {
ctx->error(ctx, "no pane: %d", data->pane);
- return;
+ return (-1);
}
}
@@ -81,7 +81,7 @@ cmd_resize_pane_down_exec(struct cmd *self, struct cmd_ctx *ctx)
adjust = strtonum(data->arg, 1, INT_MAX, &errstr);
if (errstr != NULL) {
ctx->error(ctx, "adjustment %s: %s", errstr, data->arg);
- return;
+ return (-1);
}
}
@@ -93,7 +93,7 @@ cmd_resize_pane_down_exec(struct cmd *self, struct cmd_ctx *ctx)
if (TAILQ_NEXT(wp, entry) == NULL) {
if (wp == TAILQ_FIRST(&wl->window->panes)) {
/* Only one pane. */
- goto out;
+ return (0);
}
wp = TAILQ_PREV(wp, window_panes, entry);
}
@@ -114,7 +114,5 @@ cmd_resize_pane_down_exec(struct cmd *self, struct cmd_ctx *ctx)
server_redraw_window(wl->window);
-out:
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-resize-pane-up.c b/cmd-resize-pane-up.c
index f3b80f0..dbc3d4c 100644
--- a/cmd-resize-pane-up.c
+++ b/cmd-resize-pane-up.c
@@ -27,7 +27,7 @@
*/
void cmd_resize_pane_up_init(struct cmd *, int);
-void cmd_resize_pane_up_exec(struct cmd *, struct cmd_ctx *);
+int cmd_resize_pane_up_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_resize_pane_up_entry = {
"resize-pane-up", "resizep-up",
@@ -54,7 +54,7 @@ cmd_resize_pane_up_init(struct cmd *self, int key)
data->arg = xstrdup("5");
}
-void
+int
cmd_resize_pane_up_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_pane_data *data = self->data;
@@ -64,14 +64,14 @@ cmd_resize_pane_up_exec(struct cmd *self, struct cmd_ctx *ctx)
u_int adjust;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
if (data->pane == -1)
wp = wl->window->active;
else {
wp = window_pane_at_index(wl->window, data->pane);
if (wp == NULL) {
ctx->error(ctx, "no pane: %d", data->pane);
- return;
+ return (-1);
}
}
@@ -81,7 +81,7 @@ cmd_resize_pane_up_exec(struct cmd *self, struct cmd_ctx *ctx)
adjust = strtonum(data->arg, 1, INT_MAX, &errstr);
if (errstr != NULL) {
ctx->error(ctx, "adjustment %s: %s", errstr, data->arg);
- return;
+ return (-1);
}
}
@@ -94,7 +94,7 @@ cmd_resize_pane_up_exec(struct cmd *self, struct cmd_ctx *ctx)
if (wq == NULL) {
if (wp == TAILQ_FIRST(&wl->window->panes)) {
/* Only one pane. */
- goto out;
+ return (0);
}
wq = wp;
wp = TAILQ_PREV(wq, window_panes, entry);
@@ -109,7 +109,5 @@ cmd_resize_pane_up_exec(struct cmd *self, struct cmd_ctx *ctx)
server_redraw_window(wl->window);
-out:
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c
index 2b60e00..7a986e1 100644
--- a/cmd-respawn-window.c
+++ b/cmd-respawn-window.c
@@ -26,7 +26,7 @@
* Respawn a window (restart the command). Kill existing if -k given.
*/
-void cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_respawn_window_entry = {
"respawn-window", "respawnw",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_respawn_window_entry = {
cmd_target_print
};
-void
+int
cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -54,7 +54,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
u_int i;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
- return;
+ return (-1);
w = wl->window;
if (!(data->flags & CMD_KFLAG)) {
@@ -63,7 +63,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
continue;
ctx->error(ctx,
"window still active: %s:%d", s->name, wl->idx);
- return;
+ return (-1);
}
}
@@ -79,13 +79,12 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
window_pane_resize(wp, w->sx, w->sy);
if (window_pane_spawn(wp, data->arg, NULL, env) != 0) {
ctx->error(ctx, "respawn failed: %s:%d", s->name, wl->idx);
- return;
+ return (-1);
}
screen_reinit(&wp->base);
recalculate_sizes();
server_redraw_window(w);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c
index 5307245..0399873 100644
--- a/cmd-save-buffer.c
+++ b/cmd-save-buffer.c
@@ -28,7 +28,7 @@
* Saves a session paste buffer to a file.
*/
-void cmd_save_buffer_exec(struct cmd *, struct cmd_ctx *);
+int cmd_save_buffer_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_save_buffer_entry = {
"save-buffer", "saveb",
@@ -43,7 +43,7 @@ const struct cmd_entry cmd_save_buffer_entry = {
cmd_buffer_print
};
-void
+int
cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_buffer_data *data = self->data;
@@ -53,18 +53,22 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
FILE *f;
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
if (data->buffer == -1) {
- if ((pb = paste_get_top(&s->buffers)) == NULL)
+ if ((pb = paste_get_top(&s->buffers)) == NULL) {
ctx->error(ctx, "no buffers");
+ return (-1);
+ }
} else {
- if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL)
+ if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
ctx->error(ctx, "no buffer %d", data->buffer);
+ return (-1);
+ }
}
if (pb == NULL)
- return;
+ return (0);
mask = umask(S_IRWXG | S_IRWXO);
if (data->flags & CMD_AFLAG)
@@ -73,18 +77,17 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
f = fopen(data->arg, "w");
if (f == NULL) {
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
- return;
+ return (-1);
}
if (fwrite(pb->data, 1, strlen(pb->data), f) != strlen(pb->data)) {
ctx->error(ctx, "%s: fwrite error", data->arg);
fclose(f);
- return;
+ return (-1);
}
fclose(f);
umask(mask);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-scroll-mode.c b/cmd-scroll-mode.c
index ae573d5..5216306 100644
--- a/cmd-scroll-mode.c
+++ b/cmd-scroll-mode.c
@@ -24,7 +24,7 @@
* Enter scroll mode.
*/
-void cmd_scroll_mode_exec(struct cmd *, struct cmd_ctx *);
+int cmd_scroll_mode_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_scroll_mode_entry = {
"scroll-mode", NULL,
@@ -39,17 +39,16 @@ const struct cmd_entry cmd_scroll_mode_entry = {
cmd_target_print
};
-void
+int
cmd_scroll_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct winlink *wl;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
window_pane_set_mode(wl->window->active, &window_scroll_mode);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-select-pane.c b/cmd-select-pane.c
index 1f39d80..598590d 100644
--- a/cmd-select-pane.c
+++ b/cmd-select-pane.c
@@ -24,7 +24,7 @@
* Select pane.
*/
-void cmd_select_pane_exec(struct cmd *, struct cmd_ctx *);
+int cmd_select_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_select_pane_entry = {
"select-pane", "selectp",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_select_pane_entry = {
cmd_pane_print
};
-void
+int
cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_pane_data *data = self->data;
@@ -47,23 +47,22 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
struct window_pane *wp;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
if (data->pane == -1)
wp = wl->window->active;
else {
wp = window_pane_at_index(wl->window, data->pane);
if (wp == NULL) {
ctx->error(ctx, "no pane: %d", data->pane);
- return;
+ return (-1);
}
}
if (wp->flags & PANE_HIDDEN) {
ctx->error(ctx, "pane %d is hidden", data->pane);
- return;
+ return (-1);
}
window_set_active_pane(wl->window, wp);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-select-prompt.c b/cmd-select-prompt.c
index d75661d..d13cb9b 100644
--- a/cmd-select-prompt.c
+++ b/cmd-select-prompt.c
@@ -26,7 +26,7 @@
* Prompt for window index and select it.
*/
-void cmd_select_prompt_exec(struct cmd *, struct cmd_ctx *);
+int cmd_select_prompt_exec(struct cmd *, struct cmd_ctx *);
int cmd_select_prompt_callback(void *, const char *);
@@ -43,22 +43,21 @@ const struct cmd_entry cmd_select_prompt_entry = {
cmd_target_print
};
-void
+int
cmd_select_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct client *c;
if ((c = cmd_find_client(ctx, data->target)) == NULL)
- return;
+ return (-1);
if (c->prompt_string != NULL)
- return;
+ return (0);
server_set_client_prompt(c, "index ", cmd_select_prompt_callback, c, 0);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
int
diff --git a/cmd-select-window.c b/cmd-select-window.c
index ecb9822..48d135a 100644
--- a/cmd-select-window.c
+++ b/cmd-select-window.c
@@ -27,7 +27,7 @@
*/
void cmd_select_window_init(struct cmd *, int);
-void cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_select_window_entry = {
"select-window", "selectw",
@@ -53,7 +53,7 @@ cmd_select_window_init(struct cmd *self, int key)
xasprintf(&data->target, ":%d", key - '0');
}
-void
+int
cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -61,12 +61,11 @@ cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct session *s;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
- return;
+ return (-1);
if (session_select(s, wl->idx) == 0)
server_redraw_session(s);
recalculate_sizes();
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-send-keys.c b/cmd-send-keys.c
index 6ea49b8..545089c 100644
--- a/cmd-send-keys.c
+++ b/cmd-send-keys.c
@@ -27,7 +27,7 @@
*/
int cmd_send_keys_parse(struct cmd *, int, char **, char **);
-void cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
+int cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
void cmd_send_keys_send(struct cmd *, struct buffer *);
void cmd_send_keys_recv(struct cmd *, struct buffer *);
void cmd_send_keys_free(struct cmd *);
@@ -106,7 +106,7 @@ usage:
return (-1);
}
-void
+int
cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_send_keys_data *data = self->data;
@@ -114,18 +114,17 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
u_int i;
if (data == NULL)
- return;
+ return (-1);
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
for (i = 0; i < data->nkeys; i++) {
window_pane_key(
wl->window->active, ctx->curclient, data->keys[i]);
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
void
diff --git a/cmd-send-prefix.c b/cmd-send-prefix.c
index 389bb2e..123867d 100644
--- a/cmd-send-prefix.c
+++ b/cmd-send-prefix.c
@@ -24,7 +24,7 @@
* Send prefix key as a key.
*/
-void cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *);
+int cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_send_prefix_entry = {
"send-prefix", NULL,
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_send_prefix_entry = {
cmd_target_print
};
-void
+int
cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -48,11 +48,10 @@ cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
int key;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
- return;
+ return (-1);
key = options_get_number(&s->options, "prefix");
window_pane_key(wl->window->active, ctx->curclient, key);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-server-info.c b/cmd-server-info.c
index 836a00d..e3b66f9 100644
--- a/cmd-server-info.c
+++ b/cmd-server-info.c
@@ -31,7 +31,7 @@
* Show various information about server.
*/
-void cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
+int cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_server_info_entry = {
"server-info", "info",
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_server_info_entry = {
NULL
};
-void
+int
cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{
struct tty_term *term;
@@ -141,6 +141,5 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
}
ctx->print(ctx, "");
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-set-buffer.c b/cmd-set-buffer.c
index 7249706..6a2f7bc 100644
--- a/cmd-set-buffer.c
+++ b/cmd-set-buffer.c
@@ -26,7 +26,7 @@
* Add or set a session paste buffer.
*/
-void cmd_set_buffer_exec(struct cmd *, struct cmd_ctx *);
+int cmd_set_buffer_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_set_buffer_entry = {
"set-buffer", "setb",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_set_buffer_entry = {
cmd_buffer_print
};
-void
+int
cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_buffer_data *data = self->data;
@@ -49,16 +49,15 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
u_int limit;
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
limit = options_get_number(&s->options, "buffer-limit");
if (data->buffer == -1)
paste_add(&s->buffers, data->arg, limit);
- else {
- if (paste_replace(&s->buffers, data->buffer, data->arg) != 0)
- ctx->error(ctx, "no buffer %d", data->buffer);
+ else if (paste_replace(&s->buffers, data->buffer, data->arg) != 0) {
+ ctx->error(ctx, "no buffer %d", data->buffer);
+ return (-1);
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-set-option.c b/cmd-set-option.c
index 87dedd5..68aed97 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -27,7 +27,7 @@
* Set an option.
*/
-void cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
+int cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_set_option_entry = {
"set-option", "set",
@@ -68,7 +68,7 @@ const struct set_option_entry set_option_table[NSETOPTION] = {
{ "status-right-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
};
-void
+int
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_option_data *data = self->data;
@@ -82,13 +82,13 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
oo = &global_options;
else {
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
oo = &s->options;
}
if (*data->option == '\0') {
ctx->error(ctx, "invalid option");
- return;
+ return (-1);
}
entry = NULL;
@@ -98,7 +98,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
continue;
if (entry != NULL) {
ctx->error(ctx, "ambiguous option: %s", data->option);
- return;
+ return (-1);
}
entry = &set_option_table[i];
@@ -108,25 +108,25 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
}
if (entry == NULL) {
ctx->error(ctx, "unknown option: %s", data->option);
- return;
+ return (-1);
}
if (data->flags & CMD_UFLAG) {
if (data->flags & CMD_GFLAG) {
ctx->error(ctx,
"can't unset global option: %s", entry->name);
- return;
+ return (-1);
}
if (data->value != NULL) {
ctx->error(ctx,
"value passed to unset option: %s", entry->name);
- return;
+ return (-1);
}
if (options_remove(oo, entry->name) != 0) {
ctx->error(ctx,
"can't unset option, not set: %s", entry->name);
- return;
+ return (-1);
}
ctx->info(ctx, "unset option: %s", entry->name);
} else {
@@ -159,6 +159,5 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
server_redraw_client(c);
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-set-password.c b/cmd-set-password.c
index 0bde072..3e04fcd 100644
--- a/cmd-set-password.c
+++ b/cmd-set-password.c
@@ -28,7 +28,7 @@
*/
int cmd_set_password_parse(struct cmd *, int, char **, char **);
-void cmd_set_password_exec(struct cmd *, struct cmd_ctx *);
+int cmd_set_password_exec(struct cmd *, struct cmd_ctx *);
void cmd_set_password_send(struct cmd *, struct buffer *);
void cmd_set_password_recv(struct cmd *, struct buffer *);
void cmd_set_password_free(struct cmd *);
@@ -102,14 +102,14 @@ usage:
return (-1);
}
-void
+int
cmd_set_password_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_set_password_data *data = self->data;
if (data->password == NULL) {
ctx->error(ctx, "failed to encrypt password");
- return;
+ return (-1);
}
if (server_password != NULL)
@@ -120,8 +120,7 @@ cmd_set_password_exec(struct cmd *self, struct cmd_ctx *ctx)
server_password = xstrdup(data->password);
log_debug("pw now %s", server_password);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
void
diff --git a/cmd-set-window-option.c b/cmd-set-window-option.c
index dd0373a..458fe3c 100644
--- a/cmd-set-window-option.c
+++ b/cmd-set-window-option.c
@@ -28,7 +28,7 @@
*/
int cmd_set_window_option_parse(struct cmd *, int, char **, char **);
-void cmd_set_window_option_exec(struct cmd *, struct cmd_ctx *);
+int cmd_set_window_option_exec(struct cmd *, struct cmd_ctx *);
void cmd_set_window_option_send(struct cmd *, struct buffer *);
void cmd_set_window_option_recv(struct cmd *, struct buffer *);
void cmd_set_window_option_free(struct cmd *);
@@ -69,7 +69,7 @@ const struct set_option_entry set_window_option_table[NSETWINDOWOPTION] = {
{ "xterm-keys", SET_OPTION_FLAG, 0, 0, NULL },
};
-void
+int
cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_option_data *data = self->data;
@@ -83,13 +83,13 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
oo = &global_window_options;
else {
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
oo = &wl->window->options;
}
if (*data->option == '\0') {
ctx->error(ctx, "invalid option");
- return;
+ return (-1);
}
entry = NULL;
@@ -99,7 +99,7 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
continue;
if (entry != NULL) {
ctx->error(ctx, "ambiguous option: %s", data->option);
- return;
+ return (-1);
}
entry = &set_window_option_table[i];
@@ -109,25 +109,25 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
}
if (entry == NULL) {
ctx->error(ctx, "unknown option: %s", data->option);
- return;
+ return (-1);
}
if (data->flags & CMD_UFLAG) {
if (data->flags & CMD_GFLAG) {
ctx->error(ctx,
"can't unset global option: %s", entry->name);
- return;
+ return (-1);
}
if (data->value != NULL) {
ctx->error(ctx,
"value passed to unset option: %s", entry->name);
- return;
+ return (-1);
}
if (options_remove(oo, entry->name) != 0) {
ctx->error(ctx,
"can't unset option, not set: %s", entry->name);
- return;
+ return (-1);
}
ctx->info(ctx, "unset option: %s", entry->name);
} else {
@@ -160,6 +160,5 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
server_redraw_client(c);
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-show-buffer.c b/cmd-show-buffer.c
index 80099cf..b28d0dd 100644
--- a/cmd-show-buffer.c
+++ b/cmd-show-buffer.c
@@ -26,7 +26,7 @@
* Show a session paste buffer.
*/
-void cmd_show_buffer_exec(struct cmd *, struct cmd_ctx *);
+int cmd_show_buffer_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_show_buffer_entry = {
"show-buffer", "showb",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_show_buffer_entry = {
cmd_buffer_print
};
-void
+int
cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_buffer_data *data = self->data;
@@ -52,14 +52,16 @@ cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
size_t len;
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
if (data->buffer == -1) {
- if ((pb = paste_get_top(&s->buffers)) == NULL)
+ if ((pb = paste_get_top(&s->buffers)) == NULL) {
ctx->error(ctx, "no buffers");
- } else {
- if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL)
- ctx->error(ctx, "no buffer %d", data->buffer);
+ return (-1);
+ }
+ } else if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
+ ctx->error(ctx, "no buffer %d", data->buffer);
+ return (-1);
}
if (pb != NULL) {
@@ -83,6 +85,5 @@ cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
ctx->print(ctx, buf);
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-show-options.c b/cmd-show-options.c
index 63fda9d..73d1473 100644
--- a/cmd-show-options.c
+++ b/cmd-show-options.c
@@ -27,7 +27,7 @@
* Show options.
*/
-void cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
+int cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_show_options_entry = {
"show-options", "show",
@@ -42,7 +42,7 @@ const struct cmd_entry cmd_show_options_entry = {
cmd_target_print
};
-void
+int
cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -57,7 +57,7 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
oo = &global_options;
else {
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
oo = &s->options;
}
@@ -101,6 +101,5 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
}
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-show-window-options.c b/cmd-show-window-options.c
index f2f90f7..76e9317 100644
--- a/cmd-show-window-options.c
+++ b/cmd-show-window-options.c
@@ -27,7 +27,7 @@
* Show window options.
*/
-void cmd_show_window_options_exec(struct cmd *, struct cmd_ctx *);
+int cmd_show_window_options_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_show_window_options_entry = {
"show-window-options", "showw",
@@ -42,7 +42,7 @@ const struct cmd_entry cmd_show_window_options_entry = {
cmd_target_print
};
-void
+int
cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -57,7 +57,7 @@ cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx)
oo = &global_window_options;
else {
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
oo = &wl->window->options;
}
@@ -101,6 +101,5 @@ cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx)
}
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-source-file.c b/cmd-source-file.c
index 5877833..040422a 100644
--- a/cmd-source-file.c
+++ b/cmd-source-file.c
@@ -25,7 +25,7 @@
*/
int cmd_source_file_parse(struct cmd *, int, char **, char **);
-void cmd_source_file_exec(struct cmd *, struct cmd_ctx *);
+int cmd_source_file_exec(struct cmd *, struct cmd_ctx *);
void cmd_source_file_send(struct cmd *, struct buffer *);
void cmd_source_file_recv(struct cmd *, struct buffer *);
void cmd_source_file_free(struct cmd *);
@@ -88,7 +88,7 @@ usage:
return (-1);
}
-void
+int
cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_source_file_data *data = self->data;
@@ -97,11 +97,10 @@ cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
if (load_cfg(data->path, &cause) != 0) {
ctx->error(ctx, "%s", cause);
xfree(cause);
- return;
+ return (-1);
}
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
void
diff --git a/cmd-split-window.c b/cmd-split-window.c
index 00473eb..4826cd3 100644
--- a/cmd-split-window.c
+++ b/cmd-split-window.c
@@ -28,7 +28,7 @@
*/
int cmd_split_window_parse(struct cmd *, int, char **, char **);
-void cmd_split_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_split_window_exec(struct cmd *, struct cmd_ctx *);
void cmd_split_window_send(struct cmd *, struct buffer *);
void cmd_split_window_recv(struct cmd *, struct buffer *);
void cmd_split_window_free(struct cmd *);
@@ -104,7 +104,7 @@ usage:
return (-1);
}
-void
+int
cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_split_window_data *data = self->data;
@@ -118,7 +118,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
u_int i, hlimit;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
- return;
+ return (-1);
w = wl->window;
if (session_index(s, &i) != 0)
@@ -137,7 +137,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
hlimit = options_get_number(&s->options, "history-limit");
if ((wp = window_add_pane(w, cmd, cwd, env, hlimit)) == NULL) {
ctx->error(ctx, "command failed: %s", cmd);
- return;
+ return (-1);
}
server_redraw_window(w);
@@ -148,8 +148,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
} else
server_status_session(s);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
void
diff --git a/cmd-start-server.c b/cmd-start-server.c
index b29adaf..852fb3a 100644
--- a/cmd-start-server.c
+++ b/cmd-start-server.c
@@ -24,7 +24,7 @@
* Start the server and do nothing else.
*/
-void cmd_start_server_exec(struct cmd *, struct cmd_ctx *);
+int cmd_start_server_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_start_server_entry = {
"start-server", "start",
@@ -39,9 +39,8 @@ const struct cmd_entry cmd_start_server_entry = {
NULL
};
-void
-cmd_start_server_exec(unused struct cmd *self, struct cmd_ctx *ctx)
+int
+cmd_start_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
{
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-suspend-client.c b/cmd-suspend-client.c
index c208afd..42475dd 100644
--- a/cmd-suspend-client.c
+++ b/cmd-suspend-client.c
@@ -27,7 +27,7 @@
* Suspend client with SIGTSTP.
*/
-void cmd_suspend_client_exec(struct cmd *, struct cmd_ctx *);
+int cmd_suspend_client_exec(struct cmd *, struct cmd_ctx *);
struct cmd_suspend_client_data {
char *name;
@@ -47,19 +47,18 @@ const struct cmd_entry cmd_suspend_client_entry = {
cmd_target_print
};
-void
+int
cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct client *c;
if ((c = cmd_find_client(ctx, data->target)) == NULL)
- return;
+ return (-1);
tty_stop_tty(&c->tty);
c->flags |= CLIENT_SUSPENDED;
server_write_client(c, MSG_SUSPEND, NULL, 0);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-swap-window.c b/cmd-swap-window.c
index 7bd4346..3a8f2e2 100644
--- a/cmd-swap-window.c
+++ b/cmd-swap-window.c
@@ -26,7 +26,7 @@
* Swap one window with another.
*/
-void cmd_swap_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_swap_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_swap_window_entry = {
"swap-window", "swapw",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_swap_window_entry = {
cmd_srcdst_print
};
-void
+int
cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_srcdst_data *data = self->data;
@@ -50,12 +50,12 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct window *w;
if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL)
- return;
+ return (-1);
if ((wl_dst = cmd_find_window(ctx, data->dst, &dst)) == NULL)
- return;
+ return (-1);
if (wl_dst->window == wl_src->window)
- goto out;
+ return (0);
w = wl_dst->window;
wl_dst->window = wl_src->window;
@@ -71,7 +71,5 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
server_redraw_session(dst);
recalculate_sizes();
-out:
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-switch-client.c b/cmd-switch-client.c
index 26a0056..93e7b0a 100644
--- a/cmd-switch-client.c
+++ b/cmd-switch-client.c
@@ -28,7 +28,7 @@
*/
int cmd_switch_client_parse(struct cmd *, int, char **, char **);
-void cmd_switch_client_exec(struct cmd *, struct cmd_ctx *);
+int cmd_switch_client_exec(struct cmd *, struct cmd_ctx *);
void cmd_switch_client_send(struct cmd *, struct buffer *);
void cmd_switch_client_recv(struct cmd *, struct buffer *);
void cmd_switch_client_free(struct cmd *);
@@ -88,7 +88,7 @@ usage:
return (-1);
}
-void
+int
cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_switch_client_data *data = self->data;
@@ -96,20 +96,19 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
struct session *s;
if (data == NULL)
- return;
+ return (0);
if ((c = cmd_find_client(ctx, data->name)) == NULL)
- return;
+ return (-1);
if ((s = cmd_find_session(ctx, data->target)) == NULL)
- return;
+ return (-1);
c->session = s;
recalculate_sizes();
server_redraw_client(c);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
void
diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c
index 6f2c996..3fd4e40 100644
--- a/cmd-unbind-key.c
+++ b/cmd-unbind-key.c
@@ -25,7 +25,7 @@
*/
int cmd_unbind_key_parse(struct cmd *, int, char **, char **);
-void cmd_unbind_key_exec(struct cmd *, struct cmd_ctx *);
+int cmd_unbind_key_exec(struct cmd *, struct cmd_ctx *);
void cmd_unbind_key_send(struct cmd *, struct buffer *);
void cmd_unbind_key_recv(struct cmd *, struct buffer *);
void cmd_unbind_key_free(struct cmd *);
@@ -81,18 +81,17 @@ error:
return (-1);
}
-void
+int
cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
{
struct cmd_unbind_key_data *data = self->data;
if (data == NULL)
- return;
+ return (0);
key_bindings_remove(data->key);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
void
diff --git a/cmd-unlink-window.c b/cmd-unlink-window.c
index fdf5933..3bc189f 100644
--- a/cmd-unlink-window.c
+++ b/cmd-unlink-window.c
@@ -24,7 +24,7 @@
* Unlink a window, unless it would be destroyed by doing so (only one link).
*/
-void cmd_unlink_window_exec(struct cmd *, struct cmd_ctx *);
+int cmd_unlink_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_unlink_window_entry = {
"unlink-window", "unlinkw",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_unlink_window_entry = {
cmd_target_print
};
-void
+int
cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -50,11 +50,11 @@ cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int destroyed;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
- return;
+ return (-1);
if (wl->window->references == 1) {
ctx->error(ctx, "window is only linked to one session");
- return;
+ return (-1);
}
destroyed = session_detach(s, wl);
@@ -70,6 +70,5 @@ cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
}
recalculate_sizes();
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd-up-pane.c b/cmd-up-pane.c
index 3c9605e..8031cef 100644
--- a/cmd-up-pane.c
+++ b/cmd-up-pane.c
@@ -24,7 +24,7 @@
* Move up a pane.
*/
-void cmd_up_pane_exec(struct cmd *, struct cmd_ctx *);
+int cmd_up_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_up_pane_entry = {
"up-pane", "upp",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_up_pane_entry = {
cmd_target_print
};
-void
+int
cmd_up_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
@@ -47,7 +47,7 @@ cmd_up_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
struct window *w;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
- return;
+ return (-1);
w = wl->window;
do {
@@ -56,6 +56,5 @@ cmd_up_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
w->active = TAILQ_LAST(&w->panes, window_panes);
} while (w->active->flags & PANE_HIDDEN);
- if (ctx->cmdclient != NULL)
- server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+ return (0);
}
diff --git a/cmd.c b/cmd.c
index 4905c5c..d5581d9 100644
--- a/cmd.c
+++ b/cmd.c
@@ -170,14 +170,14 @@ usage:
return (NULL);
}
-void
+int
cmd_exec(struct cmd *cmd, struct cmd_ctx *ctx)
{
if (server_locked) {
ctx->error(ctx, "server is locked");
- return;
+ return (-1);
}
- cmd->entry->exec(cmd, ctx);
+ return (cmd->entry->exec(cmd, ctx));
}
void
diff --git a/server-msg.c b/server-msg.c
index d2ed1ee..7b6acf7 100644
--- a/server-msg.c
+++ b/server-msg.c
@@ -132,14 +132,14 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
{
struct msg_command_data data;
struct cmd_ctx ctx;
+ struct cmd_list *cmdlist;
struct cmd *cmd;
if (hdr->size < sizeof data)
fatalx("bad MSG_COMMAND size");
buffer_read(c->in, &data, sizeof data);
- cmd = cmd_recv(c->in);
- log_debug("got command %s from client %d", cmd->entry->name, c->fd);
+ cmdlist = cmd_list_recv(c->in);
server_activity = time(NULL);
ctx.error = server_msg_fn_command_error;
@@ -152,16 +152,21 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
ctx.cmdclient = c;
- /* XXX */
- if (data.pid != -1 && (cmd->entry->flags & CMD_CANTNEST)) {
- server_msg_fn_command_error(&ctx, "sessions "
- "should be nested with care. unset $TMUX to force");
- cmd_free(cmd);
- return (0);
+ if (data.pid != -1) {
+ TAILQ_FOREACH(cmd, cmdlist, qentry) {
+ if (cmd->entry->flags & CMD_CANTNEST) {
+ server_msg_fn_command_error(&ctx,
+ "sessions should be nested with care. "
+ "unset $TMUX to force");
+ cmd_list_free(cmdlist);
+ return (0);
+ }
+ }
}
- cmd_exec(cmd, &ctx);
- cmd_free(cmd);
+ if (cmd_list_exec(cmdlist, &ctx) != 1)
+ server_write_client(c, MSG_EXIT, NULL, 0);
+ cmd_list_free(cmdlist);
return (0);
}
diff --git a/tmux.c b/tmux.c
index e02c80e..5aa1cd1 100644
--- a/tmux.c
+++ b/tmux.c
@@ -179,7 +179,8 @@ main(int argc, char **argv)
struct client_ctx cctx;
struct msg_command_data cmddata;
struct buffer *b;
- struct cmd *cmd;
+ struct cmd_list *cmdlist;
+ struct cmd *cmd;
struct pollfd pfd;
struct hdr hdr;
const char *shell;
@@ -328,7 +329,7 @@ main(int argc, char **argv)
log_warnx("can't specify a command when unlocking");
exit(1);
}
- cmd = NULL;
+ cmdlist = NULL;
if ((pass = getpass("Password: ")) == NULL)
exit(1);
start_server = 0;
@@ -337,11 +338,24 @@ main(int argc, char **argv)
cmd = xmalloc(sizeof *cmd);
cmd->entry = &cmd_new_session_entry;
cmd->entry->init(cmd, 0);
- } else if ((cmd = cmd_parse(argc, argv, &cause)) == NULL) {
- log_warnx("%s", cause);
- exit(1);
+
+ cmdlist = xmalloc(sizeof *cmdlist);
+ TAILQ_INIT(cmdlist);
+ TAILQ_INSERT_HEAD(cmdlist, cmd, qentry);
+ } else {
+ cmdlist = cmd_list_parse(argc, argv, &cause);
+ if (cmdlist == NULL) {
+ log_warnx("%s", cause);
+ exit(1);
+ }
+ }
+ start_server = 0;
+ TAILQ_FOREACH(cmd, cmdlist, qentry) {
+ if (cmd->entry->flags & CMD_STARTSERVER) {
+ start_server = 1;
+ break;
+ }
}
- start_server = cmd->entry->flags & CMD_STARTSERVER;
}
memset(&cctx, 0, sizeof cctx);
@@ -354,8 +368,8 @@ main(int argc, char **argv)
client_write_server(
&cctx, MSG_UNLOCK, BUFFER_OUT(b), BUFFER_USED(b));
} else {
- cmd_send(cmd, b);
- cmd_free(cmd);
+ cmd_list_send(cmdlist, b);
+ cmd_list_free(cmdlist);
client_fill_session(&cmddata);
client_write_server2(&cctx, MSG_COMMAND,
&cmddata, sizeof cmddata, BUFFER_OUT(b), BUFFER_USED(b));
@@ -389,6 +403,7 @@ main(int argc, char **argv)
case MSG_EXIT:
n = 0;
goto out;
+ case MSG_ERROR:
case MSG_PRINT:
if (hdr.size > INT_MAX - 1)
fatalx("bad MSG_PRINT size");
@@ -397,15 +412,6 @@ main(int argc, char **argv)
if (hdr.size != 0)
buffer_remove(cctx.srv_in, hdr.size);
goto restart;
- case MSG_ERROR:
- if (hdr.size > INT_MAX - 1)
- fatalx("bad MSG_ERROR size");
- log_warnx("%.*s",
- (int) hdr.size, BUFFER_OUT(cctx.srv_in));
- if (hdr.size != 0)
- buffer_remove(cctx.srv_in, hdr.size);
- n = 1;
- goto out;
case MSG_READY:
n = client_main(&cctx);
goto out;
diff --git a/tmux.h b/tmux.h
index e9d8ee5..34d1706 100644
--- a/tmux.h
+++ b/tmux.h
@@ -832,7 +832,7 @@ struct cmd_entry {
void (*init)(struct cmd *, int);
int (*parse)(struct cmd *, int, char **, char **);
- void (*exec)(struct cmd *, struct cmd_ctx *);
+ int (*exec)(struct cmd *, struct cmd_ctx *);
void (*send)(struct cmd *, struct buffer *);
void (*recv)(struct cmd *, struct buffer *);
void (*free)(struct cmd *);
@@ -1080,7 +1080,7 @@ int arg_parse_window(const char *, struct session **, int *);
/* cmd.c */
struct cmd *cmd_parse(int, char **, char **);
-void cmd_exec(struct cmd *, struct cmd_ctx *);
+int cmd_exec(struct cmd *, struct cmd_ctx *);
void cmd_send(struct cmd *, struct buffer *);
struct cmd *cmd_recv(struct buffer *);
void cmd_free(struct cmd *);
@@ -1157,7 +1157,7 @@ extern const struct cmd_entry cmd_up_pane_entry;
/* cmd-list.c */
struct cmd_list *cmd_list_parse(int, char **, char **);
-void cmd_list_exec(struct cmd_list *, struct cmd_ctx *);
+int cmd_list_exec(struct cmd_list *, struct cmd_ctx *);
void cmd_list_send(struct cmd_list *, struct buffer *);
struct cmd_list *cmd_list_recv(struct buffer *);
void cmd_list_free(struct cmd_list *);
@@ -1173,7 +1173,6 @@ size_t cmd_prarg(char *, size_t, const char *, char *);
#define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
void cmd_target_init(struct cmd *, int);
int cmd_target_parse(struct cmd *, int, char **, char **);
-void cmd_target_exec(struct cmd *, struct cmd_ctx *);
void cmd_target_send(struct cmd *, struct buffer *);
void cmd_target_recv(struct cmd *, struct buffer *);
void cmd_target_free(struct cmd *);
@@ -1183,7 +1182,6 @@ size_t cmd_target_print(struct cmd *, char *, size_t);
#define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
void cmd_srcdst_init(struct cmd *, int);
int cmd_srcdst_parse(struct cmd *, int, char **, char **);
-void cmd_srcdst_exec(struct cmd *, struct cmd_ctx *);
void cmd_srcdst_send(struct cmd *, struct buffer *);
void cmd_srcdst_recv(struct cmd *, struct buffer *);
void cmd_srcdst_free(struct cmd *);
@@ -1193,7 +1191,6 @@ size_t cmd_srcdst_print(struct cmd *, char *, size_t);
#define CMD_BUFFER_CLIENT_USAGE "[-b buffer-index] [-t target-client]"
void cmd_buffer_init(struct cmd *, int);
int cmd_buffer_parse(struct cmd *, int, char **, char **);
-void cmd_buffer_exec(struct cmd *, struct cmd_ctx *);
void cmd_buffer_send(struct cmd *, struct buffer *);
void cmd_buffer_recv(struct cmd *, struct buffer *);
void cmd_buffer_free(struct cmd *);
@@ -1203,7 +1200,6 @@ size_t cmd_buffer_print(struct cmd *, char *, size_t);
#define CMD_OPTION_CLIENT_USAGE "[-gu] [-t target-client] option [value]"
void cmd_option_init(struct cmd *, int);
int cmd_option_parse(struct cmd *, int, char **, char **);
-void cmd_option_exec(struct cmd *, struct cmd_ctx *);
void cmd_option_send(struct cmd *, struct buffer *);
void cmd_option_recv(struct cmd *, struct buffer *);
void cmd_option_free(struct cmd *);
@@ -1213,7 +1209,6 @@ size_t cmd_option_print(struct cmd *, char *, size_t);
#define CMD_PANE_CLIENT_USAGE "[-t target-client] [-p pane-index]"
void cmd_pane_init(struct cmd *, int);
int cmd_pane_parse(struct cmd *, int, char **, char **);
-void cmd_pane_exec(struct cmd *, struct cmd_ctx *);
void cmd_pane_send(struct cmd *, struct buffer *);
void cmd_pane_recv(struct cmd *, struct buffer *);
void cmd_pane_free(struct cmd *);