version 1.7, 2016/10/16 17:55:14 |
version 1.8, 2016/10/16 19:04:05 |
|
|
hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs, |
hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs, |
const char *fmt, ...) |
const char *fmt, ...) |
{ |
{ |
struct hook *hook; |
struct hook *hook; |
va_list ap; |
va_list ap; |
char *name; |
char *name; |
struct cmd_q *new_cmdq, *loop; |
struct cmdq_item *new_item, *loop; |
|
|
va_start(ap, fmt); |
va_start(ap, fmt); |
xvasprintf(&name, fmt, ap); |
xvasprintf(&name, fmt, ap); |
|
|
} |
} |
log_debug("running hook %s", name); |
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); |
loop->hook = xstrdup(name); |
free(name); |
free(name); |
|
|
cmdq_append(c, new_cmdq); |
cmdq_append(c, new_item); |
} |
} |
|
|
void |
void |
hooks_insert(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs, |
hooks_insert(struct hooks *hooks, struct cmdq_item *item, |
const char *fmt, ...) |
struct cmd_find_state *fs, const char *fmt, ...) |
{ |
{ |
struct hook *hook; |
struct hook *hook; |
va_list ap; |
va_list ap; |
char *name; |
char *name; |
struct cmd_q *new_cmdq, *loop; |
struct cmdq_item *new_item, *loop; |
|
|
if (cmdq->flags & CMD_Q_NOHOOKS) |
if (item->flags & CMDQ_NOHOOKS) |
return; |
return; |
|
|
va_start(ap, fmt); |
va_start(ap, fmt); |
|
|
free(name); |
free(name); |
return; |
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); |
loop->hook = xstrdup(name); |
free(name); |
free(name); |
|
|
if (cmdq != NULL) |
if (item != NULL) |
cmdq_insert_after(cmdq, new_cmdq); |
cmdq_insert_after(item, new_item); |
else |
else |
cmdq_append(NULL, new_cmdq); |
cmdq_append(NULL, new_item); |
} |
} |