From b7a82c980fe7e0c1f9029b55be97422428d65d5a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 11 Jan 2017 09:11:51 +0100 Subject: Clean up code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/vu-arithm.c | 49 +++++++++---------------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) (limited to 'src/vu-arithm.c') diff --git a/src/vu-arithm.c b/src/vu-arithm.c index 61f60fd..fd0ff6a 100644 --- a/src/vu-arithm.c +++ b/src/vu-arithm.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include "arg.h" #include "stream.h" #include "util.h" @@ -9,15 +8,11 @@ #include #include +USAGE("right-hand-stream") + /* Because the syntax for a function returning a function pointer is disgusting. */ typedef void (*process_func)(struct stream *left, struct stream *right, size_t n); -static void -usage(void) -{ - eprintf("usage: %s operation right-hand-stream\n", argv0); -} - #define LIST_OPERATORS\ X(add, *lh += rh)\ X(sub, *lh -= rh)\ @@ -64,32 +59,20 @@ main(int argc, char *argv[]) { struct stream left; struct stream right; - ssize_t r; - size_t i, n; + size_t n; process_func process = NULL; - ARGBEGIN { - default: - usage(); - } ARGEND; - - if (argc != 2) - usage(); + ENOFLAGS(argc != 2); left.file = ""; left.fd = STDIN_FILENO; einit_stream(&left); right.file = argv[1]; - right.fd = open(right.file, O_RDONLY); - if (right.fd < 0) - eprintf("open %s:", right.file); + right.fd = eopen(right.file, O_RDONLY); einit_stream(&right); - if (left.width != right.width || left.height != right.height) - eprintf("videos do not have the same geometry\n"); - if (left.pixel_size != right.pixel_size) - eprintf("videos use incompatible pixel formats\n"); + echeck_compat(&left, &right); if (!strcmp(left.pixfmt, "xyza")) process = get_lf_process(argv[0]); @@ -115,12 +98,7 @@ main(int argc, char *argv[]) process(&left, &right, n); - for (i = 0; i < n; i += (size_t)r) { - r = write(STDOUT_FILENO, left.buf + i, n - i); - if (r < 0) - eprintf("write :"); - } - + ewriteall(STDOUT_FILENO, left.buf, n, ""); if ((n & 3) || left.ptr != right.ptr) { memmove(left.buf, left.buf + n, left.ptr); memmove(right.buf, right.buf + n, right.ptr); @@ -130,11 +108,7 @@ main(int argc, char *argv[]) if (right.fd >= 0) close(right.fd); - for (i = 0; i < left.ptr; i += (size_t)r) { - r = write(STDOUT_FILENO, left.buf + i, left.ptr - i); - if (r < 0) - eprintf("write :"); - } + ewriteall(STDOUT_FILENO, left.buf, left.ptr, ""); if (left.fd >= 0) { for (;;) { @@ -144,12 +118,7 @@ main(int argc, char *argv[]) left.fd = -1; break; } - - for (i = 0; i < left.ptr; i += (size_t)r) { - r = write(STDOUT_FILENO, left.buf + i, left.ptr - i); - if (r < 0) - eprintf("write :"); - } + ewriteall(STDOUT_FILENO, left.buf, left.ptr, ""); } } -- cgit v1.2.3-70-g09d2