diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-05-19 17:36:16 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-05-19 17:36:16 +0200 |
commit | 5e61115ea45c621867941e52e6ac016680415656 (patch) | |
tree | 7e92d0ee0720d907b4b35bfa510c3969c79eaaa8 /util-linux/scriptreplay.c | |
parent | 5a49d284a6a9f6cf2076f23561f95aebdfd44592 (diff) | |
download | busybox-w32-5e61115ea45c621867941e52e6ac016680415656.tar.gz busybox-w32-5e61115ea45c621867941e52e6ac016680415656.tar.bz2 busybox-w32-5e61115ea45c621867941e52e6ac016680415656.zip |
scriptreplay: new applet. +423 bytes
Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/scriptreplay.c')
-rw-r--r-- | util-linux/scriptreplay.c | 38 |
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 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * scriptreplay - play back typescripts, using timing information | ||
4 | * | ||
5 | * pascal.bellard@ads-lu.com | ||
6 | * | ||
7 | * Licensed under GPLv2 or later, see file License in this tarball for details. | ||
8 | * | ||
9 | */ | ||
10 | #include "libbb.h" | ||
11 | |||
12 | int scriptreplay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
13 | int 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 | |||
21 | if (argv[2]) { | ||
22 | script = argv[2]; | ||
23 | if (argv[3]) | ||
24 | factor /= atof(argv[3]); | ||
25 | } | ||
26 | |||
27 | tfp = xfopen_for_read(argv[1]); | ||
28 | fd = xopen(script, O_RDONLY); | ||
29 | while (fscanf(tfp, "%lf %lu\n", &delay, &count) == 2) { | ||
30 | usleep(delay * factor); | ||
31 | bb_copyfd_exact_size(fd, STDOUT_FILENO, count); | ||
32 | } | ||
33 | #if ENABLE_FEATURE_CLEAN_UP | ||
34 | close(fd); | ||
35 | fclose(tfp); | ||
36 | #endif | ||
37 | return EXIT_SUCCESS; | ||
38 | } | ||