static char *sccsid
= "@(#)script.c 4.5 (Berkeley) 83/07/02";
char *fname
= "typescript";
char *line
= "/dev/ptyXX";
while (argc
> 0 && argv
[0][0] == '-') {
"usage: script [ -a ] [ typescript ]\n");
if ((fscript
= fopen(fname
, aflg
? "a" : "w")) == NULL
) {
printf("Script started, file is %s\n", fname
);
(void) signal(SIGCHLD
, finish
);
while ((cc
= read(0, ibuf
, BUFSIZ
)) > 0)
(void) write(master
, ibuf
, cc
);
if (wait3(&status
, WNOHANG
, 0) != child
)
tvec
= time((time_t *)0);
fprintf(fscript
, "Script started on %s", ctime(&tvec
));
cc
= read(master
, obuf
, sizeof (obuf
));
(void) write(1, obuf
, cc
);
(void) fwrite(obuf
, 1, cc
, fscript
);
tvec
= time((time_t *)0);
fprintf(fscript
,"\nscript done on %s", ctime(&tvec
));
ioctl(t
, TIOCNOTTY
, (char *)0);
execl(shell
, "sh", "-i", 0);
ioctl(0, TIOCSETP
, (char *)&sbuf
);
ioctl(0, TIOCSETP
, (char *)&b
);
printf("Script done, file is %s\n", fname
);
for (c
= 'p'; c
<= 's'; c
++) {
line
[strlen("/dev/pty")] = c
;
line
[strlen("/dev/ptyp")] = '0';
if (stat(line
, &stb
) < 0)
for (i
= 0; i
< 16; i
++) {
line
[strlen("/dev/ptyp")] = "0123456789abcdef"[i
];
ioctl(0, TIOCGETP
, (char *)&b
);
ioctl(0, TIOCGETC
, (char *)&tc
);
ioctl(0, TIOCGETD
, (char *)&l
);
ioctl(0, TIOCGLTC
, (char *)&lc
);
ioctl(0, TIOCLGET
, (char *)&lb
);
fprintf(stderr
, "Out of pty's\n");
line
[strlen("/dev/")] = 't';
ioctl(slave
, TIOCSETP
, (char *)&b
);
ioctl(slave
, TIOCSETC
, (char *)&tc
);
ioctl(slave
, TIOCSLTC
, (char *)&lc
);
ioctl(slave
, TIOCLSET
, (char *)&lb
);
ioctl(slave
, TIOCSETD
, (char *)&l
);