3
0

scriptreplay.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 source tree.
  8. *
  9. */
  10. //usage:#define scriptreplay_trivial_usage
  11. //usage: "timingfile [typescript [divisor]]"
  12. //usage:#define scriptreplay_full_usage "\n\n"
  13. //usage: "Play back typescripts, using timing information"
  14. #include "libbb.h"
  15. int scriptreplay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  16. int scriptreplay_main(int argc UNUSED_PARAM, char **argv)
  17. {
  18. const char *script = "typescript";
  19. double delay, factor = 1000000.0;
  20. int fd;
  21. unsigned long count;
  22. FILE *tfp;
  23. if (!argv[1])
  24. bb_show_usage();
  25. if (argv[2]) {
  26. script = argv[2];
  27. if (argv[3])
  28. factor /= atof(argv[3]);
  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. }
  36. if (ENABLE_FEATURE_CLEAN_UP) {
  37. close(fd);
  38. fclose(tfp);
  39. }
  40. return EXIT_SUCCESS;
  41. }