Print for the less easy commands.

This commit is contained in:
Nicholas Marriott 2008-06-05 17:12:11 +00:00
parent 642c0b00ab
commit ee1a7fded7
13 changed files with 258 additions and 53 deletions

8
TODO
View File

@ -83,3 +83,11 @@
- each command should have a print op as well for list keys
- fix occasion start server problems
- test and fix wsvt25
- look again at stuff that doesn't use flags
swap-window
switch-client
audit for lookup window
link-window
look for dstidx
also lookup dstsess with find_session
---

View File

@ -1,4 +1,4 @@
/* $Id: cmd-attach-session.c,v 1.16 2008-06-05 16:35:31 nicm Exp $ */
/* $Id: cmd-attach-session.c,v 1.17 2008-06-05 17:12:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -31,6 +31,7 @@ void cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
void cmd_attach_session_send(struct cmd *, struct buffer *);
void cmd_attach_session_recv(struct cmd *, struct buffer *);
void cmd_attach_session_free(struct cmd *);
void cmd_attach_session_print(struct cmd *, char *, size_t);
struct cmd_attach_session_data {
char *cname;
@ -48,7 +49,7 @@ const struct cmd_entry cmd_attach_session_entry = {
cmd_attach_session_recv,
cmd_attach_session_free,
NULL,
NULL
cmd_attach_session_print
};
int
@ -162,3 +163,20 @@ cmd_attach_session_free(struct cmd *self)
xfree(data->sname);
xfree(data);
}
void
cmd_attach_session_print(struct cmd *self, char *buf, size_t len)
{
struct cmd_attach_session_data *data = self->data;
size_t off = 0;
off += xsnprintf(buf, len, "%s", self->entry->name);
if (data == NULL)
return;
if (off < len && data->flag_detach)
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);
}

View File

@ -1,4 +1,4 @@
/* $Id: cmd-generic.c,v 1.6 2008-06-05 16:35:31 nicm Exp $ */
/* $Id: cmd-generic.c,v 1.7 2008-06-05 17:12:10 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>

View File

@ -1,4 +1,4 @@
/* $Id: cmd-link-window.c,v 1.17 2008-06-05 16:35:31 nicm Exp $ */
/* $Id: cmd-link-window.c,v 1.18 2008-06-05 17:12:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -32,13 +32,14 @@ void cmd_link_window_exec(struct cmd *, struct cmd_ctx *);
void cmd_link_window_send(struct cmd *, struct buffer *);
void cmd_link_window_recv(struct cmd *, struct buffer *);
void cmd_link_window_free(struct cmd *);
void cmd_link_window_print(struct cmd *, char *, size_t);
struct cmd_link_window_data {
char *cname;
char *sname;
int idx;
int flag_detached;
int flag_kill;
int dstidx;
int srcidx;
char *srcname;
};
@ -53,7 +54,7 @@ const struct cmd_entry cmd_link_window_entry = {
cmd_link_window_recv,
cmd_link_window_free,
NULL,
NULL
cmd_link_window_print
};
int
@ -68,7 +69,7 @@ cmd_link_window_parse(struct cmd *self, int argc, char **argv, char **cause)
data->sname = NULL;
data->flag_detached = 0;
data->flag_kill = 0;
data->dstidx = -1;
data->idx = -1;
data->srcidx = -1;
data->srcname = NULL;
@ -84,7 +85,7 @@ cmd_link_window_parse(struct cmd *self, int argc, char **argv, char **cause)
data->flag_detached = 1;
break;
case 'i':
data->dstidx = strtonum(optarg, 0, INT_MAX, &errstr);
data->idx = strtonum(optarg, 0, INT_MAX, &errstr);
if (errstr != NULL) {
xasprintf(cause, "index %s", errstr);
goto error;
@ -155,12 +156,12 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
}
}
if (data->dstidx < 0)
data->dstidx = -1;
if (data->flag_kill && data->dstidx != -1) {
wl2 = winlink_find_by_index(&s->windows, data->dstidx);
if (data->idx < 0)
data->idx = -1;
if (data->flag_kill && data->idx != -1) {
wl2 = winlink_find_by_index(&s->windows, data->idx);
if (wl2 == NULL) {
ctx->error(ctx, "no window %d", data->dstidx);
ctx->error(ctx, "no window %d", data->idx);
return;
}
@ -185,9 +186,9 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
*/
}
wl = session_attach(s, wl->window, data->dstidx);
wl = session_attach(s, wl->window, data->idx);
if (wl == NULL) {
ctx->error(ctx, "index in use: %d", data->dstidx);
ctx->error(ctx, "index in use: %d", data->idx);
return;
}
@ -237,3 +238,28 @@ cmd_link_window_free(struct cmd *self)
xfree(data->srcname);
xfree(data);
}
void
cmd_link_window_print(struct cmd *self, char *buf, size_t len)
{
struct cmd_link_window_data *data = self->data;
size_t off = 0;
off += xsnprintf(buf, len, "%s", self->entry->name);
if (data == NULL)
return;
if (off < len && data->flag_detached)
off += xsnprintf(buf + off, len - off, " -d");
if (off < len && data->flag_kill)
off += xsnprintf(buf + off, len - off, " -k");
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->srcname != NULL)
off += xsnprintf(buf + off, len - off, " %s", data->srcname);
if (off < len && data->srcidx != -1)
off += xsnprintf(buf + off, len - off, " %d", data->srcidx);
}

