Commit | Line | Data |
---|---|---|
051b1e55 | 1 | /* |
c9686c12 KB |
2 | * Copyright (c) 1983 The Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that the above copyright notice and this paragraph are | |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
051b1e55 DF |
16 | */ |
17 | ||
05862919 | 18 | #ifndef lint |
c9686c12 KB |
19 | static char sccsid[] = "@(#)tipout.c 5.2 (Berkeley) %G%"; |
20 | #endif /* not lint */ | |
05862919 | 21 | |
eed8c72e BJ |
22 | #include "tip.h" |
23 | /* | |
24 | * tip | |
25 | * | |
26 | * lower fork of tip -- handles passive side | |
27 | * reading from the remote host | |
28 | */ | |
29 | ||
05862919 | 30 | static jmp_buf sigbuf; |
6b46907f | 31 | |
eed8c72e BJ |
32 | /* |
33 | * TIPOUT wait state routine -- | |
34 | * sent by TIPIN when it wants to posses the remote host | |
35 | */ | |
36 | intIOT() | |
37 | { | |
05862919 | 38 | |
eed8c72e BJ |
39 | write(repdes[1],&ccc,1); |
40 | read(fildes[0], &ccc,1); | |
05862919 | 41 | longjmp(sigbuf, 1); |
eed8c72e BJ |
42 | } |
43 | ||
44 | /* | |
45 | * Scripting command interpreter -- | |
46 | * accepts script file name over the pipe and acts accordingly | |
47 | */ | |
48 | intEMT() | |
49 | { | |
50 | char c, line[256]; | |
51 | register char *pline = line; | |
52 | char reply; | |
53 | ||
eed8c72e | 54 | read(fildes[0], &c, 1); |
3f48242d | 55 | while (c != '\n') { |
eed8c72e BJ |
56 | *pline++ = c; |
57 | read(fildes[0], &c, 1); | |
58 | } | |
59 | *pline = '\0'; | |
60 | if (boolean(value(SCRIPT)) && fscript != NULL) | |
61 | fclose(fscript); | |
62 | if (pline == line) { | |
63 | boolean(value(SCRIPT)) = FALSE; | |
64 | reply = 'y'; | |
65 | } else { | |
66 | if ((fscript = fopen(line, "a")) == NULL) | |
67 | reply = 'n'; | |
68 | else { | |
69 | reply = 'y'; | |
70 | boolean(value(SCRIPT)) = TRUE; | |
71 | } | |
72 | } | |
73 | write(repdes[1], &reply, 1); | |
05862919 | 74 | longjmp(sigbuf, 1); |
eed8c72e BJ |
75 | } |
76 | ||
77 | intTERM() | |
78 | { | |
05862919 | 79 | |
eed8c72e BJ |
80 | if (boolean(value(SCRIPT)) && fscript != NULL) |
81 | fclose(fscript); | |
82 | exit(0); | |
83 | } | |
84 | ||
85 | intSYS() | |
86 | { | |
05862919 | 87 | |
eed8c72e | 88 | boolean(value(BEAUTIFY)) = !boolean(value(BEAUTIFY)); |
05862919 | 89 | longjmp(sigbuf, 1); |
eed8c72e BJ |
90 | } |
91 | ||
92 | /* | |
93 | * ****TIPOUT TIPOUT**** | |
94 | */ | |
95 | tipout() | |
96 | { | |
c731dacc BS |
97 | char buf[BUFSIZ]; |
98 | register char *cp; | |
99 | register int cnt; | |
e2326c44 | 100 | extern int errno; |
05862919 | 101 | int omask; |
c731dacc | 102 | |
eed8c72e BJ |
103 | signal(SIGINT, SIG_IGN); |
104 | signal(SIGQUIT, SIG_IGN); | |
105 | signal(SIGEMT, intEMT); /* attention from TIPIN */ | |
106 | signal(SIGTERM, intTERM); /* time to go signal */ | |
107 | signal(SIGIOT, intIOT); /* scripting going on signal */ | |
108 | signal(SIGHUP, intTERM); /* for dial-ups */ | |
109 | signal(SIGSYS, intSYS); /* beautify toggle */ | |
05862919 SL |
110 | (void) setjmp(sigbuf); |
111 | for (omask = 0;; sigsetmask(omask)) { | |
112 | cnt = read(FD, buf, BUFSIZ); | |
e2326c44 SL |
113 | if (cnt <= 0) { |
114 | /* lost carrier */ | |
115 | if (cnt < 0 && errno == EIO) { | |
1722c749 | 116 | sigblock(sigmask(SIGTERM)); |
e2326c44 SL |
117 | intTERM(); |
118 | /*NOTREACHED*/ | |
119 | } | |
120 | continue; | |
121 | } | |
1722c749 | 122 | #define ALLSIGS sigmask(SIGEMT)|sigmask(SIGTERM)|sigmask(SIGIOT)|sigmask(SIGSYS) |
05862919 | 123 | omask = sigblock(ALLSIGS); |
c731dacc BS |
124 | for (cp = buf; cp < buf + cnt; cp++) |
125 | *cp &= 0177; | |
126 | write(1, buf, cnt); | |
eed8c72e | 127 | if (boolean(value(SCRIPT)) && fscript != NULL) { |
c731dacc | 128 | if (!boolean(value(BEAUTIFY))) { |
3463e9c6 | 129 | fwrite(buf, 1, cnt, fscript); |
c731dacc BS |
130 | continue; |
131 | } | |
05862919 SL |
132 | for (cp = buf; cp < buf + cnt; cp++) |
133 | if ((*cp >= ' ' && *cp <= '~') || | |
134 | any(*cp, value(EXCEPTIONS))) | |
135 | putc(*cp, fscript); | |
eed8c72e BJ |
136 | } |
137 | } | |
138 | } |