3
0

scriptreplay.c 886 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. int scriptreplay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  12. int scriptreplay_main(int argc UNUSED_PARAM, char **argv)
  13. {
  14. const char *script = "typescript";
  15. double delay, factor = 1000000.0;
  16. int fd;
  17. unsigned long count;
  18. FILE *tfp;
  19. if (!argv[1])
  20. bb_show_usage();
  21. if (argv[2]) {
  22. script = argv[2];
  23. if (argv[3])
  24. factor /= atof(argv[3]);
  25. }
  26. tfp = xfopen_for_read(argv[1]);
  27. fd = xopen(script, O_RDONLY);
  28. while (fscanf(tfp, "%lf %lu\n", &delay, &count) == 2) {
  29. usleep(delay * factor);
  30. bb_copyfd_exact_size(fd, STDOUT_FILENO, count);
  31. }
  32. if (ENABLE_FEATURE_CLEAN_UP) {
  33. close(fd);
  34. fclose(tfp);
  35. }
  36. return EXIT_SUCCESS;
  37. }