commit b3e3c8d6bb59edbc6b8b3341bea4e1f3afb3a341
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Mon May 1 22:46:46 2017 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Mon May 1 22:46:46 2017 +0200
Fix blind-skip-pattern
Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
diff --git a/src/blind-skip-pattern.c b/src/blind-skip-pattern.c
index 8fdf570..d77e3f2 100644
--- a/src/blind-skip-pattern.c
+++ b/src/blind-skip-pattern.c
_AT_@ -11,17 +11,17 @@ USAGE("(skipped-frames | +included-frames) ...")
static int
process_frame(struct stream *stream, int include, size_t rown)
{
- size_t h, n;
+ size_t h, n, m;
int anything = 0;
for (h = stream->height; h; h--) {
- for (n = rown; n; n -= stream->ptr) {
- stream->ptr = 0;
- if (!eread_stream(stream, n))
+ for (n = rown; n; n -= m, anything = 1) {
+ if (!stream->ptr && !eread_stream(stream, n))
goto done;
- anything = 1;
+ m = MIN(stream->ptr, n);
if (include)
- ewriteall(STDOUT_FILENO, stream->buf, stream->ptr, "<stdout>");
+ ewriteall(STDOUT_FILENO, stream->buf, m, "<stdout>");
+ memmove(stream->buf, stream->buf + m, stream->ptr -= m);
}
}
done:
_AT_@ -29,7 +29,7 @@ done:
if (anything && h)
eprintf("%s: is shorted than expected\n", stream->file);
- return !anything;
+ return anything;
}
int
_AT_@ -52,13 +52,13 @@ main(int argc, char *argv[])
include = argv[i][0] == '+';
n = etozu_arg(include ? "included frame count" : "skipped frame count",
argv[i] + include, 0, SIZE_MAX);
- ns[i] = n;
+ total += ns[i] = n;
includes[i] = (char)include;
}
if (!total)
eprintf("null pattern is not allowed");
- for (i = 0, total = 0, f = stream.frames;; i = (i + 1) % argc) {
+ for (i = 0, total = 0, f = stream.frames; f; i = (i + 1) % argc) {
include = (int)includes[i];
for (n = ns[i]; n-- && f--;)
total += (size_t)include;
_AT_@ -72,10 +72,12 @@ main(int argc, char *argv[])
for (i = 0;; i = (i + 1) % argc) {
include = (int)includes[i];
- n = ns[i];
- while (n-- && process_frame(&stream, include, rown));
+ for (n = ns[i]; n--;)
+ if (!process_frame(&stream, include, rown))
+ goto done;
}
+done:
free(includes);
free(ns);
return 0;
Received on Tue May 02 2017 - 00:11:47 CEST
This archive was generated by hypermail 2.3.0
: Tue May 02 2017 - 00:13:03 CEST