From 3f86d6d46014ca55e42cecd570d7f269b1d386b3 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 13 Apr 2020 15:55:51 +0000 Subject: When adding a list of commands to the queue, instead of automatically creating a new state for each group of commands, require the caller to create one and use it for all the commands in the list. This means the current target works even with list with multiple groups (which can happen if they are defined with newlines). --- cmd.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'cmd.c') diff --git a/cmd.c b/cmd.c index d0a8c267..b7b144b4 100644 --- a/cmd.c +++ b/cmd.c @@ -392,6 +392,13 @@ cmd_get_args(struct cmd *cmd) return (cmd->args); } +/* Get group for command. */ +u_int +cmd_get_group(struct cmd *cmd) +{ + return (cmd->group); +} + /* Get file and line for command. */ void cmd_get_source(struct cmd *cmd, const char **file, u_int *line) @@ -646,24 +653,16 @@ cmd_list_print(struct cmd_list *cmdlist, int escaped) /* Get first command in list. */ struct cmd * -cmd_list_first(struct cmd_list *cmdlist, u_int *group) +cmd_list_first(struct cmd_list *cmdlist) { - struct cmd *cmd; - - cmd = TAILQ_FIRST(cmdlist->list); - if (cmd != NULL && group != NULL) - *group = cmd->group; - return (cmd); + return (TAILQ_FIRST(cmdlist->list)); } /* Get next command in list. */ struct cmd * -cmd_list_next(struct cmd *cmd, u_int *group) +cmd_list_next(struct cmd *cmd) { - cmd = TAILQ_NEXT(cmd, qentry); - if (cmd != NULL && group != NULL) - *group = cmd->group; - return (cmd); + return (TAILQ_NEXT(cmd, qentry)); } /* Do all of the commands in this command list have this flag? */ -- cgit From 34804f2709a16dca45dc072fb53d03f79db61e51 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 13 Apr 2020 16:19:37 +0000 Subject: When parsing strings, put all commands in one group even if there are newlines. This means that for example bind q { a \n b } and bind q "a ; b" are the same. Also log commands in different groups separated by ;; rather than ; (a command list like this should never be user visible). --- cmd.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'cmd.c') diff --git a/cmd.c b/cmd.c index b7b144b4..bc807cbe 100644 --- a/cmd.c +++ b/cmd.c @@ -624,7 +624,7 @@ cmd_list_free(struct cmd_list *cmdlist) char * cmd_list_print(struct cmd_list *cmdlist, int escaped) { - struct cmd *cmd; + struct cmd *cmd, *next; char *buf, *this; size_t len; @@ -634,15 +634,24 @@ cmd_list_print(struct cmd_list *cmdlist, int escaped) TAILQ_FOREACH(cmd, cmdlist->list, qentry) { this = cmd_print(cmd); - len += strlen(this) + 4; + len += strlen(this) + 6; buf = xrealloc(buf, len); strlcat(buf, this, len); - if (TAILQ_NEXT(cmd, qentry) != NULL) { - if (escaped) - strlcat(buf, " \\; ", len); - else - strlcat(buf, " ; ", len); + + next = TAILQ_NEXT(cmd, qentry); + if (next != NULL) { + if (cmd->group != next->group) { + if (escaped) + strlcat(buf, " \\;\\; ", len); + else + strlcat(buf, " ;; ", len); + } else { + if (escaped) + strlcat(buf, " \\; ", len); + else + strlcat(buf, " ; ", len); + } } free(this); -- cgit