• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得cocoawindowspythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdombtronvb.netdirectxarduinopreviewerゲームエンジン

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


Commit MetaInfo

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

Log Message

update to ttyrec-1.0.5

Change Summary

差異

--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,11 @@
11 CC = gcc
22 CFLAGS = -O2
3-VERSION = 1.0.4
3+VERSION = 1.0.5
44
5-TARGET = ttyrec ttyplay
5+TARGET = ttyrec ttyplay ttytime
66
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
89
910 all: $(TARGET)
1011
@@ -14,6 +15,9 @@ ttyrec: ttyrec.o io.o
1415 ttyplay: ttyplay.o io.o
1516 $(CC) $(CFLAGS) -o ttyplay ttyplay.o io.o
1617
18+ttytime: ttytime.o io.o
19+ $(CC) $(CFLAGS) -o ttytime ttytime.o io.o
20+
1721 clean:
1822 rm -f *.o $(TARGET) ttyrecord *~
1923
--- a/io.c
+++ b/io.c
@@ -35,6 +35,7 @@
3535 #include <stdlib.h>
3636 #include <assert.h>
3737 #include <string.h>
38+#include <errno.h>
3839
3940 #include "ttyrec.h"
4041
@@ -108,3 +109,14 @@ write_header (FILE *fp, Header *h)
108109 return 1;
109110 }
110111
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+
--- a/io.h
+++ b/io.h
@@ -5,5 +5,6 @@
55
66 int read_header (FILE *fp, Header *h);
77 int write_header (FILE *fp, Header *h);
8+FILE* efopen (const char *path, const char *mode);
89
910 #endif
--- a/ttyplay.c
+++ b/ttyplay.c
@@ -36,7 +36,6 @@
3636 #include <assert.h>
3737 #include <unistd.h>
3838 #include <sys/time.h>
39-#include <errno.h>
4039 #include <string.h>
4140
4241 #include "ttyrec.h"
@@ -193,17 +192,6 @@ usage (void)
193192 exit(EXIT_FAILURE);
194193 }
195194
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-
207195 int
208196 main (int argc, char **argv)
209197 {
--- a/ttyrec.c
+++ b/ttyrec.c
@@ -77,6 +77,16 @@
7777 #include <libutil.h>
7878 #endif
7979
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+
8090 void done(void);
8191 void fail(void);
8292 void fixtty(void);
@@ -104,6 +114,7 @@ char line[] = "/dev/ptyXX";
104114 #endif
105115 #endif /* !SVR4 */
106116 int aflg;
117+int uflg;
107118
108119 int
109120 main(argc, argv)
@@ -115,14 +126,18 @@ main(argc, argv)
115126 void finish();
116127 char *getenv();
117128
118- while ((ch = getopt(argc, argv, "a")) != EOF)
129+ while ((ch = getopt(argc, argv, "auh?")) != EOF)
119130 switch((char)ch) {
120131 case 'a':
121132 aflg++;
122133 break;
134+ case 'u':
135+ uflg++;
136+ break;
137+ case 'h':
123138 case '?':
124139 default:
125- fprintf(stderr, _("usage: script [-a] [file]\n"));
140+ fprintf(stderr, _("usage: ttyrec [-u] [-a] [file]\n"));
126141 exit(1);
127142 }
128143 argc -= optind;
@@ -203,6 +218,63 @@ finish()
203218 done();
204219 }
205220
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+
206278 void
207279 dooutput()
208280 {
@@ -222,6 +294,8 @@ dooutput()
222294 cc = read(master, obuf, BUFSIZ);
223295 if (cc <= 0)
224296 break;
297+ if (uflg)
298+ check_output(obuf, cc);
225299 h.len = cc;
226300 gettimeofday(&h.tv, NULL);
227301 (void) write(1, obuf, cc);
@@ -370,19 +444,23 @@ getslave()
370444 perror("open(fd, O_RDWR)");
371445 fail();
372446 }
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);
384463 }
385- (void) ioctl(0, TIOCGWINSZ, (char *)&win);
386464 #else /* !SVR4 */
387465 #ifndef HAVE_openpty
388466 line[strlen("/dev/")] = 't';
--- /dev/null
+++ b/ttytime.c
@@ -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+}