|
|
1.1 root 1: /* %W%
2: */
3: #include "uucp.h"
4: VERSION(%W%);
5:
6: #ifdef V8
7: #include <sys/ttyio.h>
8: #else
9: #include <sgtty.h>
10: #endif
11:
12: static struct sg_spds {
13: int sp_val,
14: sp_name;
15: } spds[] = {
16: { 300, B300},
17: { 600, B600},
18: {1200, B1200},
19: {2400, B2400},
20: {4800, B4800},
21: {9600, B9600},
22: #ifdef EXTA
23: {19200, EXTA},
24: #endif
25: #ifdef B19200
26: {19200, B19200},
27: #endif
28: #ifdef B38400
29: {38400, B38400},
30: #endif
31: {0, 0}
32: };
33:
34: #define PACKSIZE 64
35: #define HEADERSIZE 6
36: #define SNDFILE 'S'
37: #define RCVFILE 'R'
38: #define RESET 'X'
39:
40: int linebaudrate = 0; /* for speedup hook in pk (unused in ATTSV) */
41:
42: #ifdef ATTSV
43:
44: static struct termio Savettyb;
45: /*
46: * set speed/echo/mode...
47: * tty -> terminal name
48: * spwant -> speed
49: * type -> type
50: *
51: * if spwant == 0, speed is untouched
52: * type is unused, but needed for compatibility
53: *
54: * return:
55: * none
56: */
57: fixline(tty, spwant, type)
58: int tty, spwant, type;
59: {
60: register struct sg_spds *ps;
61: struct termio ttbuf;
62: int speed = -1;
63:
64: DEBUG(6, "fixline(%d, ", tty);
65: DEBUG(6, "%d)\n", spwant);
66: if (ioctl(tty, TCGETA, &ttbuf) != 0)
67: return;
68: if (spwant > 0) {
69: for (ps = spds; ps->sp_val; ps++)
70: if (ps->sp_val == spwant) {
71: speed = ps->sp_name;
72: break;
73: }
74: ASSERT(speed >= 0, "BAD SPEED", "", speed);
75: ttbuf.c_cflag = speed;
76: } else
77: ttbuf.c_cflag &= CBAUD;
78: ttbuf.c_iflag = ttbuf.c_oflag = ttbuf.c_lflag = (ushort)0;
79:
80: #ifdef NO_MODEM_CTRL
81: /* CLOCAL may cause problems on pdp11s with DHs */
82: if (type == D_DIRECT) {
83: DEBUG(4, "fixline - direct\n", "");
84: ttbuf.c_cflag |= CLOCAL;
85: } else
86: #endif NO_MODEM_CTRL
87:
88: ttbuf.c_cflag &= ~CLOCAL;
89: ttbuf.c_cflag |= (CS8 | CREAD | (speed ? HUPCL : 0));
90: ttbuf.c_cc[VMIN] = HEADERSIZE;
91: ttbuf.c_cc[VTIME] = 1;
92:
93: ASSERT(ioctl(tty, TCSETA, &ttbuf) >= 0,
94: "RETURN FROM fixline ioctl", "", errno);
95: return;
96: }
97:
98: sethup(dcf)
99: int dcf;
100: {
101: struct termio ttbuf;
102:
103: if (ioctl(dcf, TCGETA, &ttbuf) != 0)
104: return;
105: if (!(ttbuf.c_cflag & HUPCL)) {
106: ttbuf.c_cflag |= HUPCL;
107: (void) ioctl(dcf, TCSETA, &ttbuf);
108: }
109: }
110:
111: genbrk(fn)
112: register int fn;
113: {
114: if (isatty(fn))
115: (void) ioctl(fn, TCSBRK, 0);
116: }
117:
118:
119: /*
120: * optimize line setting for sending or receiving files
121: * return:
122: * none
123: */
124: setline(type)
125: register char type;
126: {
127: static struct termio tbuf;
128:
129: if (ioctl(Ifn, TCGETA, &tbuf) != 0)
130: return;
131: DEBUG(2, "setline - %c\n", type);
132: switch (type) {
133: case RCVFILE:
134: if (tbuf.c_cc[VMIN] != PACKSIZE) {
135: tbuf.c_cc[VMIN] = PACKSIZE;
136: (void) ioctl(Ifn, TCSETAW, &tbuf);
137: }
138: break;
139:
140: case SNDFILE:
141: case RESET:
142: if (tbuf.c_cc[VMIN] != HEADERSIZE) {
143: tbuf.c_cc[VMIN] = HEADERSIZE;
144: (void) ioctl(Ifn, TCSETAW, &tbuf);
145: }
146: break;
147: }
148: }
149:
150: savline()
151: {
152: int ret;
153:
154: ret = ioctl(0, TCGETA, &Savettyb);
155: Savettyb.c_cflag = (Savettyb.c_cflag & ~CS8) | CS7;
156: Savettyb.c_oflag |= OPOST;
157: Savettyb.c_lflag |= (ISIG|ICANON|ECHO);
158: return(ret);
159: }
160:
161: /***
162: * sytfixline(tty, spwant) set speed/echo/mode...
163: * int tty, spwant;
164: *
165: * return codes: none
166: */
167:
168: sytfixline(tty, spwant)
169: int tty, spwant;
170: {
171: struct termio ttbuf;
172: struct sg_spds *ps;
173: int speed = -1;
174: int ret;
175:
176: for (ps = spds; ps->sp_val >= 0; ps++)
177: if (ps->sp_val == spwant)
178: speed = ps->sp_name;
179: DEBUG(4, "sytfixline - speed= %d\n", speed);
180: ASSERT(speed >= 0, "BAD SPEED", "", speed);
181: (void) ioctl(tty, TCGETA, &ttbuf);
182: ttbuf.c_iflag = (ushort)0;
183: ttbuf.c_oflag = (ushort)0;
184: ttbuf.c_lflag = (ushort)0;
185: ttbuf.c_cflag = speed;
186: ttbuf.c_cflag |= (CS8|CLOCAL);
187: ttbuf.c_cc[VMIN] = 6;
188: ttbuf.c_cc[VTIME] = 1;
189: ret = ioctl(tty, TCSETAW, &ttbuf);
190: ASSERT(ret >= 0, "RETURN FROM sytfixline", "", ret);
191: return;
192: }
193:
194: sytfix2line(tty)
195: int tty;
196: {
197: struct termio ttbuf;
198: int ret;
199:
200: (void) ioctl(tty, TCGETA, &ttbuf);
201: ttbuf.c_cflag &= ~CLOCAL;
202: ttbuf.c_cflag |= CREAD|HUPCL;
203: ret = ioctl(tty, TCSETAW, &ttbuf);
204: ASSERT(ret >= 0, "RETURN FROM sytfix2line", "", ret);
205: return;
206: }
207:
208:
209: restline()
210: {
211: return(ioctl(0, TCSETA, &Savettyb));
212: }
213:
214: #else
215:
216: static struct sgttyb Savettyb;
217: #ifdef V8
218: static struct ttydevb Savedevb;
219: #endif
220:
221: /***
222: * fixline(tty, spwant, type) set speed/echo/mode...
223: * int tty, spwant;
224: *
225: * if spwant == 0, speed is untouched
226: * type is unused, but needed for compatibility
227: *
228: * return codes: none
229: */
230:
231: /*ARGSUSED*/
232: fixline(tty, spwant, type)
233: int tty, spwant, type;
234: {
235: struct sgttyb ttbuf;
236: #ifdef V8
237: struct ttydevb dvbuf;
238: #endif
239: struct sg_spds *ps;
240: int speed = -1;
241:
242: DEBUG(6, "fixline(%d, ", tty);
243: DEBUG(6, "%d)\n", spwant);
244:
245: ioctl(tty, TIOCGETP, &ttbuf);
246: #ifdef V8
247: if (ioctl(tty, TIOCGDEV, &dvbuf) < 0) {
248: dvbuf.ospeed = ttbuf.sg_ospeed;
249: dvbuf.ispeed = ttbuf.sg_ispeed;
250: }
251: #endif
252: if (spwant > 0) {
253: for (ps = spds; ps->sp_val; ps++)
254: if (ps->sp_val == spwant) {
255: speed = ps->sp_name;
256: break;
257: }
258: ASSERT(speed >= 0, "BAD SPEED", "", speed);
259: #ifdef V8
260: dvbuf.ispeed = dvbuf.ospeed = speed;
261: #endif
262: ttbuf.sg_ispeed = ttbuf.sg_ospeed = speed;
263: } else {
264: for (ps = spds; ps->sp_val; ps++)
265: if (ps->sp_name == dvbuf.ispeed) {
266: spwant = ps->sp_val;
267: break;
268: }
269: ASSERT(spwant >= 0, "BAD SPEED", "", spwant);
270: }
271: ttbuf.sg_flags &=~ ECHO;
272: ttbuf.sg_flags |= RAW|ANYP;
273: (void) ioctl(tty, TIOCSETP, &ttbuf);
274: #ifdef V8
275: dvbuf.flags |= F8BIT;
276: (void) ioctl(tty, TIOCSDEV, &dvbuf);
277: #endif
278: (void) ioctl(tty, TIOCHPCL, STBNULL);
279: (void) ioctl(tty, TIOCEXCL, STBNULL);
280: linebaudrate = spwant; /* for hacks in pk driver */
281: return;
282: }
283:
284: sethup(dcf)
285: int dcf;
286: {
287: if (isatty(dcf))
288: (void) ioctl(dcf, TIOCHPCL, STBNULL);
289: }
290:
291: /***
292: * genbrk send a break
293: *
294: * return codes; none
295: */
296:
297: genbrk(fn)
298: {
299: (void) ioctl(fn, TIOCSBRK, 0);
300: #ifndef V8
301: nap(HZ/10); /* 0.1 second break */
302: (void) ioctl(fn, TIOCCBRK, 0);
303: #endif
304: }
305:
306: /*
307: * V7 and RT aren't smart enough for this -- linebaudrate is the best
308: * they can do.
309: */
310: /*ARGSUSED*/
311: setline(dummy) { }
312:
313: savline()
314: {
315: int ret;
316:
317: ret = ioctl(0, TIOCGETP, &Savettyb);
318: Savettyb.sg_flags |= ECHO;
319: Savettyb.sg_flags &= ~RAW;
320: #ifdef V8
321: ioctl(0, TIOCGDEV, &Savedevb);
322: #endif
323: return(ret);
324: }
325:
326: restline()
327: {
328: if (ioctl(0, TIOCSETP, &Savettyb) < 0)
329: return (-1);
330: #ifdef V8
331: if (ioctl(0, TIOCSDEV, &Savedevb) < 0)
332: return (-1);
333: #endif
334: return (0);
335: }
336: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.