diff options
author | nicm <nicm> | 2020-04-13 16:19:37 +0000 |
---|---|---|
committer | nicm <nicm> | 2020-04-13 16:19:37 +0000 |
commit | 34804f2709a16dca45dc072fb53d03f79db61e51 (patch) | |
tree | f48af448b3e6ed6b91207a828b7603e0f407ef48 /cmd-parse.y | |
parent | 3f86d6d46014ca55e42cecd570d7f269b1d386b3 (diff) | |
download | rtmux-34804f2709a16dca45dc072fb53d03f79db61e51.tar.gz rtmux-34804f2709a16dca45dc072fb53d03f79db61e51.tar.bz2 rtmux-34804f2709a16dca45dc072fb53d03f79db61e51.zip |
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).
Diffstat (limited to 'cmd-parse.y')
-rw-r--r-- | cmd-parse.y | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/cmd-parse.y b/cmd-parse.y index aabfe2d3..2ca0124a 100644 --- a/cmd-parse.y +++ b/cmd-parse.y @@ -700,15 +700,17 @@ cmd_parse_build_commands(struct cmd_parse_commands *cmds, /* * Parse each command into a command list. Create a new command list - * for each line so they get a new group (so the queue knows which ones - * to remove if a command fails when executed). + * for each line (unless the flag is set) so they get a new group (so + * the queue knows which ones to remove if a command fails when + * executed). */ result = cmd_list_new(); TAILQ_FOREACH(cmd, cmds, entry) { log_debug("%s: %u %s", __func__, cmd->line, cmd->name); cmd_log_argv(cmd->argc, cmd->argv, __func__); - if (cmdlist == NULL || cmd->line != line) { + if (cmdlist == NULL || + ((~pi->flags & CMD_PARSE_ONEGROUP) && cmd->line != line)) { if (cmdlist != NULL) { cmd_parse_print_commands(pi, line, cmdlist); cmd_list_move(result, cmdlist); @@ -775,6 +777,19 @@ cmd_parse_from_file(FILE *f, struct cmd_parse_input *pi) struct cmd_parse_result * cmd_parse_from_string(const char *s, struct cmd_parse_input *pi) { + struct cmd_parse_input input; + + if (pi == NULL) { + memset(&input, 0, sizeof input); + pi = &input; + } + + /* + * When parsing a string, put commands in one group even if there are + * multiple lines. This means { a \n b } is identical to "a ; b" when + * given as an argument to another command. + */ + pi->flags |= CMD_PARSE_ONEGROUP; return (cmd_parse_from_buffer(s, strlen(s), pi)); } |