diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-05-10 21:29:46 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-05-10 21:29:46 +0200 |
| commit | 19ad368f68164b99a2cfedb11747d7ca2d040ee0 (patch) | |
| tree | 5afb9c2f3c3c91d8bef7264a84180d60aedc9a7e /src/blind-split.c | |
| parent | Cleaner code (diff) | |
| download | blind-19ad368f68164b99a2cfedb11747d7ca2d040ee0.tar.gz blind-19ad368f68164b99a2cfedb11747d7ca2d040ee0.tar.bz2 blind-19ad368f68164b99a2cfedb11747d7ca2d040ee0.tar.xz | |
Cleaner code
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/blind-split.c')
| -rw-r--r-- | src/blind-split.c | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/src/blind-split.c b/src/blind-split.c index f6949f6..2014e52 100644 --- a/src/blind-split.c +++ b/src/blind-split.c @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) { struct stream stream; - size_t *ends, i, parts, ptr, end, n; + size_t *ends, i, parts, n; char *to_end; FILE *fp; int fd, unknown_length = 0; @@ -28,54 +28,37 @@ main(int argc, char *argv[]) usage(); eopen_stream(&stream, NULL); - echeck_dimensions(&stream, WIDTH | HEIGHT | LENGTH, NULL); + echeck_dimensions(&stream, WIDTH | HEIGHT, NULL); parts = (size_t)argc / 2; ends = alloca(parts * sizeof(*ends)); to_end = alloca(parts); for (i = 0; i < parts; i++) { - to_end[i] = 0; - if (!strcmp(argv[i * 2 + 1], "end")) { + if ((to_end[i] = !strcmp(argv[i * 2 + 1], "end"))) ends[i] = unknown_length ? SIZE_MAX : stream.frames; - to_end[i] = 1; - } else if (tozu(argv[i * 2 + 1], 0, SIZE_MAX, ends + i)) { + else if (tozu(argv[i * 2 + 1], 0, SIZE_MAX, ends + i)) eprintf("the end point must be an integer in [0, %zu]\n", SIZE_MAX); - } + if (i && ends[i] <= ends[i - 1]) eprintf("the end points must be in strictly ascending order\n"); if (!unknown_length && ends[i] > stream.frames) eprintf("frame %zu is beyond the end of the video\n", ends[i]); } - ptr = 0; for (i = 0; i < parts; i++) { fd = eopen(argv[i * 2], O_WRONLY | O_CREAT | O_TRUNC, 0666); - fp = fdopen(fd, "wb"); - if (!fp) + if (!(fp = fdopen(fd, "wb"))) eprintf("fdopen %s:", argv[i * 2]); - stream.frames = ends[i] - (i ? ends[i - 1] : 0); + n = ends[i] - (i ? ends[i - 1] : 0); + stream.frames = (to_end[i] && unknown_length) ? 0 : n; fprint_stream_head(fp, &stream); efflush(fp, argv[i * 2]); - for (end = to_end[i] ? SIZE_MAX : ends[i] * stream.frame_size; ptr < end; ptr += n) { - n = end - ptr; - if (stream.ptr) { - n = MIN(stream.ptr, n); - ewriteall(fd, stream.buf, n, argv[i * 2]); - memmove(stream.buf, stream.buf + n, stream.ptr -= n); - } else if ((n = eread_stream(&stream, n))) { - ewriteall(fd, stream.buf, n, argv[i * 2]); - stream.ptr = 0; - } else if (ptr % stream.frame_size) { - eprintf("%s: incomplete frame\n", stream.file); - } else if (!unknown_length || !to_end[i]) { + if (esend_frames(&stream, fd, n, argv[i * 2]) != n) + if (!unknown_length || !to_end[i]) eprintf("%s: file is shorter than expected\n", stream.file); - } else { - break; - } - } if (fclose(fp)) eprintf("%s:", argv[i * 2]); |
