blind-skip-pattern.c (1172B)
1 /* See LICENSE file for copyright and license details. */ 2 #include "common.h" 3 4 USAGE("(skipped-frames | +included-frames) ...") 5 6 int 7 main(int argc, char *argv[]) 8 { 9 struct stream stream; 10 int i, include, outfd; 11 size_t f, n, total = 0; 12 char *includes; 13 size_t *ns; 14 15 UNOFLAGS(!argc); 16 17 eopen_stream(&stream, NULL); 18 19 includes = emalloc((size_t)argc); 20 ns = ecalloc((size_t)argc, sizeof(*ns)); 21 22 for (i = 0; i < argc; i++) { 23 include = argv[i][0] == '+'; 24 n = etozu_arg(include ? "included frame count" : "skipped frame count", 25 argv[i] + include, 0, SIZE_MAX); 26 total += ns[i] = n; 27 includes[i] = (char)include; 28 } 29 if (!total) 30 eprintf("null pattern is not allowed"); 31 32 for (i = 0, total = 0, f = stream.frames; f; i = (i + 1) % argc) { 33 include = (int)includes[i]; 34 for (n = ns[i]; n-- && f--;) 35 total += (size_t)include; 36 } 37 38 stream.frames = total; 39 echeck_dimensions(&stream, WIDTH, NULL); 40 fprint_stream_head(stdout, &stream); 41 efflush(stdout, "<stdout>"); 42 43 for (i = 0;; i = (i + 1) % argc) { 44 outfd = includes[i] ? STDOUT_FILENO : -1; 45 if (!esend_frames(&stream, outfd, ns[i], "<stdout>")) 46 break; 47 } 48 49 free(includes); 50 free(ns); 51 return 0; 52 }