From b342bd0b462f69a9fc9a59d52bcd4bb34b57114f Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 16 Oct 2016 19:04:05 +0000 Subject: Mass rename struct cmd_q to struct cmdq_item and related. --- hooks.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'hooks.c') diff --git a/hooks.c b/hooks.c index cdd2cf45..3fa79e49 100644 --- a/hooks.c +++ b/hooks.c @@ -143,10 +143,10 @@ void hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs, const char *fmt, ...) { - struct hook *hook; - va_list ap; - char *name; - struct cmd_q *new_cmdq, *loop; + struct hook *hook; + va_list ap; + char *name; + struct cmdq_item *new_item, *loop; va_start(ap, fmt); xvasprintf(&name, fmt, ap); @@ -159,25 +159,25 @@ hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs, } log_debug("running hook %s", name); - new_cmdq = cmdq_get_command(hook->cmdlist, fs, NULL, CMD_Q_NOHOOKS); + new_item = cmdq_get_command(hook->cmdlist, fs, NULL, CMDQ_NOHOOKS); - for (loop = new_cmdq; loop != NULL; loop = loop->next) + for (loop = new_item; loop != NULL; loop = loop->next) loop->hook = xstrdup(name); free(name); - cmdq_append(c, new_cmdq); + cmdq_append(c, new_item); } void -hooks_insert(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs, - const char *fmt, ...) +hooks_insert(struct hooks *hooks, struct cmdq_item *item, + struct cmd_find_state *fs, const char *fmt, ...) { - struct hook *hook; - va_list ap; - char *name; - struct cmd_q *new_cmdq, *loop; + struct hook *hook; + va_list ap; + char *name; + struct cmdq_item *new_item, *loop; - if (cmdq->flags & CMD_Q_NOHOOKS) + if (item->flags & CMDQ_NOHOOKS) return; va_start(ap, fmt); @@ -189,16 +189,16 @@ hooks_insert(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs, free(name); return; } - log_debug("running hook %s (parent %p)", name, cmdq); + log_debug("running hook %s (parent %p)", name, item); - new_cmdq = cmdq_get_command(hook->cmdlist, fs, NULL, CMD_Q_NOHOOKS); + new_item = cmdq_get_command(hook->cmdlist, fs, NULL, CMDQ_NOHOOKS); - for (loop = new_cmdq; loop != NULL; loop = loop->next) + for (loop = new_item; loop != NULL; loop = loop->next) loop->hook = xstrdup(name); free(name); - if (cmdq != NULL) - cmdq_insert_after(cmdq, new_cmdq); + if (item != NULL) + cmdq_insert_after(item, new_item); else - cmdq_append(NULL, new_cmdq); + cmdq_append(NULL, new_item); } -- cgit From 3f35b5299fb2c08637aa12757185e5b82eeb3fc1 Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 16 Oct 2016 19:36:37 +0000 Subject: 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. --- hooks.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'hooks.c') 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); } -- cgit