|
|
1.1 root 1: /*
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: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: static char sccsid[] = "@(#)tipout.c 5.3 (Berkeley) 6/1/90";
22: #endif /* not lint */
23:
24: #include "tip.h"
25: /*
26: * tip
27: *
28: * lower fork of tip -- handles passive side
29: * reading from the remote host
30: */
31:
32: static jmp_buf sigbuf;
33:
34: /*
35: * TIPOUT wait state routine --
36: * sent by TIPIN when it wants to posses the remote host
37: */
38: intIOT()
39: {
40:
41: write(repdes[1],&ccc,1);
42: read(fildes[0], &ccc,1);
43: longjmp(sigbuf, 1);
44: }
45:
46: /*
47: * Scripting command interpreter --
48: * accepts script file name over the pipe and acts accordingly
49: */
50: intEMT()
51: {
52: char c, line[256];
53: register char *pline = line;
54: char reply;
55:
56: read(fildes[0], &c, 1);
57: while (c != '\n') {
58: *pline++ = c;
59: read(fildes[0], &c, 1);
60: }
61: *pline = '\0';
62: if (boolean(value(SCRIPT)) && fscript != NULL)
63: fclose(fscript);
64: if (pline == line) {
65: boolean(value(SCRIPT)) = FALSE;
66: reply = 'y';
67: } else {
68: if ((fscript = fopen(line, "a")) == NULL)
69: reply = 'n';
70: else {
71: reply = 'y';
72: boolean(value(SCRIPT)) = TRUE;
73: }
74: }
75: write(repdes[1], &reply, 1);
76: longjmp(sigbuf, 1);
77: }
78:
79: intTERM()
80: {
81:
82: if (boolean(value(SCRIPT)) && fscript != NULL)
83: fclose(fscript);
84: exit(0);
85: }
86:
87: intSYS()
88: {
89:
90: boolean(value(BEAUTIFY)) = !boolean(value(BEAUTIFY));
91: longjmp(sigbuf, 1);
92: }
93:
94: /*
95: * ****TIPOUT TIPOUT****
96: */
97: tipout()
98: {
99: char buf[BUFSIZ];
100: register char *cp;
101: register int cnt;
102: extern int errno;
103: int omask;
104:
105: signal(SIGINT, SIG_IGN);
106: signal(SIGQUIT, SIG_IGN);
107: signal(SIGEMT, intEMT); /* attention from TIPIN */
108: signal(SIGTERM, intTERM); /* time to go signal */
109: signal(SIGIOT, intIOT); /* scripting going on signal */
110: signal(SIGHUP, intTERM); /* for dial-ups */
111: signal(SIGSYS, intSYS); /* beautify toggle */
112: (void) setjmp(sigbuf);
113: for (omask = 0;; sigsetmask(omask)) {
114: cnt = read(FD, buf, BUFSIZ);
115: if (cnt <= 0) {
116: /* lost carrier */
117: if (cnt < 0 && errno == EIO) {
118: sigblock(sigmask(SIGTERM));
119: intTERM();
120: /*NOTREACHED*/
121: }
122: continue;
123: }
124: #define ALLSIGS sigmask(SIGEMT)|sigmask(SIGTERM)|sigmask(SIGIOT)|sigmask(SIGSYS)
125: omask = sigblock(ALLSIGS);
126: for (cp = buf; cp < buf + cnt; cp++)
127: *cp &= 0177;
128: write(1, buf, cnt);
129: if (boolean(value(SCRIPT)) && fscript != NULL) {
130: if (!boolean(value(BEAUTIFY))) {
131: fwrite(buf, 1, cnt, fscript);
132: continue;
133: }
134: for (cp = buf; cp < buf + cnt; cp++)
135: if ((*cp >= ' ' && *cp <= '~') ||
136: any(*cp, value(EXCEPTIONS)))
137: putc(*cp, fscript);
138: }
139: }
140: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.