reformatting
[unix-history] / usr / src / usr.bin / tip / tipout.c
CommitLineData
3f48242d 1/* tipout.c 4.4 81/11/29 */
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));
70}
71
72/*
73 * ****TIPOUT TIPOUT****
74 */
75tipout()
76{
77 signal(SIGINT, SIG_IGN);
78 signal(SIGQUIT, SIG_IGN);
79 signal(SIGEMT, intEMT); /* attention from TIPIN */
80 signal(SIGTERM, intTERM); /* time to go signal */
81 signal(SIGIOT, intIOT); /* scripting going on signal */
82 signal(SIGHUP, intTERM); /* for dial-ups */
83 signal(SIGSYS, intSYS); /* beautify toggle */
84
3f48242d 85 while (1) {
eed8c72e
BJ
86 do {
87 intflag = 0;
88 read(FD,&ch,1);
89 ch &= 0177;
3f48242d 90 } while (intflag);
eed8c72e
BJ
91 write(1, &ch, 1);
92 if (boolean(value(SCRIPT)) && fscript != NULL) {
93 if (boolean(value(BEAUTIFY)) && ch < 040 &&
94 !any(ch, value(EXCEPTIONS)))
95 continue;
96 putc(ch, fscript);
97 }
98 }
99}