mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-03 17:24:18 +00:00 
			
		
		
		
	Use ctx->client/ctx->session inline instead of temporary variables which were
being reused and causing confusion and problems.
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-attach-session.c,v 1.7 2007-10-19 09:21:25 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-attach-session.c,v 1.8 2007-11-13 09:53:46 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -83,24 +83,22 @@ void
 | 
			
		||||
cmd_attach_session_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_attach_session_data	*data = ptr;
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
	struct session			*s = ctx->session;
 | 
			
		||||
 | 
			
		||||
	if (ctx->flags & CMD_KEY)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	if (!(c->flags & CLIENT_TERMINAL)) {
 | 
			
		||||
	if (!(ctx->client->flags & CLIENT_TERMINAL)) {
 | 
			
		||||
		ctx->error(ctx, "not a terminal");
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (data->flag_detach)
 | 
			
		||||
		server_write_session(s, MSG_DETACH, NULL, 0);
 | 
			
		||||
	c->session = s;
 | 
			
		||||
		server_write_session(ctx->session, MSG_DETACH, NULL, 0);
 | 
			
		||||
	ctx->client->session = ctx->session;
 | 
			
		||||
 | 
			
		||||
	server_write_client(c, MSG_READY, NULL, 0);
 | 
			
		||||
	server_write_client(ctx->client, MSG_READY, NULL, 0);
 | 
			
		||||
	recalculate_sizes();
 | 
			
		||||
	server_redraw_client(c);
 | 
			
		||||
	server_redraw_client(ctx->client);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-bind-key.c,v 1.5 2007-10-19 09:21:25 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-bind-key.c,v 1.6 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -92,7 +92,6 @@ void
 | 
			
		||||
cmd_bind_key_exec(void *ptr, unused struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_bind_key_data	*data = ptr;
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
 | 
			
		||||
	if (data == NULL)
 | 
			
		||||
		return;
 | 
			
		||||
@@ -101,7 +100,7 @@ cmd_bind_key_exec(void *ptr, unused struct cmd_ctx *ctx)
 | 
			
		||||
	data->cmd = NULL;	/* avoid free */
 | 
			
		||||
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-detach-session.c,v 1.6 2007-10-19 09:21:25 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-detach-session.c,v 1.7 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -84,8 +84,7 @@ void
 | 
			
		||||
cmd_detach_session_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_detach_session_data	*data = ptr, std = { 0 };
 | 
			
		||||
	struct client			*c = ctx->client, *cp;
 | 
			
		||||
	struct session			*s = ctx->session;
 | 
			
		||||
	struct client			*c;
 | 
			
		||||
	u_int				 i;
 | 
			
		||||
 | 
			
		||||
	if (data == NULL)
 | 
			
		||||
@@ -93,16 +92,16 @@ cmd_detach_session_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
 | 
			
		||||
	if (data->flag_all) {
 | 
			
		||||
		for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
 | 
			
		||||
			cp = ARRAY_ITEM(&clients, i);
 | 
			
		||||
			if (cp == NULL || cp->session != s)
 | 
			
		||||
			c = ARRAY_ITEM(&clients, i);
 | 
			
		||||
			if (c == NULL || c->session != ctx->session)
 | 
			
		||||
				continue;
 | 
			
		||||
			server_write_client(cp, MSG_DETACH, NULL, 0);
 | 
			
		||||
			server_write_client(c, MSG_DETACH, NULL, 0);
 | 
			
		||||
		}
 | 
			
		||||
	} else if (ctx->flags & CMD_KEY)
 | 
			
		||||
		server_write_client(c, MSG_DETACH, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_DETACH, NULL, 0);
 | 
			
		||||
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-has-session.c,v 1.1 2007-10-25 17:44:24 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-has-session.c,v 1.2 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -44,8 +44,6 @@ const struct cmd_entry cmd_has_session_entry = {
 | 
			
		||||
void
 | 
			
		||||
cmd_has_session_exec(unused void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct client	*c = ctx->client;
 | 
			
		||||
	
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-kill-session.c,v 1.1 2007-11-12 14:21:40 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-kill-session.c,v 1.2 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -46,18 +46,17 @@ void
 | 
			
		||||
cmd_kill_session_exec(unused void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct client	*c;
 | 
			
		||||
	struct session	*s = ctx->session;
 | 
			
		||||
	u_int		 i;
 | 
			
		||||
	
 | 
			
		||||
	for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
 | 
			
		||||
		c = ARRAY_ITEM(&clients, i);
 | 
			
		||||
		if (c->session == s) {
 | 
			
		||||
		if (c->session == ctx->session) {
 | 
			
		||||
			c->session = NULL;
 | 
			
		||||
			server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	session_destroy(s);
 | 
			
		||||
	session_destroy(ctx->session);
 | 
			
		||||
	
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-kill-window.c,v 1.4 2007-10-30 10:59:43 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-kill-window.c,v 1.5 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -90,8 +90,8 @@ void
 | 
			
		||||
cmd_kill_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_kill_window_data	*data = ptr, std = { -1 };
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
	struct session			*s = ctx->session;
 | 
			
		||||
	struct client			*c;
 | 
			
		||||
	struct winlinks			*wwl = &ctx->session->windows;
 | 
			
		||||
	struct winlink			*wl;
 | 
			
		||||
	u_int		 		 i;
 | 
			
		||||
	int		 		 destroyed;
 | 
			
		||||
@@ -100,16 +100,16 @@ cmd_kill_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
		data = &std;
 | 
			
		||||
 | 
			
		||||
	if (data->idx == -1)
 | 
			
		||||
		wl = s->curw;
 | 
			
		||||
	else if ((wl = winlink_find_by_index(&s->windows, data->idx)) == NULL) {
 | 
			
		||||
		wl = ctx->session->curw;
 | 
			
		||||
	else if ((wl = winlink_find_by_index(wwl, data->idx)) == NULL) {
 | 
			
		||||
		ctx->error(ctx, "no window %d", data->idx);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 	destroyed = session_detach(s, wl);
 | 
			
		||||
 	destroyed = session_detach(ctx->session, wl);
 | 
			
		||||
	for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
 | 
			
		||||
		c = ARRAY_ITEM(&clients, i);
 | 
			
		||||
		if (c == NULL || c->session != s)
 | 
			
		||||
		if (c == NULL || c->session != ctx->session)
 | 
			
		||||
			continue;
 | 
			
		||||
		if (destroyed) {
 | 
			
		||||
			c->session = NULL;
 | 
			
		||||
@@ -119,7 +119,7 @@ cmd_kill_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-last-window.c,v 1.3 2007-10-04 22:04:01 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-last-window.c,v 1.4 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -42,14 +42,11 @@ const struct cmd_entry cmd_last_window_entry = {
 | 
			
		||||
void
 | 
			
		||||
cmd_last_window_exec(unused void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct client	*c = ctx->client;
 | 
			
		||||
	struct session	*s = ctx->session;
 | 
			
		||||
 | 
			
		||||
	if (session_last(s) == 0)
 | 
			
		||||
		server_redraw_session(s);
 | 
			
		||||
	if (session_last(ctx->session) == 0)
 | 
			
		||||
		server_redraw_session(ctx->session);
 | 
			
		||||
	else
 | 
			
		||||
		ctx->error(ctx, "no last window"); 
 | 
			
		||||
	
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-link-window.c,v 1.4 2007-10-30 10:59:43 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-link-window.c,v 1.5 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -106,7 +106,6 @@ void
 | 
			
		||||
cmd_link_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_link_window_data	*data = ptr;
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
	struct session			*dst = ctx->session, *src;
 | 
			
		||||
	struct winlink			*wl;
 | 
			
		||||
 | 
			
		||||
@@ -144,7 +143,7 @@ cmd_link_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
		server_status_session(dst);
 | 
			
		||||
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-list-keys.c,v 1.3 2007-10-04 22:04:01 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-list-keys.c,v 1.4 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -42,7 +42,6 @@ const struct cmd_entry cmd_list_keys_entry = {
 | 
			
		||||
void
 | 
			
		||||
cmd_list_keys_exec(unused void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct client	*c = ctx->client;
 | 
			
		||||
	struct binding	*bd;
 | 
			
		||||
	const char	*key;
 | 
			
		||||
	u_int		 i;
 | 
			
		||||
@@ -55,5 +54,5 @@ cmd_list_keys_exec(unused void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-list-sessions.c,v 1.7 2007-10-26 12:29:07 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-list-sessions.c,v 1.8 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -43,8 +43,7 @@ const struct cmd_entry cmd_list_sessions_entry = {
 | 
			
		||||
void
 | 
			
		||||
cmd_list_sessions_exec(unused void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct client	*c = ctx->client;
 | 
			
		||||
	struct session	*s = ctx->session;
 | 
			
		||||
	struct session	*s;
 | 
			
		||||
	struct winlink	*wl;
 | 
			
		||||
	char		*tim;
 | 
			
		||||
	u_int		 i, n;
 | 
			
		||||
@@ -60,10 +59,10 @@ cmd_list_sessions_exec(unused void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
		tim = ctime(&s->tim);
 | 
			
		||||
		*strchr(tim, '\n') = '\0';
 | 
			
		||||
 | 
			
		||||
		ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]", s->name,
 | 
			
		||||
		    n, tim, s->sx, s->sy);
 | 
			
		||||
		ctx->print(ctx, "%s: %u windows"
 | 
			
		||||
		    " (created %s) [%ux%u]", s->name, n, tim, s->sx, s->sy);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-list-windows.c,v 1.6 2007-10-31 14:26:26 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-list-windows.c,v 1.7 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -42,18 +42,16 @@ const struct cmd_entry cmd_list_windows_entry = {
 | 
			
		||||
void
 | 
			
		||||
cmd_list_windows_exec(unused void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct client	*c = ctx->client;
 | 
			
		||||
	struct session	*s = ctx->session;
 | 
			
		||||
	struct winlink	*wl;
 | 
			
		||||
	struct window	*w;
 | 
			
		||||
 | 
			
		||||
	RB_FOREACH(wl, winlinks, &s->windows) {
 | 
			
		||||
	RB_FOREACH(wl, winlinks, &ctx->session->windows) {
 | 
			
		||||
		w = wl->window;
 | 
			
		||||
		ctx->print(ctx, "%d: %s \"%s\" (%s) [%ux%u]", wl->idx,
 | 
			
		||||
		    w->name, w->screen.title, ttyname(w->fd),
 | 
			
		||||
		ctx->print(ctx, "%d: %s \"%s\" (%s) [%ux%u]",
 | 
			
		||||
		    wl->idx, w->name, w->screen.title, ttyname(w->fd),
 | 
			
		||||
		    w->screen.sx, w->screen.sy);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-new-session.c,v 1.15 2007-11-09 16:04:29 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-new-session.c,v 1.16 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -100,7 +100,7 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_new_session_data	*data = ptr;
 | 
			
		||||
	struct cmd_new_session_data	 std = { NULL, NULL, NULL, 0 };
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
	struct client			*c;
 | 
			
		||||
	char				*cmd;
 | 
			
		||||
	u_int				 sy;
 | 
			
		||||
	
 | 
			
		||||
@@ -110,6 +110,7 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
	if (ctx->flags & CMD_KEY)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	c = ctx->client;
 | 
			
		||||
	if (!data->flag_detached && !(c->flags & CLIENT_TERMINAL)) {
 | 
			
		||||
		ctx->error(ctx, "not a terminal");
 | 
			
		||||
		return;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-new-window.c,v 1.11 2007-10-26 16:57:32 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-new-window.c,v 1.12 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -106,8 +106,6 @@ cmd_new_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_new_window_data	*data = ptr;
 | 
			
		||||
	struct cmd_new_window_data	 std = { NULL, NULL, -1, 0 };
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
	struct session			*s = ctx->session;
 | 
			
		||||
	struct winlink			*wl;
 | 
			
		||||
	char				*cmd;
 | 
			
		||||
 | 
			
		||||
@@ -120,18 +118,19 @@ cmd_new_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
 | 
			
		||||
	if (data->idx < 0)
 | 
			
		||||
		data->idx = -1;
 | 
			
		||||
	if ((wl = session_new(s, data->name, cmd, data->idx)) == NULL) {
 | 
			
		||||
	wl = session_new(ctx->session, data->name, cmd, data->idx);
 | 
			
		||||
	if (wl == NULL) {
 | 
			
		||||
		ctx->error(ctx, "command failed: %s", cmd);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	if (!data->flag_detached) {
 | 
			
		||||
		session_select(s, wl->idx);
 | 
			
		||||
		server_redraw_session(s);
 | 
			
		||||
		session_select(ctx->session, wl->idx);
 | 
			
		||||
		server_redraw_session(ctx->session);
 | 
			
		||||
	} else
 | 
			
		||||
		server_status_session(s);
 | 
			
		||||
		server_status_session(ctx->session);
 | 
			
		||||
	
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-next-window.c,v 1.3 2007-10-04 22:04:01 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-next-window.c,v 1.4 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -42,14 +42,11 @@ const struct cmd_entry cmd_next_window_entry = {
 | 
			
		||||
void
 | 
			
		||||
cmd_next_window_exec(unused void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct client	*c = ctx->client;
 | 
			
		||||
	struct session	*s = ctx->session;
 | 
			
		||||
 | 
			
		||||
	if (session_next(s) == 0)
 | 
			
		||||
		server_redraw_session(s);
 | 
			
		||||
	if (session_next(ctx->session) == 0)
 | 
			
		||||
		server_redraw_session(ctx->session);
 | 
			
		||||
	else
 | 
			
		||||
		ctx->error(ctx, "no next window"); 
 | 
			
		||||
	
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-previous-window.c,v 1.3 2007-10-04 22:04:01 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-previous-window.c,v 1.4 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -42,14 +42,11 @@ const struct cmd_entry cmd_previous_window_entry = {
 | 
			
		||||
void
 | 
			
		||||
cmd_previous_window_exec(unused void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct client	*c = ctx->client;
 | 
			
		||||
	struct session	*s = ctx->session;
 | 
			
		||||
 | 
			
		||||
	if (session_previous(s) == 0)
 | 
			
		||||
		server_redraw_session(s);
 | 
			
		||||
	if (session_previous(ctx->session) == 0)
 | 
			
		||||
		server_redraw_session(ctx->session);
 | 
			
		||||
	else
 | 
			
		||||
		ctx->error(ctx, "no previous window"); 
 | 
			
		||||
	
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-refresh-session.c,v 1.1 2007-10-19 09:21:25 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-refresh-session.c,v 1.2 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -84,8 +84,7 @@ void
 | 
			
		||||
cmd_refresh_session_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_refresh_session_data	*data = ptr, std = { 0 };
 | 
			
		||||
	struct client			*c = ctx->client, *cp;
 | 
			
		||||
	struct session			*s = ctx->session;
 | 
			
		||||
	struct client			*c;
 | 
			
		||||
	u_int				 i;
 | 
			
		||||
 | 
			
		||||
	if (data == NULL)
 | 
			
		||||
@@ -93,16 +92,16 @@ cmd_refresh_session_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
 | 
			
		||||
	if (data->flag_all) {
 | 
			
		||||
		for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
 | 
			
		||||
			cp = ARRAY_ITEM(&clients, i);
 | 
			
		||||
			if (cp == NULL || cp->session != s)
 | 
			
		||||
			c = ARRAY_ITEM(&clients, i);
 | 
			
		||||
			if (c == NULL || c->session != ctx->session)
 | 
			
		||||
				continue;
 | 
			
		||||
			server_redraw_client(cp);
 | 
			
		||||
			server_redraw_client(c);
 | 
			
		||||
		}
 | 
			
		||||
	} else if (ctx->flags & CMD_KEY)
 | 
			
		||||
		server_redraw_client(c);
 | 
			
		||||
		server_redraw_client(ctx->client);
 | 
			
		||||
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-rename-session.c,v 1.1 2007-11-09 11:02:01 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-rename-session.c,v 1.2 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -83,17 +83,15 @@ void
 | 
			
		||||
cmd_rename_session_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_rename_session_data	*data = ptr;
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
	struct session			*s = ctx->session;
 | 
			
		||||
 | 
			
		||||
	if (data == NULL)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	xfree(s->name);
 | 
			
		||||
	s->name = xstrdup(data->newname);
 | 
			
		||||
	xfree(ctx->session->name);
 | 
			
		||||
	ctx->session->name = xstrdup(data->newname);
 | 
			
		||||
	
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-rename-window.c,v 1.11 2007-11-09 11:02:01 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-rename-window.c,v 1.12 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -94,26 +94,25 @@ void
 | 
			
		||||
cmd_rename_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_rename_window_data	*data = ptr;
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
	struct session			*s = ctx->session;
 | 
			
		||||
	struct winlinks			*wwl = &ctx->session->windows;
 | 
			
		||||
	struct winlink			*wl;
 | 
			
		||||
 | 
			
		||||
	if (data == NULL)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	if (data->idx == -1)
 | 
			
		||||
		wl = s->curw;
 | 
			
		||||
	else if ((wl = winlink_find_by_index(&s->windows, data->idx)) == NULL) {
 | 
			
		||||
		wl = ctx->session->curw;
 | 
			
		||||
	else if ((wl = winlink_find_by_index(wwl, data->idx)) == NULL) {
 | 
			
		||||
		ctx->error(ctx, "no window %d", data->idx);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	xfree(wl->window->name);
 | 
			
		||||
	wl->window->name = xstrdup(data->newname);
 | 
			
		||||
 | 
			
		||||
	server_status_session(s);
 | 
			
		||||
	server_status_session(ctx->session);
 | 
			
		||||
	
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-select-window.c,v 1.8 2007-11-09 16:04:29 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-select-window.c,v 1.9 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -102,15 +102,13 @@ void
 | 
			
		||||
cmd_select_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_select_window_data	*data = ptr;
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
	struct session			*s = ctx->session;
 | 
			
		||||
 | 
			
		||||
	if (data == NULL)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	switch (session_select(s, data->idx)) {
 | 
			
		||||
	switch (session_select(ctx->session, data->idx)) {
 | 
			
		||||
	case 0:
 | 
			
		||||
		server_redraw_session(s);
 | 
			
		||||
		server_redraw_session(ctx->session);
 | 
			
		||||
		break;
 | 
			
		||||
	case 1:
 | 
			
		||||
		break;
 | 
			
		||||
@@ -120,7 +118,7 @@ cmd_select_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-send-prefix.c,v 1.3 2007-10-26 12:29:07 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-send-prefix.c,v 1.4 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -42,12 +42,11 @@ const struct cmd_entry cmd_send_prefix_entry = {
 | 
			
		||||
void
 | 
			
		||||
cmd_send_prefix_exec(unused void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct client	*c = ctx->client;
 | 
			
		||||
	struct window	*w = ctx->client->session->curw->window;
 | 
			
		||||
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY)) {
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	if (ctx->flags & CMD_KEY)
 | 
			
		||||
		input_translate_key(w->out, prefix_key);
 | 
			
		||||
 | 
			
		||||
	input_translate_key(c->session->curw->window->out, prefix_key);
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))	
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-set-option.c,v 1.11 2007-10-30 10:59:43 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-set-option.c,v 1.12 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -88,7 +88,7 @@ void
 | 
			
		||||
cmd_set_option_exec(void *ptr, unused struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_set_option_data	*data = ptr;
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
	struct client			*c;
 | 
			
		||||
	const char			*errstr;
 | 
			
		||||
	u_int				 i;
 | 
			
		||||
	int				 number, bool, key;
 | 
			
		||||
@@ -199,7 +199,7 @@ cmd_set_option_exec(void *ptr, unused struct cmd_ctx *ctx)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-swap-window.c,v 1.1 2007-10-30 11:10:33 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-swap-window.c,v 1.2 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -106,7 +106,6 @@ void
 | 
			
		||||
cmd_swap_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_swap_window_data	*data = ptr;
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
	struct session			*dst = ctx->session, *src;
 | 
			
		||||
	struct winlink			*srcwl, *dstwl;
 | 
			
		||||
	struct window			*w;
 | 
			
		||||
@@ -157,7 +156,7 @@ cmd_swap_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
		server_redraw_session(dst);
 | 
			
		||||
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-unbind-key.c,v 1.5 2007-10-19 09:21:26 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-unbind-key.c,v 1.6 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -85,7 +85,6 @@ void
 | 
			
		||||
cmd_unbind_key_exec(void *ptr, unused struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_unbind_key_data	*data = ptr;
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
 | 
			
		||||
	if (data == NULL)
 | 
			
		||||
		return;
 | 
			
		||||
@@ -93,7 +92,7 @@ cmd_unbind_key_exec(void *ptr, unused struct cmd_ctx *ctx)
 | 
			
		||||
	key_bindings_remove(data->key);
 | 
			
		||||
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: cmd-unlink-window.c,v 1.2 2007-10-30 10:59:43 nicm Exp $ */
 | 
			
		||||
/* $Id: cmd-unlink-window.c,v 1.3 2007-11-13 09:53:47 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -90,8 +90,8 @@ void
 | 
			
		||||
cmd_unlink_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_unlink_window_data	*data = ptr;
 | 
			
		||||
	struct client			*c = ctx->client;
 | 
			
		||||
	struct session			*s = ctx->session;
 | 
			
		||||
	struct client			*c;
 | 
			
		||||
	struct winlinks			*wwl = &ctx->session->windows;
 | 
			
		||||
	struct winlink			*wl;
 | 
			
		||||
	u_int		 		 i;
 | 
			
		||||
	int		 		 destroyed;
 | 
			
		||||
@@ -102,9 +102,9 @@ cmd_unlink_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
	if (data->idx < 0)
 | 
			
		||||
		data->idx = -1;
 | 
			
		||||
	if (data->idx == -1)
 | 
			
		||||
		wl = s->curw;
 | 
			
		||||
		wl = ctx->session->curw;
 | 
			
		||||
	else {
 | 
			
		||||
		wl = winlink_find_by_index(&s->windows, data->idx);
 | 
			
		||||
		wl = winlink_find_by_index(wwl, data->idx);
 | 
			
		||||
		if (wl == NULL) {
 | 
			
		||||
			ctx->error(ctx, "no window %d", data->idx);
 | 
			
		||||
			return;
 | 
			
		||||
@@ -116,10 +116,10 @@ cmd_unlink_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 	destroyed = session_detach(s, wl);
 | 
			
		||||
 	destroyed = session_detach(ctx->session, wl);
 | 
			
		||||
	for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
 | 
			
		||||
		c = ARRAY_ITEM(&clients, i);
 | 
			
		||||
		if (c == NULL || c->session != s)
 | 
			
		||||
		if (c == NULL || c->session != ctx->session)
 | 
			
		||||
			continue;
 | 
			
		||||
		if (destroyed) {
 | 
			
		||||
			c->session = NULL;
 | 
			
		||||
@@ -129,7 +129,7 @@ cmd_unlink_window_exec(void *ptr, struct cmd_ctx *ctx)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!(ctx->flags & CMD_KEY))
 | 
			
		||||
		server_write_client(c, MSG_EXIT, NULL, 0);
 | 
			
		||||
		server_write_client(ctx->client, MSG_EXIT, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user