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-next-frame.c | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) (limited to 'src/vu-next-frame.c') diff --git a/src/vu-next-frame.c b/src/vu-next-frame.c index f5ff4c0..667acf5 100644 --- a/src/vu-next-frame.c +++ b/src/vu-next-frame.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include "arg.h" #include "stream.h" #include "util.h" @@ -7,40 +6,28 @@ #include #include +#undef eprintf #define eprintf(...) enprintf(2, __VA_ARGS__) -static void -usage(void) -{ - eprintf("usage: %s width height pixel-format ...\n", argv0); -} +USAGE("width height pixel-format ...") int main(int argc, char *argv[]) { struct stream stream; - size_t ptr, n, w; - ssize_t r; + size_t n, w; int i, anything = 0; char *p; - ARGBEGIN { - default: - usage(); - } ARGEND; - - if (argc < 3) - usage(); + ENOFLAGS(argc < 3); stream.frames = 1; stream.fd = STDIN_FILENO; stream.file = ""; stream.pixfmt[0] = '\0'; - if (tozu(argv[0], 1, SIZE_MAX, &stream.width)) - eprintf("the width must be an integer in [1, %zu]\n", SIZE_MAX); - if (tozu(argv[1], 1, SIZE_MAX, &stream.height)) - eprintf("the height must be an integer in [1, %zu]\n", SIZE_MAX); + stream.width = etozu_arg("the width", argv[0], 1, SIZE_MAX); + stream.height = etozu_arg("the height", argv[1], 1, SIZE_MAX); argv += 2, argc -= 2; n = (size_t)argc - 1; @@ -57,28 +44,22 @@ main(int argc, char *argv[]) eset_pixel_size(&stream); fprint_stream_head(stdout, &stream); - fflush(stdout); - if (ferror(stdout)) - eprintf(":"); + efflush(stdout, ""); + w = stream.width * stream.pixel_size; while (stream.height) { stream.height--; - for (w = stream.width * stream.pixel_size; w; w -= n) { + for (n = w; n; n -= stream.ptr) { stream.ptr = 0; - n = eread_stream(&stream, w); - if (n == 0) + if (!eread_stream(&stream, n)) goto done; anything = 1; - for (ptr = 0; ptr < stream.ptr; ptr += (size_t)r) { - r = write(STDOUT_FILENO, stream.buf + ptr, stream.ptr - ptr); - if (r < 0) - eprintf("write :"); - } + ewriteall(STDOUT_FILENO, stream.buf, stream.ptr, ""); } } done: - if (stream.height || w) + if (stream.height || n) eprintf("incomplete frame\n"); return !anything; -- cgit v1.2.3-70-g09d2