View | Details | Raw Unified | Return to bug 31205
Collapse All | Expand All

(-)Makefile (+2 lines)
Lines 4-7 Link Here
4
LDADD=	-lutil
4
LDADD=	-lutil
5
DPADD=	${LIBUTIL}
5
DPADD=	${LIBUTIL}
6
6
7
WARNS?=	2
8
7
.include <bsd.prog.mk>
9
.include <bsd.prog.mk>
(-)script.1 (-1 / +5 lines)
Lines 41-46 Link Here
41
.Sh SYNOPSIS
41
.Sh SYNOPSIS
42
.Nm
42
.Nm
43
.Op Fl a
43
.Op Fl a
44
.Op Fl A
44
.Op Fl k
45
.Op Fl k
45
.Op Fl q
46
.Op Fl q
46
.Op Fl t Ar time
47
.Op Fl t Ar time
Lines 77-82 Link Here
77
or
78
or
78
.Pa typescript ,
79
.Pa typescript ,
79
retaining the prior contents.
80
retaining the prior contents.
81
.It Fl A
82
Skip the ASCII 13 characters from the script output file.
80
.It Fl k
83
.It Fl k
81
Log keys sent to program as well as output.
84
Log keys sent to program as well as output.
82
.It Fl q
85
.It Fl q
Lines 141-147 Link Here
141
.Nm Script
144
.Nm Script
142
places
145
places
143
.Sy everything
146
.Sy everything
144
in the log file, including linefeeds and backspaces.
147
(except if you use the -A option), in the log file,
148
including linefeeds and backspaces.
145
This is not what the naive user expects.
149
This is not what the naive user expects.
146
.Pp
150
.Pp
147
It is not possible to specify a command without also naming the script file
151
It is not possible to specify a command without also naming the script file
(-)script.c (-7 / +31 lines)
Lines 66-73 Link Here
66
FILE	*fscript;
66
FILE	*fscript;
67
int	master, slave;
67
int	master, slave;
68
int	child;
68
int	child;
69
char	*fname;
69
const char	*fname;
70
int	qflg;
70
int	Aflg, qflg;
71
71
72
struct	termios tt;
72
struct	termios tt;
73
73
Lines 76-81 Link Here
76
void	doshell __P((char **));
76
void	doshell __P((char **));
77
void	fail __P((void));
77
void	fail __P((void));
78
void	finish __P((void));
78
void	finish __P((void));
79
void	log_write __P((const char *, int));
79
static void usage __P((void));
80
static void usage __P((void));
80
81
81
int
82
int
Lines 95-105 Link Here
95
	int flushtime = 30;
96
	int flushtime = 30;
96
97
97
	aflg = kflg = 0;
98
	aflg = kflg = 0;
98
	while ((ch = getopt(argc, argv, "aqkt:")) != -1)
99
	while ((ch = getopt(argc, argv, "aAqkt:")) != -1)
99
		switch(ch) {
100
		switch(ch) {
100
		case 'a':
101
		case 'a':
101
			aflg = 1;
102
			aflg = 1;
102
			break;
103
			break;
104
		case 'A':
105
			Aflg = 1;
106
			break;
103
		case 'q':
107
		case 'q':
104
			qflg = 1;
108
			qflg = 1;
105
			break;
109
			break;
Lines 177-183 Link Here
177
				(void)write(master, ibuf, cc);
181
				(void)write(master, ibuf, cc);
178
				if (kflg && tcgetattr(master, &stt) >= 0 &&
182
				if (kflg && tcgetattr(master, &stt) >= 0 &&
179
				    ((stt.c_lflag & ECHO) == 0)) {
183
				    ((stt.c_lflag & ECHO) == 0)) {
180
					(void)fwrite(ibuf, 1, cc, fscript);
184
					log_write(ibuf, cc);
181
				}
185
				}
182
			}
186
			}
183
		}
187
		}
Lines 186-192 Link Here
186
			if (cc <= 0)
190
			if (cc <= 0)
187
				break;
191
				break;
188
			(void)write(STDOUT_FILENO, obuf, cc);
192
			(void)write(STDOUT_FILENO, obuf, cc);
189
			(void)fwrite(obuf, 1, cc, fscript);
193
			log_write(obuf, cc);
190
		}
194
		}
191
		tvec = time(0);
195
		tvec = time(0);
192
		if (tvec - start >= flushtime) {
196
		if (tvec - start >= flushtime) {
Lines 202-208 Link Here
202
usage()
206
usage()
203
{
207
{
204
	(void)fprintf(stderr,
208
	(void)fprintf(stderr,
205
	    "usage: script [-a] [-q] [-k] [-t time] [file] [command]\n");
209
	    "usage: script [-a] [-A] [-q] [-k] [-t time] [file] [command]\n");
206
	exit(1);
210
	exit(1);
207
}
211
}
208
212
Lines 232-238 Link Here
232
doshell(av)
236
doshell(av)
233
	char **av;
237
	char **av;
234
{
238
{
235
	char *shell;
239
	const char *shell;
236
240
237
	shell = getenv("SHELL");
241
	shell = getenv("SHELL");
238
	if (shell == NULL)
242
	if (shell == NULL)
Lines 273-276 Link Here
273
	(void)fclose(fscript);
277
	(void)fclose(fscript);
274
	(void)close(master);
278
	(void)close(master);
275
	exit(eno);
279
	exit(eno);
280
}
281
282
void
283
log_write(const char *buf, int size)
284
{
285
	int off, i;
286
287
	if (!Aflg) {
288
		(void)fwrite(buf, 1, size, fscript);
289
		return;
290
	}
291
	off = 0;
292
	do {
293
		i = 0;
294
		while ((off + i < size) && (buf[off + i] != '\r'))
295
			i++;
296
		if (i > 0)
297
			(void)fwrite(buf + off, 1, i, fscript);
298
		off += i + 1;
299
	} while (off < size);
276
}
300
}

Return to bug 31205