// // slowcat -- time delayed file copy. // // - Line-by-line filter with settable delay between line bursts. // - This is useful for testing tools that read live data logs. // // 02-Jun-2010 Tom Van Baak (tvb) www.LeapSecond.com/tools // #include #include void main (int argc, char *argv[]) { char line[1000]; double seconds; long burst, n = 0; seconds = (argc > 1) ? atof(argv[1]) : 0.0; fprintf(stderr, "** %.3lf seconds delay between bursts\n", seconds); burst = (argc > 2) ? atol(argv[2]) : 1; fprintf(stderr, "** %ld lines per burst\n", burst); for (n = 0; fgets(line, sizeof line, stdin) != NULL; n += 1) { fputs(line, stdout); fflush(stdout); if ((n % burst) == burst - 1 && seconds > 0.0) { fprintf(stderr, "\r%ld\r", n + 1); _sleep((long)(seconds * 1000.0)); } } fprintf(stderr, "\n"); }