• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

ttyrecのfork. Original: http://0xcc.net/ttyrec/


コミットメタ情報

リビジョンdeaece55bebe537d4d0b27293606c98de910a172 (tree)
日時2019-12-09 16:25:35
作者IWAMOTO Kouichi <sue@iwmt...>
コミッターIWAMOTO Kouichi

ログメッセージ

update to ttyrec-1.0.8

変更サマリ

差分

--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
11 CC = gcc
22 CFLAGS = -O2
3-VERSION = 1.0.7
3+VERSION = 1.0.8
44
55 TARGET = ttyrec ttyplay ttytime
66
--- a/ttyplay.c
+++ b/ttyplay.c
@@ -80,14 +80,29 @@ timeval_div (struct timeval tv1, double n)
8080 double
8181 ttywait (struct timeval prev, struct timeval cur, double speed)
8282 {
83+ static struct timeval drift = {0, 0};
84+ struct timeval start;
8385 struct timeval diff = timeval_diff(prev, cur);
8486 fd_set readfs;
8587
88+ gettimeofday(&start, NULL);
89+
8690 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+ }
8895
8996 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. */
91106 if (FD_ISSET(0, &readfs)) { /* a user hits a character? */
92107 char c;
93108 read(STDIN_FILENO, &c, 1); /* drain the character */
@@ -104,6 +119,15 @@ ttywait (struct timeval prev, struct timeval cur, double speed)
104119 speed = 1.0;
105120 break;
106121 }
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));
107131 }
108132 return speed;
109133 }
--- a/ttyrec.c
+++ b/ttyrec.c
@@ -50,11 +50,12 @@
5050 #include <sys/file.h>
5151 #include <sys/signal.h>
5252 #include <stdio.h>
53+#include <time.h>
5354 #include <unistd.h>
5455 #include <string.h>
56+#include <stdlib.h>
5557
5658 #if defined(SVR4)
57-#include <stdlib.h>
5859 #include <fcntl.h>
5960 #include <stropts.h>
6061 #endif /* SVR4 */
@@ -279,15 +280,13 @@ void
279280 dooutput()
280281 {
281282 int cc;
282- time_t tvec, time();
283- char obuf[BUFSIZ], *ctime();
283+ char obuf[BUFSIZ];
284284
285285 setbuf(stdout, NULL);
286286 (void) close(0);
287287 #ifdef HAVE_openpty
288288 (void) close(slave);
289289 #endif
290- tvec = time((time_t *)NULL);
291290 for (;;) {
292291 Header h;
293292
@@ -368,11 +367,7 @@ fail()
368367 void
369368 done()
370369 {
371- time_t tvec, time();
372- char *ctime();
373-
374370 if (subchild) {
375- tvec = time((time_t *)NULL);
376371 (void) fclose(fscript);
377372 (void) close(master);
378373 } else {