Pass return code from _exec; allow command sequences to work from the command line.

This commit is contained in:
Nicholas Marriott 2009-01-19 18:23:40 +00:00
parent 5f6a351df7
commit 93230a64bc
68 changed files with 458 additions and 494 deletions

11
CHANGES
View File

@ -1,5 +1,8 @@
19 January 2009 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 * 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. no sessions are created in .tmux.conf this will cause an error.
* Clean up starting server by making initial client get a special socketpair. * Clean up starting server by making initial client get a special socketpair.
@ -23,9 +26,9 @@
bind x lsk \; lsc bind x lsk \; lsc
Commands are executed from left to right and, importantly, an error does NOT Commands are executed from left to right. Also note that command sequences do
stop execution. Also note that command sequences do not support repeat-time not support repeat-time repetition unless all commands making up the sequence
repetition unless all commands making up the sequence support it. support it.
* suspend-client command to suspend a client. Don't try to background it * suspend-client command to suspend a client. Don't try to background it
though... though...
* Mark attached sessions in sessions lists. Suggested by Simon Kuhnle. * Mark attached sessions in sessions lists. Suggested by Simon Kuhnle.
@ -964,7 +967,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other (including mutt, emacs). No status bar yet and no key remapping or other
customisation. customisation.
$Id: CHANGES,v 1.221 2009-01-19 17:16:09 nicm Exp $ $Id: CHANGES,v 1.222 2009-01-19 18:23:40 nicm Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms

1
TODO
View File

@ -83,4 +83,3 @@
- bring back -l/-p on splitw so i can do "splitw -p 75 elinks" - 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 - UTF-8 combining characters don't work (probably should be width 1 but are
listed as 2) listed as 2)

View File

@ -1,4 +1,4 @@
/* $Id: cmd-attach-session.c,v 1.22 2009-01-19 17:16:09 nicm Exp $ */ /* $Id: cmd-attach-session.c,v 1.23 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Attach existing session to the current terminal. * 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 = { const struct cmd_entry cmd_attach_session_entry = {
"attach-session", "attach", "attach-session", "attach",
@ -39,7 +39,7 @@ const struct cmd_entry cmd_attach_session_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
@ -47,24 +47,24 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
char *cause; char *cause;
if (ctx->curclient != NULL) if (ctx->curclient != NULL)
return; return (0);
if (ARRAY_LENGTH(&sessions) == 0) { if (ARRAY_LENGTH(&sessions) == 0) {
ctx->error(ctx, "no sessions"); ctx->error(ctx, "no sessions");
return; return (-1);
} }
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) { if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
ctx->error(ctx, "not a terminal"); ctx->error(ctx, "not a terminal");
return; return (-1);
} }
if (tty_open(&ctx->cmdclient->tty, &cause) != 0) { if (tty_open(&ctx->cmdclient->tty, &cause) != 0) {
ctx->error(ctx, "%s", cause); ctx->error(ctx, "%s", cause);
xfree(cause); xfree(cause);
return; return (-1);
} }
if (data->flags & CMD_DFLAG) 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); server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
recalculate_sizes(); recalculate_sizes();
server_redraw_client(ctx->cmdclient); server_redraw_client(ctx->cmdclient);
return (1);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-bind-key.c,v 1.18 2009-01-18 14:40:48 nicm Exp $ */ /* $Id: cmd-bind-key.c,v 1.19 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -25,7 +25,7 @@
*/ */
int cmd_bind_key_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_bind_key_recv(struct cmd *, struct buffer *); void cmd_bind_key_recv(struct cmd *, struct buffer *);
void cmd_bind_key_free(struct cmd *); void cmd_bind_key_free(struct cmd *);
@ -89,19 +89,18 @@ error:
return (-1); return (-1);
} }
void int
cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_bind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
{ {
struct cmd_bind_key_data *data = self->data; struct cmd_bind_key_data *data = self->data;
if (data == NULL) if (data == NULL)
return; return (0);
key_bindings_add(data->key, data->cmdlist); key_bindings_add(data->key, data->cmdlist);
data->cmdlist = NULL; /* avoid free */ data->cmdlist = NULL; /* avoid free */
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-choose-session.c,v 1.5 2009-01-18 19:10:08 nicm Exp $ */ /* $Id: cmd-choose-session.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Enter choice mode to choose a session. * 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); void cmd_choose_session_callback(void *, int);
@ -45,7 +45,7 @@ struct cmd_choose_session_data {
u_int client; u_int client;
}; };
void int
cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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) { if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively"); ctx->error(ctx, "must be run interactively");
return; return (-1);
} }
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) 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) if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
goto out; return (0);
cur = idx = 0; cur = idx = 0;
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { 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( window_choose_ready(
wl->window->active, cur, cmd_choose_session_callback, cdata); wl->window->active, cur, cmd_choose_session_callback, cdata);
out: return (0);
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-choose-window.c,v 1.6 2009-01-18 19:10:08 nicm Exp $ */ /* $Id: cmd-choose-window.c,v 1.7 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Enter choice mode to choose a window. * 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); void cmd_choose_window_callback(void *, int);
@ -45,7 +45,7 @@ struct cmd_choose_window_data {
u_int session; u_int session;
}; };
void int
cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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) { if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively"); ctx->error(ctx, "must be run interactively");
return; return (-1);
} }
s = ctx->curclient->session; s = ctx->curclient->session;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) 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) if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
goto out; return (0);
cur = idx = 0; cur = idx = 0;
RB_FOREACH(wm, winlinks, &s->windows) { RB_FOREACH(wm, winlinks, &s->windows) {
@ -87,9 +87,7 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
window_choose_ready( window_choose_ready(
wl->window->active, cur, cmd_choose_window_callback, cdata); wl->window->active, cur, cmd_choose_window_callback, cdata);
out: return (0);
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-clock-mode.c,v 1.2 2009-01-11 23:31:46 nicm Exp $ */ /* $Id: cmd-clock-mode.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Enter clock mode. * 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 = { const struct cmd_entry cmd_clock_mode_entry = {
"clock-mode", NULL, "clock-mode", NULL,
@ -39,17 +39,16 @@ const struct cmd_entry cmd_clock_mode_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
struct winlink *wl; struct winlink *wl;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
window_pane_set_mode(wl->window->active, &window_clock_mode); window_pane_set_mode(wl->window->active, &window_clock_mode);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-command-prompt.c,v 1.11 2009-01-18 17:20:52 nicm Exp $ */ /* $Id: cmd-command-prompt.c,v 1.12 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -28,7 +28,7 @@
*/ */
void cmd_command_prompt_init(struct cmd *, int); 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 *); 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) cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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; char *hdr, *ptr;
if ((c = cmd_find_client(ctx, data->target)) == NULL) if ((c = cmd_find_client(ctx, data->target)) == NULL)
return; return (-1);
if (c->prompt_string != NULL) if (c->prompt_string != NULL)
return; return (0);
cdata = xmalloc(sizeof *cdata); cdata = xmalloc(sizeof *cdata);
cdata->c = c; 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); server_set_client_prompt(c, hdr, cmd_command_prompt_callback, cdata, 0);
xfree(hdr); xfree(hdr);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
int int

View File

