ttyrecのfork. Original: http://0xcc.net/ttyrec/
リビジョン | 10e4127d9dfdd87619997c03b4fbe0b835adbc93 (tree) |
---|---|
日時 | 2019-12-09 16:15:15 |
作者 | IWAMOTO Kouichi <sue@iwmt...> |
コミッター | IWAMOTO Kouichi |
update to ttyrec-1.0.5
@@ -1,10 +1,11 @@ | ||
1 | 1 | CC = gcc |
2 | 2 | CFLAGS = -O2 |
3 | -VERSION = 1.0.4 | |
3 | +VERSION = 1.0.5 | |
4 | 4 | |
5 | -TARGET = ttyrec ttyplay | |
5 | +TARGET = ttyrec ttyplay ttytime | |
6 | 6 | |
7 | -DIST = ttyrec.c ttyplay.c ttyrec.h io.c io.h README Makefile ttyrec.1 ttyplay.1 | |
7 | +DIST = ttyrec.c ttyplay.c ttyrec.h io.c io.h ttytime.c\ | |
8 | + README Makefile ttyrec.1 ttyplay.1 | |
8 | 9 | |
9 | 10 | all: $(TARGET) |
10 | 11 |
@@ -14,6 +15,9 @@ ttyrec: ttyrec.o io.o | ||
14 | 15 | ttyplay: ttyplay.o io.o |
15 | 16 | $(CC) $(CFLAGS) -o ttyplay ttyplay.o io.o |
16 | 17 | |
18 | +ttytime: ttytime.o io.o | |
19 | + $(CC) $(CFLAGS) -o ttytime ttytime.o io.o | |
20 | + | |
17 | 21 | clean: |
18 | 22 | rm -f *.o $(TARGET) ttyrecord *~ |
19 | 23 |
@@ -35,6 +35,7 @@ | ||
35 | 35 | #include <stdlib.h> |
36 | 36 | #include <assert.h> |
37 | 37 | #include <string.h> |
38 | +#include <errno.h> | |
38 | 39 | |
39 | 40 | #include "ttyrec.h" |
40 | 41 |
@@ -108,3 +109,14 @@ write_header (FILE *fp, Header *h) | ||
108 | 109 | return 1; |
109 | 110 | } |
110 | 111 | |
112 | +FILE * | |
113 | +efopen (const char *path, const char *mode) | |
114 | +{ | |
115 | + FILE *fp = fopen(path, mode); | |
116 | + if (fp == NULL) { | |
117 | + fprintf(stderr, "ttyplay: %s: %s\n", path, strerror(errno)); | |
118 | + exit(EXIT_FAILURE); | |
119 | + } | |
120 | + return fp; | |
121 | +} | |
122 | + |
@@ -5,5 +5,6 @@ | ||
5 | 5 | |
6 | 6 | int read_header (FILE *fp, Header *h); |
7 | 7 | int write_header (FILE *fp, Header *h); |
8 | +FILE* efopen (const char *path, const char *mode); | |
8 | 9 | |
9 | 10 | #endif |
@@ -36,7 +36,6 @@ | ||
36 | 36 | #include <assert.h> |
37 | 37 | #include <unistd.h> |
38 | 38 | #include <sys/time.h> |
39 | -#include <errno.h> | |
40 | 39 | #include <string.h> |
41 | 40 | |
42 | 41 | #include "ttyrec.h" |
@@ -193,17 +192,6 @@ usage (void) | ||
193 | 192 | exit(EXIT_FAILURE); |
194 | 193 | } |
195 | 194 | |
196 | -FILE * | |
197 | -efopen (const char *path, const char *mode) | |
198 | -{ | |
199 | - FILE *fp = fopen(path, mode); | |
200 | - if (fp == NULL) { | |
201 | - fprintf(stderr, "ttyplay: %s: %s\n", path, strerror(errno)); | |
202 | - exit(EXIT_FAILURE); | |
203 | - } | |
204 | - return fp; | |
205 | -} | |
206 | - | |
207 | 195 | int |
208 | 196 | main (int argc, char **argv) |
209 | 197 | { |
@@ -77,6 +77,16 @@ | ||
77 | 77 | #include <libutil.h> |
78 | 78 | #endif |
79 | 79 | |
80 | +#if defined(SVR4) && !defined(CDEL) | |
81 | +#if defined(_POSIX_VDISABLE) | |
82 | +#define CDEL _POSIX_VDISABLE | |
83 | +#elif defined(CDISABLE) | |
84 | +#define CDEL CDISABLE | |
85 | +#else /* not _POSIX_VISIBLE && not CDISABLE */ | |
86 | +#define CDEL 255 | |
87 | +#endif /* not _POSIX_VISIBLE && not CDISABLE */ | |
88 | +#endif /* SVR4 && ! CDEL */ | |
89 | + | |
80 | 90 | void done(void); |
81 | 91 | void fail(void); |
82 | 92 | void fixtty(void); |
@@ -104,6 +114,7 @@ char line[] = "/dev/ptyXX"; | ||
104 | 114 | #endif |
105 | 115 | #endif /* !SVR4 */ |
106 | 116 | int aflg; |
117 | +int uflg; | |
107 | 118 | |
108 | 119 | int |
109 | 120 | main(argc, argv) |
@@ -115,14 +126,18 @@ main(argc, argv) | ||
115 | 126 | void finish(); |
116 | 127 | char *getenv(); |
117 | 128 | |
118 | - while ((ch = getopt(argc, argv, "a")) != EOF) | |
129 | + while ((ch = getopt(argc, argv, "auh?")) != EOF) | |
119 | 130 | switch((char)ch) { |
120 | 131 | case 'a': |
121 | 132 | aflg++; |
122 | 133 | break; |
134 | + case 'u': | |
135 | + uflg++; | |
136 | + break; | |
137 | + case 'h': | |
123 | 138 | case '?': |
124 | 139 | default: |
125 | - fprintf(stderr, _("usage: script [-a] [file]\n")); | |
140 | + fprintf(stderr, _("usage: ttyrec [-u] [-a] [file]\n")); | |
126 | 141 | exit(1); |
127 | 142 | } |
128 | 143 | argc -= optind; |
@@ -203,6 +218,63 @@ finish() | ||
203 | 218 | done(); |
204 | 219 | } |
205 | 220 | |
221 | +struct linebuf { | |
222 | + char str[BUFSIZ + 1]; /* + 1 for an additional NULL character.*/ | |
223 | + int len; | |
224 | +}; | |
225 | + | |
226 | + | |
227 | +void | |
228 | +check_line (const char *line) | |
229 | +{ | |
230 | + static int uuencode_mode = 0; | |
231 | + static FILE *uudecode; | |
232 | + | |
233 | + if (uuencode_mode == 1) { | |
234 | + fprintf(uudecode, "%s", line); | |
235 | + if (strcmp(line, "end\n") == 0) { | |
236 | + pclose(uudecode); | |
237 | + uuencode_mode = 0; | |
238 | + } | |
239 | + } else { | |
240 | + int dummy; char dummy2[BUFSIZ]; | |
241 | + if (sscanf(line, "begin %o %s", &dummy, dummy2) == 2) { | |
242 | + /* | |
243 | + * uuencode line found! | |
244 | + */ | |
245 | + uudecode = popen("uudecode", "w"); | |
246 | + fprintf(uudecode, "%s", line); | |
247 | + uuencode_mode = 1; | |
248 | + } | |
249 | + } | |
250 | +} | |
251 | + | |
252 | +void | |
253 | +check_output(const char *str, int len) | |
254 | +{ | |
255 | + static struct linebuf lbuf = {"", 0}; | |
256 | + int i; | |
257 | + | |
258 | + for (i = 0; i < len; i++) { | |
259 | + if (lbuf.len < BUFSIZ) { | |
260 | + lbuf.str[lbuf.len] = str[i]; | |
261 | + if (lbuf.str[lbuf.len] == '\r') { | |
262 | + lbuf.str[lbuf.len] = '\n'; | |
263 | + } | |
264 | + lbuf.len++; | |
265 | + if (lbuf.str[lbuf.len - 1] == '\n') { | |
266 | + if (lbuf.len > 1) { /* skip a blank line. */ | |
267 | + lbuf.str[lbuf.len] = '\0'; | |
268 | + check_line(lbuf.str); | |
269 | + } | |
270 | + lbuf.len = 0; | |
271 | + } | |
272 | + } else {/* buffer overflow */ | |
273 | + lbuf.len = 0; | |
274 | + } | |
275 | + } | |
276 | +} | |
277 | + | |
206 | 278 | void |
207 | 279 | dooutput() |
208 | 280 | { |
@@ -222,6 +294,8 @@ dooutput() | ||
222 | 294 | cc = read(master, obuf, BUFSIZ); |
223 | 295 | if (cc <= 0) |
224 | 296 | break; |
297 | + if (uflg) | |
298 | + check_output(obuf, cc); | |
225 | 299 | h.len = cc; |
226 | 300 | gettimeofday(&h.tv, NULL); |
227 | 301 | (void) write(1, obuf, cc); |
@@ -370,19 +444,23 @@ getslave() | ||
370 | 444 | perror("open(fd, O_RDWR)"); |
371 | 445 | fail(); |
372 | 446 | } |
373 | - if (ioctl(slave, I_PUSH, "ptem") < 0) { | |
374 | - perror("ioctl(fd, I_PUSH, ptem)"); | |
375 | - fail(); | |
376 | - } | |
377 | - if (ioctl(slave, I_PUSH, "ldterm") < 0) { | |
378 | - perror("ioctl(fd, I_PUSH, ldterm)"); | |
379 | - fail(); | |
380 | - } | |
381 | - if (ioctl(slave, I_PUSH, "ttcompat") < 0) { | |
382 | - perror("ioctl(fd, I_PUSH, ttcompat)"); | |
383 | - fail(); | |
447 | + if (isastream(slave)) { | |
448 | + if (ioctl(slave, I_PUSH, "ptem") < 0) { | |
449 | + perror("ioctl(fd, I_PUSH, ptem)"); | |
450 | + fail(); | |
451 | + } | |
452 | + if (ioctl(slave, I_PUSH, "ldterm") < 0) { | |
453 | + perror("ioctl(fd, I_PUSH, ldterm)"); | |
454 | + fail(); | |
455 | + } | |
456 | +#ifndef _HPUX_SOURCE | |
457 | + if (ioctl(slave, I_PUSH, "ttcompat") < 0) { | |
458 | + perror("ioctl(fd, I_PUSH, ttcompat)"); | |
459 | + fail(); | |
460 | + } | |
461 | +#endif | |
462 | + (void) ioctl(0, TIOCGWINSZ, (char *)&win); | |
384 | 463 | } |
385 | - (void) ioctl(0, TIOCGWINSZ, (char *)&win); | |
386 | 464 | #else /* !SVR4 */ |
387 | 465 | #ifndef HAVE_openpty |
388 | 466 | line[strlen("/dev/")] = 't'; |
@@ -0,0 +1,69 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 1980 Regents of the University of California. | |
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 | + | |
38 | +#include "io.h" | |
39 | +#include "ttyrec.h" | |
40 | + | |
41 | +int | |
42 | +calc_time (const char *filename) | |
43 | +{ | |
44 | + Header start, end; | |
45 | + FILE *fp = efopen(filename, "r"); | |
46 | + | |
47 | + read_header(fp, &start); | |
48 | + fseek(fp, start.len, SEEK_CUR); | |
49 | + while (1) { | |
50 | + Header h; | |
51 | + if (read_header(fp, &h) == 0) { | |
52 | + break; | |
53 | + } | |
54 | + end = h; | |
55 | + fseek(fp, h.len, SEEK_CUR); | |
56 | + } | |
57 | + return end.tv.tv_sec - start.tv.tv_sec; | |
58 | +} | |
59 | + | |
60 | +int | |
61 | +main (int argc, char **argv) | |
62 | +{ | |
63 | + int i; | |
64 | + for (i = 1; i < argc; i++) { | |
65 | + char *filename = argv[i]; | |
66 | + printf("%7d %s\n", calc_time(filename), filename); | |
67 | + } | |
68 | + return 0; | |
69 | +} |