ttyrecのfork. Original: http://0xcc.net/ttyrec/
Revision | deaece55bebe537d4d0b27293606c98de910a172 (tree) |
---|---|
Time | 2019-12-09 16:25:35 |
Author | IWAMOTO Kouichi <sue@iwmt...> |
Commiter | IWAMOTO Kouichi |
update to ttyrec-1.0.8
@@ -1,6 +1,6 @@ | ||
1 | 1 | CC = gcc |
2 | 2 | CFLAGS = -O2 |
3 | -VERSION = 1.0.7 | |
3 | +VERSION = 1.0.8 | |
4 | 4 | |
5 | 5 | TARGET = ttyrec ttyplay ttytime |
6 | 6 |
@@ -80,14 +80,29 @@ timeval_div (struct timeval tv1, double n) | ||
80 | 80 | double |
81 | 81 | ttywait (struct timeval prev, struct timeval cur, double speed) |
82 | 82 | { |
83 | + static struct timeval drift = {0, 0}; | |
84 | + struct timeval start; | |
83 | 85 | struct timeval diff = timeval_diff(prev, cur); |
84 | 86 | fd_set readfs; |
85 | 87 | |
88 | + gettimeofday(&start, NULL); | |
89 | + | |
86 | 90 | assert(speed != 0); |
87 | - diff = timeval_div(diff, speed); | |
91 | + diff = timeval_diff(drift, timeval_div(diff, speed)); | |
92 | + if (diff.tv_sec < 0) { | |
93 | + diff.tv_sec = diff.tv_usec = 0; | |
94 | + } | |
88 | 95 | |
89 | 96 | FD_SET(STDIN_FILENO, &readfs); |
90 | - select(1, &readfs, NULL, NULL, &diff); /* skip if a user hits any key */ | |
97 | + /* | |
98 | + * We use select() for sleeping with subsecond precision. | |
99 | + * select() is also used to wait user's input from a keyboard. | |
100 | + * | |
101 | + * Save "diff" since select(2) may overwrite it to {0, 0}. | |
102 | + */ | |
103 | + struct timeval orig_diff = diff; | |
104 | + select(1, &readfs, NULL, NULL, &diff); | |
105 | + diff = orig_diff; /* Restore the original diff value. */ | |
91 | 106 | if (FD_ISSET(0, &readfs)) { /* a user hits a character? */ |
92 | 107 | char c; |
93 | 108 | read(STDIN_FILENO, &c, 1); /* drain the character */ |
@@ -104,6 +119,15 @@ ttywait (struct timeval prev, struct timeval cur, double speed) | ||
104 | 119 | speed = 1.0; |
105 | 120 | break; |
106 | 121 | } |
122 | + drift.tv_sec = drift.tv_usec = 0; | |
123 | + } else { | |
124 | + struct timeval stop; | |
125 | + gettimeofday(&stop, NULL); | |
126 | + /* Hack to accumulate the drift */ | |
127 | + if (diff.tv_sec == 0 && diff.tv_usec == 0) { | |
128 | + diff = timeval_diff(drift, diff); // diff = 0 - drift. | |
129 | + } | |
130 | + drift = timeval_diff(diff, timeval_diff(start, stop)); | |
107 | 131 | } |
108 | 132 | return speed; |
109 | 133 | } |
@@ -50,11 +50,12 @@ | ||
50 | 50 | #include <sys/file.h> |
51 | 51 | #include <sys/signal.h> |
52 | 52 | #include <stdio.h> |
53 | +#include <time.h> | |
53 | 54 | #include <unistd.h> |
54 | 55 | #include <string.h> |
56 | +#include <stdlib.h> | |
55 | 57 | |
56 | 58 | #if defined(SVR4) |
57 | -#include <stdlib.h> | |
58 | 59 | #include <fcntl.h> |
59 | 60 | #include <stropts.h> |
60 | 61 | #endif /* SVR4 */ |
@@ -279,15 +280,13 @@ void | ||
279 | 280 | dooutput() |
280 | 281 | { |
281 | 282 | int cc; |
282 | - time_t tvec, time(); | |
283 | - char obuf[BUFSIZ], *ctime(); | |
283 | + char obuf[BUFSIZ]; | |
284 | 284 | |
285 | 285 | setbuf(stdout, NULL); |
286 | 286 | (void) close(0); |
287 | 287 | #ifdef HAVE_openpty |
288 | 288 | (void) close(slave); |
289 | 289 | #endif |
290 | - tvec = time((time_t *)NULL); | |
291 | 290 | for (;;) { |
292 | 291 | Header h; |
293 | 292 |
@@ -368,11 +367,7 @@ fail() | ||
368 | 367 | void |
369 | 368 | done() |
370 | 369 | { |
371 | - time_t tvec, time(); | |
372 | - char *ctime(); | |
373 | - | |
374 | 370 | if (subchild) { |
375 | - tvec = time((time_t *)NULL); | |
376 | 371 | (void) fclose(fscript); |
377 | 372 | (void) close(master); |
378 | 373 | } else { |