Simplify runtime variable substitution

The operations bindsym, bindcode, and for_window extract a new (nested)
command to be run from their last arguments. The argc/argv interface
for commands hides a measure of preprocessing (removing quotes,
unescaping characters, and performing variable substitution). Before
this commit, this preprocessing was applied twice for the nested
commands. To provide variable substitution for nested commands, commit
067fe9d047 introduced a double-escaping method (simplifying
$$x to $x in the first preprocessing pass, and $x to the appropriate
value in the second. This commit ensures that the nested commands are
only preprocessed once, so that the double-escape trick is no longer
required.

The preprocessing code in execute_command, config_command, and
config_subcommand has been moved to a new function, preprocess_arg,
which performs quote stripping, unescaping, and variable expansion as
necessary, while preserving special cases for cmd_set and cmd_exec,
and adding new special cases for cmd_for_window, cmd_bindsym, and
cmd_bindcode, in which the trailing portion of their argument lists
are passed on unmodified as the single final argument.
This commit is contained in:
mstoeckl 2018-08-25 19:33:28 -04:00
parent ed147aed30
commit 01757979de
5 changed files with 131 additions and 57 deletions

View file

@ -51,7 +51,7 @@ struct cmd_handler *find_handler(char *line, struct cmd_handler *cmd_handlers,
/**
* Parse and executes a command.
*/
struct cmd_results *execute_command(char *command, struct sway_seat *seat);
struct cmd_results *execute_command(const char *command, struct sway_seat *seat);
/**
* Parse and handles a command during config file loading.
*