diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
commit | f7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch) | |
tree | a3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/doveadm/doveadm-print-tab.c | |
parent | Initial commit. (diff) | |
download | dovecot-upstream.tar.xz dovecot-upstream.zip |
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/doveadm/doveadm-print-tab.c')
-rw-r--r-- | src/doveadm/doveadm-print-tab.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/doveadm/doveadm-print-tab.c b/src/doveadm/doveadm-print-tab.c new file mode 100644 index 0000000..c5871ec --- /dev/null +++ b/src/doveadm/doveadm-print-tab.c @@ -0,0 +1,76 @@ +/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "array.h" +#include "ostream.h" +#include "doveadm-print-private.h" + +struct doveadm_print_tab_context { + unsigned int header_idx, header_count; + + bool header_written:1; +}; + +static struct doveadm_print_tab_context ctx; + +static void doveadm_print_tab_flush_header(void) +{ + if (!ctx.header_written) { + if (!doveadm_print_hide_titles) + o_stream_nsend(doveadm_print_ostream, "\n", 1); + ctx.header_written = TRUE; + } +} + +static void +doveadm_print_tab_header(const struct doveadm_print_header *hdr) +{ + ctx.header_count++; + if (!doveadm_print_hide_titles) { + if (ctx.header_count > 1) + o_stream_nsend(doveadm_print_ostream, "\t", 1); + o_stream_nsend_str(doveadm_print_ostream, hdr->title); + } +} + +static void doveadm_print_tab_print(const char *value) +{ + doveadm_print_tab_flush_header(); + if (ctx.header_idx > 0) + o_stream_nsend(doveadm_print_ostream, "\t", 1); + o_stream_nsend_str(doveadm_print_ostream, value); + + if (++ctx.header_idx == ctx.header_count) { + ctx.header_idx = 0; + o_stream_nsend(doveadm_print_ostream, "\n", 1); + } +} + +static void +doveadm_print_tab_print_stream(const unsigned char *value, size_t size) +{ + if (size == 0) { + doveadm_print_tab_print(""); + return; + } + doveadm_print_tab_flush_header(); + if (ctx.header_idx > 0) + o_stream_nsend(doveadm_print_ostream, "\t", 1); + o_stream_nsend(doveadm_print_ostream, value, size); +} + +static void doveadm_print_tab_flush(void) +{ + doveadm_print_tab_flush_header(); +} + +struct doveadm_print_vfuncs doveadm_print_tab_vfuncs = { + "tab", + + NULL, + NULL, + doveadm_print_tab_header, + doveadm_print_tab_print, + doveadm_print_tab_print_stream, + doveadm_print_tab_flush +}; |