aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2008-06-02 22:09:49 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2008-06-02 22:09:49 +0000
commit8731755ab4dc79f95f0a5ed8dfc8ae3bb9536256 (patch)
treeb561c06699cfbdb0d771f5b7eda29587662f13c8
parent95cc21c25180d0f2e7b488983e3078834343d162 (diff)
downloadrtmux-8731755ab4dc79f95f0a5ed8dfc8ae3bb9536256.tar.gz
rtmux-8731755ab4dc79f95f0a5ed8dfc8ae3bb9536256.tar.bz2
rtmux-8731755ab4dc79f95f0a5ed8dfc8ae3bb9536256.zip
Add a windowonly generic command and use it where appropriate. Also trim includes and unused.
-rw-r--r--TODO3
-rw-r--r--cmd-bind-key.c4
-rw-r--r--cmd-copy-mode.c23
-rw-r--r--cmd-detach-client.c4
-rw-r--r--cmd-generic.c110
-rw-r--r--cmd-has-session.c5
-rw-r--r--cmd-kill-session.c5
-rw-r--r--cmd-kill-window.c118
-rw-r--r--cmd-last-window.c5
-rw-r--r--cmd-list-windows.c5
-rw-r--r--cmd-next-window.c5
-rw-r--r--cmd-paste-buffer.c28
-rw-r--r--cmd-previous-window.c5
-rw-r--r--cmd-refresh-client.c4
-rw-r--r--cmd-scroll-mode.c21
-rw-r--r--cmd-send-prefix.c5
-rw-r--r--cmd-unlink-window.c124
-rw-r--r--tmux.h9
18 files changed, 187 insertions, 296 deletions
diff --git a/TODO b/TODO
index c90f9ede..3b0efa35 100644
--- a/TODO
+++ b/TODO
@@ -69,8 +69,7 @@
- poll(2) is broken on OS X/Darwin, a workaround for this would be nice
- different screen model? layers perhaps? hmm
- cfg file improvements: * comments to EOL
-- index on *-mode and other stuff that targets a window but is currently
- sessiononly
+- select-window can become windowonly...
---
[18:20] *priteau* i found something in tmux that could be tweaked to be better
diff --git a/cmd-bind-key.c b/cmd-bind-key.c
index 3ad55797..49535b97 100644
--- a/cmd-bind-key.c
+++ b/cmd-bind-key.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-bind-key.c,v 1.10 2008-06-02 21:08:36 nicm Exp $ */
+/* $Id: cmd-bind-key.c,v 1.11 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -90,7 +90,7 @@ error:
}
void
-cmd_bind_key_exec(void *ptr, unused struct cmd_ctx *ctx)
+cmd_bind_key_exec(void *ptr, struct cmd_ctx *ctx)
{
struct cmd_bind_key_data *data = ptr;
diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c
index 7c2246ec..20ea5c15 100644
--- a/cmd-copy-mode.c
+++ b/cmd-copy-mode.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-copy-mode.c,v 1.6 2008-06-02 21:36:51 nicm Exp $ */
+/* $Id: cmd-copy-mode.c,v 1.7 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,9 +18,6 @@
#include <sys/types.h>
-#include <getopt.h>
-#include <stdlib.h>
-
#include "tmux.h"
/*
@@ -31,24 +28,24 @@ void cmd_copy_mode_exec(void *, struct cmd_ctx *);
const struct cmd_entry cmd_copy_mode_entry = {
"copy-mode", NULL,
- CMD_SESSIONONLY_USAGE,
+ CMD_WINDOWONLY_USAGE,
0,
- cmd_sessiononly_parse,
+ cmd_windowonly_parse,
cmd_copy_mode_exec,
- cmd_sessiononly_send,
- cmd_sessiononly_recv,
- cmd_sessiononly_free
+ cmd_windowonly_send,
+ cmd_windowonly_recv,
+ cmd_windowonly_free
};
void
-cmd_copy_mode_exec(unused void *ptr, struct cmd_ctx *ctx)
+cmd_copy_mode_exec(void *ptr, struct cmd_ctx *ctx)
{
- struct session *s;
+ struct winlink *wl;
- if ((s = cmd_sessiononly_get(ptr, ctx)) == NULL)
+ if ((wl = cmd_windowonly_get(ptr, ctx, NULL)) == NULL)
return;
- window_set_mode(s->curw->window, &window_copy_mode);
+ window_set_mode(wl->window, &window_copy_mode);
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
diff --git a/cmd-detach-client.c b/cmd-detach-client.c
index fd0e5f55..f93df01b 100644
--- a/cmd-detach-client.c
+++ b/cmd-detach-client.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-detach-client.c,v 1.2 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-detach-client.c,v 1.3 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,8 +18,6 @@
#include <sys/types.h>
-#include <getopt.h>
-
#include "tmux.h"
/*
diff --git a/cmd-generic.c b/cmd-generic.c
index a27f5924..070bbd0d 100644
--- a/cmd-generic.c
+++ b/cmd-generic.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-generic.c,v 1.2 2008-06-02 21:08:36 nicm Exp $ */
+/* $Id: cmd-generic.c,v 1.3 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <getopt.h>
+#include <stdlib.h>
#include "tmux.h"
@@ -30,6 +31,11 @@ struct cmd_sessiononly_data {
char *sname;
};
+struct cmd_windowonly_data {
+ char *sname;
+ int idx;
+};
+
int
cmd_clientonly_parse(
struct cmd *self, void **ptr, int argc, char **argv, char **cause)
@@ -173,3 +179,105 @@ cmd_sessiononly_get(void *ptr, struct cmd_ctx *ctx)
return (cmd_find_session(ctx, data->sname));
return (cmd_find_session(ctx, NULL));
}
+
+int
+cmd_windowonly_parse(
+ struct cmd *self, void **ptr, int argc, char **argv, char **cause)
+{
+ struct cmd_windowonly_data *data;
+ int opt;
+ const char *errstr;
+
+ *ptr = data = xmalloc(sizeof *data);
+ data->sname = NULL;
+ data->idx = -1;
+
+ while ((opt = getopt(argc, argv, "i:s:")) != EOF) {
+ switch (opt) {
+ case 'i':
+ data->idx = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL) {
+ xasprintf(cause, "index %s", errstr);
+ goto error;
+ }
+ break;
+ case 's':
+ data->sname = xstrdup(optarg);
+ break;
+ default:
+ goto usage;
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ if (argc != 0)
+ goto usage;
+
+ return (0);
+
+usage:
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
+
+error:
+ self->entry->free(data);
+ return (-1);
+}
+
+void
+cmd_windowonly_send(void *ptr, struct buffer *b)
+{
+ struct cmd_windowonly_data *data = ptr;
+
+ buffer_write(b, data, sizeof *data);
+ cmd_send_string(b, data->sname);
+}
+
+void
+cmd_windowonly_recv(void **ptr, struct buffer *b)
+{
+ struct cmd_windowonly_data *data;
+
+ *ptr = data = xmalloc(sizeof *data);
+ buffer_read(b, data, sizeof *data);
+ data->sname = cmd_recv_string(b);
+}
+
+void
+cmd_windowonly_free(void *ptr)
+{
+ struct cmd_windowonly_data *data = ptr;
+
+ if (data->sname != NULL)
+ xfree(data->sname);
+ xfree(data);
+}
+
+struct winlink *
+cmd_windowonly_get(void *ptr, struct cmd_ctx *ctx, struct session **sp)
+{
+ struct cmd_windowonly_data *data = ptr;
+ struct session *s;
+ struct winlink *wl;
+ int idx;
+
+ if (data != NULL) {
+ s = cmd_find_session(ctx, data->sname);
+ idx = data->idx;
+ } else {
+ s = cmd_find_session(ctx, NULL);
+ idx = -1;
+ }
+ if (s == NULL)
+ return (NULL);
+
+ if (sp != NULL)
+ *sp = s;
+
+ if (idx == -1)
+ return (s->curw);
+ if ((wl = winlink_find_by_index(&s->windows, idx)) == NULL) {
+ ctx->error(ctx, "no window %d", idx);
+ return (NULL);
+ }
+ return (wl);
+}
diff --git a/cmd-has-session.c b/cmd-has-session.c
index ff724d4a..4e34d11e 100644
--- a/cmd-has-session.c
+++ b/cmd-has-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-has-session.c,v 1.5 2008-06-02 21:08:36 nicm Exp $ */
+/* $Id: cmd-has-session.c,v 1.6 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,9 +18,6 @@
#include <sys/types.h>
-#include <getopt.h>
-#include <string.h>
-
#include "tmux.h"
/*
diff --git a/cmd-kill-session.c b/cmd-kill-session.c
index cb9bf33f..63d9ae1c 100644
--- a/cmd-kill-session.c
+++ b/cmd-kill-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-kill-session.c,v 1.6 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-kill-session.c,v 1.7 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,9 +18,6 @@
#include <sys/types.h>
-#include <getopt.h>
-#include <stdlib.h>
-
#include "tmux.h"
/*
diff --git a/cmd-kill-window.c b/cmd-kill-window.c
index ad859302..b88f5adc 100644
--- a/cmd-kill-window.c
+++ b/cmd-kill-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-kill-window.c,v 1.9 2008-06-02 21:08:36 nicm Exp $ */
+/* $Id: cmd-kill-window.c,v 1.10 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,102 +18,36 @@
#include <sys/types.h>
-#include <getopt.h>
-#include <stdlib.h>
-
#include "tmux.h"
/*
* Destroy window.
*/
-int cmd_kill_window_parse(struct cmd *, void **, int, char **, char **);
void cmd_kill_window_exec(void *, struct cmd_ctx *);
-void cmd_kill_window_send(void *, struct buffer *);
-void cmd_kill_window_recv(void **, struct buffer *);
-void cmd_kill_window_free(void *);
-
-struct cmd_kill_window_data {
- char *sname;
- int idx;
-};
const struct cmd_entry cmd_kill_window_entry = {
"kill-window", "killw",
- "[-i index] [-s session-name]",
+ CMD_WINDOWONLY_USAGE,
0,
- cmd_kill_window_parse,
+ cmd_windowonly_parse,
cmd_kill_window_exec,
- cmd_kill_window_send,
- cmd_kill_window_recv,
- cmd_kill_window_free
+ cmd_windowonly_send,
+ cmd_windowonly_recv,
+ cmd_windowonly_free
};
-int
-cmd_kill_window_parse(
- struct cmd *self, void **ptr, int argc, char **argv, char **cause)
-{
- struct cmd_kill_window_data *data;
- const char *errstr;
- int opt;
-
- *ptr = data = xmalloc(sizeof *data);
- data->sname = NULL;
- data->idx = -1;
-
- while ((opt = getopt(argc, argv, "i:s:")) != EOF) {
- switch (opt) {
- case 'i':
- data->idx = strtonum(optarg, 0, INT_MAX, &errstr);
- if (errstr != NULL) {
- xasprintf(cause, "index %s", errstr);
- goto error;
- }
- break;
- case 's':
- data->sname = xstrdup(optarg);
- break;
- default:
- goto usage;
- }
- }
- argc -= optind;
- argv += optind;
- if (argc != 0)
- goto usage;
-
- return (0);
-
-usage:
- xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
-
-error:
- cmd_kill_window_free(data);
- return (-1);
-}
-
void
cmd_kill_window_exec(void *ptr, struct cmd_ctx *ctx)
{
- struct cmd_kill_window_data *data = ptr, std = { NULL, -1 };
- struct session *s;
- struct client *c;
- struct winlink *wl;
- u_int i;
- int destroyed;
+ struct winlink *wl;
+ struct session *s;
+ struct client *c;
+ u_int i;
+ int destroyed;
- if (data == NULL)
- data = &std;
-
- if ((s = cmd_find_session(ctx, data->sname)) == NULL)
- return;
-
- if (data->idx == -1)
- wl = s->curw;
- else if ((wl = winlink_find_by_index(&s->windows, data->idx)) == NULL) {
- ctx->error(ctx, "no window %d", data->idx);
+ if ((wl = cmd_windowonly_get(ptr, ctx, &s)) == NULL)
return;
- }
destroyed = session_detach(s, wl);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
@@ -130,31 +64,3 @@ cmd_kill_window_exec(void *ptr, struct cmd_ctx *ctx)
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
}
-
-void
-cmd_kill_window_send(void *ptr, struct buffer *b)
-{
- struct cmd_kill_window_data *data = ptr;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->sname);
-}
-
-void
-cmd_kill_window_recv(void **ptr, struct buffer *b)
-{
- struct cmd_kill_window_data *data;
-
- *ptr = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
-}
-
-void
-cmd_kill_window_free(void *ptr)
-{
- struct cmd_kill_window_data *data = ptr;
-
- if (data->sname != NULL)
- xfree(data->sname);
- xfree(data);
-}
diff --git a/cmd-last-window.c b/cmd-last-window.c
index 88e0a538..d6f4e687 100644
--- a/cmd-last-window.c
+++ b/cmd-last-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-last-window.c,v 1.7 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-last-window.c,v 1.8 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,9 +18,6 @@
#include <sys/types.h>
-#include <getopt.h>
-#include <string.h>
-
#include "tmux.h"
/*
diff --git a/cmd-list-windows.c b/cmd-list-windows.c
index 55d5a92f..7ac60e5e 100644
--- a/cmd-list-windows.c
+++ b/cmd-list-windows.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-list-windows.c,v 1.16 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-list-windows.c,v 1.17 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,7 +18,6 @@
#include <sys/types.h>
-#include <getopt.h>
#include <unistd.h>
#include "tmux.h"
@@ -41,7 +40,7 @@ const struct cmd_entry cmd_list_windows_entry = {
};
void
-cmd_list_windows_exec(unused void *ptr, struct cmd_ctx *ctx)
+cmd_list_windows_exec(void *ptr, struct cmd_ctx *ctx)
{
struct session *s;
struct winlink *wl;
diff --git a/cmd-next-window.c b/cmd-next-window.c
index e07aaa0b..f2c1c214 100644
--- a/cmd-next-window.c
+++ b/cmd-next-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-next-window.c,v 1.7 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-next-window.c,v 1.8 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,9 +18,6 @@
#include <sys/types.h>
-#include <getopt.h>
-#include <string.h>
-
#include "tmux.h"
/*
diff --git a/cmd-paste-buffer.c b/cmd-paste-buffer.c
index ba16f3fc..d0be9c9b 100644
--- a/cmd-paste-buffer.c
+++ b/cmd-paste-buffer.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-paste-buffer.c,v 1.4 2008-06-02 21:36:51 nicm Exp $ */
+/* $Id: cmd-paste-buffer.c,v 1.5 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,8 +18,6 @@
#include <sys/types.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <string.h>
#include "tmux.h"
@@ -32,27 +30,27 @@ void cmd_paste_buffer_exec(void *, struct cmd_ctx *);
const struct cmd_entry cmd_paste_buffer_entry = {
"paste-buffer", "paste",
- CMD_SESSIONONLY_USAGE,
+ CMD_WINDOWONLY_USAGE,
0,
- cmd_sessiononly_parse,
+ cmd_windowonly_parse,
cmd_paste_buffer_exec,
- cmd_sessiononly_send,
- cmd_sessiononly_recv,
- cmd_sessiononly_free
+ cmd_windowonly_send,
+ cmd_windowonly_recv,
+ cmd_windowonly_free
};
void
-cmd_paste_buffer_exec(unused void *ptr, struct cmd_ctx *ctx)
+cmd_paste_buffer_exec(void *ptr, struct cmd_ctx *ctx)
{
- struct session *s;
- struct window *w;
+ struct winlink *wl;
- if ((s = cmd_sessiononly_get(ptr, ctx)) == NULL)
+ if ((wl = cmd_windowonly_get(ptr, ctx, NULL)) == NULL)
return;
- w = s->curw->window;
- if (paste_buffer != NULL && *paste_buffer != '\0')
- buffer_write(w->out, paste_buffer, strlen(paste_buffer));
+ if (paste_buffer != NULL && *paste_buffer != '\0') {
+ buffer_write(
+ wl->window->out, paste_buffer, strlen(paste_buffer));
+ }
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
diff --git a/cmd-previous-window.c b/cmd-previous-window.c
index dd7560ce..42149f01 100644
--- a/cmd-previous-window.c
+++ b/cmd-previous-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-previous-window.c,v 1.7 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-previous-window.c,v 1.8 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,9 +18,6 @@
#include <sys/types.h>
-#include <getopt.h>
-#include <string.h>
-
#include "tmux.h"
/*
diff --git a/cmd-refresh-client.c b/cmd-refresh-client.c
index 4c1e6327..d1ecebb2 100644
--- a/cmd-refresh-client.c
+++ b/cmd-refresh-client.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-refresh-client.c,v 1.2 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-refresh-client.c,v 1.3 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,8 +18,6 @@
#include <sys/types.h>
-#include <getopt.h>
-
#include "tmux.h"
/*
diff --git a/cmd-scroll-mode.c b/cmd-scroll-mode.c
index 86432fd8..0688e0a9 100644
--- a/cmd-scroll-mode.c
+++ b/cmd-scroll-mode.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-scroll-mode.c,v 1.8 2008-06-02 21:36:51 nicm Exp $ */
+/* $Id: cmd-scroll-mode.c,v 1.9 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,9 +18,6 @@
#include <sys/types.h>
-#include <getopt.h>
-#include <stdlib.h>
-
#include "tmux.h"
/*
@@ -31,24 +28,24 @@ void cmd_scroll_mode_exec(void *, struct cmd_ctx *);
const struct cmd_entry cmd_scroll_mode_entry = {
"scroll-mode", NULL,
- CMD_SESSIONONLY_USAGE,
+ CMD_WINDOWONLY_USAGE,
0,
- cmd_sessiononly_parse,
+ cmd_windowonly_parse,
cmd_scroll_mode_exec,
- cmd_sessiononly_send,
- cmd_sessiononly_recv,
- cmd_sessiononly_free
+ cmd_windowonly_send,
+ cmd_windowonly_recv,
+ cmd_windowonly_free
};
void
cmd_scroll_mode_exec(void *ptr, struct cmd_ctx *ctx)
{
- struct session *s;
+ struct winlink *wl;
- if ((s = cmd_sessiononly_get(ptr, ctx)) == NULL)
+ if ((wl = cmd_windowonly_get(ptr, ctx, NULL)) == NULL)
return;
- window_set_mode(s->curw->window, &window_scroll_mode);
+ window_set_mode(wl->window, &window_scroll_mode);
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
diff --git a/cmd-send-prefix.c b/cmd-send-prefix.c
index ce887dd7..7a29511a 100644
--- a/cmd-send-prefix.c
+++ b/cmd-send-prefix.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-send-prefix.c,v 1.8 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-send-prefix.c,v 1.9 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,9 +18,6 @@
#include <sys/types.h>
-#include <getopt.h>
-#include <unistd.h>
-
#include "tmux.h"
/*
diff --git a/cmd-unlink-window.c b/cmd-unlink-window.c
index e1c88f23..d44f3d9f 100644
--- a/cmd-unlink-window.c
+++ b/cmd-unlink-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-unlink-window.c,v 1.7 2008-06-02 21:08:36 nicm Exp $ */
+/* $Id: cmd-unlink-window.c,v 1.8 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,108 +18,38 @@
#include <sys/types.h>
-#include <getopt.h>
-#include <stdlib.h>
-
#include "tmux.h"
/*
* Unlink a window, unless it would be destroyed by doing so (only one link).
*/
-int cmd_unlink_window_parse(struct cmd *, void **, int, char **, char **);
void cmd_unlink_window_exec(void *, struct cmd_ctx *);
-void cmd_unlink_window_send(void *, struct buffer *);
-void cmd_unlink_window_recv(void **, struct buffer *);
-void cmd_unlink_window_free(void *);
-
-struct cmd_unlink_window_data {
- char *sname;
- int idx;
-};
const struct cmd_entry cmd_unlink_window_entry = {
"unlink-window", "unlinkw",
- "[-i index] [-s session-name]",
+ CMD_WINDOWONLY_USAGE,
0,
- cmd_unlink_window_parse,
+ cmd_windowonly_parse,
cmd_unlink_window_exec,
- cmd_unlink_window_send,
- cmd_unlink_window_recv,
- cmd_unlink_window_free
-};
-
-int
-cmd_unlink_window_parse(
- struct cmd *self, void **ptr, int argc, char **argv, char **cause)
-{
- struct cmd_unlink_window_data *data;
- const char *errstr;
- int opt;
-
- *ptr = data = xmalloc(sizeof *data);
- data->sname = NULL;
- data->idx = -1;
-
- while ((opt = getopt(argc, argv, "i:s:")) != EOF) {
- switch (opt) {
- case 'i':
- data->idx = strtonum(optarg, 0, INT_MAX, &errstr);
- if (errstr != NULL) {
- xasprintf(cause, "index %s", errstr);
- goto error;
- }
- break;
- case 's':
- data->sname = xstrdup(optarg);
- break;
- default:
- goto usage;
- }
- }
- argc -= optind;
- argv += optind;
- if (argc != 0)
- goto usage;
-
- return (0);
+ cmd_windowonly_send,
+ cmd_windowonly_recv,
+ cmd_windowonly_free
-usage:
- xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
-
-error:
- cmd_unlink_window_free(data);
- return (-1);
-}
+};
void
cmd_unlink_window_exec(void *ptr, struct cmd_ctx *ctx)
{
- struct cmd_unlink_window_data *data = ptr;
- struct session *s;
- struct client *c;
- struct winlink *wl;
- u_int i;
- int destroyed;
-
- if (data == NULL)
- return;
+ struct winlink *wl;
+ struct session *s;
+ struct client *c;
+ u_int i;
+ int destroyed;
- if ((s = cmd_find_session(ctx, data->sname)) == NULL)
+ if ((wl = cmd_windowonly_get(ptr, ctx, &s)) == NULL)
return;
- if (data->idx < 0)
- data->idx = -1;
- if (data->idx == -1)
- wl = s->curw;
- else {
- wl = winlink_find_by_index(&s->windows, data->idx);
- if (wl == NULL) {
- ctx->error(ctx, "no window %d", data->idx);
- return;
- }
- }
-
if (wl->window->references == 1) {
ctx->error(ctx, "window is only linked to one session");
return;
@@ -140,31 +70,3 @@ cmd_unlink_window_exec(void *ptr, struct cmd_ctx *ctx)
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
}
-
-void
-cmd_unlink_window_send(void *ptr, struct buffer *b)
-{
- struct cmd_unlink_window_data *data = ptr;
-
- buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->sname);
-}
-
-void
-cmd_unlink_window_recv(void **ptr, struct buffer *b)
-{
- struct cmd_unlink_window_data *data;
-
- *ptr = data = xmalloc(sizeof *data);
- buffer_read(b, data, sizeof *data);
-}
-
-void
-cmd_unlink_window_free(void *ptr)
-{
- struct cmd_unlink_window_data *data = ptr;
-
- if (data->sname != NULL)
- xfree(data->sname);
- xfree(data);
-}
diff --git a/tmux.h b/tmux.h
index 61474ebf..646c6ff5 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.119 2008-06-02 21:36:51 nicm Exp $ */
+/* $Id: tmux.h,v 1.120 2008-06-02 22:09:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -780,6 +780,13 @@ void cmd_sessiononly_send(void *, struct buffer *);
void cmd_sessiononly_recv(void **, struct buffer *);
void cmd_sessiononly_free(void *);
struct session *cmd_sessiononly_get(void *, struct cmd_ctx *);
+#define CMD_WINDOWONLY_USAGE "[-i index] [-s session-name]"
+int cmd_windowonly_parse(struct cmd *, void **, int, char **, char **);
+void cmd_windowonly_exec(void *, struct cmd_ctx *);
+void cmd_windowonly_send(void *, struct buffer *);
+void cmd_windowonly_recv(void **, struct buffer *);
+void cmd_windowonly_free(void *);
+struct winlink *cmd_windowonly_get(void *, struct cmd_ctx *, struct session **);
/* client.c */
int client_init(const char *, struct client_ctx *, int);