mirror of
https://github.com/tmux/tmux.git
synced 2025-09-01 20:57:00 +00:00
Merge branch 'obsd-master'
This commit is contained in:
127
cmd.c
127
cmd.c
@ -206,8 +206,27 @@ const struct cmd_entry *cmd_table[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
/* Instance of a command. */
|
||||
struct cmd {
|
||||
const struct cmd_entry *entry;
|
||||
struct args *args;
|
||||
u_int group;
|
||||
|
||||
char *file;
|
||||
u_int line;
|
||||
|
||||
char *alias;
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
TAILQ_ENTRY(cmd) qentry;
|
||||
};
|
||||
TAILQ_HEAD(cmds, cmd);
|
||||
|
||||
/* Next group number for new command list. */
|
||||
static u_int cmd_list_next_group = 1;
|
||||
|
||||
/* Log an argument vector. */
|
||||
void printflike(3, 4)
|
||||
cmd_log_argv(int argc, char **argv, const char *fmt, ...)
|
||||
{
|
||||
@ -224,6 +243,7 @@ cmd_log_argv(int argc, char **argv, const char *fmt, ...)
|
||||
free(prefix);
|
||||
}
|
||||
|
||||
/* Prepend to an argument vector. */
|
||||
void
|
||||
cmd_prepend_argv(int *argc, char ***argv, char *arg)
|
||||
{
|
||||
@ -240,6 +260,7 @@ cmd_prepend_argv(int *argc, char ***argv, char *arg)
|
||||
(*argc)++;
|
||||
}
|
||||
|
||||
/* Append to an argument vector. */
|
||||
void
|
||||
cmd_append_argv(int *argc, char ***argv, char *arg)
|
||||
{
|
||||
@ -247,6 +268,7 @@ cmd_append_argv(int *argc, char ***argv, char *arg)
|
||||
(*argv)[(*argc)++] = xstrdup(arg);
|
||||
}
|
||||
|
||||
/* Pack an argument vector up into a buffer. */
|
||||
int
|
||||
cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
|
||||
{
|
||||
@ -269,6 +291,7 @@ cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Unpack an argument vector from a packed buffer. */
|
||||
int
|
||||
cmd_unpack_argv(char *buf, size_t len, int argc, char ***argv)
|
||||
{
|
||||
@ -297,6 +320,7 @@ cmd_unpack_argv(char *buf, size_t len, int argc, char ***argv)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Copy an argument vector, ensuring it is terminated by NULL. */
|
||||
char **
|
||||
cmd_copy_argv(int argc, char **argv)
|
||||
{
|
||||
@ -313,6 +337,7 @@ cmd_copy_argv(int argc, char **argv)
|
||||
return (new_argv);
|
||||
}
|
||||
|
||||
/* Free an argument vector. */
|
||||
void
|
||||
cmd_free_argv(int argc, char **argv)
|
||||
{
|
||||
@ -325,6 +350,7 @@ cmd_free_argv(int argc, char **argv)
|
||||
free(argv);
|
||||
}
|
||||
|
||||
/* Convert argument vector to a string. */
|
||||
char *
|
||||
cmd_stringify_argv(int argc, char **argv)
|
||||
{
|
||||
@ -351,6 +377,31 @@ cmd_stringify_argv(int argc, char **argv)
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/* Get entry for command. */
|
||||
const struct cmd_entry *
|
||||
cmd_get_entry(struct cmd *cmd)
|
||||
{
|
||||
return (cmd->entry);
|
||||
}
|
||||
|
||||
/* Get arguments for command. */
|
||||
struct args *
|
||||
cmd_get_args(struct cmd *cmd)
|
||||
{
|
||||
return (cmd->args);
|
||||
}
|
||||
|
||||
/* Get file and line for command. */
|
||||
void
|
||||
cmd_get_source(struct cmd *cmd, const char **file, u_int *line)
|
||||
{
|
||||
if (file != NULL)
|
||||
*file = cmd->file;
|
||||
if (line != NULL)
|
||||
*line = cmd->line;
|
||||
}
|
||||
|
||||
/* Look for an alias for a command. */
|
||||
char *
|
||||
cmd_get_alias(const char *name)
|
||||
{
|
||||
@ -381,6 +432,7 @@ cmd_get_alias(const char *name)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Look up a command entry by name. */
|
||||
static const struct cmd_entry *
|
||||
cmd_find(const char *name, char **cause)
|
||||
{
|
||||
@ -430,6 +482,7 @@ ambiguous:
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Parse a single command from an argument vector. */
|
||||
struct cmd *
|
||||
cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
|
||||
{
|
||||
@ -478,6 +531,7 @@ usage:
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Free a command. */
|
||||
void
|
||||
cmd_free(struct cmd *cmd)
|
||||
{
|
||||
@ -490,6 +544,7 @@ cmd_free(struct cmd *cmd)
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
/* Get a command as a string. */
|
||||
char *
|
||||
cmd_print(struct cmd *cmd)
|
||||
{
|
||||
@ -505,6 +560,7 @@ cmd_print(struct cmd *cmd)
|
||||
return (out);
|
||||
}
|
||||
|
||||
/* Create a new command list. */
|
||||
struct cmd_list *
|
||||
cmd_list_new(void)
|
||||
{
|
||||
@ -513,29 +569,33 @@ cmd_list_new(void)
|
||||
cmdlist = xcalloc(1, sizeof *cmdlist);
|
||||
cmdlist->references = 1;
|
||||
cmdlist->group = cmd_list_next_group++;
|
||||
TAILQ_INIT(&cmdlist->list);
|
||||
cmdlist->list = xcalloc(1, sizeof *cmdlist->list);
|
||||
TAILQ_INIT(cmdlist->list);
|
||||
return (cmdlist);
|
||||
}
|
||||
|
||||
/* Append a command to a command list. */
|
||||
void
|
||||
cmd_list_append(struct cmd_list *cmdlist, struct cmd *cmd)
|
||||
{
|
||||
cmd->group = cmdlist->group;
|
||||
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||
TAILQ_INSERT_TAIL(cmdlist->list, cmd, qentry);
|
||||
}
|
||||
|
||||
/* Move all commands from one command list to another */
|
||||
void
|
||||
cmd_list_move(struct cmd_list *cmdlist, struct cmd_list *from)
|
||||
{
|
||||
struct cmd *cmd, *cmd1;
|
||||
|
||||
TAILQ_FOREACH_SAFE(cmd, &from->list, qentry, cmd1) {
|
||||
TAILQ_REMOVE(&from->list, cmd, qentry);
|
||||
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||
TAILQ_FOREACH_SAFE(cmd, from->list, qentry, cmd1) {
|
||||
TAILQ_REMOVE(from->list, cmd, qentry);
|
||||
TAILQ_INSERT_TAIL(cmdlist->list, cmd, qentry);
|
||||
}
|
||||
cmdlist->group = cmd_list_next_group++;
|
||||
}
|
||||
|
||||
/* Free a command list. */
|
||||
void
|
||||
cmd_list_free(struct cmd_list *cmdlist)
|
||||
{
|
||||
@ -544,14 +604,15 @@ cmd_list_free(struct cmd_list *cmdlist)
|
||||
if (--cmdlist->references != 0)
|
||||
return;
|
||||
|
||||
TAILQ_FOREACH_SAFE(cmd, &cmdlist->list, qentry, cmd1) {
|
||||
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
|
||||
TAILQ_FOREACH_SAFE(cmd, cmdlist->list, qentry, cmd1) {
|
||||
TAILQ_REMOVE(cmdlist->list, cmd, qentry);
|
||||
cmd_free(cmd);
|
||||
}
|
||||
|
||||
free(cmdlist->list);
|
||||
free(cmdlist);
|
||||
}
|
||||
|
||||
/* Get a command list as a string. */
|
||||
char *
|
||||
cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
||||
{
|
||||
@ -562,7 +623,7 @@ cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
||||
len = 1;
|
||||
buf = xcalloc(1, len);
|
||||
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||
TAILQ_FOREACH(cmd, cmdlist->list, qentry) {
|
||||
this = cmd_print(cmd);
|
||||
|
||||
len += strlen(this) + 4;
|
||||
@ -582,6 +643,54 @@ cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/* Get first command in list. */
|
||||
struct cmd *
|
||||
cmd_list_first(struct cmd_list *cmdlist, u_int *group)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
|
||||
cmd = TAILQ_FIRST(cmdlist->list);
|
||||
if (cmd != NULL && group != NULL)
|
||||
*group = cmd->group;
|
||||
return (cmd);
|
||||
}
|
||||
|
||||
/* Get next command in list. */
|
||||
struct cmd *
|
||||
cmd_list_next(struct cmd *cmd, u_int *group)
|
||||
{
|
||||
cmd = TAILQ_NEXT(cmd, qentry);
|
||||
if (cmd != NULL && group != NULL)
|
||||
*group = cmd->group;
|
||||
return (cmd);
|
||||
}
|
||||
|
||||
/* Do all of the commands in this command list have this flag? */
|
||||
int
|
||||
cmd_list_all_have(struct cmd_list *cmdlist, int flag)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
|
||||
TAILQ_FOREACH(cmd, cmdlist->list, qentry) {
|
||||
if (~cmd->entry->flags & flag)
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Do any of the commands in this command list have this flag? */
|
||||
int
|
||||
cmd_list_any_have(struct cmd_list *cmdlist, int flag)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
|
||||
TAILQ_FOREACH(cmd, cmdlist->list, qentry) {
|
||||
if (cmd->entry->flags & flag)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Adjust current mouse position for a pane. */
|
||||
int
|
||||
cmd_mouse_at(struct window_pane *wp, struct mouse_event *m, u_int *xp,
|
||||
|
Reference in New Issue
Block a user