ttyrecのfork. Original: http://0xcc.net/ttyrec/
Revisão | 096ae3f3ac526c2e914897d551d26d520ff8d6ee (tree) |
---|---|
Hora | 2019-12-09 16:23:30 |
Autor | IWAMOTO Kouichi <sue@iwmt...> |
Commiter | IWAMOTO Kouichi |
update to ttyrec-1.0.7
@@ -1,6 +1,6 @@ | ||
1 | 1 | CC = gcc |
2 | 2 | CFLAGS = -O2 |
3 | -VERSION = 1.0.6 | |
3 | +VERSION = 1.0.7 | |
4 | 4 | |
5 | 5 | TARGET = ttyrec ttyplay ttytime |
6 | 6 |
@@ -8,6 +8,13 @@ or if your system is SVR4 system (Solaris etc.), | ||
8 | 8 | |
9 | 9 | % make CFLAGS=-DSVR4 |
10 | 10 | |
11 | +or if your system supports getpt(3), | |
12 | + | |
13 | + % make CFLAGS=-DHAVE_getpt | |
14 | + | |
15 | +HAVE_getpt is required if your linux system uses devfs. | |
16 | + | |
17 | + | |
11 | 18 | Usage: |
12 | 19 | |
13 | 20 | % ttyrec |
@@ -31,11 +31,12 @@ | ||
31 | 31 | * SUCH DAMAGE. |
32 | 32 | */ |
33 | 33 | |
34 | +#include <assert.h> | |
35 | +#include <errno.h> | |
34 | 36 | #include <stdio.h> |
35 | 37 | #include <stdlib.h> |
36 | -#include <assert.h> | |
37 | 38 | #include <string.h> |
38 | -#include <errno.h> | |
39 | +#include <unistd.h> | |
39 | 40 | |
40 | 41 | #include "ttyrec.h" |
41 | 42 |
@@ -127,3 +128,34 @@ efopen (const char *path, const char *mode) | ||
127 | 128 | return fp; |
128 | 129 | } |
129 | 130 | |
131 | +int | |
132 | +edup (int oldfd) | |
133 | +{ | |
134 | + int fd = dup(oldfd); | |
135 | + if (fd == -1) { | |
136 | + fprintf(stderr, "%s: dup failed: %s\n", progname, strerror(errno)); | |
137 | + exit(EXIT_FAILURE); | |
138 | + } | |
139 | + return fd; | |
140 | +} | |
141 | + | |
142 | +int | |
143 | +edup2 (int oldfd, int newfd) | |
144 | +{ | |
145 | + int fd = dup2(oldfd, newfd); | |
146 | + if (fd == -1) { | |
147 | + fprintf(stderr, "%s: dup2 failed: %s\n", progname, strerror(errno)); | |
148 | + exit(EXIT_FAILURE); | |
149 | + } | |
150 | + return fd; | |
151 | +} | |
152 | + | |
153 | +FILE * | |
154 | +efdopen (int fd, const char *mode) | |
155 | +{ | |
156 | + FILE *fp = fdopen(fd, mode); | |
157 | + if (fp == NULL) { | |
158 | + fprintf(stderr, "%s: fdopen failed: %s\n", progname, strerror(errno)); | |
159 | + exit(EXIT_FAILURE); | |
160 | + } | |
161 | +} |
@@ -3,8 +3,11 @@ | ||
3 | 3 | |
4 | 4 | #include "ttyrec.h" |
5 | 5 | |
6 | -int read_header (FILE *fp, Header *h); | |
7 | -int write_header (FILE *fp, Header *h); | |
8 | -FILE* efopen (const char *path, const char *mode); | |
6 | +int read_header (FILE *fp, Header *h); | |
7 | +int write_header (FILE *fp, Header *h); | |
8 | +FILE* efopen (const char *path, const char *mode); | |
9 | +int edup (int oldfd); | |
10 | +int edup2 (int oldfd, int newfd); | |
11 | +FILE* efdopen (int fd, const char *mode); | |
9 | 12 | |
10 | 13 | #endif |
@@ -221,6 +221,19 @@ usage (void) | ||
221 | 221 | exit(EXIT_FAILURE); |
222 | 222 | } |
223 | 223 | |
224 | +/* | |
225 | + * We do some tricks so that select(2) properly works on | |
226 | + * STDIN_FILENO in ttywait(). | |
227 | + */ | |
228 | +FILE * | |
229 | +input_from_stdin (void) | |
230 | +{ | |
231 | + FILE *fp; | |
232 | + int fd = edup(STDIN_FILENO); | |
233 | + edup2(STDOUT_FILENO, STDIN_FILENO); | |
234 | + return efdopen(fd, "r"); | |
235 | +} | |
236 | + | |
224 | 237 | int |
225 | 238 | main (int argc, char **argv) |
226 | 239 | { |
@@ -228,7 +241,7 @@ main (int argc, char **argv) | ||
228 | 241 | ReadFunc read_func = ttyread; |
229 | 242 | WaitFunc wait_func = ttywait; |
230 | 243 | ProcessFunc process = ttyplayback; |
231 | - FILE *input = stdin; | |
244 | + FILE *input = NULL; | |
232 | 245 | struct termios old, new; |
233 | 246 | |
234 | 247 | set_progname(argv[0]); |
@@ -258,7 +271,10 @@ main (int argc, char **argv) | ||
258 | 271 | |
259 | 272 | if (optind < argc) { |
260 | 273 | input = efopen(argv[optind], "r"); |
274 | + } else { | |
275 | + input = input_from_stdin(); | |
261 | 276 | } |
277 | + assert(input != NULL); | |
262 | 278 | |
263 | 279 | tcgetattr(0, &old); /* Get current terminal state */ |
264 | 280 | new = old; /* Make a copy */ |
@@ -400,6 +400,12 @@ getmaster() | ||
400 | 400 | fail(); |
401 | 401 | } |
402 | 402 | #else |
403 | +#ifdef HAVE_getpt | |
404 | + if ((master = getpt()) < 0) { | |
405 | + perror("getpt()"); | |
406 | + fail(); | |
407 | + } | |
408 | +#else | |
403 | 409 | char *pty, *bank, *cp; |
404 | 410 | struct stat stb; |
405 | 411 |
@@ -432,6 +438,7 @@ getmaster() | ||
432 | 438 | } |
433 | 439 | fprintf(stderr, _("Out of pty's\n")); |
434 | 440 | fail(); |
441 | +#endif /* not HAVE_getpt */ | |
435 | 442 | #endif /* not HAVE_openpty */ |
436 | 443 | #endif /* !SVR4 */ |
437 | 444 | } |