Denys Vlasenko | 5e61115 | 2009-05-19 17:36:16 +0200 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * scriptreplay - play back typescripts, using timing information |
| 4 | * |
| 5 | * pascal.bellard@ads-lu.com |
| 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Denys Vlasenko | 5e61115 | 2009-05-19 17:36:16 +0200 | [diff] [blame] | 8 | * |
| 9 | */ |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 10 | |
| 11 | //usage:#define scriptreplay_trivial_usage |
| 12 | //usage: "timingfile [typescript [divisor]]" |
| 13 | //usage:#define scriptreplay_full_usage "\n\n" |
| 14 | //usage: "Play back typescripts, using timing information" |
| 15 | |
Denys Vlasenko | 5e61115 | 2009-05-19 17:36:16 +0200 | [diff] [blame] | 16 | #include "libbb.h" |
| 17 | |
| 18 | int scriptreplay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 19 | int scriptreplay_main(int argc UNUSED_PARAM, char **argv) |
| 20 | { |
| 21 | const char *script = "typescript"; |
| 22 | double delay, factor = 1000000.0; |
| 23 | int fd; |
| 24 | unsigned long count; |
| 25 | FILE *tfp; |
| 26 | |
Denys Vlasenko | 997538a | 2009-07-19 23:11:45 +0200 | [diff] [blame] | 27 | if (!argv[1]) |
| 28 | bb_show_usage(); |
| 29 | |
Denys Vlasenko | 5e61115 | 2009-05-19 17:36:16 +0200 | [diff] [blame] | 30 | if (argv[2]) { |
| 31 | script = argv[2]; |
| 32 | if (argv[3]) |
| 33 | factor /= atof(argv[3]); |
| 34 | } |
| 35 | |
| 36 | tfp = xfopen_for_read(argv[1]); |
| 37 | fd = xopen(script, O_RDONLY); |
| 38 | while (fscanf(tfp, "%lf %lu\n", &delay, &count) == 2) { |
| 39 | usleep(delay * factor); |
| 40 | bb_copyfd_exact_size(fd, STDOUT_FILENO, count); |
| 41 | } |
Denys Vlasenko | 53f1791 | 2009-06-05 14:55:26 +0200 | [diff] [blame] | 42 | if (ENABLE_FEATURE_CLEAN_UP) { |
| 43 | close(fd); |
| 44 | fclose(tfp); |
| 45 | } |
Denys Vlasenko | 5e61115 | 2009-05-19 17:36:16 +0200 | [diff] [blame] | 46 | return EXIT_SUCCESS; |
| 47 | } |