summaryrefslogtreecommitdiffstats
path: root/cmd-kill-window.c
authornicm <nicm>2008-06-02 18:08:16 (GMT)
committer nicm <nicm>2008-06-02 18:08:16 (GMT)
commit263848f05bf18c8fd9ce293894ea1bfe0e678db0 (patch) (side-by-side diff)
treec0e3300759c19c241b35db427510f112211a2272 /cmd-kill-window.c
parent33a12b4e3981d3732bc90fd40384007d8a8198c7 (diff)
downloadtmux-old-263848f05bf18c8fd9ce293894ea1bfe0e678db0.zip
tmux-old-263848f05bf18c8fd9ce293894ea1bfe0e678db0.tar.gz
tmux-old-263848f05bf18c8fd9ce293894ea1bfe0e678db0.tar.bz2
Move -s and -c down a level so handling them is the responsibility of the command (with some helper functions), rather than the top-level. This changes the action command syntax so that -s and -c must be after the command rather than before.
Diffstat (limited to 'cmd-kill-window.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cmd-kill-window.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/cmd-kill-window.c b/cmd-kill-window.c
index 9c4d921..02ee076 100644
--- a/cmd-kill-window.c
+++ b/cmd-kill-window.c
@@ -27,19 +27,21 @@
* Destroy window.
*/
-int cmd_kill_window_parse(void **, int, char **, char **);
+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]",
- CMD_NOCLIENT,
+ "kill-window", "killw",
+ "[-i index] [-s session-name]",
+ 0,
cmd_kill_window_parse,
cmd_kill_window_exec,
cmd_kill_window_send,
@@ -48,16 +50,18 @@ const struct cmd_entry cmd_kill_window_entry = {
};
int
-cmd_kill_window_parse(void **ptr, int argc, char **argv, char **cause)
+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:")) != EOF) {
+ while ((opt = getopt(argc, argv, "i:s:")) != EOF) {
switch (opt) {
case 'i':
data->idx = strtonum(optarg, 0, INT_MAX, &errstr);
@@ -66,6 +70,9 @@ cmd_kill_window_parse(void **ptr, int argc, char **argv, char **cause)
goto error;
}
break;
+ case 's':
+ data->sname = xstrdup(optarg);
+ break;
default:
goto usage;
}
@@ -78,8 +85,7 @@ cmd_kill_window_parse(void **ptr, int argc, char **argv, char **cause)
return (0);
usage:
- usage(cause, "%s %s",
- cmd_kill_window_entry.name, cmd_kill_window_entry.usage);
+ usage(cause, "%s %s", self->entry->name, self->entry->usage);
error:
cmd_kill_window_free(data);
@@ -89,9 +95,9 @@ error:
void
cmd_kill_window_exec(void *ptr, struct cmd_ctx *ctx)
{
- struct cmd_kill_window_data *data = ptr, std = { -1 };
+ struct cmd_kill_window_data *data = ptr, std = { NULL, -1 };
+ struct session *s;
struct client *c;
- struct winlinks *wwl = &ctx->session->windows;
struct winlink *wl;
u_int i;
int destroyed;
@@ -99,17 +105,20 @@ cmd_kill_window_exec(void *ptr, struct cmd_ctx *ctx)
if (data == NULL)
data = &std;
+ if ((s = cmd_find_session(ctx, data->sname)) == NULL)
+ return;
+
if (data->idx == -1)
- wl = ctx->session->curw;
- else if ((wl = winlink_find_by_index(wwl, data->idx)) == NULL) {
+ wl = s->curw;
+ else if ((wl = winlink_find_by_index(&s->windows, data->idx)) == NULL) {
ctx->error(ctx, "no window %d", data->idx);
return;
}
- destroyed = session_detach(ctx->session, wl);
+ destroyed = session_detach(s, wl);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
- if (c == NULL || c->session != ctx->session)
+ if (c == NULL || c->session != s)
continue;
if (destroyed) {
c->session = NULL;
@@ -128,6 +137,7 @@ 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
@@ -144,5 +154,7 @@ cmd_kill_window_free(void *ptr)
{
struct cmd_kill_window_data *data = ptr;
+ if (data->sname != NULL)
+ xfree(data->sname);
xfree(data);
}