summaryrefslogtreecommitdiffstats
path: root/cmd-new-window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2008-06-05 21:25:00 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2008-06-05 21:25:00 +0000
commit0b9b873a5505de6fdfb8f02cfbaef5fc82831a5f (patch)
treef034330734848ce9df96ee94ab4dc6a7ad025dc9 /cmd-new-window.c
parentee1a7fded7653ffc2ba68a4188c89a7cb6e1bf1d (diff)
Big reorganisation of command-line syntax.
Diffstat (limited to 'cmd-new-window.c')
-rw-r--r--cmd-new-window.c81
1 files changed, 32 insertions, 49 deletions
diff --git a/cmd-new-window.c b/cmd-new-window.c
index 9cc3fc3d..2f30f35b 100644
--- a/cmd-new-window.c
+++ b/cmd-new-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-new-window.c,v 1.22 2008-06-05 17:12:10 nicm Exp $ */
+/* $Id: cmd-new-window.c,v 1.23 2008-06-05 21:25:00 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -36,9 +36,7 @@ void cmd_new_window_init(struct cmd *, int);
void cmd_new_window_print(struct cmd *, char *, size_t);
struct cmd_new_window_data {
- char *cname;
- char *sname;
- int idx;
+ char *target;
char *name;
char *cmd;
int flag_detached;
@@ -46,14 +44,14 @@ struct cmd_new_window_data {
const struct cmd_entry cmd_new_window_entry = {
"new-window", "neww",
- "[-d] [-c client-tty|-s session-name] [-i index] [-n name] [command]",
+ "[-d] [-t target-window] [-n window-name] [command]",
0,
+ cmd_new_window_init,
cmd_new_window_parse,
cmd_new_window_exec,
cmd_new_window_send,
cmd_new_window_recv,
cmd_new_window_free,
- cmd_new_window_init,
cmd_new_window_print
};
@@ -63,52 +61,34 @@ cmd_new_window_init(struct cmd *self, unused int arg)
struct cmd_new_window_data *data;
self->data = data = xmalloc(sizeof *data);
- data->cname = NULL;
- data->sname = NULL;
- data->idx = -1;
- data->flag_detached = 0;
+ data->target = NULL;
data->name = NULL;
data->cmd = NULL;
+ data->flag_detached = 0;
}
int
cmd_new_window_parse(struct cmd *self, int argc, char **argv, char **cause)
{
struct cmd_new_window_data *data;
- const char *errstr;
int opt;
self->entry->init(self, 0);
data = self->data;
- while ((opt = getopt(argc, argv, "c:di:n:s:")) != EOF) {
+ while ((opt = getopt(argc, argv, "dt:n:")) != EOF) {
switch (opt) {
- case 'c':
- if (data->sname != NULL)
- goto usage;
- if (data->cname == NULL)
- data->cname = xstrdup(optarg);
- break;
case 'd':
data->flag_detached = 1;
break;
- case 'i':
- data->idx = strtonum(optarg, 0, INT_MAX, &errstr);
- if (errstr != NULL) {
- xasprintf(cause, "index %s", errstr);
- goto error;
- }
+ case 't':
+ if (data->target == NULL)
+ data->target = xstrdup(optarg);
break;
case 'n':
if (data->name == NULL)
data->name = xstrdup(optarg);
break;
- case 's':
- if (data->cname != NULL)
- goto usage;
- if (data->sname == NULL)
- data->sname = xstrdup(optarg);
- break;
default:
goto usage;
}
@@ -126,7 +106,6 @@ cmd_new_window_parse(struct cmd *self, int argc, char **argv, char **cause)
usage:
xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
-error:
self->entry->free(self);
return (-1);
}
@@ -138,17 +117,29 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct session *s;
struct winlink *wl;
char *cmd;
+ int idx;
- if ((s = cmd_find_session(ctx, data->cname, data->sname)) == NULL)
+ if (data == NULL)
+ return;
+
+ if (arg_parse_window(data->target, &s, &idx) != 0) {
+ ctx->error(ctx, "bad window: %s", data->target);
return;
+ }
+ if (s == NULL)
+ s = ctx->cursession;
+ if (s == NULL)
+ s = cmd_current_session(ctx);
+ if (s == NULL) {
+ ctx->error(ctx, "session not found: %s", data->target);
+ return;
+ }
cmd = data->cmd;
if (cmd == NULL)
cmd = options_get_string(&s->options, "default-command");
- if (data->idx < 0)
- data->idx = -1;
- wl = session_new(s, data->name, cmd, data->idx);
+ wl = session_new(s, data->name, cmd, idx);
if (wl == NULL) {
ctx->error(ctx, "command failed: %s", cmd);
return;
@@ -169,8 +160,7 @@ cmd_new_window_send(struct cmd *self, struct buffer *b)
struct cmd_new_window_data *data = self->data;
buffer_write(b, data, sizeof *data);
- cmd_send_string(b, data->cname);
- cmd_send_string(b, data->sname);
+ cmd_send_string(b, data->target);
cmd_send_string(b, data->name);
cmd_send_string(b, data->cmd);
}
@@ -182,8 +172,7 @@ cmd_new_window_recv(struct cmd *self, struct buffer *b)
self->data = data = xmalloc(sizeof *data);
buffer_read(b, data, sizeof *data);
- data->cname = cmd_recv_string(b);
- data->sname = cmd_recv_string(b);
+ data->target = cmd_recv_string(b);
data->name = cmd_recv_string(b);
data->cmd = cmd_recv_string(b);
}
@@ -193,10 +182,8 @@ cmd_new_window_free(struct cmd *self)
{
struct cmd_new_window_data *data = self->data;
- if (data->cname != NULL)
- xfree(data->cname);
- if (data->sname != NULL)
- xfree(data->sname);
+ if (data->target != NULL)
+ xfree(data->target);
if (data->name != NULL)
xfree(data->name);
if (data->cmd != NULL)
@@ -215,12 +202,8 @@ cmd_new_window_print(struct cmd *self, char *buf, size_t len)
return;
if (off < len && data->flag_detached)
off += xsnprintf(buf + off, len - off, " -d");
- if (off < len && data->cname != NULL)
- off += xsnprintf(buf + off, len - off, " -c %s", data->cname);
- if (off < len && data->sname != NULL)
- off += xsnprintf(buf + off, len - off, " -s %s", data->sname);
- if (off < len && data->idx != -1)
- off += xsnprintf(buf + off, len - off, " -i %d", data->idx);
+ if (off < len && data->target != NULL)
+ off += xsnprintf(buf + off, len - off, " -t %s", data->target);
if (off < len && data->name != NULL)
off += xsnprintf(buf + off, len - off, " -n %s", data->name);
if (off < len && data->cmd != NULL)