• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

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

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


Commit MetaInfo

Revisãoc64b05514c797d98abb2c186386cc54b7c491168 (tree)
Hora2019-12-09 16:11:47
AutorIWAMOTO Kouichi <sue@iwmt...>
CommiterIWAMOTO Kouichi

Mensagem de Log

update to ttyrec-1.0.2

Mudança Sumário

Diff

--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
11 CC = gcc
22 CFLAGS = -O2
3-VERSION = 1.0.1
3+VERSION = 1.0.2
44
55 TARGET = ttyrec ttyplay
66
--- a/README
+++ b/README
@@ -1,5 +1,13 @@
11 ttyrec is a tty recorder. ttyplay is a tty player.
22
3+Installation:
4+
5+ % make
6+
7+or if your system is SVR4 series (Solaris etc.),
8+
9+ % make CFLAGS=-DSVR4
10+
311 Usage:
412
513 % ttyrec
--- a/ttyplay.c
+++ b/ttyplay.c
@@ -46,6 +46,8 @@ typedef void (*WaitFunc) (struct timeval prev,
4646 double speed);
4747 typedef int (*ReadFunc) (FILE *fp, Header *h, char **buf);
4848 typedef void (*WriteFunc) (char *buf, int len);
49+typedef void (*ProcessFunc) (FILE *fp, double speed,
50+ ReadFunc read_func, WaitFunc wait_func);
4951
5052 struct timeval
5153 timeval_diff (struct timeval tv1, struct timeval tv2)
@@ -69,8 +71,13 @@ ttywait (struct timeval prev, struct timeval cur, double speed)
6971
7072 assert(speed != 0);
7173
72- sleep(diff.tv_sec / speed);
73- usleep(diff.tv_usec / speed);
74+ /*
75+ * Use select instead of sleep and usleep because some
76+ * systems don't support usleep.
77+ */
78+ diff.tv_sec /= speed;
79+ diff.tv_usec /= speed;
80+ select(0, NULL, NULL, NULL, &diff);
7481 }
7582
7683 void
@@ -100,11 +107,12 @@ ttyread (FILE *fp, Header *h, char **buf)
100107 int
101108 ttypread (FILE *fp, Header *h, char **buf)
102109 {
110+ struct timeval w = {0, 250000};
103111 /*
104112 * Read persistently just like tail -f.
105113 */
106114 while (ttyread(fp, h, buf) == 0) {
107- usleep(250000);
115+ select(0, NULL, NULL, NULL, &w);
108116 clearerr(fp);
109117 }
110118 return 1;
@@ -160,9 +168,6 @@ ttyskipall (FILE *fp)
160168 ttyplay(fp, 0, ttyread, ttynowrite, ttynowait);
161169 }
162170
163-typedef void (*ProcessFunc) (FILE *fp, double speed,
164- ReadFunc read_func, WaitFunc wait_func);
165-
166171 void ttyplayback (FILE *fp, double speed,
167172 ReadFunc read_func, WaitFunc wait_func)
168173 {
@@ -195,6 +200,7 @@ efopen (const char *path, const char *mode)
195200 fprintf(stderr, "ttyplay: %s: %s\n", path, strerror(errno));
196201 exit(EXIT_FAILURE);
197202 }
203+ return fp;
198204 }
199205
200206 int
--- a/ttyrec.c
+++ b/ttyrec.c
@@ -51,6 +51,13 @@
5151 #include <sys/signal.h>
5252 #include <stdio.h>
5353
54+#if defined(SVR4)
55+#include <stdlib.h>
56+#include <unistd.h>
57+#include <fcntl.h>
58+#include <stropts.h>
59+#endif /* SVR4 */
60+
5461 #ifdef __linux__
5562 #include <unistd.h>
5663 #include <string.h>
@@ -90,9 +97,11 @@ struct termios tt;
9097 struct winsize win;
9198 int lb;
9299 int l;
100+#if !defined(SVR4)
93101 #ifndef HAVE_openpty
94102 char line[] = "/dev/ptyXX";
95103 #endif
104+#endif /* !SVR4 */
96105 int aflg;
97106
98107 int
@@ -177,7 +186,11 @@ doinput()
177186 void
178187 finish()
179188 {
189+#if defined(SVR4)
190+ int status;
191+#else /* !SVR4 */
180192 union wait status;
193+#endif /* !SVR4 */
181194 register int pid;
182195 register int die = 0;
183196
@@ -236,11 +249,9 @@ doshell()
236249 (void) dup2(slave, 1);
237250 (void) dup2(slave, 2);
238251 (void) close(slave);
239-#ifdef __linux__
252+
240253 execl(shell, strrchr(shell, '/') + 1, "-i", 0);
241-#else
242- execl(shell, "sh", "-i", 0);
243-#endif
254+
244255 perror(shell);
245256 fail();
246257 }
@@ -251,8 +262,20 @@ fixtty()
251262 struct termios rtt;
252263
253264 rtt = tt;
265+#if defined(SVR4)
266+ rtt.c_iflag = 0;
267+ rtt.c_lflag &= ~(ISIG|ICANON|XCASE|ECHO|ECHOE|ECHOK|ECHONL);
268+ rtt.c_oflag = OPOST;
269+ rtt.c_cc[VINTR] = CDEL;
270+ rtt.c_cc[VQUIT] = CDEL;
271+ rtt.c_cc[VERASE] = CDEL;
272+ rtt.c_cc[VKILL] = CDEL;
273+ rtt.c_cc[VEOF] = 1;
274+ rtt.c_cc[VEOL] = 0;
275+#else /* !SVR4 */
254276 cfmakeraw(&rtt);
255277 rtt.c_lflag &= ~ECHO;
278+#endif /* !SVR4 */
256279 (void) tcsetattr(0, TCSAFLUSH, &rtt);
257280 }
258281
@@ -283,6 +306,14 @@ done()
283306 void
284307 getmaster()
285308 {
309+#if defined(SVR4)
310+ (void) tcgetattr(0, &tt);
311+ (void) ioctl(0, TIOCGWINSZ, (char *)&win);
312+ if ((master = open("/dev/ptmx", O_RDWR)) < 0) {
313+ perror("open(\"/dev/ptmx\", O_RDWR)");
314+ fail();
315+ }
316+#else /* !SVR4 */
286317 #ifdef HAVE_openpty
287318 (void) tcgetattr(0, &tt);
288319 (void) ioctl(0, TIOCGWINSZ, (char *)&win);
@@ -324,11 +355,34 @@ getmaster()
324355 fprintf(stderr, _("Out of pty's\n"));
325356 fail();
326357 #endif /* not HAVE_openpty */
358+#endif /* !SVR4 */
327359 }
328360
329361 void
330362 getslave()
331363 {
364+#if defined(SVR4)
365+ (void) setsid();
366+ grantpt( master);
367+ unlockpt(master);
368+ if ((slave = open(ptsname(master), O_RDWR)) < 0) {
369+ perror("open(fd, O_RDWR)");
370+ fail();
371+ }
372+ if (ioctl(slave, I_PUSH, "ptem") < 0) {
373+ perror("ioctl(fd, I_PUSH, ptem)");
374+ fail();
375+ }
376+ if (ioctl(slave, I_PUSH, "ldterm") < 0) {
377+ perror("ioctl(fd, I_PUSH, ldterm)");
378+ fail();
379+ }
380+ if (ioctl(slave, I_PUSH, "ttcompat") < 0) {
381+ perror("ioctl(fd, I_PUSH, ttcompat)");
382+ fail();
383+ }
384+ (void) ioctl(0, TIOCGWINSZ, (char *)&win);
385+#else /* !SVR4 */
332386 #ifndef HAVE_openpty
333387 line[strlen("/dev/")] = 't';
334388 slave = open(line, O_RDWR);
@@ -341,4 +395,5 @@ getslave()
341395 #endif
342396 (void) setsid();
343397 (void) ioctl(slave, TIOCSCTTY, 0);
398+#endif /* SVR4 */
344399 }