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