@ -1,4 +1,4 @@
/* $Id: cmd-copy-mode.c,v 1.13 2009-01-11 23:31:46 nicm Exp $ */ /* $Id: cmd-copy-mode.c,v 1.14 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Enter copy mode. * 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 = { const struct cmd_entry cmd_copy_mode_entry = {
"copy-mode", NULL, "copy-mode", NULL,
@ -39,17 +39,16 @@ const struct cmd_entry cmd_copy_mode_entry = {
NULL NULL
}; };
void int
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
struct winlink *wl; struct winlink *wl;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
window_pane_set_mode(wl->window->active, &window_copy_mode); window_pane_set_mode(wl->window->active, &window_copy_mode);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-delete-buffer.c,v 1.3 2008-12-10 20:25:41 nicm Exp $ */ /* $Id: cmd-delete-buffer.c,v 1.4 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Delete a paste buffer. * 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 = { const struct cmd_entry cmd_delete_buffer_entry = {
"delete-buffer", "deleteb", "delete-buffer", "deleteb",
@ -41,22 +41,21 @@ const struct cmd_entry cmd_delete_buffer_entry = {
cmd_buffer_print cmd_buffer_print
}; };
void int
cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_buffer_data *data = self->data; struct cmd_buffer_data *data = self->data;
struct session *s; struct session *s;
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
if (data->buffer == -1) if (data->buffer == -1)
paste_free_top(&s->buffers); paste_free_top(&s->buffers);
else { else if (paste_free_index(&s->buffers, data->buffer) != 0) {
if (paste_free_index(&s->buffers, data->buffer) != 0) ctx->error(ctx, "no buffer %d", data->buffer);
ctx->error(ctx, "no buffer %d", data->buffer); return (-1);
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-detach-client.c,v 1.6 2008-06-05 21:25:00 nicm Exp $ */ /* $Id: cmd-detach-client.c,v 1.7 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Detach a client. * 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 = { const struct cmd_entry cmd_detach_client_entry = {
"detach-client", "detach", "detach-client", "detach",
@ -39,17 +39,16 @@ const struct cmd_entry cmd_detach_client_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
struct client *c; struct client *c;
if ((c = cmd_find_client(ctx, data->target)) == NULL) if ((c = cmd_find_client(ctx, data->target)) == NULL)
return; return (-1);
server_write_client(c, MSG_DETACH, NULL, 0); server_write_client(c, MSG_DETACH, NULL, 0);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-down-pane.c,v 1.2 2009-01-14 22:13:30 nicm Exp $ */ /* $Id: cmd-down-pane.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Move down a pane. * 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 = { const struct cmd_entry cmd_down_pane_entry = {
"down-pane", "downp", "down-pane", "downp",
@ -39,7 +39,7 @@ const struct cmd_entry cmd_down_pane_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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; struct window *w;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
w = wl->window; w = wl->window;
do { do {
@ -56,6 +56,5 @@ cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
w->active = TAILQ_FIRST(&w->panes); w->active = TAILQ_FIRST(&w->panes);
} while (w->active->flags & PANE_HIDDEN); } while (w->active->flags & PANE_HIDDEN);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-find-window.c,v 1.2 2009-01-18 19:10:08 nicm Exp $ */ /* $Id: cmd-find-window.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Find window containing text. * 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); void cmd_find_window_callback(void *, int);
char *cmd_find_window_search(struct window_pane *, const char *); char *cmd_find_window_search(struct window_pane *, const char *);
@ -48,7 +48,7 @@ struct cmd_find_window_data {
u_int session; u_int session;
}; };
void int
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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) { if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively"); ctx->error(ctx, "must be run interactively");
return; return (-1);
} }
s = ctx->curclient->session; s = ctx->curclient->session;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
ARRAY_INIT(&list_idx); ARRAY_INIT(&list_idx);
ARRAY_INIT(&list_ctx); 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); ctx->error(ctx, "no windows matching: %s", data->arg);
ARRAY_FREE(&list_idx); ARRAY_FREE(&list_idx);
ARRAY_FREE(&list_ctx); ARRAY_FREE(&list_ctx);
return; return (-1);
} }
if (ARRAY_LENGTH(&list_idx) == 1) { if (ARRAY_LENGTH(&list_idx) == 1) {
@ -142,8 +142,7 @@ out:
ARRAY_FREE(&list_idx); ARRAY_FREE(&list_idx);
ARRAY_FREE(&list_ctx); ARRAY_FREE(&list_ctx);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-has-session.c,v 1.11 2008-06-23 19:51:48 nicm Exp $ */ /* $Id: cmd-has-session.c,v 1.12 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Cause client to report an error and exit with 1 if session doesn't exist. * 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 = { const struct cmd_entry cmd_has_session_entry = {
"has-session", "has", "has-session", "has",
@ -39,14 +39,13 @@ const struct cmd_entry cmd_has_session_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
if (cmd_find_session(ctx, data->target) == NULL) if (cmd_find_session(ctx, data->target) == NULL)
return; return (-1);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-kill-pane.c,v 1.2 2009-01-14 19:29:32 nicm Exp $ */ /* $Id: cmd-kill-pane.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Kill pane. * 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 = { const struct cmd_entry cmd_kill_pane_entry = {
"kill-pane", "killp", "kill-pane", "killp",
@ -41,7 +41,7 @@ const struct cmd_entry cmd_kill_pane_entry = {
cmd_pane_print cmd_pane_print
}; };
void int
cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_pane_data *data = self->data; 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; struct window_pane *wp;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
if (data->pane == -1) if (data->pane == -1)
wp = wl->window->active; wp = wl->window->active;
else { else {
wp = window_pane_at_index(wl->window, data->pane); wp = window_pane_at_index(wl->window, data->pane);
if (wp == NULL) { if (wp == NULL) {
ctx->error(ctx, "no pane: %d", data->pane); ctx->error(ctx, "no pane: %d", data->pane);
return; return (-1);
} }
} }
if (window_count_panes(wl->window) == 1) { if (window_count_panes(wl->window) == 1) {
ctx->error(ctx, "can't kill pane: %d", data->pane); ctx->error(ctx, "can't kill pane: %d", data->pane);
return; return (-1);
} }
window_remove_pane(wl->window, wp); window_remove_pane(wl->window, wp);
server_redraw_window(wl->window); server_redraw_window(wl->window);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-kill-server.c,v 1.5 2008-06-05 21:25:00 nicm Exp $ */ /* $Id: cmd-kill-server.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
* Kill the server and do nothing else. * 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 = { const struct cmd_entry cmd_kill_server_entry = {
"kill-server", NULL, "kill-server", NULL,
@ -42,11 +42,10 @@ const struct cmd_entry cmd_kill_server_entry = {
NULL NULL
}; };
void int
cmd_kill_server_exec(unused struct cmd *self, struct cmd_ctx *ctx) cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
{ {
sigterm = 1; sigterm = 1;
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-kill-session.c,v 1.11 2008-06-06 20:02:27 nicm Exp $ */ /* $Id: cmd-kill-session.c,v 1.12 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
* Note this deliberately has no alias to make it hard to hit by accident. * 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 = { const struct cmd_entry cmd_kill_session_entry = {
"kill-session", NULL, "kill-session", NULL,
@ -42,7 +42,7 @@ const struct cmd_entry cmd_kill_session_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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; u_int i;
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) { for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&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); session_destroy(s);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-kill-window.c,v 1.14 2008-06-06 20:02:27 nicm Exp $ */ /* $Id: cmd-kill-window.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Destroy window. * 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 = { const struct cmd_entry cmd_kill_window_entry = {
"kill-window", "killw", "kill-window", "killw",
@ -39,7 +39,7 @@ const struct cmd_entry cmd_kill_window_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
@ -50,7 +50,7 @@ cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int destroyed; int destroyed;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL) if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return; return (-1);
destroyed = session_detach(s, wl); destroyed = session_detach(s, wl);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) { 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(); recalculate_sizes();
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-last-window.c,v 1.15 2009-01-14 22:40:17 nicm Exp $ */ /* $Id: cmd-last-window.c,v 1.16 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Move to last window. * 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 = { const struct cmd_entry cmd_last_window_entry = {
"last-window", "last", "last-window", "last",
@ -39,21 +39,22 @@ const struct cmd_entry cmd_last_window_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_last_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_last_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
struct session *s; struct session *s;
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
if (session_last(s) == 0) if (session_last(s) == 0)
server_redraw_session(s); server_redraw_session(s);
else else {
ctx->error(ctx, "no last window"); ctx->error(ctx, "no last window");
return (-1);
}
recalculate_sizes(); recalculate_sizes();
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-link-window.c,v 1.26 2008-12-10 20:25:41 nicm Exp $ */ /* $Id: cmd-link-window.c,v 1.27 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Link a window into another session. * 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 = { const struct cmd_entry cmd_link_window_entry = {
"link-window", "linkw", "link-window", "linkw",
@ -41,7 +41,7 @@ const struct cmd_entry cmd_link_window_entry = {
cmd_srcdst_print cmd_srcdst_print
}; };
void int
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_srcdst_data *data = self->data; struct cmd_srcdst_data *data = self->data;
@ -50,11 +50,11 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int idx; int idx;
if ((wl_src = cmd_find_window(ctx, data->src, NULL)) == NULL) if ((wl_src = cmd_find_window(ctx, data->src, NULL)) == NULL)
return; return (-1);
if (arg_parse_window(data->dst, &dst, &idx) != 0) { if (arg_parse_window(data->dst, &dst, &idx) != 0) {
ctx->error(ctx, "bad window: %s", data->dst); ctx->error(ctx, "bad window: %s", data->dst);
return; return (-1);
} }
if (dst == NULL) if (dst == NULL)
dst = ctx->cursession; dst = ctx->cursession;
@ -62,7 +62,7 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
dst = cmd_current_session(ctx); dst = cmd_current_session(ctx);
if (dst == NULL) { if (dst == NULL) {
ctx->error(ctx, "session not found: %s", data->dst); ctx->error(ctx, "session not found: %s", data->dst);
return; return (-1);
} }
wl_dst = NULL; 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); wl_dst = winlink_find_by_index(&dst->windows, idx);
if (wl_dst != NULL) { if (wl_dst != NULL) {
if (wl_dst->window == wl_src->window) if (wl_dst->window == wl_src->window)
goto out; return (0);
if (data->flags & CMD_KFLAG) { 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); wl_dst = session_attach(dst, wl_src->window, idx);
if (wl_dst == NULL) { if (wl_dst == NULL) {
ctx->error(ctx, "index in use: %d", idx); ctx->error(ctx, "index in use: %d", idx);
return; return (-1);
} }
if (data->flags & CMD_DFLAG) if (data->flags & CMD_DFLAG)
@ -103,7 +103,5 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
} }
recalculate_sizes(); recalculate_sizes();
out: return (0);
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-list-buffers.c,v 1.6 2009-01-18 17:20:52 nicm Exp $ */ /* $Id: cmd-list-buffers.c,v 1.7 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* List paste buffers. * 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 = { const struct cmd_entry cmd_list_buffers_entry = {
"list-buffers", "lsb", "list-buffers", "lsb",
@ -41,7 +41,7 @@ const struct cmd_entry cmd_list_buffers_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_list_buffers_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_list_buffers_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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; size_t size, in, out;
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
if (s->sx > 35) { /* leave three for ... */ if (s->sx > 35) { /* leave three for ... */
size = s->sx - 32; size = s->sx - 32;
@ -87,6 +87,5 @@ cmd_list_buffers_exec(struct cmd *self, struct cmd_ctx *ctx)
if (tmp != NULL) if (tmp != NULL)
xfree(tmp); xfree(tmp);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-list-clients.c,v 1.11 2009-01-10 01:30:38 nicm Exp $ */ /* $Id: cmd-list-clients.c,v 1.12 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
* List all clients. * 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 = { const struct cmd_entry cmd_list_clients_entry = {
"list-clients", "lsc", "list-clients", "lsc",
@ -42,7 +42,7 @@ const struct cmd_entry cmd_list_clients_entry = {
NULL NULL
}; };
void int
cmd_list_clients_exec(unused struct cmd *self, struct cmd_ctx *ctx) cmd_list_clients_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{ {
struct client *c; 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); c->session->name, c->sx, c->sy, c->tty.termname);
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-list-commands.c,v 1.2 2008-09-26 06:45:25 nicm Exp $ */ /* $Id: cmd-list-commands.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* List all commands with usages. * 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 = { const struct cmd_entry cmd_list_commands_entry = {
"list-commands", "lscm", "list-commands", "lscm",
@ -39,7 +39,7 @@ const struct cmd_entry cmd_list_commands_entry = {
NULL NULL
}; };
void int
cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx) cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{ {
const struct cmd_entry **entryp; 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++) for (entryp = cmd_table; *entryp != NULL; entryp++)
ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage); ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-list-keys.c,v 1.12 2009-01-18 14:40:48 nicm Exp $ */ /* $Id: cmd-list-keys.c,v 1.13 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* List key bindings. * 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 = { const struct cmd_entry cmd_list_keys_entry = {
"list-keys", "lsk", "list-keys", "lsk",
@ -39,7 +39,7 @@ const struct cmd_entry cmd_list_keys_entry = {
NULL NULL
}; };
void int
cmd_list_keys_exec(unused struct cmd *self, struct cmd_ctx *ctx) cmd_list_keys_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{ {
struct key_binding *bd; 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); ctx->print(ctx, "%11s: %s", key, tmp);
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-list-sessions.c,v 1.18 2009-01-18 12:13:21 nicm Exp $ */ /* $Id: cmd-list-sessions.c,v 1.19 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
* List all sessions. * 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 = { const struct cmd_entry cmd_list_sessions_entry = {
"list-sessions", "ls", "", "list-sessions", "ls", "",
@ -41,7 +41,7 @@ const struct cmd_entry cmd_list_sessions_entry = {
NULL NULL
}; };
void int
cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx) cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{ {
struct session *s; struct session *s;
@ -63,6 +63,5 @@ cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
s->flags & SESSION_UNATTACHED ? "" : " (attached)"); s->flags & SESSION_UNATTACHED ? "" : " (attached)");
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-list-windows.c,v 1.29 2009-01-14 23:39:14 nicm Exp $ */ /* $Id: cmd-list-windows.c,v 1.30 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* List windows on given session. * 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 = { const struct cmd_entry cmd_list_windows_entry = {
"list-windows", "lsw", "list-windows", "lsw",
@ -41,7 +41,7 @@ const struct cmd_entry cmd_list_windows_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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; const char *name;
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
RB_FOREACH(wl, winlinks, &s->windows) { RB_FOREACH(wl, winlinks, &s->windows) {
w = wl->window; w = wl->window;
@ -81,6 +81,5 @@ cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
} }
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-list.c,v 1.1 2009-01-18 14:40:48 nicm Exp $ */ /* $Id: cmd-list.c,v 1.2 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -60,13 +60,17 @@ bad:
return (NULL); return (NULL);
} }
void int
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx) cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
{ {
struct cmd *cmd; struct cmd *cmd;
int n;
TAILQ_FOREACH(cmd, cmdlist, qentry) TAILQ_FOREACH(cmd, cmdlist, qentry) {
cmd_exec(cmd, ctx); if ((n = cmd_exec(cmd, ctx)) != 0)
return (n);
}
return (0);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-lock-server.c,v 1.1 2009-01-11 00:48:42 nicm Exp $ */ /* $Id: cmd-lock-server.c,v 1.2 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -28,7 +28,7 @@
* Lock server. * 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 *); int cmd_lock_server_callback(void *, const char *);
@ -45,11 +45,10 @@ const struct cmd_entry cmd_lock_server_entry = {
NULL, NULL,
}; };
void int
cmd_lock_server_exec(unused struct cmd *self, struct cmd_ctx *ctx) cmd_lock_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
{ {
server_lock(); server_lock();
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-move-window.c,v 1.3 2008-12-10 20:25:41 nicm Exp $ */ /* $Id: cmd-move-window.c,v 1.4 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Move a window. * 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 = { const struct cmd_entry cmd_move_window_entry = {
"move-window", "movew", "move-window", "movew",
@ -41,7 +41,7 @@ const struct cmd_entry cmd_move_window_entry = {
cmd_srcdst_print cmd_srcdst_print
}; };
void int
cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_srcdst_data *data = self->data; 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; int destroyed, idx;
if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL) if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL)
return; return (-1);
if (arg_parse_window(data->dst, &dst, &idx) != 0) { if (arg_parse_window(data->dst, &dst, &idx) != 0) {
ctx->error(ctx, "bad window: %s", data->dst); ctx->error(ctx, "bad window: %s", data->dst);
return; return (-1);
} }
if (dst == NULL) if (dst == NULL)
dst = ctx->cursession; dst = ctx->cursession;
@ -64,7 +64,7 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
dst = cmd_current_session(ctx); dst = cmd_current_session(ctx);
if (dst == NULL) { if (dst == NULL) {
ctx->error(ctx, "session not found: %s", data->dst); ctx->error(ctx, "session not found: %s", data->dst);
return; return (-1);
} }
wl_dst = NULL; 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); wl_dst = winlink_find_by_index(&dst->windows, idx);
if (wl_dst != NULL) { if (wl_dst != NULL) {
if (wl_dst->window == wl_src->window) if (wl_dst->window == wl_src->window)
goto out; return (0);
if (data->flags & CMD_KFLAG) { 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); wl_dst = session_attach(dst, wl_src->window, idx);
if (wl_dst == NULL) { if (wl_dst == NULL) {
ctx->error(ctx, "index in use: %d", idx); ctx->error(ctx, "index in use: %d", idx);
return; return (-1);
} }
destroyed = session_detach(src, wl_src); destroyed = session_detach(src, wl_src);
@ -117,7 +117,5 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
} }
recalculate_sizes(); recalculate_sizes();
out: return (0);
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-new-session.c,v 1.35 2009-01-18 14:40:48 nicm Exp $ */ /* $Id: cmd-new-session.c,v 1.36 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -25,7 +25,7 @@
*/ */
int cmd_new_session_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_new_session_recv(struct cmd *, struct buffer *); void cmd_new_session_recv(struct cmd *, struct buffer *);
void cmd_new_session_free(struct cmd *); void cmd_new_session_free(struct cmd *);
@ -107,7 +107,7 @@ usage:
return (-1); return (-1);
} }
void int
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_new_session_data *data = self->data; 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; u_int sx, sy;
if (ctx->curclient != NULL) if (ctx->curclient != NULL)
return; return (0);
if (!data->flag_detached) { if (!data->flag_detached) {
if (c == NULL) { if (c == NULL) {
ctx->error(ctx, "no client to attach to"); ctx->error(ctx, "no client to attach to");
return; return (-1);
} }
if (!(c->flags & CLIENT_TERMINAL)) { if (!(c->flags & CLIENT_TERMINAL)) {
ctx->error(ctx, "not a terminal"); ctx->error(ctx, "not a terminal");
return; return (-1);
} }
} }
if (data->newname != NULL && session_find(data->newname) != NULL) { if (data->newname != NULL && session_find(data->newname) != NULL) {
ctx->error(ctx, "duplicate session: %s", data->newname); ctx->error(ctx, "duplicate session: %s", data->newname);
return; return (-1);
} }
cmd = data->cmd; 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) { if (!data->flag_detached && tty_open(&c->tty, &cause) != 0) {
ctx->error(ctx, "%s", cause); ctx->error(ctx, "%s", cause);
xfree(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_write_client(c, MSG_READY, NULL, 0);
server_redraw_client(c); server_redraw_client(c);
} }
return (1);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-new-window.c,v 1.28 2009-01-18 14:40:48 nicm Exp $ */ /* $Id: cmd-new-window.c,v 1.29 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
*/ */
int cmd_new_window_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_new_window_recv(struct cmd *, struct buffer *); void cmd_new_window_recv(struct cmd *, struct buffer *);
void cmd_new_window_free(struct cmd *); void cmd_new_window_free(struct cmd *);
@ -109,7 +109,7 @@ usage:
return (-1); return (-1);
} }
void int
cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_new_window_data *data = self->data; 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; int idx;
if (data == NULL) if (data == NULL)
return; return (0);
if (arg_parse_window(data->target, &s, &idx) != 0) { if (arg_parse_window(data->target, &s, &idx) != 0) {
ctx->error(ctx, "bad window: %s", data->target); ctx->error(ctx, "bad window: %s", data->target);
return; return (-1);
} }
if (s == NULL) if (s == NULL)
s = ctx->cursession; s = ctx->cursession;
@ -131,7 +131,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
s = cmd_current_session(ctx); s = cmd_current_session(ctx);
if (s == NULL) { if (s == NULL) {
ctx->error(ctx, "session not found: %s", data->target); ctx->error(ctx, "session not found: %s", data->target);
return; return (-1);
} }
cmd = data->cmd; 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); wl = session_new(s, data->name, cmd, cwd, idx);
if (wl == NULL) { if (wl == NULL) {
ctx->error(ctx, "command failed: %s", cmd); ctx->error(ctx, "command failed: %s", cmd);
return; return (-1);
} }
if (!data->flag_detached) { if (!data->flag_detached) {
session_select(s, wl->idx); session_select(s, wl->idx);
@ -153,8 +153,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
} else } else
server_status_session(s); server_status_session(s);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-next-window.c,v 1.14 2009-01-18 18:31:45 nicm Exp $ */ /* $Id: cmd-next-window.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -25,7 +25,7 @@
*/ */
void cmd_next_window_init(struct cmd *, int); 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 = { const struct cmd_entry cmd_next_window_entry = {
"next-window", "next", "next-window", "next",
@ -52,7 +52,7 @@ cmd_next_window_init(struct cmd *self, int key)
data->flags |= CMD_AFLAG; data->flags |= CMD_AFLAG;
} }
void int
cmd_next_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_next_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
@ -60,7 +60,7 @@ cmd_next_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int activity; int activity;
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
activity = 0; activity = 0;
if (data->flags & CMD_AFLAG) 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) if (session_next(s, activity) == 0)
server_redraw_session(s); server_redraw_session(s);
else else {
ctx->error(ctx, "no next window"); ctx->error(ctx, "no next window");
return (-1);
}
recalculate_sizes(); recalculate_sizes();
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-paste-buffer.c,v 1.14 2009-01-11 23:31:46 nicm Exp $ */ /* $Id: cmd-paste-buffer.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Paste paste buffer if present. * 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 = { const struct cmd_entry cmd_paste_buffer_entry = {
"paste-buffer", "pasteb", "paste-buffer", "pasteb",
@ -41,7 +41,7 @@ const struct cmd_entry cmd_paste_buffer_entry = {
cmd_buffer_print cmd_buffer_print
}; };
void int
cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_buffer_data *data = self->data; 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; struct paste_buffer *pb;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL) if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return; return (-1);
w = wl->window; w = wl->window;
if (data->buffer == -1) if (data->buffer == -1)
pb = paste_get_top(&s->buffers); pb = paste_get_top(&s->buffers);
else { 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); ctx->error(ctx, "no buffer %d", data->buffer);
return (-1);
}
} }
if (pb != NULL) 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); paste_free_index(&s->buffers, data->buffer);
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-previous-window.c,v 1.14 2009-01-18 18:31:45 nicm Exp $ */ /* $Id: cmd-previous-window.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -25,7 +25,7 @@
*/ */
void cmd_previous_window_init(struct cmd *, int); 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 = { const struct cmd_entry cmd_previous_window_entry = {
"previous-window", "prev", "previous-window", "prev",
@ -52,7 +52,7 @@ cmd_previous_window_init(struct cmd *self, int key)
data->flags |= CMD_AFLAG; data->flags |= CMD_AFLAG;
} }
void int
cmd_previous_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_previous_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
@ -60,7 +60,7 @@ cmd_previous_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int activity; int activity;
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
activity = 0; activity = 0;
if (data->flags & CMD_AFLAG) 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) if (session_previous(s, activity) == 0)
server_redraw_session(s); server_redraw_session(s);
else else {
ctx->error(ctx, "no previous window"); ctx->error(ctx, "no previous window");
return (-1);
}
recalculate_sizes(); recalculate_sizes();
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-refresh-client.c,v 1.7 2008-06-18 22:21:51 nicm Exp $ */ /* $Id: cmd-refresh-client.c,v 1.8 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Refresh client. * 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 = { const struct cmd_entry cmd_refresh_client_entry = {
"refresh-client", "refresh", "refresh-client", "refresh",
@ -39,17 +39,16 @@ const struct cmd_entry cmd_refresh_client_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
struct client *c; struct client *c;
if ((c = cmd_find_client(ctx, data->target)) == NULL) if ((c = cmd_find_client(ctx, data->target)) == NULL)
return; return (-1);
server_redraw_client(c); server_redraw_client(c);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-rename-session.c,v 1.14 2009-01-14 22:16:56 nicm Exp $ */ /* $Id: cmd-rename-session.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Change session name. * 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 = { const struct cmd_entry cmd_rename_session_entry = {
"rename-session", "rename", "rename-session", "rename",
@ -41,18 +41,17 @@ const struct cmd_entry cmd_rename_session_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
struct session *s; struct session *s;
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
xfree(s->name); xfree(s->name);
s->name = xstrdup(data->arg); s->name = xstrdup(data->arg);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-rename-window.c,v 1.24 2009-01-14 22:16:57 nicm Exp $ */ /* $Id: cmd-rename-window.c,v 1.25 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Rename a window. * 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 = { const struct cmd_entry cmd_rename_window_entry = {
"rename-window", "renamew", "rename-window", "renamew",
@ -41,7 +41,7 @@ const struct cmd_entry cmd_rename_window_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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; struct winlink *wl;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL) if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return; return (-1);
xfree(wl->window->name); xfree(wl->window->name);
wl->window->name = xstrdup(data->arg); wl->window->name = xstrdup(data->arg);
server_status_session(s); server_status_session(s);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-resize-pane-down.c,v 1.5 2009-01-14 22:16:57 nicm Exp $ */ /* $Id: cmd-resize-pane-down.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
*/ */
void cmd_resize_pane_down_init(struct cmd *, int); 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 = { const struct cmd_entry cmd_resize_pane_down_entry = {
"resize-pane-down", "resizep-down", "resize-pane-down", "resizep-down",
@ -54,7 +54,7 @@ cmd_resize_pane_down_init(struct cmd *self, int key)
data->arg = xstrdup("5"); data->arg = xstrdup("5");
} }
void int
cmd_resize_pane_down_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_resize_pane_down_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_pane_data *data = self->data; 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; u_int adjust;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
if (data->pane == -1) if (data->pane == -1)
wp = wl->window->active; wp = wl->window->active;
else { else {
wp = window_pane_at_index(wl->window, data->pane); wp = window_pane_at_index(wl->window, data->pane);
if (wp == NULL) { if (wp == NULL) {
ctx->error(ctx, "no pane: %d", data->pane); 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); adjust = strtonum(data->arg, 1, INT_MAX, &errstr);
if (errstr != NULL) { if (errstr != NULL) {
ctx->error(ctx, "adjustment %s: %s", errstr, data->arg); 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 (TAILQ_NEXT(wp, entry) == NULL) {
if (wp == TAILQ_FIRST(&wl->window->panes)) { if (wp == TAILQ_FIRST(&wl->window->panes)) {
/* Only one pane. */ /* Only one pane. */
goto out; return (0);
} }
wp = TAILQ_PREV(wp, window_panes, entry); 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); server_redraw_window(wl->window);
out: return (0);
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-resize-pane-up.c,v 1.5 2009-01-14 22:16:57 nicm Exp $ */ /* $Id: cmd-resize-pane-up.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
*/ */
void cmd_resize_pane_up_init(struct cmd *, int); 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 = { const struct cmd_entry cmd_resize_pane_up_entry = {
"resize-pane-up", "resizep-up", "resize-pane-up", "resizep-up",
@ -54,7 +54,7 @@ cmd_resize_pane_up_init(struct cmd *self, int key)
data->arg = xstrdup("5"); data->arg = xstrdup("5");
} }
void int
cmd_resize_pane_up_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_resize_pane_up_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_pane_data *data = self->data; 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; u_int adjust;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
if (data->pane == -1) if (data->pane == -1)
wp = wl->window->active; wp = wl->window->active;
else { else {
wp = window_pane_at_index(wl->window, data->pane); wp = window_pane_at_index(wl->window, data->pane);
if (wp == NULL) { if (wp == NULL) {
ctx->error(ctx, "no pane: %d", data->pane); 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); adjust = strtonum(data->arg, 1, INT_MAX, &errstr);
if (errstr != NULL) { if (errstr != NULL) {
ctx->error(ctx, "adjustment %s: %s", errstr, data->arg); 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 (wq == NULL) {
if (wp == TAILQ_FIRST(&wl->window->panes)) { if (wp == TAILQ_FIRST(&wl->window->panes)) {
/* Only one pane. */ /* Only one pane. */
goto out; return (0);
} }
wq = wp; wq = wp;
wp = TAILQ_PREV(wq, window_panes, entry); 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); server_redraw_window(wl->window);
out: return (0);
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-respawn-window.c,v 1.11 2009-01-14 22:16:57 nicm Exp $ */ /* $Id: cmd-respawn-window.c,v 1.12 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Respawn a window (restart the command). Kill existing if -k given. * 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 = { const struct cmd_entry cmd_respawn_window_entry = {
"respawn-window", "respawnw", "respawn-window", "respawnw",
@ -41,7 +41,7 @@ const struct cmd_entry cmd_respawn_window_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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; u_int i;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL) if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return; return (-1);
w = wl->window; w = wl->window;
if (!(data->flags & CMD_KFLAG)) { if (!(data->flags & CMD_KFLAG)) {
@ -63,7 +63,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
continue; continue;
ctx->error(ctx, ctx->error(ctx,
"window still active: %s:%d", s->name, wl->idx); "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); window_pane_resize(wp, w->sx, w->sy);
if (window_pane_spawn(wp, data->arg, NULL, env) != 0) { if (window_pane_spawn(wp, data->arg, NULL, env) != 0) {
ctx->error(ctx, "respawn failed: %s:%d", s->name, wl->idx); ctx->error(ctx, "respawn failed: %s:%d", s->name, wl->idx);
return; return (-1);
} }
screen_reinit(&wp->base); screen_reinit(&wp->base);
recalculate_sizes(); recalculate_sizes();
server_redraw_window(w); server_redraw_window(w);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-save-buffer.c,v 1.2 2009-01-14 22:16:57 nicm Exp $ */ /* $Id: cmd-save-buffer.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@ -28,7 +28,7 @@
* Saves a session paste buffer to a file. * 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 = { const struct cmd_entry cmd_save_buffer_entry = {
"save-buffer", "saveb", "save-buffer", "saveb",
@ -43,7 +43,7 @@ const struct cmd_entry cmd_save_buffer_entry = {
cmd_buffer_print cmd_buffer_print
}; };
void int
cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_buffer_data *data = self->data; struct cmd_buffer_data *data = self->data;
@ -53,18 +53,22 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
FILE *f; FILE *f;
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
if (data->buffer == -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"); ctx->error(ctx, "no buffers");
return (-1);
}
} else { } 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); ctx->error(ctx, "no buffer %d", data->buffer);
return (-1);
}
} }
if (pb == NULL) if (pb == NULL)
return; return (0);
mask = umask(S_IRWXG | S_IRWXO); mask = umask(S_IRWXG | S_IRWXO);
if (data->flags & CMD_AFLAG) 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"); f = fopen(data->arg, "w");
if (f == NULL) { if (f == NULL) {
ctx->error(ctx, "%s: %s", data->arg, strerror(errno)); ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
return; return (-1);
} }
if (fwrite(pb->data, 1, strlen(pb->data), f) != strlen(pb->data)) { if (fwrite(pb->data, 1, strlen(pb->data), f) != strlen(pb->data)) {
ctx->error(ctx, "%s: fwrite error", data->arg); ctx->error(ctx, "%s: fwrite error", data->arg);
fclose(f); fclose(f);
return; return (-1);
} }
fclose(f); fclose(f);
umask(mask); umask(mask);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-scroll-mode.c,v 1.14 2009-01-11 23:31:46 nicm Exp $ */ /* $Id: cmd-scroll-mode.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Enter scroll mode. * 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 = { const struct cmd_entry cmd_scroll_mode_entry = {
"scroll-mode", NULL, "scroll-mode", NULL,
@ -39,17 +39,16 @@ const struct cmd_entry cmd_scroll_mode_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_scroll_mode_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_scroll_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
struct winlink *wl; struct winlink *wl;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
window_pane_set_mode(wl->window->active, &window_scroll_mode); window_pane_set_mode(wl->window->active, &window_scroll_mode);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-select-pane.c,v 1.1 2009-01-14 19:56:55 nicm Exp $ */ /* $Id: cmd-select-pane.c,v 1.2 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Select pane. * 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 = { const struct cmd_entry cmd_select_pane_entry = {
"select-pane", "selectp", "select-pane", "selectp",
@ -39,7 +39,7 @@ const struct cmd_entry cmd_select_pane_entry = {
cmd_pane_print cmd_pane_print
}; };
void int
cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_pane_data *data = self->data; 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; struct window_pane *wp;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
if (data->pane == -1) if (data->pane == -1)
wp = wl->window->active; wp = wl->window->active;
else { else {
wp = window_pane_at_index(wl->window, data->pane); wp = window_pane_at_index(wl->window, data->pane);
if (wp == NULL) { if (wp == NULL) {
ctx->error(ctx, "no pane: %d", data->pane); ctx->error(ctx, "no pane: %d", data->pane);
return; return (-1);
} }
} }
if (wp->flags & PANE_HIDDEN) { if (wp->flags & PANE_HIDDEN) {
ctx->error(ctx, "pane %d is hidden", data->pane); ctx->error(ctx, "pane %d is hidden", data->pane);
return; return (-1);
} }
window_set_active_pane(wl->window, wp); window_set_active_pane(wl->window, wp);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-select-prompt.c,v 1.5 2009-01-11 00:48:42 nicm Exp $ */ /* $Id: cmd-select-prompt.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Prompt for window index and select it. * 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 *); int cmd_select_prompt_callback(void *, const char *);
@ -43,22 +43,21 @@ const struct cmd_entry cmd_select_prompt_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_select_prompt_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_select_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
struct client *c; struct client *c;
if ((c = cmd_find_client(ctx, data->target)) == NULL) if ((c = cmd_find_client(ctx, data->target)) == NULL)
return; return (-1);
if (c->prompt_string != NULL) if (c->prompt_string != NULL)
return; return (0);
server_set_client_prompt(c, "index ", cmd_select_prompt_callback, c, 0); server_set_client_prompt(c, "index ", cmd_select_prompt_callback, c, 0);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
int int

View File

@ -1,4 +1,4 @@
/* $Id: cmd-select-window.c,v 1.20 2008-12-10 20:25:41 nicm Exp $ */ /* $Id: cmd-select-window.c,v 1.21 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
*/ */
void cmd_select_window_init(struct cmd *, int); 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 = { const struct cmd_entry cmd_select_window_entry = {
"select-window", "selectw", "select-window", "selectw",
@ -53,7 +53,7 @@ cmd_select_window_init(struct cmd *self, int key)
xasprintf(&data->target, ":%d", key - '0'); xasprintf(&data->target, ":%d", key - '0');
} }
void int
cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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; struct session *s;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL) if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return; return (-1);
if (session_select(s, wl->idx) == 0) if (session_select(s, wl->idx) == 0)
server_redraw_session(s); server_redraw_session(s);
recalculate_sizes(); recalculate_sizes();
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-send-keys.c,v 1.17 2009-01-18 14:40:48 nicm Exp $ */ /* $Id: cmd-send-keys.c,v 1.18 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
*/ */
int cmd_send_keys_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_send_keys_recv(struct cmd *, struct buffer *); void cmd_send_keys_recv(struct cmd *, struct buffer *);
void cmd_send_keys_free(struct cmd *); void cmd_send_keys_free(struct cmd *);
@ -106,7 +106,7 @@ usage:
return (-1); return (-1);
} }
void int
cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_send_keys_data *data = self->data; 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; u_int i;
if (data == NULL) if (data == NULL)
return; return (-1);
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
for (i = 0; i < data->nkeys; i++) { for (i = 0; i < data->nkeys; i++) {
window_pane_key( window_pane_key(
wl->window->active, ctx->curclient, data->keys[i]); wl->window->active, ctx->curclient, data->keys[i]);
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-send-prefix.c,v 1.22 2009-01-14 22:13:30 nicm Exp $ */ /* $Id: cmd-send-prefix.c,v 1.23 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Send prefix key as a key. * 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 = { const struct cmd_entry cmd_send_prefix_entry = {
"send-prefix", NULL, "send-prefix", NULL,
@ -39,7 +39,7 @@ const struct cmd_entry cmd_send_prefix_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
@ -48,11 +48,10 @@ cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
int key; int key;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL) if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return; return (-1);
key = options_get_number(&s->options, "prefix"); key = options_get_number(&s->options, "prefix");
window_pane_key(wl->window->active, ctx->curclient, key); window_pane_key(wl->window->active, ctx->curclient, key);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-server-info.c,v 1.8 2009-01-18 18:06:37 nicm Exp $ */ /* $Id: cmd-server-info.c,v 1.9 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -31,7 +31,7 @@
* Show various information about server. * 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 = { const struct cmd_entry cmd_server_info_entry = {
"server-info", "info", "server-info", "info",
@ -46,7 +46,7 @@ const struct cmd_entry cmd_server_info_entry = {
NULL NULL
}; };
void int
cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx) cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{ {
struct tty_term *term; struct tty_term *term;
@ -141,6 +141,5 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
} }
ctx->print(ctx, ""); ctx->print(ctx, "");
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-set-buffer.c,v 1.5 2009-01-14 22:16:57 nicm Exp $ */ /* $Id: cmd-set-buffer.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Add or set a session paste buffer. * 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 = { const struct cmd_entry cmd_set_buffer_entry = {
"set-buffer", "setb", "set-buffer", "setb",
@ -41,7 +41,7 @@ const struct cmd_entry cmd_set_buffer_entry = {
cmd_buffer_print cmd_buffer_print
}; };
void int
cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_buffer_data *data = self->data; 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; u_int limit;
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
limit = options_get_number(&s->options, "buffer-limit"); limit = options_get_number(&s->options, "buffer-limit");
if (data->buffer == -1) if (data->buffer == -1)
paste_add(&s->buffers, data->arg, limit); paste_add(&s->buffers, data->arg, limit);
else { else if (paste_replace(&s->buffers, data->buffer, data->arg) != 0) {
if (paste_replace(&s->buffers, data->buffer, data->arg) != 0) ctx->error(ctx, "no buffer %d", data->buffer);
ctx->error(ctx, "no buffer %d", data->buffer); return (-1);
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-set-option.c,v 1.54 2009-01-14 22:13:30 nicm Exp $ */ /* $Id: cmd-set-option.c,v 1.55 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
* Set an option. * 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 = { const struct cmd_entry cmd_set_option_entry = {
"set-option", "set", "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 }, { "status-right-length", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL },
}; };
void int
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_option_data *data = self->data; 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; oo = &global_options;
else { else {
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
oo = &s->options; oo = &s->options;
} }
if (*data->option == '\0') { if (*data->option == '\0') {
ctx->error(ctx, "invalid option"); ctx->error(ctx, "invalid option");
return; return (-1);
} }
entry = NULL; entry = NULL;
@ -98,7 +98,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
continue; continue;
if (entry != NULL) { if (entry != NULL) {
ctx->error(ctx, "ambiguous option: %s", data->option); ctx->error(ctx, "ambiguous option: %s", data->option);
return; return (-1);
} }
entry = &set_option_table[i]; entry = &set_option_table[i];
@ -108,25 +108,25 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
} }
if (entry == NULL) { if (entry == NULL) {
ctx->error(ctx, "unknown option: %s", data->option); ctx->error(ctx, "unknown option: %s", data->option);
return; return (-1);
} }
if (data->flags & CMD_UFLAG) { if (data->flags & CMD_UFLAG) {
if (data->flags & CMD_GFLAG) { if (data->flags & CMD_GFLAG) {
ctx->error(ctx, ctx->error(ctx,
"can't unset global option: %s", entry->name); "can't unset global option: %s", entry->name);
return; return (-1);
} }
if (data->value != NULL) { if (data->value != NULL) {
ctx->error(ctx, ctx->error(ctx,
"value passed to unset option: %s", entry->name); "value passed to unset option: %s", entry->name);
return; return (-1);
} }
if (options_remove(oo, entry->name) != 0) { if (options_remove(oo, entry->name) != 0) {
ctx->error(ctx, ctx->error(ctx,
"can't unset option, not set: %s", entry->name); "can't unset option, not set: %s", entry->name);
return; return (-1);
} }
ctx->info(ctx, "unset option: %s", entry->name); ctx->info(ctx, "unset option: %s", entry->name);
} else { } else {
@ -159,6 +159,5 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
server_redraw_client(c); server_redraw_client(c);
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-set-password.c,v 1.2 2009-01-18 14:40:48 nicm Exp $ */ /* $Id: cmd-set-password.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -28,7 +28,7 @@
*/ */
int cmd_set_password_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_set_password_recv(struct cmd *, struct buffer *); void cmd_set_password_recv(struct cmd *, struct buffer *);
void cmd_set_password_free(struct cmd *); void cmd_set_password_free(struct cmd *);
@ -102,14 +102,14 @@ usage:
return (-1); return (-1);
} }
void int
cmd_set_password_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_set_password_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_set_password_data *data = self->data; struct cmd_set_password_data *data = self->data;
if (data->password == NULL) { if (data->password == NULL) {
ctx->error(ctx, "failed to encrypt password"); ctx->error(ctx, "failed to encrypt password");
return; return (-1);
} }
if (server_password != NULL) if (server_password != NULL)
@ -120,8 +120,7 @@ cmd_set_password_exec(struct cmd *self, struct cmd_ctx *ctx)
server_password = xstrdup(data->password); server_password = xstrdup(data->password);
log_debug("pw now %s", server_password); log_debug("pw now %s", server_password);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-set-window-option.c,v 1.20 2009-01-18 14:40:48 nicm Exp $ */ /* $Id: cmd-set-window-option.c,v 1.21 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -28,7 +28,7 @@
*/ */
int cmd_set_window_option_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_set_window_option_recv(struct cmd *, struct buffer *); void cmd_set_window_option_recv(struct cmd *, struct buffer *);
void cmd_set_window_option_free(struct cmd *); 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 }, { "xterm-keys", SET_OPTION_FLAG, 0, 0, NULL },
}; };
void int
cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_option_data *data = self->data; 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; oo = &global_window_options;
else { else {
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
oo = &wl->window->options; oo = &wl->window->options;
} }
if (*data->option == '\0') { if (*data->option == '\0') {
ctx->error(ctx, "invalid option"); ctx->error(ctx, "invalid option");
return; return (-1);
} }
entry = NULL; entry = NULL;
@ -99,7 +99,7 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
continue; continue;
if (entry != NULL) { if (entry != NULL) {
ctx->error(ctx, "ambiguous option: %s", data->option); ctx->error(ctx, "ambiguous option: %s", data->option);
return; return (-1);
} }
entry = &set_window_option_table[i]; 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) { if (entry == NULL) {
ctx->error(ctx, "unknown option: %s", data->option); ctx->error(ctx, "unknown option: %s", data->option);
return; return (-1);
} }
if (data->flags & CMD_UFLAG) { if (data->flags & CMD_UFLAG) {
if (data->flags & CMD_GFLAG) { if (data->flags & CMD_GFLAG) {
ctx->error(ctx, ctx->error(ctx,
"can't unset global option: %s", entry->name); "can't unset global option: %s", entry->name);
return; return (-1);
} }
if (data->value != NULL) { if (data->value != NULL) {
ctx->error(ctx, ctx->error(ctx,
"value passed to unset option: %s", entry->name); "value passed to unset option: %s", entry->name);
return; return (-1);
} }
if (options_remove(oo, entry->name) != 0) { if (options_remove(oo, entry->name) != 0) {
ctx->error(ctx, ctx->error(ctx,
"can't unset option, not set: %s", entry->name); "can't unset option, not set: %s", entry->name);
return; return (-1);
} }
ctx->info(ctx, "unset option: %s", entry->name); ctx->info(ctx, "unset option: %s", entry->name);
} else { } else {
@ -160,6 +160,5 @@ cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx)
server_redraw_client(c); server_redraw_client(c);
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-show-buffer.c,v 1.3 2008-12-10 20:25:41 nicm Exp $ */ /* $Id: cmd-show-buffer.c,v 1.4 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Show a session paste buffer. * 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 = { const struct cmd_entry cmd_show_buffer_entry = {
"show-buffer", "showb", "show-buffer", "showb",
@ -41,7 +41,7 @@ const struct cmd_entry cmd_show_buffer_entry = {
cmd_buffer_print cmd_buffer_print
}; };
void int
cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_buffer_data *data = self->data; 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; size_t len;
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
if (data->buffer == -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"); ctx->error(ctx, "no buffers");
} else { return (-1);
if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) }
ctx->error(ctx, "no buffer %d", data->buffer); } else if ((pb = paste_get_index(&s->buffers, data->buffer)) == NULL) {
ctx->error(ctx, "no buffer %d", data->buffer);
return (-1);
} }
if (pb != NULL) { if (pb != NULL) {
@ -83,6 +85,5 @@ cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
ctx->print(ctx, buf); ctx->print(ctx, buf);
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-show-options.c,v 1.9 2008-12-10 20:25:41 nicm Exp $ */ /* $Id: cmd-show-options.c,v 1.10 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
* Show options. * 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 = { const struct cmd_entry cmd_show_options_entry = {
"show-options", "show", "show-options", "show",
@ -42,7 +42,7 @@ const struct cmd_entry cmd_show_options_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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; oo = &global_options;
else { else {
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
oo = &s->options; oo = &s->options;
} }
@ -101,6 +101,5 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
} }
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-show-window-options.c,v 1.5 2008-12-10 20:25:41 nicm Exp $ */ /* $Id: cmd-show-window-options.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
* Show window options. * 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 = { const struct cmd_entry cmd_show_window_options_entry = {
"show-window-options", "showw", "show-window-options", "showw",
@ -42,7 +42,7 @@ const struct cmd_entry cmd_show_window_options_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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; oo = &global_window_options;
else { else {
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
oo = &wl->window->options; oo = &wl->window->options;
} }
@ -101,6 +101,5 @@ cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx)
} }
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-source-file.c,v 1.4 2009-01-18 14:40:48 nicm Exp $ */ /* $Id: cmd-source-file.c,v 1.5 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org> * Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
@ -25,7 +25,7 @@
*/ */
int cmd_source_file_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_source_file_recv(struct cmd *, struct buffer *); void cmd_source_file_recv(struct cmd *, struct buffer *);
void cmd_source_file_free(struct cmd *); void cmd_source_file_free(struct cmd *);
@ -88,7 +88,7 @@ usage:
return (-1); return (-1);
} }
void int
cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_source_file_data *data = self->data; 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) { if (load_cfg(data->path, &cause) != 0) {
ctx->error(ctx, "%s", cause); ctx->error(ctx, "%s", cause);
xfree(cause); xfree(cause);
return; return (-1);
} }
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-split-window.c,v 1.5 2009-01-18 14:40:48 nicm Exp $ */ /* $Id: cmd-split-window.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -28,7 +28,7 @@
*/ */
int cmd_split_window_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_split_window_recv(struct cmd *, struct buffer *); void cmd_split_window_recv(struct cmd *, struct buffer *);
void cmd_split_window_free(struct cmd *); void cmd_split_window_free(struct cmd *);
@ -104,7 +104,7 @@ usage:
return (-1); return (-1);
} }
void int
cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_split_window_data *data = self->data; 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; u_int i, hlimit;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL) if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return; return (-1);
w = wl->window; w = wl->window;
if (session_index(s, &i) != 0) 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"); hlimit = options_get_number(&s->options, "history-limit");
if ((wp = window_add_pane(w, cmd, cwd, env, hlimit)) == NULL) { if ((wp = window_add_pane(w, cmd, cwd, env, hlimit)) == NULL) {
ctx->error(ctx, "command failed: %s", cmd); ctx->error(ctx, "command failed: %s", cmd);
return; return (-1);
} }
server_redraw_window(w); server_redraw_window(w);
@ -148,8 +148,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
} else } else
server_status_session(s); server_status_session(s);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-start-server.c,v 1.5 2008-06-05 21:25:00 nicm Exp $ */ /* $Id: cmd-start-server.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Start the server and do nothing else. * 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 = { const struct cmd_entry cmd_start_server_entry = {
"start-server", "start", "start-server", "start",
@ -39,9 +39,8 @@ const struct cmd_entry cmd_start_server_entry = {
NULL NULL
}; };
void int
cmd_start_server_exec(unused struct cmd *self, struct cmd_ctx *ctx) cmd_start_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
{ {
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-suspend-client.c,v 1.1 2009-01-18 12:09:42 nicm Exp $ */ /* $Id: cmd-suspend-client.c,v 1.2 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,7 @@
* Suspend client with SIGTSTP. * 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 { struct cmd_suspend_client_data {
char *name; char *name;
@ -47,19 +47,18 @@ const struct cmd_entry cmd_suspend_client_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
struct client *c; struct client *c;
if ((c = cmd_find_client(ctx, data->target)) == NULL) if ((c = cmd_find_client(ctx, data->target)) == NULL)
return; return (-1);
tty_stop_tty(&c->tty); tty_stop_tty(&c->tty);
c->flags |= CLIENT_SUSPENDED; c->flags |= CLIENT_SUSPENDED;
server_write_client(c, MSG_SUSPEND, NULL, 0); server_write_client(c, MSG_SUSPEND, NULL, 0);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-swap-window.c,v 1.14 2008-12-10 20:25:41 nicm Exp $ */ /* $Id: cmd-swap-window.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,7 +26,7 @@
* Swap one window with another. * 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 = { const struct cmd_entry cmd_swap_window_entry = {
"swap-window", "swapw", "swap-window", "swapw",
@ -41,7 +41,7 @@ const struct cmd_entry cmd_swap_window_entry = {
cmd_srcdst_print cmd_srcdst_print
}; };
void int
cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_srcdst_data *data = self->data; 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; struct window *w;
if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL) 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) if ((wl_dst = cmd_find_window(ctx, data->dst, &dst)) == NULL)
return; return (-1);
if (wl_dst->window == wl_src->window) if (wl_dst->window == wl_src->window)
goto out; return (0);
w = wl_dst->window; w = wl_dst->window;
wl_dst->window = wl_src->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); server_redraw_session(dst);
recalculate_sizes(); recalculate_sizes();
out: return (0);
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-switch-client.c,v 1.14 2009-01-18 14:40:48 nicm Exp $ */ /* $Id: cmd-switch-client.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -28,7 +28,7 @@
*/ */
int cmd_switch_client_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_switch_client_recv(struct cmd *, struct buffer *); void cmd_switch_client_recv(struct cmd *, struct buffer *);
void cmd_switch_client_free(struct cmd *); void cmd_switch_client_free(struct cmd *);
@ -88,7 +88,7 @@ usage:
return (-1); return (-1);
} }
void int
cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_switch_client_data *data = self->data; 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; struct session *s;
if (data == NULL) if (data == NULL)
return; return (0);
if ((c = cmd_find_client(ctx, data->name)) == NULL) if ((c = cmd_find_client(ctx, data->name)) == NULL)
return; return (-1);
if ((s = cmd_find_session(ctx, data->target)) == NULL) if ((s = cmd_find_session(ctx, data->target)) == NULL)
return; return (-1);
c->session = s; c->session = s;
recalculate_sizes(); recalculate_sizes();
server_redraw_client(c); server_redraw_client(c);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-unbind-key.c,v 1.15 2008-12-10 20:25:41 nicm Exp $ */ /* $Id: cmd-unbind-key.c,v 1.16 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -25,7 +25,7 @@
*/ */
int cmd_unbind_key_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_unbind_key_recv(struct cmd *, struct buffer *); void cmd_unbind_key_recv(struct cmd *, struct buffer *);
void cmd_unbind_key_free(struct cmd *); void cmd_unbind_key_free(struct cmd *);
@ -81,18 +81,17 @@ error:
return (-1); return (-1);
} }
void int
cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx) cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
{ {
struct cmd_unbind_key_data *data = self->data; struct cmd_unbind_key_data *data = self->data;
if (data == NULL) if (data == NULL)
return; return (0);
key_bindings_remove(data->key); key_bindings_remove(data->key);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-unlink-window.c,v 1.12 2008-06-06 20:02:27 nicm Exp $ */ /* $Id: cmd-unlink-window.c,v 1.13 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Unlink a window, unless it would be destroyed by doing so (only one link). * 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 = { const struct cmd_entry cmd_unlink_window_entry = {
"unlink-window", "unlinkw", "unlink-window", "unlinkw",
@ -39,7 +39,7 @@ const struct cmd_entry cmd_unlink_window_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; struct cmd_target_data *data = self->data;
@ -50,11 +50,11 @@ cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int destroyed; int destroyed;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL) if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return; return (-1);
if (wl->window->references == 1) { if (wl->window->references == 1) {
ctx->error(ctx, "window is only linked to one session"); ctx->error(ctx, "window is only linked to one session");
return; return (-1);
} }
destroyed = session_detach(s, wl); destroyed = session_detach(s, wl);
@ -70,6 +70,5 @@ cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
} }
recalculate_sizes(); recalculate_sizes();
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: cmd-up-pane.c,v 1.2 2009-01-14 22:13:30 nicm Exp $ */ /* $Id: cmd-up-pane.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,7 +24,7 @@
* Move up a pane. * 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 = { const struct cmd_entry cmd_up_pane_entry = {
"up-pane", "upp", "up-pane", "upp",
@ -39,7 +39,7 @@ const struct cmd_entry cmd_up_pane_entry = {
cmd_target_print cmd_target_print
}; };
void int
cmd_up_pane_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_up_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct cmd_target_data *data = self->data; 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; struct window *w;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return; return (-1);
w = wl->window; w = wl->window;
do { do {
@ -56,6 +56,5 @@ cmd_up_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
w->active = TAILQ_LAST(&w->panes, window_panes); w->active = TAILQ_LAST(&w->panes, window_panes);
} while (w->active->flags & PANE_HIDDEN); } while (w->active->flags & PANE_HIDDEN);
if (ctx->cmdclient != NULL) return (0);
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

8
cmd.c
View File

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.82 2009-01-18 17:20:52 nicm Exp $ */ /* $Id: cmd.c,v 1.83 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -170,14 +170,14 @@ usage:
return (NULL); return (NULL);
} }
void int
cmd_exec(struct cmd *cmd, struct cmd_ctx *ctx) cmd_exec(struct cmd *cmd, struct cmd_ctx *ctx)
{ {
if (server_locked) { if (server_locked) {
ctx->error(ctx, "server is locked"); ctx->error(ctx, "server is locked");
return; return (-1);
} }
cmd->entry->exec(cmd, ctx); return (cmd->entry->exec(cmd, ctx));
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: server-msg.c,v 1.59 2009-01-18 21:26:44 nicm Exp $ */ /* $Id: server-msg.c,v 1.60 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -132,14 +132,14 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
{ {
struct msg_command_data data; struct msg_command_data data;
struct cmd_ctx ctx; struct cmd_ctx ctx;
struct cmd_list *cmdlist;
struct cmd *cmd; struct cmd *cmd;
if (hdr->size < sizeof data) if (hdr->size < sizeof data)
fatalx("bad MSG_COMMAND size"); fatalx("bad MSG_COMMAND size");
buffer_read(c->in, &data, sizeof data); buffer_read(c->in, &data, sizeof data);
cmd = cmd_recv(c->in); cmdlist = cmd_list_recv(c->in);
log_debug("got command %s from client %d", cmd->entry->name, c->fd);
server_activity = time(NULL); server_activity = time(NULL);
ctx.error = server_msg_fn_command_error; ctx.error = server_msg_fn_command_error;
@ -152,16 +152,21 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
ctx.cmdclient = c; ctx.cmdclient = c;
/* XXX */ if (data.pid != -1) {
if (data.pid != -1 && (cmd->entry->flags & CMD_CANTNEST)) { TAILQ_FOREACH(cmd, cmdlist, qentry) {
server_msg_fn_command_error(&ctx, "sessions " if (cmd->entry->flags & CMD_CANTNEST) {
"should be nested with care. unset $TMUX to force"); server_msg_fn_command_error(&ctx,
cmd_free(cmd); "sessions should be nested with care. "
return (0); "unset $TMUX to force");
cmd_list_free(cmdlist);
return (0);
}
}
} }
cmd_exec(cmd, &ctx); if (cmd_list_exec(cmdlist, &ctx) != 1)
cmd_free(cmd); server_write_client(c, MSG_EXIT, NULL, 0);
cmd_list_free(cmdlist);
return (0); return (0);
} }

