From 4751eda976c09f2409e93364b6b76fdc950bcda6 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 2 Jun 2017 21:30:19 +0200 Subject: Add blind-interleave, blind-cat-rows, and blind-cat-cols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blind-cat-cols.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/blind-cat-cols.c (limited to 'src/blind-cat-cols.c') diff --git a/src/blind-cat-cols.c b/src/blind-cat-cols.c new file mode 100644 index 0000000..e20e913 --- /dev/null +++ b/src/blind-cat-cols.c @@ -0,0 +1,42 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +USAGE("(file columns) ...") + +int +main(int argc, char *argv[]) +{ + struct stream *streams; + size_t parts, width = 0, *cols, i; + + UNOFLAGS(argc % 2 || !argc); + + parts = (size_t)argc / 2; + streams = emalloc2(parts, sizeof(*streams)); + cols = alloca(parts * sizeof(*cols)); + + for (i = 0; i < parts; i++) { + eopen_stream(streams + i, argv[i * 2]); + cols[i] = etozu_arg("columns", argv[i * 2 + 1], 1, SIZE_MAX); + if (streams[i].width > SIZE_MAX - width) + eprintf("output video is too tall\n"); + width += streams[i].width; + if (i) { + streams[i].width = streams->width; + echeck_compat(streams, streams + i); + } + } + + streams->width = width; + fprint_stream_head(stdout, streams); + efflush(stdout, ""); + + for (i = 0; i < parts; i++, i = i == parts ? 0 : i) + if (esend_pixels(streams + i, STDOUT_FILENO, cols[i], "") != cols[i]) + break; + for (i = 0; i < parts; i++) + close(streams[i].fd); + + free(streams); + return 0; +} -- cgit v1.2.3-70-g09d2