ttyrecのfork. Original: http://0xcc.net/ttyrec/
リビジョン | 0472267f03a982555cedfc732ed0cc733956a2d4 (tree) |
---|---|
日時 | 2019-12-09 16:13:42 |
作者 | IWAMOTO Kouichi <sue@iwmt...> |
コミッター | IWAMOTO Kouichi |
update to ttyrec-1.0.3
@@ -1,16 +1,18 @@ | ||
1 | 1 | CC = gcc |
2 | 2 | CFLAGS = -O2 |
3 | -VERSION = 1.0.2 | |
3 | +VERSION = 1.0.3 | |
4 | 4 | |
5 | 5 | TARGET = ttyrec ttyplay |
6 | 6 | |
7 | +DIST = ttyrec.c ttyplay.c ttyrec.h io.c io.h README Makefile ttyrec.1 ttyplay.1 | |
8 | + | |
7 | 9 | all: $(TARGET) |
8 | 10 | |
9 | -ttyrec: ttyrec.c | |
10 | - $(CC) $(CFLAGS) -o ttyrec ttyrec.c | |
11 | +ttyrec: ttyrec.o io.o | |
12 | + $(CC) $(CFLAGS) -o ttyrec ttyrec.o io.o | |
11 | 13 | |
12 | -ttyplay: ttyplay.c | |
13 | - $(CC) $(CFLAGS) -o ttyplay ttyplay.c | |
14 | +ttyplay: ttyplay.o io.o | |
15 | + $(CC) $(CFLAGS) -o ttyplay ttyplay.o io.o | |
14 | 16 | |
15 | 17 | clean: |
16 | 18 | rm -f *.o $(TARGET) ttyrecord *~ |
@@ -20,6 +22,6 @@ dist: | ||
20 | 22 | rm -f ttyrec-$(VERSION).tar.gz |
21 | 23 | |
22 | 24 | mkdir ttyrec-$(VERSION) |
23 | - cp ttyrec.c ttyplay.c ttyrec.h README Makefile ttyrec-$(VERSION) | |
25 | + cp $(DIST) ttyrec-$(VERSION) | |
24 | 26 | tar zcf ttyrec-$(VERSION).tar.gz ttyrec-$(VERSION) |
25 | 27 | rm -rf ttyrec-$(VERSION) |
@@ -4,7 +4,7 @@ Installation: | ||
4 | 4 | |
5 | 5 | % make |
6 | 6 | |
7 | -or if your system is SVR4 series (Solaris etc.), | |
7 | +or if your system is SVR4 system (Solaris etc.), | |
8 | 8 | |
9 | 9 | % make CFLAGS=-DSVR4 |
10 | 10 |
@@ -0,0 +1,110 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2000 Satoru Takabayashi <satoru@namazu.org> | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or without | |
6 | + * modification, are permitted provided that the following conditions | |
7 | + * are met: | |
8 | + * 1. Redistributions of source code must retain the above copyright | |
9 | + * notice, this list of conditions and the following disclaimer. | |
10 | + * 2. Redistributions in binary form must reproduce the above copyright | |
11 | + * notice, this list of conditions and the following disclaimer in the | |
12 | + * documentation and/or other materials provided with the distribution. | |
13 | + * 3. All advertising materials mentioning features or use of this software | |
14 | + * must display the following acknowledgement: | |
15 | + * This product includes software developed by the University of | |
16 | + * California, Berkeley and its contributors. | |
17 | + * 4. Neither the name of the University nor the names of its contributors | |
18 | + * may be used to endorse or promote products derived from this software | |
19 | + * without specific prior written permission. | |
20 | + * | |
21 | + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | + * SUCH DAMAGE. | |
32 | + */ | |
33 | + | |
34 | +#include <stdio.h> | |
35 | +#include <stdlib.h> | |
36 | +#include <assert.h> | |
37 | +#include <string.h> | |
38 | + | |
39 | +#include "ttyrec.h" | |
40 | + | |
41 | +#define SWAP_ENDIAN(val) ((unsigned int) ( \ | |
42 | + (((unsigned int) (val) & (unsigned int) 0x000000ffU) << 24) | \ | |
43 | + (((unsigned int) (val) & (unsigned int) 0x0000ff00U) << 8) | \ | |
44 | + (((unsigned int) (val) & (unsigned int) 0x00ff0000U) >> 8) | \ | |
45 | + (((unsigned int) (val) & (unsigned int) 0xff000000U) >> 24))) | |
46 | + | |
47 | +static int | |
48 | +is_little_endian () | |
49 | +{ | |
50 | + static int retval = -1; | |
51 | + | |
52 | + if (retval == -1) { | |
53 | + int n = 1; | |
54 | + char *p = (char *)&n; | |
55 | + char x[] = {1, 0, 0, 0}; | |
56 | + | |
57 | + assert(sizeof(int) == 4); | |
58 | + | |
59 | + if (memcmp(p, x, 4) == 0) { | |
60 | + retval = 1; | |
61 | + } else { | |
62 | + retval = 0; | |
63 | + } | |
64 | + } | |
65 | + | |
66 | + return retval; | |
67 | +} | |
68 | + | |
69 | +static int | |
70 | +convert_to_little_endian (int x) | |
71 | +{ | |
72 | + if (is_little_endian()) { | |
73 | + return x; | |
74 | + } else { | |
75 | + return SWAP_ENDIAN(x); | |
76 | + } | |
77 | +} | |
78 | + | |
79 | +int | |
80 | +read_header (FILE *fp, Header *h) | |
81 | +{ | |
82 | + int buf[3]; | |
83 | + | |
84 | + if (fread(buf, sizeof(int), 3, fp) == 0) { | |
85 | + return 0; | |
86 | + } | |
87 | + | |
88 | + h->tv.tv_sec = convert_to_little_endian(buf[0]); | |
89 | + h->tv.tv_usec = convert_to_little_endian(buf[1]); | |
90 | + h->len = convert_to_little_endian(buf[2]); | |
91 | + | |
92 | + return 1; | |
93 | +} | |
94 | + | |
95 | +int | |
96 | +write_header (FILE *fp, Header *h) | |
97 | +{ | |
98 | + int buf[3]; | |
99 | + | |
100 | + buf[0] = convert_to_little_endian(h->tv.tv_sec); | |
101 | + buf[1] = convert_to_little_endian(h->tv.tv_usec); | |
102 | + buf[2] = convert_to_little_endian(h->len); | |
103 | + | |
104 | + if (fwrite(buf, sizeof(int), 3, fp) == 0) { | |
105 | + return 0; | |
106 | + } | |
107 | + | |
108 | + return 1; | |
109 | +} | |
110 | + |
@@ -0,0 +1,9 @@ | ||
1 | +#ifndef __TTYREC_IO_H__ | |
2 | +#define __TTYREC_IO_H__ | |
3 | + | |
4 | +#include "ttyrec.h" | |
5 | + | |
6 | +int read_header (FILE *fp, Header *h); | |
7 | +int write_header (FILE *fp, Header *h); | |
8 | + | |
9 | +#endif |
@@ -0,0 +1,45 @@ | ||
1 | +.TH TTYPLAY 1 | |
2 | +.SH NAME | |
3 | +ttyplay \- a player of the tty session recorded by ttyrec | |
4 | +.SH SYNOPSIS | |
5 | +.br | |
6 | +.B ttyplay | |
7 | +.I [\-s SPEED] [\-n] [\-p] file | |
8 | +.br | |
9 | +.SH DESCRIPTION | |
10 | +.B Ttyplay | |
11 | +plays the tty session in | |
12 | +.IR file , | |
13 | +which was recorded previously by | |
14 | +.BR ttyrec (1). | |
15 | +.PP | |
16 | +When | |
17 | +.B \-p | |
18 | +option is given, | |
19 | +.B ttyplay | |
20 | +output the | |
21 | +.I file | |
22 | +as it grows. | |
23 | +It means that you can see the "live" shell session | |
24 | +running by another user. | |
25 | +.SH OPTIONS | |
26 | +.TP | |
27 | +.BI \-s " SPEED" | |
28 | +multiple the playing speed by | |
29 | +.I SPEED | |
30 | +(default is 1). | |
31 | +.TP | |
32 | +.B \-n | |
33 | +no wait mode. | |
34 | +Ignore the timing information in | |
35 | +.IR file . | |
36 | +.TP | |
37 | +.B \-p | |
38 | +peek another person's tty session. | |
39 | +.SH "SEE ALSO" | |
40 | +.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). | |
45 | + |
@@ -40,6 +40,7 @@ | ||
40 | 40 | #include <string.h> |
41 | 41 | |
42 | 42 | #include "ttyrec.h" |
43 | +#include "io.h" | |
43 | 44 | |
44 | 45 | typedef void (*WaitFunc) (struct timeval prev, |
45 | 46 | struct timeval cur, |
@@ -89,7 +90,7 @@ ttynowait (struct timeval prev, struct timeval cur, double speed) | ||
89 | 90 | int |
90 | 91 | ttyread (FILE *fp, Header *h, char **buf) |
91 | 92 | { |
92 | - if (fread(h, sizeof(Header), 1, fp) == 0) { | |
93 | + if (read_header(fp, h) == 0) { | |
93 | 94 | return 0; |
94 | 95 | } |
95 | 96 |
@@ -0,0 +1,52 @@ | ||
1 | +.TH TTYREC 1 | |
2 | +.SH NAME | |
3 | +ttyrec \- a tty recorder | |
4 | +.SH SYNOPSIS | |
5 | +.br | |
6 | +.B ttyrec | |
7 | +.I "[\-a] [file]" | |
8 | +.br | |
9 | +.SH DESCRIPTION | |
10 | +.B Ttyrec | |
11 | +is a tty recorder. | |
12 | +It is a derivative of | |
13 | +.BR script (1) | |
14 | +command for recording timing information with microsecond accuracy as well. | |
15 | +It can record emacs -nw, vi, lynx, or any programs running on tty. | |
16 | +.PP | |
17 | +.B Ttyrec | |
18 | +invokes a shell and records the session until the shell exits. | |
19 | +Recorded data can be played back with | |
20 | +.BR ttyplay (1). | |
21 | +If the argument | |
22 | +.I file | |
23 | +is given, the session will be recorded in that file. | |
24 | +Otherwise, | |
25 | +.I ttyrecord | |
26 | +is used as default. | |
27 | +.SH OPTIONS | |
28 | +.TP | |
29 | +.B \-a | |
30 | +Append the output to | |
31 | +.I file | |
32 | +or | |
33 | +.IR ttyrecord , | |
34 | +rather than overwriting it. | |
35 | +.SH ENVIRONMENT | |
36 | +.TP | |
37 | +.I SHELL | |
38 | +If the variable | |
39 | +.I SHELL | |
40 | +exists, the shell forked by | |
41 | +.B ttyrec | |
42 | +will be that shell. | |
43 | +If it's not set, | |
44 | +the Bourne shell is assumed. | |
45 | +(Most shells set this variable automatically). | |
46 | +.SH "SEE ALSO" | |
47 | +.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). | |
52 | + |
@@ -65,6 +65,7 @@ | ||
65 | 65 | |
66 | 66 | #include <sys/time.h> |
67 | 67 | #include "ttyrec.h" |
68 | +#include "io.h" | |
68 | 69 | |
69 | 70 | #define HAVE_inet_aton |
70 | 71 | #define HAVE_scsi_h |
@@ -224,7 +225,7 @@ dooutput() | ||
224 | 225 | h.len = cc; |
225 | 226 | gettimeofday(&h.tv, NULL); |
226 | 227 | (void) write(1, obuf, cc); |
227 | - (void) fwrite(&h, sizeof(Header), 1, fscript); | |
228 | + (void) write_header(fscript, &h); | |
228 | 229 | (void) fwrite(obuf, 1, cc, fscript); |
229 | 230 | } |
230 | 231 | done(); |
@@ -365,7 +366,7 @@ getslave() | ||
365 | 366 | (void) setsid(); |
366 | 367 | grantpt( master); |
367 | 368 | unlockpt(master); |
368 | - if ((slave = open(ptsname(master), O_RDWR)) < 0) { | |
369 | + if ((slave = open((const char *)ptsname(master), O_RDWR)) < 0) { | |
369 | 370 | perror("open(fd, O_RDWR)"); |
370 | 371 | fail(); |
371 | 372 | } |
@@ -1,5 +1,7 @@ | ||
1 | -#ifndef _TTYPLAYER_H | |
2 | -#define _TTYPLAYER_H | |
1 | +#ifndef __TTYREC_H__ | |
2 | +#define __TTYREC_H__ | |
3 | + | |
4 | +#include "sys/time.h" | |
3 | 5 | |
4 | 6 | typedef struct header { |
5 | 7 | struct timeval tv; |