42
tmux.c
View File

@ -1,4 +1,4 @@
/* $Id: tmux.c,v 1.98 2009-01-18 12:09:42 nicm Exp $ */ /* $Id: tmux.c,v 1.99 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -179,7 +179,8 @@ main(int argc, char **argv)
struct client_ctx cctx; struct client_ctx cctx;
struct msg_command_data cmddata; struct msg_command_data cmddata;
struct buffer *b; struct buffer *b;
struct cmd *cmd; struct cmd_list *cmdlist;
struct cmd *cmd;
struct pollfd pfd; struct pollfd pfd;
struct hdr hdr; struct hdr hdr;
const char *shell; const char *shell;
@ -328,7 +329,7 @@ main(int argc, char **argv)
log_warnx("can't specify a command when unlocking"); log_warnx("can't specify a command when unlocking");
exit(1); exit(1);
} }
cmd = NULL; cmdlist = NULL;
if ((pass = getpass("Password: ")) == NULL) if ((pass = getpass("Password: ")) == NULL)
exit(1); exit(1);
start_server = 0; start_server = 0;
@ -337,11 +338,24 @@ main(int argc, char **argv)
cmd = xmalloc(sizeof *cmd); cmd = xmalloc(sizeof *cmd);
cmd->entry = &cmd_new_session_entry; cmd->entry = &cmd_new_session_entry;
cmd->entry->init(cmd, 0); cmd->entry->init(cmd, 0);
} else if ((cmd = cmd_parse(argc, argv, &cause)) == NULL) {
log_warnx("%s", cause); cmdlist = xmalloc(sizeof *cmdlist);
exit(1); 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); memset(&cctx, 0, sizeof cctx);
@ -354,8 +368,8 @@ main(int argc, char **argv)
client_write_server( client_write_server(
&cctx, MSG_UNLOCK, BUFFER_OUT(b), BUFFER_USED(b)); &cctx, MSG_UNLOCK, BUFFER_OUT(b), BUFFER_USED(b));
} else { } else {
cmd_send(cmd, b); cmd_list_send(cmdlist, b);
cmd_free(cmd); cmd_list_free(cmdlist);
client_fill_session(&cmddata); client_fill_session(&cmddata);
client_write_server2(&cctx, MSG_COMMAND, client_write_server2(&cctx, MSG_COMMAND,
&cmddata, sizeof cmddata, BUFFER_OUT(b), BUFFER_USED(b)); &cmddata, sizeof cmddata, BUFFER_OUT(b), BUFFER_USED(b));
@ -389,6 +403,7 @@ main(int argc, char **argv)
case MSG_EXIT: case MSG_EXIT:
n = 0; n = 0;
goto out; goto out;
case MSG_ERROR:
case MSG_PRINT: case MSG_PRINT:
if (hdr.size > INT_MAX - 1) if (hdr.size > INT_MAX - 1)
fatalx("bad MSG_PRINT size"); fatalx("bad MSG_PRINT size");
@ -397,15 +412,6 @@ main(int argc, char **argv)
if (hdr.size != 0) if (hdr.size != 0)
buffer_remove(cctx.srv_in, hdr.size); buffer_remove(cctx.srv_in, hdr.size);
goto restart; 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: case MSG_READY:
n = client_main(&cctx); n = client_main(&cctx);
goto out; goto out;

13
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.242 2009-01-19 17:16:09 nicm Exp $ */ /* $Id: tmux.h,v 1.243 2009-01-19 18:23:40 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -832,7 +832,7 @@ struct cmd_entry {
void (*init)(struct cmd *, int); void (*init)(struct cmd *, int);
int (*parse)(struct cmd *, int, char **, char **); 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 (*send)(struct cmd *, struct buffer *);
void (*recv)(struct cmd *, struct buffer *); void (*recv)(struct cmd *, struct buffer *);
void (*free)(struct cmd *); void (*free)(struct cmd *);
@ -1080,7 +1080,7 @@ int arg_parse_window(const char *, struct session **, int *);
/* cmd.c */ /* cmd.c */
struct cmd *cmd_parse(int, char **, char **); 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 *); void cmd_send(struct cmd *, struct buffer *);
struct cmd *cmd_recv(struct buffer *); struct cmd *cmd_recv(struct buffer *);
void cmd_free(struct cmd *); void cmd_free(struct cmd *);
@ -1157,7 +1157,7 @@ extern const struct cmd_entry cmd_up_pane_entry;
/* cmd-list.c */ /* cmd-list.c */
struct cmd_list *cmd_list_parse(int, char **, char **); 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 *); void cmd_list_send(struct cmd_list *, struct buffer *);
struct cmd_list *cmd_list_recv(struct buffer *); struct cmd_list *cmd_list_recv(struct buffer *);
void cmd_list_free(struct cmd_list *); 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]" #define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
void cmd_target_init(struct cmd *, int); void cmd_target_init(struct cmd *, int);
int cmd_target_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_target_recv(struct cmd *, struct buffer *); void cmd_target_recv(struct cmd *, struct buffer *);
void cmd_target_free(struct cmd *); 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]" #define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
void cmd_srcdst_init(struct cmd *, int); void cmd_srcdst_init(struct cmd *, int);
int cmd_srcdst_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_srcdst_recv(struct cmd *, struct buffer *); void cmd_srcdst_recv(struct cmd *, struct buffer *);
void cmd_srcdst_free(struct cmd *); 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]" #define CMD_BUFFER_CLIENT_USAGE "[-b buffer-index] [-t target-client]"
void cmd_buffer_init(struct cmd *, int); void cmd_buffer_init(struct cmd *, int);
int cmd_buffer_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_buffer_recv(struct cmd *, struct buffer *); void cmd_buffer_recv(struct cmd *, struct buffer *);
void cmd_buffer_free(struct cmd *); 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]" #define CMD_OPTION_CLIENT_USAGE "[-gu] [-t target-client] option [value]"
void cmd_option_init(struct cmd *, int); void cmd_option_init(struct cmd *, int);
int cmd_option_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_option_recv(struct cmd *, struct buffer *); void cmd_option_recv(struct cmd *, struct buffer *);
void cmd_option_free(struct cmd *); 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]" #define CMD_PANE_CLIENT_USAGE "[-t target-client] [-p pane-index]"
void cmd_pane_init(struct cmd *, int); void cmd_pane_init(struct cmd *, int);
int cmd_pane_parse(struct cmd *, int, char **, char **); 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_send(struct cmd *, struct buffer *);
void cmd_pane_recv(struct cmd *, struct buffer *); void cmd_pane_recv(struct cmd *, struct buffer *);
void cmd_pane_free(struct cmd *); void cmd_pane_free(struct cmd *);