blob: 6eaba43fa607ef63d471a51836742e1fae7f130a [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 *
9 */
10#include "libbb.h"
11
12int scriptreplay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
13int scriptreplay_main(int argc UNUSED_PARAM, char **argv)
14{
15 const char *script = "typescript";
16 double delay, factor = 1000000.0;
17 int fd;
18 unsigned long count;
19 FILE *tfp;
20
Denys Vlasenko997538a2009-07-19 23:11:45 +020021 if (!argv[1])
22 bb_show_usage();
23
Denys Vlasenko5e611152009-05-19 17:36:16 +020024 if (argv[2]) {
25 script = argv[2];
26 if (argv[3])
27 factor /= atof(argv[3]);
28 }
29
30 tfp = xfopen_for_read(argv[1]);
31 fd = xopen(script, O_RDONLY);
32 while (fscanf(tfp, "%lf %lu\n", &delay, &count) == 2) {
33 usleep(delay * factor);
34 bb_copyfd_exact_size(fd, STDOUT_FILENO, count);
35 }
Denys Vlasenko53f17912009-06-05 14:55:26 +020036 if (ENABLE_FEATURE_CLEAN_UP) {
37 close(fd);
38 fclose(tfp);
39 }
Denys Vlasenko5e611152009-05-19 17:36:16 +020040 return EXIT_SUCCESS;
41}