summaryrefslogtreecommitdiffstats
path: root/cmd-queue.c
diff options
context:
space:
mode:
authornicm <nicm>2017-04-22 10:22:39 +0000
committernicm <nicm>2017-04-22 10:22:39 +0000
commitee45a8a149e1a3c8fe7c232a9e32f3a007e21bee (patch)
tree21cc9cafd10d55cd7cd92ec616d08ac59adc4a0a /cmd-queue.c
parent2c0f826c360fc5a8f0e125759b596eb28441ba65 (diff)
Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands with special requirements call it themselves and update the target for hooks to use.
Diffstat (limited to 'cmd-queue.c')
-rw-r--r--cmd-queue.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/cmd-queue.c b/cmd-queue.c
index 99ec6055..5165df17 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -189,14 +189,34 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
return (first);
}
+/* Fill in flag for a command. */
+static enum cmd_retval
+cmdq_find_flag(struct cmdq_item *item, struct cmd_find_state *fs,
+ const struct cmd_entry_flag *flag)
+{
+ const char *value;
+
+ if (flag->flag == 0) {
+ cmd_find_clear_state(fs, 0);
+ return (CMD_RETURN_NORMAL);
+ }
+
+ value = args_get(item->cmd->args, flag->flag);
+ if (cmd_find_target(fs, item, value, flag->type, flag->flags) != 0) {
+ cmd_find_clear_state(fs, 0);
+ return (CMD_RETURN_ERROR);
+ }
+ return (CMD_RETURN_NORMAL);
+}
+
/* Fire command on command queue. */
static enum cmd_retval
cmdq_fire_command(struct cmdq_item *item)
{
struct client *c = item->client;
struct cmd *cmd = item->cmd;
+ const struct cmd_entry *entry = cmd->entry;
enum cmd_retval retval;
- const char *name;
struct cmd_find_state *fsp, fs;
int flags;
@@ -205,27 +225,27 @@ cmdq_fire_command(struct cmdq_item *item)
if (item->client == NULL)
item->client = cmd_find_client(item, NULL, 1);
-
- if (cmd_prepare_state(cmd, item) != 0) {
- retval = CMD_RETURN_ERROR;
+ retval = cmdq_find_flag(item, &item->source, &entry->source);
+ if (retval == CMD_RETURN_ERROR)
+ goto out;
+ retval = cmdq_find_flag(item, &item->target, &entry->target);
+ if (retval == CMD_RETURN_ERROR)
goto out;
- }
- retval = cmd->entry->exec(cmd, item);
+ retval = entry->exec(cmd, item);
if (retval == CMD_RETURN_ERROR)
goto out;
- if (cmd->entry->flags & CMD_AFTERHOOK) {
- name = cmd->entry->name;
- if (cmd_find_valid_state(&item->state.tflag))
- fsp = &item->state.tflag;
+ if (entry->flags & CMD_AFTERHOOK) {
+ if (cmd_find_valid_state(&item->target))
+ fsp = &item->target;
else if (cmd_find_valid_state(&item->shared->current))
fsp = &item->shared->current;
else if (cmd_find_from_client(&fs, item->client) == 0)
fsp = &fs;
else
goto out;
- hooks_insert(fsp->s->hooks, item, fsp, "after-%s", name);
+ hooks_insert(fsp->s->hooks, item, fsp, "after-%s", entry->name);
}
out: