date and time created 83/02/24 12:55:54 by mckusick
[unix-history] / usr / src / usr.bin / tip / tipout.c
CommitLineData
3463e9c6 1/* tipout.c 4.6 82/01/06 */
eed8c72e
BJ
2#include "tip.h"
3/*
4 * tip
5 *
6 * lower fork of tip -- handles passive side
7 * reading from the remote host
8 */
9
10/*
11 * TIPOUT wait state routine --
12 * sent by TIPIN when it wants to posses the remote host
13 */
14intIOT()
15{
16 signal(SIGIOT, SIG_IGN);
17 write(repdes[1],&ccc,1);
18 read(fildes[0], &ccc,1);
19 signal(SIGIOT, intIOT);
20 intflag = 1;
21}
22
23/*
24 * Scripting command interpreter --
25 * accepts script file name over the pipe and acts accordingly
26 */
27intEMT()
28{
29 char c, line[256];
30 register char *pline = line;
31 char reply;
32
33 signal(SIGEMT, SIG_IGN);
34 read(fildes[0], &c, 1);
3f48242d 35 while (c != '\n') {
eed8c72e
BJ
36 *pline++ = c;
37 read(fildes[0], &c, 1);
38 }
39 *pline = '\0';
40 if (boolean(value(SCRIPT)) && fscript != NULL)
41 fclose(fscript);
42 if (pline == line) {
43 boolean(value(SCRIPT)) = FALSE;
44 reply = 'y';
45 } else {
46 if ((fscript = fopen(line, "a")) == NULL)
47 reply = 'n';
48 else {
49 reply = 'y';
50 boolean(value(SCRIPT)) = TRUE;
51 }
52 }
53 write(repdes[1], &reply, 1);
54 signal(SIGEMT, intEMT);
55 intflag = 1;
56}
57
58intTERM()
59{
60 signal(SIGTERM, SIG_IGN);
61 if (boolean(value(SCRIPT)) && fscript != NULL)
62 fclose(fscript);
63 exit(0);
64}
65
66intSYS()
67{
68 signal(SIGSYS, intSYS);
69 boolean(value(BEAUTIFY)) = !boolean(value(BEAUTIFY));
c731dacc 70 intflag = 1;
eed8c72e
BJ
71}
72
73/*
74 * ****TIPOUT TIPOUT****
75 */
76tipout()
77{
c731dacc
BS
78 char buf[BUFSIZ];
79 register char *cp;
80 register int cnt;
81
eed8c72e
BJ
82 signal(SIGINT, SIG_IGN);
83 signal(SIGQUIT, SIG_IGN);
84 signal(SIGEMT, intEMT); /* attention from TIPIN */
85 signal(SIGTERM, intTERM); /* time to go signal */
86 signal(SIGIOT, intIOT); /* scripting going on signal */
87 signal(SIGHUP, intTERM); /* for dial-ups */
88 signal(SIGSYS, intSYS); /* beautify toggle */
89
c731dacc 90 for (;;) {
eed8c72e
BJ
91 do {
92 intflag = 0;
c731dacc 93 cnt = read(FD, buf, BUFSIZ);
3f48242d 94 } while (intflag);
c731dacc
BS
95 if (cnt <= 0)
96 continue;
97 for (cp = buf; cp < buf + cnt; cp++)
98 *cp &= 0177;
99 write(1, buf, cnt);
eed8c72e 100 if (boolean(value(SCRIPT)) && fscript != NULL) {
c731dacc 101 if (!boolean(value(BEAUTIFY))) {
3463e9c6 102 fwrite(buf, 1, cnt, fscript);
c731dacc
BS
103 continue;
104 }
105 for (cp = buf; cp < buf + cnt; cp++) {
106 if (*cp < ' ' && !any(*cp, value(EXCEPTIONS)))
eed8c72e 107 continue;
c731dacc
BS
108 putc(*cp, fscript);
109 }
eed8c72e
BJ
110 }
111 }
112}