ttyrex

ttyrec with more options
git clone https://a3nm.net/git/ttyrex/
Log | Files | Refs | README

commit e90093fac502fbaf2384fc99dc423517124e14c5
parent 1ca7750b29b507eb7ab6d8d218346540834f47d3
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Thu, 18 Oct 2012 13:05:01 +0200

Add ttyplay -j TIME to jump to a specific time

Diffstat:
README | 2++
ttyplay.1 | 7++++++-
ttyplay.c | 31++++++++++++++++++++++---------
3 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/README b/README @@ -11,6 +11,8 @@ record grow huge: with -l, you will get something like the first limit bytes of garbage, 2*limit bytes every second spent displaying garbage, and the last limit bytes of the garbage, which resembles more or less what you are likely to see. +ttyplay now has an additional -j option to jump to a specific time. + ttytime now display the start timestamp of each file along with the duration. -- Antoine Amarilli <a3nm@a3nm.net> diff --git a/ttyplay.1 b/ttyplay.1 @@ -7,7 +7,7 @@ ttyplay \- player of the tty session recorded by ttyrec .SH SYNOPSIS .br .B ttyplay -.I [\-s SPEED] [\-n] [\-p] file +.I [\-s SPEED] [\-j] [\-n] [\-p] file .br .SH DESCRIPTION .B Ttyplay @@ -51,6 +51,11 @@ multiple the playing speed by .I SPEED (default is 1). .TP +.BI \-j " TIMESTAMP" +run in no wait mode until reaching +.I TIMESTAMP +and then revert to normal speed. +.TP .B \-n no wait mode. Ignore the timing information in diff --git a/ttyplay.c b/ttyplay.c @@ -47,7 +47,7 @@ typedef double (*WaitFunc) (struct timeval prev, double speed); typedef int (*ReadFunc) (FILE *fp, Header *h, char **buf); typedef void (*WriteFunc) (char *buf, int len); -typedef void (*ProcessFunc) (FILE *fp, double speed, +typedef void (*ProcessFunc) (FILE *fp, int jump, double speed, ReadFunc read_func, WaitFunc wait_func); struct timeval @@ -212,7 +212,7 @@ ttynowrite (char *buf, int len) } void -ttyplay (FILE *fp, double speed, ReadFunc read_func, +ttyplay (FILE *fp, int jump, double speed, ReadFunc read_func, WriteFunc write_func, WaitFunc wait_func) { int first_time = 1; @@ -234,6 +234,10 @@ ttyplay (FILE *fp, double speed, ReadFunc read_func, speed = wait_func(prev, h.tv, speed); } while (speed == 0.0); } + if (jump && h.tv.tv_sec > jump) { + jump = 0; + wait_func = ttywait; + } first_time = 0; write_func(buf, h.len); @@ -248,20 +252,20 @@ ttyskipall (FILE *fp) /* * Skip all records. */ - ttyplay(fp, 0, ttyread, ttynowrite, ttynowait); + ttyplay(fp, 0, 0, ttyread, ttynowrite, ttynowait); } -void ttyplayback (FILE *fp, double speed, +void ttyplayback (FILE *fp, int jump, double speed, ReadFunc read_func, WaitFunc wait_func) { - ttyplay(fp, speed, ttyread, ttywrite, wait_func); + ttyplay(fp, jump, speed, ttyread, ttywrite, wait_func); } -void ttypeek (FILE *fp, double speed, +void ttypeek (FILE *fp, int jump, double speed, ReadFunc read_func, WaitFunc wait_func) { ttyskipall(fp); - ttyplay(fp, speed, ttypread, ttywrite, ttynowait); + ttyplay(fp, jump, speed, ttypread, ttywrite, ttynowait); } @@ -291,6 +295,7 @@ int main (int argc, char **argv) { double speed = 1.0; + int jump = 0; ReadFunc read_func = ttyread; WaitFunc wait_func = ttywait; ProcessFunc process = ttyplayback; @@ -299,7 +304,7 @@ main (int argc, char **argv) set_progname(argv[0]); while (1) { - int ch = getopt(argc, argv, "s:np"); + int ch = getopt(argc, argv, "s:npj:"); if (ch == EOF) { break; } @@ -311,6 +316,14 @@ main (int argc, char **argv) } sscanf(optarg, "%lf", &speed); break; + case 'j': + if (optarg == NULL) { + perror("-j option requires an argument"); + exit(EXIT_FAILURE); + } + sscanf(optarg, "%d", &jump); + wait_func = ttynowait; + break; case 'n': wait_func = ttynowait; break; @@ -334,7 +347,7 @@ main (int argc, char **argv) new.c_lflag &= ~(ICANON | ECHO | ECHONL); /* unbuffered, no echo */ tcsetattr(0, TCSANOW, &new); /* Make it current */ - process(input, speed, read_func, wait_func); + process(input, jump, speed, read_func, wait_func); tcsetattr(0, TCSANOW, &old); /* Return terminal state */ return 0;