aboutsummaryrefslogtreecommitdiff
path: root/util-linux/scriptreplay.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-05-20 12:20:48 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-05-20 12:20:48 +0200
commite18255d1dadc9686daa328fa121423b47d2f6af4 (patch)
treeabea08a2f62c5fa9322086d5b0151b602636da2b /util-linux/scriptreplay.c
parente424423a7b164e0c343c180a944844fd27ccbe97 (diff)
parent38478a600f52eb8f00d260a2f99d8430b9aba1e8 (diff)
downloadbusybox-e18255d1dadc9686daa328fa121423b47d2f6af4.tar.gz
Merge branch 'master' of git+ssh://vda@busybox.net/var/lib/git/busybox
Diffstat (limited to 'util-linux/scriptreplay.c')
-rw-r--r--util-linux/scriptreplay.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/util-linux/scriptreplay.c b/util-linux/scriptreplay.c
new file mode 100644
index 000000000..038dbdfe1
--- /dev/null
+++ b/util-linux/scriptreplay.c
@@ -0,0 +1,38 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * scriptreplay - play back typescripts, using timing information
+ *
+ * pascal.bellard@ads-lu.com
+ *
+ * Licensed under GPLv2 or later, see file License in this tarball for details.
+ *
+ */
+#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;
+
+ 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);
+ }
+#if ENABLE_FEATURE_CLEAN_UP
+ close(fd);
+ fclose(tfp);
+#endif
+ return EXIT_SUCCESS;
+}