Split parsing and execution of commands

Due to variable substitution and string unescaping, parsing
commands necessitates allocation. Because allocation can fail,
commands (invoked, via bindings or criteria) may in turn fail
when memory is restricted, which is most often the case in
anomalous situations (i.e., a memory leak in sway, overcommit
disabled, bad config/ipc, etc.).

This commit defines a `struct stored_command` in which a parsed
command can be stored, and then executed from. Command execution
in execute_command now generates a series of struct
stored_command, which are promptly invoked by
execute_stored_command.
This commit is contained in:
mstoeckl 2018-08-23 17:25:48 -04:00
parent e86d99acd6
commit f8b9c796f4
2 changed files with 71 additions and 46 deletions

View file

@ -51,7 +51,20 @@ 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);
struct stored_command {
sway_cmd *handle;
int argc;
char** argv;
struct criteria* criteria;
};
/**
* Executes a pre-parsed command. (Returns NULL if command was not unsuccessful: TODO, fix)
*/
struct cmd_results *execute_stored_command(const struct stored_command *command,
struct sway_seat *seat);
/**
* Parse and handles a command during config file loading.
*