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