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 | */ |
Denys Vlasenko | dd898c9 | 2016-11-23 11:46:32 +0100 | [diff] [blame] | 10 | //config:config SCRIPTREPLAY |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 11 | //config: bool "scriptreplay (2.6 kb)" |
Denys Vlasenko | dd898c9 | 2016-11-23 11:46:32 +0100 | [diff] [blame] | 12 | //config: default y |
| 13 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 14 | //config: This program replays a typescript, using timing information |
| 15 | //config: given by script -t. |
Denys Vlasenko | dd898c9 | 2016-11-23 11:46:32 +0100 | [diff] [blame] | 16 | |
| 17 | //applet:IF_SCRIPTREPLAY(APPLET(scriptreplay, BB_DIR_BIN, BB_SUID_DROP)) |
| 18 | |
| 19 | //kbuild:lib-$(CONFIG_SCRIPTREPLAY) += scriptreplay.o |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 20 | |
| 21 | //usage:#define scriptreplay_trivial_usage |
| 22 | //usage: "timingfile [typescript [divisor]]" |
| 23 | //usage:#define scriptreplay_full_usage "\n\n" |
| 24 | //usage: "Play back typescripts, using timing information" |
| 25 | |
Denys Vlasenko | 5e61115 | 2009-05-19 17:36:16 +0200 | [diff] [blame] | 26 | #include "libbb.h" |
| 27 | |
| 28 | int scriptreplay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 29 | int scriptreplay_main(int argc UNUSED_PARAM, char **argv) |
| 30 | { |
| 31 | const char *script = "typescript"; |
| 32 | double delay, factor = 1000000.0; |
| 33 | int fd; |
| 34 | unsigned long count; |
| 35 | FILE *tfp; |
| 36 | |
Denys Vlasenko | 997538a | 2009-07-19 23:11:45 +0200 | [diff] [blame] | 37 | if (!argv[1]) |
| 38 | bb_show_usage(); |
| 39 | |
Denys Vlasenko | 5e61115 | 2009-05-19 17:36:16 +0200 | [diff] [blame] | 40 | if (argv[2]) { |
| 41 | script = argv[2]; |
| 42 | if (argv[3]) |
| 43 | factor /= atof(argv[3]); |
| 44 | } |
| 45 | |
| 46 | tfp = xfopen_for_read(argv[1]); |
| 47 | fd = xopen(script, O_RDONLY); |
| 48 | while (fscanf(tfp, "%lf %lu\n", &delay, &count) == 2) { |
| 49 | usleep(delay * factor); |
| 50 | bb_copyfd_exact_size(fd, STDOUT_FILENO, count); |
| 51 | } |
Denys Vlasenko | 53f1791 | 2009-06-05 14:55:26 +0200 | [diff] [blame] | 52 | if (ENABLE_FEATURE_CLEAN_UP) { |
| 53 | close(fd); |
| 54 | fclose(tfp); |
| 55 | } |
Denys Vlasenko | 5e61115 | 2009-05-19 17:36:16 +0200 | [diff] [blame] | 56 | return EXIT_SUCCESS; |
| 57 | } |