blob: e3083ab93ae91d701c8af03c9c0440e53ca80292 [file] [log] [blame]
Denys Vlasenko5e611152009-05-19 17:36:16 +02001/* vi: set sw=4 ts=4: */
2/*
3 * scriptreplay - play back typescripts, using timing information
4 *
5 * pascal.bellard@ads-lu.com
6 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Denys Vlasenko5e611152009-05-19 17:36:16 +02008 */
Denys Vlasenkodd898c92016-11-23 11:46:32 +01009//config:config SCRIPTREPLAY
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020010//config: bool "scriptreplay (2.6 kb)"
Denys Vlasenkodd898c92016-11-23 11:46:32 +010011//config: default y
12//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020013//config: This program replays a typescript, using timing information
14//config: given by script -t.
Denys Vlasenkodd898c92016-11-23 11:46:32 +010015
16//applet:IF_SCRIPTREPLAY(APPLET(scriptreplay, BB_DIR_BIN, BB_SUID_DROP))
17
18//kbuild:lib-$(CONFIG_SCRIPTREPLAY) += scriptreplay.o
Pere Orga5bc8c002011-04-11 03:29:49 +020019
20//usage:#define scriptreplay_trivial_usage
Denys Vlasenkodd55d5d2017-08-07 01:53:17 +020021//usage: "TIMINGFILE [TYPESCRIPT [DIVISOR]]"
Pere Orga5bc8c002011-04-11 03:29:49 +020022//usage:#define scriptreplay_full_usage "\n\n"
23//usage: "Play back typescripts, using timing information"
24
Denys Vlasenko5e611152009-05-19 17:36:16 +020025#include "libbb.h"
26
27int scriptreplay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
28int 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 Vlasenko997538a2009-07-19 23:11:45 +020036 if (!argv[1])
37 bb_show_usage();
38
Denys Vlasenko5e611152009-05-19 17:36:16 +020039 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 Vlasenko53f17912009-06-05 14:55:26 +020051 if (ENABLE_FEATURE_CLEAN_UP) {
52 close(fd);
53 fclose(tfp);
54 }
Denys Vlasenko5e611152009-05-19 17:36:16 +020055 return EXIT_SUCCESS;
56}