diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2008-06-02 22:09:49 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2008-06-02 22:09:49 +0000 |
commit | 8731755ab4dc79f95f0a5ed8dfc8ae3bb9536256 (patch) | |
tree | b561c06699cfbdb0d771f5b7eda29587662f13c8 /cmd-kill-window.c | |
parent | 95cc21c25180d0f2e7b488983e3078834343d162 (diff) | |
download | rtmux-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.
Diffstat (limited to 'cmd-kill-window.c')
-rw-r--r-- | cmd-kill-window.c | 118 |
1 files changed, 12 insertions, 106 deletions
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); -} |