summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-queue.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2016-10-16 19:36:37 +0000
committernicm <nicm@openbsd.org>2016-10-16 19:36:37 +0000
commitdaa6f31e7a6ed03cc91ded4699edcb2d6ce31467 (patch)
tree1e225148e8ca5ed5870bf8b584b1e37592b5d0b0 /usr.bin/tmux/cmd-queue.c
parentMove libcrypto, librpcsvc and gnu/usr.bin/cc/include from RDIRS to PRDIRS, (diff)
downloadwireguard-openbsd-daa6f31e7a6ed03cc91ded4699edcb2d6ce31467.tar.xz
wireguard-openbsd-daa6f31e7a6ed03cc91ded4699edcb2d6ce31467.zip
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 'usr.bin/tmux/cmd-queue.c')
-rw-r--r--usr.bin/tmux/cmd-queue.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index 377f06da83f..6db90945bb8 100644
--- a/usr.bin/tmux/cmd-queue.c
+++ b/usr.bin/tmux/cmd-queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-queue.c,v 1.44 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.45 2016/10/16 19:36:37 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -102,7 +102,8 @@ cmdq_insert_after(struct cmdq_item *after, struct cmdq_item *item)
static void
cmdq_remove(struct cmdq_item *item)
{
- free((void *)item->hook);
+ if (item->formats != NULL)
+ format_free(item->formats);
if (item->client != NULL)
server_client_unref(item->client);
@@ -241,6 +242,28 @@ cmdq_fire_callback(struct cmdq_item *item)
return (item->cb(item, item->data));
}
+/* Add a format to command queue. */
+void
+cmdq_format(struct cmdq_item *item, const char *key, const char *fmt, ...)
+{
+ va_list ap;
+ struct cmdq_item *loop;
+ char *value;
+
+ va_start(ap, fmt);
+ xvasprintf(&value, fmt, ap);
+ va_end(ap);
+
+ for (loop = item; loop != NULL; loop = item->next) {
+ if (loop->formats == NULL)
+ loop->formats = format_create(NULL, 0);
+ format_add(loop->formats, key, "%s", value);
+ }
+
+ free(value);
+}
+
+
/* Process next item on command queue. */
u_int
cmdq_next(struct client *c)