• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

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

修訂b684765cd88bdbfb09262ed904bbc41b9942af3d (tree)
時間2019-12-09 16:16:31
作者IWAMOTO Kouichi <sue@iwmt...>
CommiterIWAMOTO Kouichi

Log Message

update to ttyrec-1.0.6

Change Summary

差異

--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,11 @@
11 CC = gcc
22 CFLAGS = -O2
3-VERSION = 1.0.5
3+VERSION = 1.0.6
44
55 TARGET = ttyrec ttyplay ttytime
66
77 DIST = ttyrec.c ttyplay.c ttyrec.h io.c io.h ttytime.c\
8- README Makefile ttyrec.1 ttyplay.1
8+ README Makefile ttyrec.1 ttyplay.1 ttytime.1
99
1010 all: $(TARGET)
1111
--- a/io.c
+++ b/io.c
@@ -109,12 +109,19 @@ write_header (FILE *fp, Header *h)
109109 return 1;
110110 }
111111
112+static char *progname = "";
113+void
114+set_progname (const char *name)
115+{
116+ progname = strdup(name);
117+}
118+
112119 FILE *
113120 efopen (const char *path, const char *mode)
114121 {
115122 FILE *fp = fopen(path, mode);
116123 if (fp == NULL) {
117- fprintf(stderr, "ttyplay: %s: %s\n", path, strerror(errno));
124+ fprintf(stderr, "%s: %s: %s\n", progname, path, strerror(errno));
118125 exit(EXIT_FAILURE);
119126 }
120127 return fp;
--- a/ttyplay.1
+++ b/ttyplay.1
@@ -1,6 +1,9 @@
1+.\"
2+.\" This manual page is written by NAKANO Takeo <nakano@webmasters.gr.jp>
3+.\"
14 .TH TTYPLAY 1
25 .SH NAME
3-ttyplay \- a player of the tty session recorded by ttyrec
6+ttyplay \- player of the tty session recorded by ttyrec
47 .SH SYNOPSIS
58 .br
69 .B ttyplay
@@ -22,6 +25,22 @@ output the
2225 as it grows.
2326 It means that you can see the "live" shell session
2427 running by another user.
28+.PP
29+If you hit any key during playback, it will go right to the next
30+character typed. This is handy when examining sessions where a user
31+spends a lot of time at a prompt.
32+.PP
33+Additionally, there are some special keys defined:
34+.TP
35+.BI + " or " f
36+ double the speed of playback.
37+.TP
38+.BI \- " or " s
39+ halve the speed of playback.
40+.TP
41+.BI 1
42+set playback to speed 1.0 again.
43+
2544 .SH OPTIONS
2645 .TP
2746 .BI \-s " SPEED"
@@ -38,8 +57,6 @@ Ignore the timing information in
3857 peek another person's tty session.
3958 .SH "SEE ALSO"
4059 .BR script (1),
41-.BR ttyrec (1)
42-.SH AUTHOR
43-This manual page is written by NAKANO Takeo <nakano@webmasters.gr.jp>
44-for the Debian GNU/Linux system (but may be used by others).
60+.BR ttyrec (1),
61+.BR ttytime (1)
4562
--- a/ttyplay.c
+++ b/ttyplay.c
@@ -35,13 +35,14 @@
3535 #include <stdlib.h>
3636 #include <assert.h>
3737 #include <unistd.h>
38+#include <termios.h>
3839 #include <sys/time.h>
3940 #include <string.h>
4041
4142 #include "ttyrec.h"
4243 #include "io.h"
4344
44-typedef void (*WaitFunc) (struct timeval prev,
45+typedef double (*WaitFunc) (struct timeval prev,
4546 struct timeval cur,
4647 double speed);
4748 typedef int (*ReadFunc) (FILE *fp, Header *h, char **buf);
@@ -52,38 +53,66 @@ typedef void (*ProcessFunc) (FILE *fp, double speed,
5253 struct timeval
5354 timeval_diff (struct timeval tv1, struct timeval tv2)
5455 {
55- struct timeval tv;
56+ struct timeval diff;
5657
57- tv.tv_sec = tv2.tv_sec - tv1.tv_sec;
58- tv.tv_usec = tv2.tv_usec - tv1.tv_usec;
59- if (tv.tv_usec < 0) {
60- tv.tv_sec--;
61- tv.tv_usec += 1000000;
58+ diff.tv_sec = tv2.tv_sec - tv1.tv_sec;
59+ diff.tv_usec = tv2.tv_usec - tv1.tv_usec;
60+ if (diff.tv_usec < 0) {
61+ diff.tv_sec--;
62+ diff.tv_usec += 1000000;
6263 }
6364
64- return tv;
65+ return diff;
6566 }
6667
67-void
68+struct timeval
69+timeval_div (struct timeval tv1, double n)
70+{
71+ double x = ((double)tv1.tv_sec + (double)tv1.tv_usec / 1000000.0) / n;
72+ struct timeval div;
73+
74+ div.tv_sec = (int)x;
75+ div.tv_usec = (x - (int)x) * 1000000;
76+
77+ return div;
78+}
79+
80+double
6881 ttywait (struct timeval prev, struct timeval cur, double speed)
6982 {
7083 struct timeval diff = timeval_diff(prev, cur);
84+ fd_set readfs;
7185
7286 assert(speed != 0);
87+ diff = timeval_div(diff, speed);
7388
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);
89+ FD_SET(STDIN_FILENO, &readfs);
90+ select(1, &readfs, NULL, NULL, &diff); /* skip if a user hits any key */
91+ if (FD_ISSET(0, &readfs)) { /* a user hits a character? */
92+ char c;
93+ read(STDIN_FILENO, &c, 1); /* drain the character */
94+ switch (c) {
95+ case '+':
96+ case 'f':
97+ speed *= 2;
98+ break;
99+ case '-':
100+ case 's':
101+ speed /= 2;
102+ break;
103+ case '1':
104+ speed = 1.0;
105+ break;
106+ }
107+ }
108+ return speed;
81109 }
82110
83-void
111+double
84112 ttynowait (struct timeval prev, struct timeval cur, double speed)
85113 {
86114 /* do nothing */
115+ return 0; /* Speed isn't important. */
87116 }
88117
89118 int
@@ -149,7 +178,7 @@ ttyplay (FILE *fp, double speed, ReadFunc read_func,
149178 }
150179
151180 if (!first_time) {
152- wait_func(prev, h.tv, speed);
181+ speed = wait_func(prev, h.tv, speed);
153182 }
154183 first_time = 0;
155184
@@ -200,7 +229,9 @@ main (int argc, char **argv)
200229 WaitFunc wait_func = ttywait;
201230 ProcessFunc process = ttyplayback;
202231 FILE *input = stdin;
232+ struct termios old, new;
203233
234+ set_progname(argv[0]);
204235 while (1) {
205236 int ch = getopt(argc, argv, "s:np");
206237 if (ch == EOF) {
@@ -229,7 +260,13 @@ main (int argc, char **argv)
229260 input = efopen(argv[optind], "r");
230261 }
231262
263+ tcgetattr(0, &old); /* Get current terminal state */
264+ new = old; /* Make a copy */
265+ new.c_lflag &= ~(ICANON | ECHO | ECHONL); /* unbuffered, no echo */
266+ tcsetattr(0, TCSANOW, &new); /* Make it current */
267+
232268 process(input, speed, read_func, wait_func);
269+ tcsetattr(0, TCSANOW, &old); /* Return terminal state */
233270
234271 return 0;
235272 }
--- a/ttyrec.1
+++ b/ttyrec.1
@@ -1,10 +1,13 @@
1+.\"
2+.\" This manual page is written by NAKANO Takeo <nakano@webmasters.gr.jp>
3+.\"
14 .TH TTYREC 1
25 .SH NAME
36 ttyrec \- a tty recorder
47 .SH SYNOPSIS
58 .br
69 .B ttyrec
7-.I "[\-a] [file]"
10+.I "[\-a][\-u] [file]"
811 .br
912 .SH DESCRIPTION
1013 .B Ttyrec
@@ -32,6 +35,27 @@ Append the output to
3235 or
3336 .IR ttyrecord ,
3437 rather than overwriting it.
38+.TP
39+.B \-u
40+With this option,
41+.B ttyrec
42+automatically calls
43+.BR uudecode (1)
44+and saves its output when uuencoded data appear on the session.
45+It allow you to transfer files from remote host.
46+You can call
47+.B ttyrec
48+with this option, login to the remote host
49+and invoke
50+.BR uuencode (1)
51+on it for the file you want to transfer.
52+.TP
53+.BI \-e " command"
54+Invoke
55+.I command
56+when ttyrec starts.
57+
58+
3559 .SH ENVIRONMENT
3660 .TP
3761 .I SHELL
@@ -45,8 +69,8 @@ the Bourne shell is assumed.
4569 (Most shells set this variable automatically).
4670 .SH "SEE ALSO"
4771 .BR script (1),
48-.BR ttyplay (1)
49-.SH AUTHOR
50-This manual page is written by NAKANO Takeo <nakano@webmasters.gr.jp>
51-for the Debian GNU/Linux system (but may be used by others).
72+.BR ttyplay (1),
73+.BR ttytime (1),
74+.BR uuencode (1),
75+.BR uudecode (1)
5276
--- a/ttyrec.c
+++ b/ttyrec.c
@@ -50,19 +50,15 @@
5050 #include <sys/file.h>
5151 #include <sys/signal.h>
5252 #include <stdio.h>
53+#include <unistd.h>
54+#include <string.h>
5355
5456 #if defined(SVR4)
5557 #include <stdlib.h>
56-#include <unistd.h>
5758 #include <fcntl.h>
5859 #include <stropts.h>
5960 #endif /* SVR4 */
6061
61-#ifdef __linux__
62-#include <unistd.h>
63-#include <string.h>
64-#endif
65-
6662 #include <sys/time.h>
6763 #include "ttyrec.h"
6864 #include "io.h"
@@ -94,7 +90,7 @@ void getmaster(void);
9490 void getslave(void);
9591 void doinput(void);
9692 void dooutput(void);
97-void doshell(void);
93+void doshell(const char*);
9894
9995 char *shell;
10096 FILE *fscript;
@@ -125,8 +121,9 @@ main(argc, argv)
125121 int ch;
126122 void finish();
127123 char *getenv();
124+ char *command = NULL;
128125
129- while ((ch = getopt(argc, argv, "auh?")) != EOF)
126+ while ((ch = getopt(argc, argv, "aue:h?")) != EOF)
130127 switch((char)ch) {
131128 case 'a':
132129 aflg++;
@@ -134,10 +131,13 @@ main(argc, argv)
134131 case 'u':
135132 uflg++;
136133 break;
134+ case 'e':
135+ command = strdup(optarg);
136+ break;
137137 case 'h':
138138 case '?':
139139 default:
140- fprintf(stderr, _("usage: ttyrec [-u] [-a] [file]\n"));
140+ fprintf(stderr, _("usage: ttyrec [-u] [-e command] [-a] [file]\n"));
141141 exit(1);
142142 }
143143 argc -= optind;
@@ -175,7 +175,7 @@ main(argc, argv)
175175 if (child)
176176 dooutput();
177177 else
178- doshell();
178+ doshell(command);
179179 }
180180 doinput();
181181
@@ -306,7 +306,7 @@ dooutput()
306306 }
307307
308308 void
309-doshell()
309+doshell(const char* command)
310310 {
311311 /***
312312 int t;
@@ -325,8 +325,11 @@ doshell()
325325 (void) dup2(slave, 2);
326326 (void) close(slave);
327327
328- execl(shell, strrchr(shell, '/') + 1, "-i", 0);
329-
328+ if (!command) {
329+ execl(shell, strrchr(shell, '/') + 1, "-i", 0);
330+ } else {
331+ execl(shell, strrchr(shell, '/') + 1, "-c", command, 0);
332+ }
330333 perror(shell);
331334 fail();
332335 }
--- /dev/null
+++ b/ttytime.1
@@ -0,0 +1,27 @@
1+.\"
2+.\" This manual page is written by NAKANO Takeo <nakano@webmasters.gr.jp>
3+.\"
4+.TH TTYTIME 1
5+.SH NAME
6+ttytime \- print the time of the recorded session data by ttyrec(1)
7+.SH SYNOPSIS
8+.br
9+.B ttytime
10+.I file...
11+.SH DESCRIPTION
12+.B Ttytime
13+tells you the time of recorded data in seconds.
14+For example:
15+.sp
16+.RS
17+.nf
18+% ttytime *.tty
19+ 173 foo.tty
20+ 1832 bar.tty
21+.fi
22+.RE
23+.SH "SEE ALSO"
24+.BR script (1),
25+.BR ttyrec (1),
26+.BR ttyplay (1)
27+
--- a/ttytime.c
+++ b/ttytime.c
@@ -61,6 +61,7 @@ int
6161 main (int argc, char **argv)
6262 {
6363 int i;
64+ set_progname(argv[0]);
6465 for (i = 1; i < argc; i++) {
6566 char *filename = argv[i];
6667 printf("%7d %s\n", calc_time(filename), filename);