View File

@ -1,4 +1,4 @@
/* $Id: cmd-new-session.c,v 1.25 2008-06-05 16:35:31 nicm Exp $ */
/* $Id: cmd-new-session.c,v 1.26 2008-06-05 17:12:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -32,6 +32,7 @@ void cmd_new_session_send(struct cmd *, struct buffer *);
void cmd_new_session_recv(struct cmd *, struct buffer *);
void cmd_new_session_free(struct cmd *);
void cmd_new_session_init(struct cmd *, int);
void cmd_new_session_print(struct cmd *, char *, size_t);
struct cmd_new_session_data {
char *name;
@ -50,7 +51,7 @@ const struct cmd_entry cmd_new_session_entry = {
cmd_new_session_recv,
cmd_new_session_free,
cmd_new_session_init,
NULL
cmd_new_session_print
};
void
@ -210,3 +211,8 @@ cmd_new_session_free(struct cmd *self)
xfree(data->cmd);
xfree(data);
}
void
cmd_new_session_print(struct cmd *cmd, char *buf, size_t len)
{
}

View File

@ -1,4 +1,4 @@
/* $Id: cmd-new-window.c,v 1.21 2008-06-05 16:35:31 nicm Exp $ */
/* $Id: cmd-new-window.c,v 1.22 2008-06-05 17:12:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -33,13 +33,14 @@ void cmd_new_window_send(struct cmd *, struct buffer *);
void cmd_new_window_recv(struct cmd *, struct buffer *);
void cmd_new_window_free(struct cmd *);
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 *name;
char *cmd;
int idx;
int flag_detached;
};
@ -53,7 +54,7 @@ const struct cmd_entry cmd_new_window_entry = {
cmd_new_window_recv,
cmd_new_window_free,
cmd_new_window_init,
NULL
cmd_new_window_print
};
void
@ -202,3 +203,26 @@ cmd_new_window_free(struct cmd *self)
xfree(data->cmd);
xfree(data);
}
void
cmd_new_window_print(struct cmd *self, char *buf, size_t len)
{
struct cmd_new_window_data *data = self->data;
size_t off = 0;
off += xsnprintf(buf, len, "%s", self->entry->name);
if (data == NULL)
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->name != NULL)
off += xsnprintf(buf + off, len - off, " -n %s", data->name);
if (off < len && data->cmd != NULL)
off += xsnprintf(buf + off, len - off, " %s", data->cmd);
}

View File

@ -1,4 +1,4 @@
/* $Id: cmd-rename-session.c,v 1.9 2008-06-05 16:35:32 nicm Exp $ */
/* $Id: cmd-rename-session.c,v 1.10 2008-06-05 17:12:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -32,6 +32,7 @@ void cmd_rename_session_exec(struct cmd *, struct cmd_ctx *);
void cmd_rename_session_send(struct cmd *, struct buffer *);
void cmd_rename_session_recv(struct cmd *, struct buffer *);
void cmd_rename_session_free(struct cmd *);
void cmd_rename_session_print(struct cmd *, char *, size_t);
struct cmd_rename_session_data {
char *cname;
@ -49,7 +50,7 @@ const struct cmd_entry cmd_rename_session_entry = {
cmd_rename_session_recv,
cmd_rename_session_free,
NULL,
NULL
cmd_rename_session_print
};
int
@ -152,3 +153,8 @@ cmd_rename_session_free(struct cmd *self)
xfree(data->newname);
xfree(data);
}
void
cmd_rename_session_print(struct cmd *cmd, char *buf, size_t len)
{
}

View File

@ -1,4 +1,4 @@
/* $Id: cmd-rename-window.c,v 1.20 2008-06-05 16:35:32 nicm Exp $ */
/* $Id: cmd-rename-window.c,v 1.21 2008-06-05 17:12:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -32,6 +32,7 @@ void cmd_rename_window_exec(struct cmd *, struct cmd_ctx *);
void cmd_rename_window_send(struct cmd *, struct buffer *);
void cmd_rename_window_recv(struct cmd *, struct buffer *);
void cmd_rename_window_free(struct cmd *);
void cmd_rename_window_print(struct cmd *, char *, size_t);
struct cmd_rename_window_data {
char *cname;
@ -50,7 +51,7 @@ const struct cmd_entry cmd_rename_window_entry = {
cmd_rename_window_recv,
cmd_rename_window_free,
NULL,
NULL
cmd_rename_window_print
};
int
@ -167,3 +168,22 @@ cmd_rename_window_free(struct cmd *self)
xfree(data->newname);
xfree(data);
}
void
cmd_rename_window_print(struct cmd *self, char *buf, size_t len)
{
struct cmd_rename_window_data *data = self->data;
size_t off = 0;
off += xsnprintf(buf, len, "%s", self->entry->name);
if (data == NULL)
return;
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->newname != NULL)
off += xsnprintf(buf + off, len - off, " %s", data->newname);
}

View File

@ -1,4 +1,4 @@
/* $Id: cmd-send-keys.c,v 1.8 2008-06-05 16:35:32 nicm Exp $ */
/* $Id: cmd-send-keys.c,v 1.9 2008-06-05 17:12:10 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -32,6 +32,7 @@ void cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
void cmd_send_keys_send(struct cmd *, struct buffer *);
void cmd_send_keys_recv(struct cmd *, struct buffer *);
void cmd_send_keys_free(struct cmd *);
void cmd_send_keys_print(struct cmd *, char *, size_t);
struct cmd_send_keys_data {
char *cname;
@ -51,7 +52,7 @@ const struct cmd_entry cmd_send_keys_entry = {
cmd_send_keys_recv,
cmd_send_keys_free,
NULL,
NULL
cmd_send_keys_print
};
int
@ -181,3 +182,27 @@ cmd_send_keys_free(struct cmd *self)
xfree(data->sname);
xfree(data);
}
void
cmd_send_keys_print(struct cmd *self, char *buf, size_t len)
{
struct cmd_send_keys_data *data = self->data;
size_t off = 0;
u_int i;
off += xsnprintf(buf, len, "%s", self->entry->name);
if (data == NULL)
return;
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);
for (i = 0; i < data->nkeys; i++) {
if (off >= len)
break;
off += xsnprintf(buf + off,
len - off, " %s", key_string_lookup_key(data->keys[i]));
}
}

View File

@ -1,4 +1,4 @@
/* $Id: cmd-set-option.c,v 1.23 2008-06-05 16:35:32 nicm Exp $ */
/* $Id: cmd-set-option.c,v 1.24 2008-06-05 17:12:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -33,6 +33,7 @@ void cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
void cmd_set_option_send(struct cmd *, struct buffer *);
void cmd_set_option_recv(struct cmd *, struct buffer *);
void cmd_set_option_free(struct cmd *);
void cmd_set_option_print(struct cmd *, char *, size_t);
struct cmd_set_option_data {
char *cname;
@ -52,7 +53,7 @@ const struct cmd_entry cmd_set_option_entry = {
cmd_set_option_recv,
cmd_set_option_free,
NULL,
NULL
cmd_set_option_print
};
int
@ -315,3 +316,18 @@ cmd_set_option_free(struct cmd *self)
xfree(data->value);
xfree(data);
}
void
cmd_set_option_print(struct cmd *self, char *buf, size_t len)
{
struct cmd_set_option_data *data = self->data;
size_t off = 0;
off += xsnprintf(buf, len, "%s", self->entry->name);
if (data == NULL)
return;
if (off < len && data->option != NULL)
off += xsnprintf(buf + off, len - off, " %s", data->option);
if (off < len && data->value != NULL)
off += xsnprintf(buf + off, len - off, " %s", data->value);
}

View File

@ -1,4 +1,4 @@
/* $Id: cmd-set-window-option.c,v 1.3 2008-06-05 16:35:32 nicm Exp $ */
/* $Id: cmd-set-window-option.c,v 1.4 2008-06-05 17:12:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -33,6 +33,7 @@ void cmd_set_window_option_exec(struct cmd *, struct cmd_ctx *);
void cmd_set_window_option_send(struct cmd *, struct buffer *);
void cmd_set_window_option_recv(struct cmd *, struct buffer *);
void cmd_set_window_option_free(struct cmd *);
void cmd_set_window_option_print(struct cmd *, char *, size_t);
struct cmd_set_window_option_data {
char *cname;
@ -52,7 +53,7 @@ const struct cmd_entry cmd_set_window_option_entry = {
cmd_set_window_option_recv,
cmd_set_window_option_free,
NULL,
NULL
cmd_set_window_option_print
};
int
@ -222,3 +223,18 @@ cmd_set_window_option_free(struct cmd *self)
xfree(data->value);
xfree(data);
}
void
cmd_set_window_option_print(struct cmd *self, char *buf, size_t len)
{
struct cmd_set_window_option_data *data = self->data;
size_t off = 0;
off += xsnprintf(buf, len, "%s", self->entry->name);
if (data == NULL)
return;
if (off < len && data->option != NULL)
off += xsnprintf(buf + off, len - off, " %s", data->option);
if (off < len && data->value != NULL)
off += xsnprintf(buf + off, len - off, " %s", data->value);
}

View File

@ -1,4 +1,4 @@
/* $Id: cmd-swap-window.c,v 1.9 2008-06-05 16:35:32 nicm Exp $ */
/* $Id: cmd-swap-window.c,v 1.10 2008-06-05 17:12:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -32,11 +32,12 @@ void cmd_swap_window_exec(struct cmd *, struct cmd_ctx *);
void cmd_swap_window_send(struct cmd *, struct buffer *);
void cmd_swap_window_recv(struct cmd *, struct buffer *);
void cmd_swap_window_free(struct cmd *);
void cmd_swap_window_print(struct cmd *, char *, size_t);
struct cmd_swap_window_data {
char *cname;
char *sname;
int dstidx;
int idx;
int srcidx;
char *srcname;
int flag_detached;
@ -44,7 +45,7 @@ struct cmd_swap_window_data {
const struct cmd_entry cmd_swap_window_entry = {
"swap-window", "swapw",
"[-c client-tty|-s session-name] [-i index] session-name index",
"[-d] [-c client-tty|-s session-name] [-i index] session-name index",
0,
cmd_swap_window_parse,
cmd_swap_window_exec,
@ -52,7 +53,7 @@ const struct cmd_entry cmd_swap_window_entry = {
cmd_swap_window_recv,
cmd_swap_window_free,
NULL,
NULL
cmd_swap_window_print
};
int
@ -66,7 +67,7 @@ cmd_swap_window_parse(struct cmd *self, int argc, char **argv, char **cause)
data->cname = NULL;
data->sname = NULL;
data->flag_detached = 0;
data->dstidx = -1;
data->idx = -1;
data->srcidx = -1;
data->srcname = NULL;
@ -82,7 +83,7 @@ cmd_swap_window_parse(struct cmd *self, int argc, char **argv, char **cause)
data->flag_detached = 1;
break;
case 'i':
data->dstidx = strtonum(optarg, 0, INT_MAX, &errstr);
data->idx = strtonum(optarg, 0, INT_MAX, &errstr);
if (errstr != NULL) {
xasprintf(cause, "index %s", errstr);
goto error;
@ -151,14 +152,14 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
}
}
if (data->dstidx < 0)
data->dstidx = -1;
if (data->dstidx == -1)
if (data->idx < 0)
data->idx = -1;
if (data->idx == -1)
dstwl = s->curw;
else {
dstwl = winlink_find_by_index(&s->windows, data->dstidx);
dstwl = winlink_find_by_index(&s->windows, data->idx);
if (dstwl == NULL) {
ctx->error(ctx, "no window %d", data->dstidx);
ctx->error(ctx, "no window %d", data->idx);
return;
}
}
@ -216,3 +217,26 @@ cmd_swap_window_free(struct cmd *self)
xfree(data->srcname);
xfree(data);
}
void
cmd_swap_window_print(struct cmd *self, char *buf, size_t len)
{
struct cmd_swap_window_data *data = self->data;
size_t off = 0;
off += xsnprintf(buf, len, "%s", self->entry->name);
if (data == NULL)
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->srcname != NULL)
off += xsnprintf(buf + off, len - off, " %s", data->srcname);
if (off < len && data->srcidx != -1)
off += xsnprintf(buf + off, len - off, " %d", data->srcidx);
}

View File

@ -1,4 +1,4 @@
/* $Id: cmd-switch-client.c,v 1.7 2008-06-05 16:35:32 nicm Exp $ */
/* $Id: cmd-switch-client.c,v 1.8 2008-06-05 17:12:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -33,6 +33,7 @@ void cmd_switch_client_exec(struct cmd *, struct cmd_ctx *);
void cmd_switch_client_send(struct cmd *, struct buffer *);
void cmd_switch_client_recv(struct cmd *, struct buffer *);
void cmd_switch_client_free(struct cmd *);
void cmd_switch_client_print(struct cmd *, char *, size_t);
struct cmd_switch_client_data {
char *cname;
@ -49,7 +50,7 @@ const struct cmd_entry cmd_switch_client_entry = {
cmd_switch_client_recv,
cmd_switch_client_free,
NULL,
NULL
cmd_switch_client_print
};
int
@ -145,3 +146,18 @@ cmd_switch_client_free(struct cmd *self)
xfree(data->name);
xfree(data);
}
void
cmd_switch_client_print(struct cmd *self, char *buf, size_t len)
{
struct cmd_switch_client_data *data = self->data;
size_t off = 0;
off += xsnprintf(buf, len, "%s", self->entry->name);
if (data == NULL)
return;
if (off < len && data->cname != NULL)
off += xsnprintf(buf + off, len - off, " -c %s", data->cname);
if (off < len && data->name != NULL)
off += xsnprintf(buf + off, len - off, " %s", data->name);
}