2009-05-19 15:36:16 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* scriptreplay - play back typescripts, using timing information
|
|
|
|
*
|
|
|
|
* pascal.bellard@ads-lu.com
|
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2009-05-19 15:36:16 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-11-23 10:46:32 +00:00
|
|
|
//config:config SCRIPTREPLAY
|
2017-07-18 20:01:24 +00:00
|
|
|
//config: bool "scriptreplay (2.6 kb)"
|
2016-11-23 10:46:32 +00:00
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 07:50:55 +00:00
|
|
|
//config: This program replays a typescript, using timing information
|
|
|
|
//config: given by script -t.
|
2016-11-23 10:46:32 +00:00
|
|
|
|
|
|
|
//applet:IF_SCRIPTREPLAY(APPLET(scriptreplay, BB_DIR_BIN, BB_SUID_DROP))
|
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_SCRIPTREPLAY) += scriptreplay.o
|
2011-04-11 01:29:49 +00:00
|
|
|
|
|
|
|
//usage:#define scriptreplay_trivial_usage
|
|
|
|
//usage: "timingfile [typescript [divisor]]"
|
|
|
|
//usage:#define scriptreplay_full_usage "\n\n"
|
|
|
|
//usage: "Play back typescripts, using timing information"
|
|
|
|
|
2009-05-19 15:36:16 +00:00
|
|
|
#include "libbb.h"
|
|
|
|
|
|
|
|
int scriptreplay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
int scriptreplay_main(int argc UNUSED_PARAM, char **argv)
|
|
|
|
{
|
|
|
|
const char *script = "typescript";
|
|
|
|
double delay, factor = 1000000.0;
|
|
|
|
int fd;
|
|
|
|
unsigned long count;
|
|
|
|
FILE *tfp;
|
|
|
|
|
2009-07-19 21:11:45 +00:00
|
|
|
if (!argv[1])
|
|
|
|
bb_show_usage();
|
|
|
|
|
2009-05-19 15:36:16 +00:00
|
|
|
if (argv[2]) {
|
|
|
|
script = argv[2];
|
|
|
|
if (argv[3])
|
|
|
|
factor /= atof(argv[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
tfp = xfopen_for_read(argv[1]);
|
|
|
|
fd = xopen(script, O_RDONLY);
|
|
|
|
while (fscanf(tfp, "%lf %lu\n", &delay, &count) == 2) {
|
|
|
|
usleep(delay * factor);
|
|
|
|
bb_copyfd_exact_size(fd, STDOUT_FILENO, count);
|
|
|
|
}
|
2009-06-05 12:55:26 +00:00
|
|
|
if (ENABLE_FEATURE_CLEAN_UP) {
|
|
|
|
close(fd);
|
|
|
|
fclose(tfp);
|
|
|
|
}
|
2009-05-19 15:36:16 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|