Lose usage and move it into the struct.

pull/1/head
Nicholas Marriott 2007-10-04 21:48:11 +00:00
parent 5a3b92c2df
commit 75e1e4b91e
16 changed files with 64 additions and 119 deletions

View File

@ -1,4 +1,4 @@
/* $Id: cmd-attach-session.c,v 1.3 2007-10-04 21:21:48 nicm Exp $ */
/* $Id: cmd-attach-session.c,v 1.4 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,6 @@
*/
int cmd_attach_session_parse(void **, int, char **, char **);
const char *cmd_attach_session_usage(void);
void cmd_attach_session_exec(void *, struct cmd_ctx *);
void cmd_attach_session_send(void *, struct buffer *);
void cmd_attach_session_recv(void **, struct buffer *);
@ -38,9 +37,9 @@ struct cmd_attach_session_data {
};
const struct cmd_entry cmd_attach_session_entry = {
CMD_NEWWINDOW, "attach-session", "attach", 0,
CMD_NEWWINDOW, "attach-session", "attach", "[-d]",
0,
cmd_attach_session_parse,
cmd_attach_session_usage,
cmd_attach_session_exec,
cmd_attach_session_send,
cmd_attach_session_recv,
@ -73,18 +72,13 @@ cmd_attach_session_parse(void **ptr, int argc, char **argv, char **cause)
return (0);
usage:
usage(cause, "%s", cmd_attach_session_usage());
usage(cause, "%s %s",
cmd_attach_session_entry.name, cmd_attach_session_entry.usage);
cmd_attach_session_free(data);
return (-1);
}
const char *
cmd_attach_session_usage(void)
{
return ("attach-session [-d]");
}
void
cmd_attach_session_exec(void *ptr, struct cmd_ctx *ctx)
{

View File

@ -1,4 +1,4 @@
/* $Id: cmd-bind-key.c,v 1.2 2007-10-04 10:11:32 nicm Exp $ */
/* $Id: cmd-bind-key.c,v 1.3 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,6 @@
*/
int cmd_bind_key_parse(void **, int, char **, char **);
const char *cmd_bind_key_usage(void);
void cmd_bind_key_exec(void *, struct cmd_ctx *);
void cmd_bind_key_send(void *, struct buffer *);
void cmd_bind_key_recv(void **, struct buffer *);
@ -39,9 +38,9 @@ struct cmd_bind_key_data {
};
const struct cmd_entry cmd_bind_key_entry = {
CMD_BINDKEY, "bind-key", "bind", CMD_NOSESSION,
CMD_BINDKEY, "bind-key", "bind", "key command [arguments]",
CMD_NOSESSION,
cmd_bind_key_parse,
cmd_bind_key_usage,
cmd_bind_key_exec,
cmd_bind_key_send,
cmd_bind_key_recv,
@ -81,19 +80,14 @@ cmd_bind_key_parse(void **ptr, int argc, char **argv, char **cause)
return (0);
usage:
usage(cause, "%s", cmd_bind_key_usage());
usage(cause, "%s %s",
cmd_bind_key_entry.name, cmd_bind_key_entry.usage);
error:
cmd_bind_key_free(data);
return (-1);
}
const char *
cmd_bind_key_usage(void)
{
return ("bind-key key command [arguments]");
}
void
cmd_bind_key_exec(void *ptr, unused struct cmd_ctx *ctx)
{

View File

@ -1,4 +1,4 @@
/* $Id: cmd-detach-session.c,v 1.3 2007-10-04 10:11:32 nicm Exp $ */
/* $Id: cmd-detach-session.c,v 1.4 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -28,7 +28,6 @@
*/
int cmd_detach_session_parse(void **, int, char **, char **);
const char *cmd_detach_session_usage(void);
void cmd_detach_session_exec(void *, struct cmd_ctx *);
void cmd_detach_session_send(void *, struct buffer *);
void cmd_detach_session_recv(void **, struct buffer *);
@ -39,9 +38,9 @@ struct cmd_detach_session_data {
};
const struct cmd_entry cmd_detach_session_entry = {
CMD_DETACHSESSION, "detach-session", "detach", 0,
CMD_DETACHSESSION, "detach-session", "detach", "[-a]",
0,
cmd_detach_session_parse,
cmd_detach_session_usage,
cmd_detach_session_exec,
cmd_detach_session_send,
cmd_detach_session_recv,
@ -74,18 +73,13 @@ cmd_detach_session_parse(void **ptr, int argc, char **argv, char **cause)
return (0);
usage:
usage(cause, "%s", cmd_detach_session_usage());
usage(cause, "%s %s",
cmd_detach_session_entry.name, cmd_detach_session_entry.usage);
cmd_detach_session_free(data);
return (-1);
}
const char *
cmd_detach_session_usage(void)
{
return ("detach-session [-a]");
}
void
cmd_detach_session_exec(void *ptr, struct cmd_ctx *ctx)
{

View File

@ -1,4 +1,4 @@
/* $Id: cmd-last-window.c,v 1.1 2007-10-04 00:02:10 nicm Exp $ */
/* $Id: cmd-last-window.c,v 1.2 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -30,8 +30,8 @@
void cmd_last_window_exec(void *, struct cmd_ctx *);
const struct cmd_entry cmd_last_window_entry = {
CMD_LASTWINDOW, "last-window", "last", 0,
NULL,
CMD_LASTWINDOW, "last-window", "last", "",
0,
NULL,
cmd_last_window_exec,
NULL,

View File

@ -1,4 +1,4 @@
/* $Id: cmd-list-keys.c,v 1.1 2007-10-04 00:18:59 nicm Exp $ */
/* $Id: cmd-list-keys.c,v 1.2 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -30,8 +30,8 @@
void cmd_list_keys_exec(void *, struct cmd_ctx *);
const struct cmd_entry cmd_list_keys_entry = {
CMD_LISTKEYS, "list-keys", "lsk", CMD_NOSESSION,
NULL,
CMD_LISTKEYS, "list-keys", "lsk", "",
CMD_NOSESSION,
NULL,
cmd_list_keys_exec,
NULL,

View File

@ -1,4 +1,4 @@
/* $Id: cmd-list-sessions.c,v 1.2 2007-10-04 00:02:10 nicm Exp $ */
/* $Id: cmd-list-sessions.c,v 1.3 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -30,8 +30,8 @@
void cmd_list_sessions_exec(void *, struct cmd_ctx *);
const struct cmd_entry cmd_list_sessions_entry = {
CMD_LISTSESSIONS, "list-sessions", "ls", CMD_NOSESSION,
NULL,
CMD_LISTSESSIONS, "list-sessions", "ls", "",
CMD_NOSESSION,
NULL,
cmd_list_sessions_exec,
NULL,

View File

@ -1,4 +1,4 @@
/* $Id: cmd-new-session.c,v 1.8 2007-10-04 20:01:09 nicm Exp $ */
/* $Id: cmd-new-session.c,v 1.9 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,6 @@
*/
int cmd_new_session_parse(void **, int, char **, char **);
const char *cmd_new_session_usage(void);
void cmd_new_session_exec(void *, struct cmd_ctx *);
void cmd_new_session_send(void *, struct buffer *);
void cmd_new_session_recv(void **, struct buffer *);
@ -40,9 +39,9 @@ struct cmd_new_session_data {
};
const struct cmd_entry cmd_new_session_entry = {
CMD_NEWSESSION, "new-session", "new", CMD_STARTSERVER|CMD_NOSESSION,
CMD_NEWSESSION, "new-session", "new", "[-d] [-n session name] [command]",
CMD_STARTSERVER|CMD_NOSESSION,
cmd_new_session_parse,
cmd_new_session_usage,
cmd_new_session_exec,
cmd_new_session_send,
cmd_new_session_recv,
@ -83,18 +82,13 @@ cmd_new_session_parse(void **ptr, int argc, char **argv, char **cause)
return (0);
usage:
usage(cause, "%s", cmd_new_session_usage());
usage(cause, "%s %s",
cmd_new_session_entry.name, cmd_new_session_entry.usage);
cmd_new_session_free(data);
return (-1);
}
const char *
cmd_new_session_usage(void)
{
return ("new-session [-d] [-n session name] [command]");
}
void
cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
{

View File

@ -1,4 +1,4 @@
/* $Id: cmd-new-window.c,v 1.5 2007-10-04 12:40:56 mxey Exp $ */
/* $Id: cmd-new-window.c,v 1.6 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -27,7 +27,6 @@
*/
int cmd_new_window_parse(void **, int, char **, char **);
const char *cmd_new_window_usage(void);
void cmd_new_window_exec(void *, struct cmd_ctx *);
void cmd_new_window_send(void *, struct buffer *);
void cmd_new_window_recv(void **, struct buffer *);
@ -40,9 +39,9 @@ struct cmd_new_window_data {
};
const struct cmd_entry cmd_new_window_entry = {
CMD_NEWWINDOW, "new-window", "neww", 0,
CMD_NEWWINDOW, "new-window", "neww", "[-d] [-n name] [command]",
0,
cmd_new_window_parse,
cmd_new_window_usage,
cmd_new_window_exec,
cmd_new_window_send,
cmd_new_window_recv,
@ -83,18 +82,13 @@ cmd_new_window_parse(void **ptr, int argc, char **argv, char **cause)
return (0);
usage:
usage(cause, "%s", cmd_new_window_usage());
usage(cause, "%s %s",
cmd_new_window_entry.name, cmd_new_window_entry.usage);
cmd_new_window_free(data);
return (-1);
}
const char *
cmd_new_window_usage(void)
{
return ("new-window [-d] [-n name] [command]");
}
void
cmd_new_window_exec(void *ptr, struct cmd_ctx *ctx)
{

View File

@ -1,4 +1,4 @@
/* $Id: cmd-next-window.c,v 1.1 2007-10-04 00:02:10 nicm Exp $ */
/* $Id: cmd-next-window.c,v 1.2 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -30,8 +30,8 @@
void cmd_next_window_exec(void *, struct cmd_ctx *);
const struct cmd_entry cmd_next_window_entry = {
CMD_NEXTWINDOW, "next-window", "next", 0,
NULL,
CMD_NEXTWINDOW, "next-window", "next", "",
0,
NULL,
cmd_next_window_exec,
NULL,

View File

@ -1,4 +1,4 @@
/* $Id: cmd-previous-window.c,v 1.1 2007-10-04 00:02:10 nicm Exp $ */
/* $Id: cmd-previous-window.c,v 1.2 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -30,8 +30,8 @@
void cmd_previous_window_exec(void *, struct cmd_ctx *);
const struct cmd_entry cmd_previous_window_entry = {
CMD_PREVIOUSWINDOW, "previous-window", "prev", 0,
NULL,
CMD_PREVIOUSWINDOW, "previous-window", "prev", "",
0,
NULL,
cmd_previous_window_exec,
NULL,

View File

@ -1,4 +1,4 @@
/* $Id: cmd-rename-window.c,v 1.2 2007-10-04 10:54:20 nicm Exp $ */
/* $Id: cmd-rename-window.c,v 1.3 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -28,7 +28,6 @@
*/
int cmd_rename_window_parse(void **, int, char **, char **);
const char *cmd_rename_window_usage(void);
void cmd_rename_window_exec(void *, struct cmd_ctx *);
void cmd_rename_window_send(void *, struct buffer *);
void cmd_rename_window_recv(void **, struct buffer *);
@ -40,9 +39,9 @@ struct cmd_rename_window_data {
};
const struct cmd_entry cmd_rename_window_entry = {
CMD_RENAMEWINDOW, "rename-window", "renamew", 0,
CMD_RENAMEWINDOW, "rename-window", "renamew", "[-i index] newname",
0,
cmd_rename_window_parse,
cmd_rename_window_usage,
cmd_rename_window_exec,
cmd_rename_window_send,
cmd_rename_window_recv,
@ -83,19 +82,14 @@ cmd_rename_window_parse(void **ptr, int argc, char **argv, char **cause)
return (0);
usage:
usage(cause, "%s", cmd_rename_window_usage());
usage(cause, "%s %s",
cmd_rename_window_entry.name, cmd_rename_window_entry.usage);
error:
cmd_rename_window_free(data);
return (-1);
}
const char *
cmd_rename_window_usage(void)
{
return ("rename-window [-i index] newname");
}
void
cmd_rename_window_exec(void *ptr, struct cmd_ctx *ctx)
{

View File

@ -1,4 +1,4 @@
/* $Id: cmd-select-window.c,v 1.1 2007-10-04 10:54:20 nicm Exp $ */
/* $Id: cmd-select-window.c,v 1.2 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -28,7 +28,6 @@
*/
int cmd_select_window_parse(void **, int, char **, char **);
const char *cmd_select_window_usage(void);
void cmd_select_window_exec(void *, struct cmd_ctx *);
void cmd_select_window_send(void *, struct buffer *);
void cmd_select_window_recv(void **, struct buffer *);
@ -39,9 +38,9 @@ struct cmd_select_window_data {
};
const struct cmd_entry cmd_select_window_entry = {
CMD_SELECTWINDOW, "select-window", "selectw", 0,
CMD_SELECTWINDOW, "select-window", "selectw", "[command]",
0,
cmd_select_window_parse,
cmd_select_window_usage,
cmd_select_window_exec,
cmd_select_window_send,
cmd_select_window_recv,
@ -91,19 +90,14 @@ cmd_select_window_parse(void **ptr, int argc, char **argv, char **cause)
return (0);
usage:
usage(cause, "%s", cmd_select_window_usage());
usage(cause, "%s %s",
cmd_select_window_entry.name, cmd_select_window_entry.usage);
error:
cmd_select_window_free(data);
return (-1);
}
const char *
cmd_select_window_usage(void)
{
return ("select-window [command]");
}
void
cmd_select_window_exec(void *ptr, struct cmd_ctx *ctx)
{

View File

@ -1,4 +1,4 @@
/* $Id: cmd-set-option.c,v 1.1 2007-10-04 10:11:32 nicm Exp $ */
/* $Id: cmd-set-option.c,v 1.2 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -41,9 +41,9 @@ struct cmd_set_option_data {
};
const struct cmd_entry cmd_set_option_entry = {
CMD_SETOPTION, "set-option", "set", CMD_NOSESSION,
CMD_SETOPTION, "set-option", "set", "option value",
CMD_NOSESSION,
cmd_set_option_parse,
cmd_set_option_usage,
cmd_set_option_exec,
cmd_set_option_send,
cmd_set_option_recv,
@ -78,18 +78,13 @@ cmd_set_option_parse(void **ptr, int argc, char **argv, char **cause)
return (0);
usage:
usage(cause, "%s", cmd_set_option_usage());
usage(cause, "%s %s",
cmd_set_option_entry.name, cmd_set_option_entry.usage);
cmd_set_option_free(data);
return (-1);
}
const char *
cmd_set_option_usage(void)
{
return ("set-option option value");
}
void
cmd_set_option_exec(void *ptr, unused struct cmd_ctx *ctx)
{

View File

@ -1,4 +1,4 @@
/* $Id: cmd-unbind-key.c,v 1.2 2007-10-04 10:11:32 nicm Exp $ */
/* $Id: cmd-unbind-key.c,v 1.3 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -38,9 +38,9 @@ struct cmd_unbind_key_data {
};
const struct cmd_entry cmd_unbind_key_entry = {
CMD_UNBINDKEY, "unbind-key", "unbind", CMD_NOSESSION,
CMD_UNBINDKEY, "unbind-key", "unbind", "key",
CMD_NOSESSION,
cmd_unbind_key_parse,
cmd_unbind_key_usage,
cmd_unbind_key_exec,
cmd_unbind_key_send,
cmd_unbind_key_recv,
@ -74,19 +74,14 @@ cmd_unbind_key_parse(void **ptr, int argc, char **argv, char **cause)
return (0);
usage:
usage(cause, "%s", cmd_unbind_key_usage());
usage(cause, "%s %s",
cmd_unbind_key_entry.name, cmd_unbind_key_entry.usage);
error:
xfree(data);
return (-1);
}
const char *
cmd_unbind_key_usage(void)
{
return ("unbind-key key");
}
void
cmd_unbind_key_exec(void *ptr, unused struct cmd_ctx *ctx)
{

7
cmd.c
View File

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.12 2007-10-04 11:52:03 nicm Exp $ */
/* $Id: cmd.c,v 1.13 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -98,10 +98,7 @@ cmd_parse(int argc, char **argv, char **cause)
return (cmd);
usage:
if (entry->usage == NULL)
usage(cause, "%s", entry->name);
else
usage(cause, "%s", entry->usage());
usage(cause, "%s %s", entry->name, entry->usage);
return (NULL);
}

4
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.48 2007-10-04 19:03:52 nicm Exp $ */
/* $Id: tmux.h,v 1.49 2007-10-04 21:48:11 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -489,13 +489,13 @@ struct cmd_entry {
enum cmd_type type;
const char *name;
const char *alias;
const char *usage;
#define CMD_STARTSERVER 0x1
#define CMD_NOSESSION 0x2
int flags;
int (*parse)(void **, int, char **, char **);
const char *(*usage)(void);
void (*exec)(void *, struct cmd_ctx *);
void (*send)(void *, struct buffer *);
void (*recv)(void **, struct buffer *);