summaryrefslogtreecommitdiffstats
path: root/hooks.c
diff options
context:
space:
mode:
authornicm <nicm>2016-10-16 19:36:37 +0000
committernicm <nicm>2016-10-16 19:36:37 +0000
commit3f35b5299fb2c08637aa12757185e5b82eeb3fc1 (patch)
tree5323b2851735c5b1052a4c2bae303f532bee191c /hooks.c
parent026ad08b56b4577beab6bad06b8a7a21602bca11 (diff)
Provide a way for hooks to tag formats onto the commands they fire so
that the user can get at additional information - now used for the "hook" format, more to come.
Diffstat (limited to 'hooks.c')
-rw-r--r--hooks.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/hooks.c b/hooks.c
index 3fa79e49..832e6f84 100644
--- a/hooks.c
+++ b/hooks.c
@@ -146,7 +146,7 @@ hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs,
struct hook *hook;
va_list ap;
char *name;
- struct cmdq_item *new_item, *loop;
+ struct cmdq_item *new_item;
va_start(ap, fmt);
xvasprintf(&name, fmt, ap);
@@ -160,12 +160,10 @@ hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs,
log_debug("running hook %s", name);
new_item = cmdq_get_command(hook->cmdlist, fs, NULL, CMDQ_NOHOOKS);
+ cmdq_format(new_item, "hook", "%s", name);
+ cmdq_append(c, new_item);
- for (loop = new_item; loop != NULL; loop = loop->next)
- loop->hook = xstrdup(name);
free(name);
-
- cmdq_append(c, new_item);
}
void
@@ -175,7 +173,7 @@ hooks_insert(struct hooks *hooks, struct cmdq_item *item,
struct hook *hook;
va_list ap;
char *name;
- struct cmdq_item *new_item, *loop;
+ struct cmdq_item *new_item;
if (item->flags & CMDQ_NOHOOKS)
return;
@@ -192,13 +190,11 @@ hooks_insert(struct hooks *hooks, struct cmdq_item *item,
log_debug("running hook %s (parent %p)", name, item);
new_item = cmdq_get_command(hook->cmdlist, fs, NULL, CMDQ_NOHOOKS);
-
- for (loop = new_item; loop != NULL; loop = loop->next)
- loop->hook = xstrdup(name);
- free(name);
-
+ cmdq_format(new_item, "hook", "%s", name);
if (item != NULL)
cmdq_insert_after(item, new_item);
else
cmdq_append(NULL, new_item);
+
+ free(name);
}