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