diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-11 09:11:51 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-11 09:11:51 +0100 |
| commit | b7a82c980fe7e0c1f9029b55be97422428d65d5a (patch) | |
| tree | 67bedc856eb1f72a2daa8ef8347b904269b06df5 /src/vu-cut.c | |
| parent | vu-crop: add -t (diff) | |
| download | blind-b7a82c980fe7e0c1f9029b55be97422428d65d5a.tar.gz blind-b7a82c980fe7e0c1f9029b55be97422428d65d5a.tar.bz2 blind-b7a82c980fe7e0c1f9029b55be97422428d65d5a.tar.xz | |
Clean up code
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/vu-cut.c')
| -rw-r--r-- | src/vu-cut.c | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/src/vu-cut.c b/src/vu-cut.c index 011e31c..a90f032 100644 --- a/src/vu-cut.c +++ b/src/vu-cut.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include "arg.h" #include "stream.h" #include "util.h" @@ -9,45 +8,31 @@ #include <string.h> #include <unistd.h> -static void -usage(void) -{ - eprintf("usage: %s start-point (end-point | 'end') file\n", argv0); -} +USAGE("start-point (end-point | 'end') file") int main(int argc, char *argv[]) { struct stream stream; - size_t frame_size, start = 0, end = 0, ptr, max, n, ptw; + size_t frame_size, start = 0, end = 0, ptr, max, n; ssize_t r; char buf[BUFSIZ]; int to_end = 0; - ARGBEGIN { - default: - usage(); - } ARGEND; - - if (argc != 3) - usage(); + ENOFLAGS(argc != 3); - if (!strcmp(argv[0], "end")) { + if (!strcmp(argv[0], "end")) eprintf("refusing to create video with zero frames\n"); - } else if (tozu(argv[0], 0, SIZE_MAX, &start)) { - eprintf("the start point must be an integer in [0, %zu]\n", SIZE_MAX); - } + else + start = etozu_arg("the start point", argv[1], 0, SIZE_MAX); - if (!strcmp(argv[1], "end")) { + if (!strcmp(argv[1], "end")) to_end = 1; - } else if (tozu(argv[1], 0, SIZE_MAX, &end)) { - eprintf("the end point must be an integer in [0, %zu]\n", SIZE_MAX); - } + else + end = etozu_arg("the end point", argv[1], 0, SIZE_MAX); stream.file = argv[2]; - stream.fd = open(stream.file, O_RDONLY); - if (stream.fd < 0) - eprintf("open %s:", stream.file); + stream.fd = eopen(stream.file, O_RDONLY); einit_stream(&stream); if (to_end) end = stream.frames; @@ -55,12 +40,9 @@ main(int argc, char *argv[]) eprintf("end point is after end of video\n"); stream.frames = end - start; fprint_stream_head(stdout, &stream); - fflush(stdout); - if (ferror(stdout)) - eprintf("<stdout>:"); - if (stream.width > SIZE_MAX / stream.height) - eprintf("%s: video is too large\n", stream.file); - frame_size = stream.width * stream.height; + efflush(stdout, "<stdout>"); + echeck_frame_size(stream.width, stream.height, stream.pixel_size, 0, stream.file); + frame_size = stream.width * stream.height * stream.pixel_size; if (stream.frames > SSIZE_MAX / frame_size) eprintf("%s: video is too large\n", stream.file); @@ -68,7 +50,7 @@ main(int argc, char *argv[]) eprintf("%s\n", start > end ? "start point is after end point" : "refusing to create video with zero frames"); - end *= frame_size; + end *= frame_size; start *= frame_size; for (ptr = start; ptr < end;) { @@ -80,11 +62,7 @@ main(int argc, char *argv[]) if (r == 0) eprintf("%s: file is shorter than expected\n", stream.file); ptr += n = (size_t)r; - for (ptw = 0; ptw < n; ptw += (size_t)r) { - r = write(STDOUT_FILENO, buf + ptw, n - ptw); - if (r < 0) - eprintf("write <stdout>:"); - } + ewriteall(STDOUT_FILENO, buf, n, "<stdout>"); } close(stream.fd); |
