summaryrefslogtreecommitdiffstats
path: root/cmd-kill-window.c
authornicm <nicm>2008-06-02 22:09:49 (GMT)
committer nicm <nicm>2008-06-02 22:09:49 (GMT)
commit6e183a7302edb730e2864bef0cb4bda6d72ce7bb (patch) (side-by-side diff)
treeeace91838502333daaa3ce6dd76d6ff6e9ff5d8e /cmd-kill-window.c
parent4a2fda594674bdec069a2cf4954b94b79c324663 (diff)
downloadtmux-old-6e183a7302edb730e2864bef0cb4bda6d72ce7bb.zip
tmux-old-6e183a7302edb730e2864bef0cb4bda6d72ce7bb.tar.gz
tmux-old-6e183a7302edb730e2864bef0cb4bda6d72ce7bb.tar.bz2
Add a windowonly generic command and use it where appropriate. Also trim includes and unused.
Diffstat (limited to 'cmd-kill-window.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cmd-kill-window.c116
1 files changed, 11 insertions, 105 deletions
diff --git a/cmd-kill-window.c b/cmd-kill-window.c
index bbdd912..50f9772 100644
--- a/cmd-kill-window.c
+++ b/cmd-kill-window.c
@@ -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);
-}